diff --git a/plugins/romanah/gokbakja/components/OrderItem.php b/plugins/romanah/gokbakja/components/OrderItem.php index 82db5d7..0673b38 100644 --- a/plugins/romanah/gokbakja/components/OrderItem.php +++ b/plugins/romanah/gokbakja/components/OrderItem.php @@ -12,6 +12,9 @@ use Carbon\Carbon; use Flash; use DB; use October\Rain\Support\Facades\Flash as FacadesFlash; +use Romanah\Gokbakja\Models\BagAction; +use Romanah\Gokbakja\Models\RulonAction; +use Romanah\Gokbakja\Models\Stock; class OrderItem extends ComponentBase { @@ -43,61 +46,72 @@ class OrderItem extends ComponentBase $notCompleteCalc = 0; if ($orderItems[$x]->order_item_type == 'rulon'){ + $stock = Stock::where("type", 'rulon')->first(); - $machineProductionsFiltered = ProductionMachineModel::where("type_id", $orderItems[$x]->type_id) - ->where("size_id", $orderItems[$x]->size_id) - ->where("color_id", $orderItems[$x]->color_id) - ->withCount([ - 'pivot_sewer AS leftSum' => function ($query) { - $query->select(DB::raw("(amount - SUM(spent_amount)) as leftSum"))->where('status', 'complated'); - } - ]) - ->withCount([ - 'pivot_sewer AS spentSum' => function ($query) { - $query->select(DB::raw("(SUM(spent_amount)) as spentSum"))->where('status', 'complated'); - } - ]) - ->get(); + $bag_type = $orderItems[$x]->type_id; + $bag_size = $orderItems[$x]->size_id; + $color = $orderItems[$x]->color_id; + $amountCalc = $orderItems[$x]->amount; - if($machineProductionsFiltered != null){ - for ($i = 0; $i < count($machineProductionsFiltered); $i++) { + $rulonCalc = RulonAction::with('product') + ->whereHas('product', function($q)use($bag_type, $bag_size, $color){ + $q->where('type_id', $bag_type) + ->where('size_id', $bag_size) + ->where('color_id', $color); + }) + ->where("stock_id", $stock->id) + ->where("status_accountant", "accept") + ->where("status_director", "accept") + ->sum('amount'); - $left = ($machineProductionsFiltered[$i]->produced_weight - $machineProductionsFiltered[$i]->spentSum); - $stockCalc += $left; - } + $stockCalc = $rulonCalc; - if($stockCalc > $orderItems[$x]->amount){ - $notCompleteCalc = 'artykmaç'; - }else{ - $notCompleteCalc = number_format(($orderItems[$x]->amount - $stockCalc),2).' kg'; - } - }else{ - $stockCalc = 0; - } - // $stockCalc = number_format(($sumOfProduced - $prodMachine[0]->spentSum),2); - - }else{ - $colorId = $orderItems[$x]->color_id; - $bag_gram = $orderItems[$x]->bag_gram; - - $sewerProductions = SewerModel::where("width", $orderItems[$x]->bag_width) - ->where("height", $orderItems[$x]->bag_height) - ->with("machin_production") - ->whereHas('machin_production', function ($query) use($colorId) { - $query->where('color_id', $colorId); - }) - ->whereHas('pivot_sewer', function ($query) use($bag_gram) { - $query->where('bag_gram', $bag_gram); - }) - ->sum("produced_bag_qty"); - $stockCalc= $sewerProductions; - - if($stockCalc > $orderItems[$x]->amount){ + if($stockCalc > 0){ $notCompleteCalc = 'artykmaç'; }else{ - $notCompleteCalc = number_format(($orderItems[$x]->amount - $stockCalc),2).' sany'; + $notCompleteCalc = $stockCalc - $amountCalc; } + + }else{ + + $stock = Stock::where("type", 'bag')->first(); + + $bag_type = $orderItems[$x]->type_id; + $bag_width = $orderItems[$x]->bag_width; + $bag_height = $orderItems[$x]->bag_height; + $color = $orderItems[$x]->color_id; + $bag_gram = $orderItems[$x]->bag_gram; + $amountCalc = $orderItems[$x]->amount; + + $bagCalc = BagAction::with('product.rulon_action.product') + ->whereHas('product.rulon_action.product', function($q)use($bag_type, $color){ + $q->where('type_id', $bag_type) + ->where('color_id', $color); + }) + ->with('product.pivot_sewer') + ->whereHas('product.pivot_sewer', function($qq)use($bag_gram){ + $qq->where('bag_gram', $bag_gram); + }) + ->with('product') + ->whereHas('product', function($qqq)use($bag_width, $bag_height){ + $qqq->where('width', $bag_width)->where('height', $bag_height); + }) + ->where("stock_id", $stock->id) + ->where("status_accountant", "accept") + ->where("status_director", "accept") + ->sum('amount'); + + + $stockCalc = $bagCalc; + + if($stockCalc > 0){ + $notCompleteCalc = 'artykmaç'; + }else{ + $notCompleteCalc = $stockCalc - $amountCalc; + } + + } $editBtnPrice = ''; @@ -131,7 +145,7 @@ class OrderItem extends ComponentBase '; if ($orderItems[$x]->order_item_type == 'rulon'){ - $html_data .= 'Rulon, '.$orderItems[$x]->type->name ?? "" .','. $orderItems[$x]->color->name ?? ""; + $html_data .= 'Rulon, '.($orderItems[$x]->type->name ?? "") .','. ($orderItems[$x]->color->name ?? ""); }else{ $html_data .= 'Halta, '. ($orderItems[$x]->color->name ?? "") .', '. (number_format($orderItems[$x]->bag_gram ?? 0, 2)) .' gr'; } diff --git a/plugins/romanah/gokbakja/models/BagAction.php b/plugins/romanah/gokbakja/models/BagAction.php index 59cb598..50c7b16 100644 --- a/plugins/romanah/gokbakja/models/BagAction.php +++ b/plugins/romanah/gokbakja/models/BagAction.php @@ -15,7 +15,7 @@ class BagAction extends Model public $belongsTo = [ 'product' => [ - 'Romanah\Gokbakja\Models\Product', + 'Romanah\Gokbakja\Models\SewerProduction', 'key'=>'product_id' ], 'stock' => [ diff --git a/plugins/romanah/gokbakja/models/SewerProduction.php b/plugins/romanah/gokbakja/models/SewerProduction.php index 40708ea..386bf56 100644 --- a/plugins/romanah/gokbakja/models/SewerProduction.php +++ b/plugins/romanah/gokbakja/models/SewerProduction.php @@ -26,9 +26,9 @@ class SewerProduction extends Model 'Romanah\Gokbakja\Models\Employee', 'key' => 'employee_id' ], - 'machin_production' => [ - 'Romanah\Gokbakja\Models\ProductionMachine', - 'key' => 'machine_production_id' + 'rulon_action' => [ + 'Romanah\Gokbakja\Models\RulonAction', + 'key' => 'rulon_action_id' ], ]; diff --git a/themes/gokbakja/pages/orders/order-detail.htm b/themes/gokbakja/pages/orders/order-detail.htm index 9a792f8..64026e1 100644 --- a/themes/gokbakja/pages/orders/order-detail.htm +++ b/themes/gokbakja/pages/orders/order-detail.htm @@ -272,7 +272,6 @@ function onStart(){ $("#bag_height").show(); $("#bag_gram").show(); - $("#rulon_type").hide(); $("#rulon_size").hide(); } diff --git a/themes/gokbakja/pages/produced/bagstock.htm b/themes/gokbakja/pages/produced/bagstock.htm index 288818d..6169499 100644 --- a/themes/gokbakja/pages/produced/bagstock.htm +++ b/themes/gokbakja/pages/produced/bagstock.htm @@ -8,12 +8,13 @@ function onStart(){ $stockId = $this->param("stockId"); $this["actions"] = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') - ->with(['product']) + ->with(['product.rulon_action.product.bag_type', 'product.rulon_action.product.color', 'product.pivot_sewer']) ->where("stock_id", $stockId) ->where("status_accountant", "accept") ->where("status_director", "accept") ->addSelect(DB::raw("SUM(amount) as quantity")) ->groupBy('romanah_gokbakja_bag_actions.product_id') + ->orderBy('id', 'DESC') ->get(); // dd($this["actions"]); } @@ -53,6 +54,9 @@ function onStart(){ № Dikiş Kody + Halta Ölçegi + Halta Gramy + Ulanylan Material Hereket Mukdary (sany) Sene @@ -64,6 +68,10 @@ function onStart(){ {{key + 1}} #Dikiş{{record.product_id}} + ini: {{record.product.width}} x boýy: {{record.product.height}} + {{record.product.pivot_sewer[0].bag_gram|number_format}} gr + + #Rulon{{record.product.rulon_action.product.id}} - {{record.product.rulon_action.product.bag_type.name}}, {{record.product.rulon_action.product.color.name}} {{record.type}} {{record.quantity|number_format}} sany @@ -76,7 +84,10 @@ function onStart(){ № - Haryt Kody + Dikiş Kody + Halta Ölçegi + Halta Gramy + Ulanylan Material Hereket Mukdary (sany) Sene diff --git a/themes/gokbakja/pages/produced/rulonstock.htm b/themes/gokbakja/pages/produced/rulonstock.htm index 4ee95d7..90d81c8 100644 --- a/themes/gokbakja/pages/produced/rulonstock.htm +++ b/themes/gokbakja/pages/produced/rulonstock.htm @@ -16,6 +16,7 @@ function onStart(){ ->where("status_director", "accept") ->addSelect(DB::raw("SUM(amount) as quantity")) ->groupBy('romanah_gokbakja_rulon_action.product_id') + ->orderBy('id', 'DESC') ->get(); // dd($this["actions"]); }