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