2023-09-17 07:01:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Romanah\Gokbakja\Components;
|
|
|
|
|
|
|
|
|
|
use Cms\Classes\ComponentBase;
|
|
|
|
|
use Romanah\Gokbakja\Models\Action as ActionModel;
|
|
|
|
|
use Redirect;
|
|
|
|
|
use Flash;
|
|
|
|
|
|
|
|
|
|
class Action extends ComponentBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function componentDetails()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'name' => 'Action',
|
|
|
|
|
'description' => 'actions settings'
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function onCreateAction()
|
|
|
|
|
{
|
|
|
|
|
$user = \Auth::user();
|
|
|
|
|
|
|
|
|
|
$data = post();
|
|
|
|
|
$actionType = $this->param("type");
|
|
|
|
|
|
|
|
|
|
if ($actionType == 'inbox') {
|
|
|
|
|
|
|
|
|
|
$createResult = new ActionModel();
|
|
|
|
|
$createResult->product_id = $data["product_id"];
|
|
|
|
|
$createResult->type = 'inbox';
|
2023-09-17 19:12:00 +00:00
|
|
|
$createResult->status_accountant = "new";
|
|
|
|
|
$createResult->status_director = "new";
|
|
|
|
|
$createResult->transport_no = $data["transport_no"];
|
|
|
|
|
$createResult->driver = $data["driver"];
|
|
|
|
|
$createResult->note = $data["note"];
|
2023-09-17 07:01:15 +00:00
|
|
|
$createResult->amount = $data["quantity"];
|
|
|
|
|
$createResult->stock_id = $data["stock_id"];
|
|
|
|
|
$createResult->user_id = $user->id;
|
|
|
|
|
|
|
|
|
|
$createResult->save();
|
|
|
|
|
// $createResult = DollorModel::create([]);
|
|
|
|
|
|
|
|
|
|
// dd($data);
|
|
|
|
|
if ($createResult) {
|
|
|
|
|
Flash::success("Action Inbox Ustunlikli Goshuldy");
|
|
|
|
|
return Redirect::refresh();
|
|
|
|
|
}
|
|
|
|
|
} elseif ($actionType == 'outbox') {
|
|
|
|
|
$qty = ActionModel::where("product_id", $data["product_id"])
|
|
|
|
|
->where("stock_id", $data["stock_id"])
|
2023-10-11 22:11:21 +00:00
|
|
|
->where("status_accountant", "accept")
|
|
|
|
|
->where("status_director", "accept")
|
2023-09-17 07:01:15 +00:00
|
|
|
->sum("amount");
|
|
|
|
|
|
|
|
|
|
// $productOutbox = ActionModel::where("product_id", $data["product_id"])
|
|
|
|
|
// ->where("stock_id", $data["stock_id"])
|
|
|
|
|
// ->where("type", "outbox")
|
|
|
|
|
// ->sum("quantity");
|
|
|
|
|
|
|
|
|
|
// $productQuantity = $productInbox - $productOutbox;
|
|
|
|
|
// dump($productQuantity);
|
|
|
|
|
if ($qty >= $data["quantity"]) {
|
|
|
|
|
$createResult = new ActionModel();
|
|
|
|
|
$createResult->product_id = $data["product_id"];
|
|
|
|
|
$createResult->type = 'outbox';
|
2023-10-11 22:11:21 +00:00
|
|
|
$createResult->amount = -$data["quantity"];
|
2023-09-17 07:01:15 +00:00
|
|
|
$createResult->stock_id = $data["stock_id"];
|
|
|
|
|
$createResult->user_id = $user->id;
|
|
|
|
|
|
|
|
|
|
$createResult->save();
|
|
|
|
|
// $createResult = DollorModel::create([]);
|
|
|
|
|
|
|
|
|
|
// dd($data);
|
|
|
|
|
if ($createResult) {
|
2023-10-11 22:11:21 +00:00
|
|
|
Flash::success("Harytlar sklatdan ustunlikli chykaryldy");
|
2023-09-17 07:01:15 +00:00
|
|
|
return Redirect::refresh();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2023-10-11 22:11:21 +00:00
|
|
|
Flash::error("Bu mukdarda haryt ýok");
|
2023-09-17 07:01:15 +00:00
|
|
|
return Redirect::refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onUpdateAction()
|
|
|
|
|
{
|
|
|
|
|
$user = \Auth::user();
|
|
|
|
|
$data = post();
|
|
|
|
|
|
|
|
|
|
$updateResult = ActionModel::where('id', $data["id"])
|
|
|
|
|
->update(array(
|
|
|
|
|
'product_id' => $data["product_id"],
|
|
|
|
|
'amount' => $data["quantity"],
|
|
|
|
|
'stock_id' => $data["stock_id"],
|
2023-09-17 19:12:00 +00:00
|
|
|
'note' => $data["note"],
|
|
|
|
|
'transport_no' => $data["transport_no"],
|
|
|
|
|
'driver' => $data["driver"],
|
2023-09-17 07:01:15 +00:00
|
|
|
'user_id' => $user->id,
|
|
|
|
|
));
|
|
|
|
|
// $createResult = DollorModel::create([]);
|
|
|
|
|
|
|
|
|
|
// dd($data);
|
|
|
|
|
if ($updateResult) {
|
|
|
|
|
Flash::success("Action Ustunlikli Uytgedildi");
|
|
|
|
|
return Redirect::refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function onGetAction()
|
|
|
|
|
{
|
|
|
|
|
$id = post('id');
|
|
|
|
|
return ActionModel::where('id', $id)->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onDeleteAction()
|
|
|
|
|
{
|
|
|
|
|
$id = post('id');
|
|
|
|
|
|
|
|
|
|
$item = ActionModel::Find($id);
|
|
|
|
|
$item->delete();
|
|
|
|
|
|
|
|
|
|
if ($item) {
|
|
|
|
|
Flash::success("Action Ustunlikli Pozuldy");
|
|
|
|
|
return Redirect::refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function onDeleteSellerAction()
|
|
|
|
|
// {
|
|
|
|
|
// $id = post('id');
|
|
|
|
|
|
|
|
|
|
// $item = SellerActionModel::Find($id);
|
|
|
|
|
// $item->delete();
|
|
|
|
|
|
|
|
|
|
// if ($item) {
|
|
|
|
|
// Flash::success("Action Ustunlikli Pozuldy");
|
|
|
|
|
// return Redirect::refresh();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public function onGetSellerAction()
|
|
|
|
|
// {
|
|
|
|
|
// $id = post('id');
|
|
|
|
|
// return SellerActionModel::where('id', $id)->first();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function onCreateSellerAction()
|
|
|
|
|
// {
|
|
|
|
|
// $user = \Auth::user();
|
|
|
|
|
|
|
|
|
|
// $data = post();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $qty = ActionModel::where("product_id", $data["product_id"])
|
|
|
|
|
// ->where("stock_id", $data["stock_id"])
|
|
|
|
|
// ->sum("quantity");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if ($qty >= $data["quantity"]) {
|
|
|
|
|
// $createResult = new ActionModel();
|
|
|
|
|
// $createResult->product_id = $data["product_id"];
|
|
|
|
|
// $createResult->type = 'outbox';
|
|
|
|
|
// $createResult->quantity = -$data["quantity"];
|
|
|
|
|
// $createResult->stock_id = $data["stock_id"];
|
|
|
|
|
// $createResult->user_id = $user->id;
|
|
|
|
|
|
|
|
|
|
// $createResult->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $createSellerResult = new SellerActionModel();
|
|
|
|
|
// $createSellerResult->seller_id = $data["seller_id"];
|
|
|
|
|
// $createSellerResult->product_id = $data["product_id"];
|
|
|
|
|
// $createSellerResult->quantity = $data["quantity"];
|
|
|
|
|
// $createSellerResult->stock_id = $data["stock_id"];
|
|
|
|
|
// $createSellerResult->user_id = $user->id;
|
|
|
|
|
|
|
|
|
|
// $createSellerResult->save();
|
|
|
|
|
// // $createResult = DollorModel::create([]);
|
|
|
|
|
|
|
|
|
|
// // dd($data);
|
|
|
|
|
// if ($createResult && $createSellerResult) {
|
|
|
|
|
// Flash::success("Action Outbox Ustunlikli Goshuldy");
|
|
|
|
|
// return Redirect::refresh();
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// Flash::error("Данного товара нет в наличии");
|
|
|
|
|
// return Redirect::refresh();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function onUpdateSellerAction()
|
|
|
|
|
// {
|
|
|
|
|
// $user = \Auth::user();
|
|
|
|
|
// $data = post();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $qty = ActionModel::where("product_id", $data["product_id"])
|
|
|
|
|
// ->where("stock_id", $data["stock_id"])
|
|
|
|
|
// ->sum("quantity");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if ($qty >= $data["quantity"]) {
|
|
|
|
|
|
|
|
|
|
// $updateResult = SellerActionModel::where('id', $data["id"])
|
|
|
|
|
// ->update(array(
|
|
|
|
|
// 'product_id' => $data["product_id"],
|
|
|
|
|
// 'quantity' => $data["quantity"],
|
|
|
|
|
// 'stock_id' => $data["stock_id"],
|
|
|
|
|
// 'user_id' => $user->id,
|
|
|
|
|
// ));
|
|
|
|
|
// // $createResult = DollorModel::create([]);
|
|
|
|
|
|
|
|
|
|
// // dd($data);
|
|
|
|
|
// if ($updateResult) {
|
|
|
|
|
// Flash::success("Action Ustunlikli Uytgedildi");
|
|
|
|
|
// return Redirect::refresh();
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// Flash::error("Данного товара нет в наличии");
|
|
|
|
|
// return Redirect::refresh();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|