235 lines
6.9 KiB
PHP
235 lines
6.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Romanah\Gokbakja\Components;
|
||
|
|
|
||
|
|
use Cms\Classes\ComponentBase;
|
||
|
|
use Romanah\Gokbakja\Models\BagAction as ActionModel;
|
||
|
|
use Redirect;
|
||
|
|
use Flash;
|
||
|
|
use Romanah\Gokbakja\Models\SewerProduction;
|
||
|
|
|
||
|
|
class BagAction extends ComponentBase
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
public function componentDetails()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name' => 'BagAction',
|
||
|
|
'description' => 'BagAction settings'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public function onCreateAction()
|
||
|
|
{
|
||
|
|
$user = \Auth::user();
|
||
|
|
|
||
|
|
$data = post();
|
||
|
|
$actionType = $data["type"];
|
||
|
|
$stock = Stock::where("type", 'bag')->first();
|
||
|
|
|
||
|
|
if ($actionType == 'inbox') {
|
||
|
|
|
||
|
|
$productionMachine = SewerProduction::where("id", $data["itemId"])->first();
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$createResult = new ActionModel();
|
||
|
|
$createResult->product_id = $data["itemId"];
|
||
|
|
$createResult->type = 'inbox';
|
||
|
|
$createResult->status_accountant = "new";
|
||
|
|
$createResult->status_director = "new";
|
||
|
|
$createResult->note = "";
|
||
|
|
$createResult->amount = $productionMachine->produced_bag_qty;
|
||
|
|
$createResult->stock_id = $stock->id;
|
||
|
|
$createResult->user_id = $user->id;
|
||
|
|
|
||
|
|
$createResult->save();
|
||
|
|
// $createResult = DollorModel::create([]);
|
||
|
|
|
||
|
|
// dd($data);
|
||
|
|
if ($createResult) {
|
||
|
|
Flash::success("Rulon Action Inbox Ustunlikli Goshuldy");
|
||
|
|
return Redirect::refresh();
|
||
|
|
}
|
||
|
|
} elseif ($actionType == 'outbox') {
|
||
|
|
$qty = ActionModel::where("product_id", $data["product_id"])
|
||
|
|
->where("stock_id", $stock->id)
|
||
|
|
->where("status_accountant", "accept")
|
||
|
|
->where("status_director", "accept")
|
||
|
|
->sum("produced_bag_qty");
|
||
|
|
|
||
|
|
// $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';
|
||
|
|
$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("Harytlar sklatdan ustunlikli chykaryldy");
|
||
|
|
return Redirect::refresh();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
Flash::error("Bu mukdarda haryt ýok");
|
||
|
|
return Redirect::refresh();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function onUpdateAction()
|
||
|
|
{
|
||
|
|
$user = \Auth::user();
|
||
|
|
$data = post();
|
||
|
|
|
||
|
|
$updateResult = ActionModel::where('id', $data["id"])
|
||
|
|
->update(array(
|
||
|
|
'note' => $data["note"],
|
||
|
|
'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();
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
}
|