title = "actions/bag-report" url = "/actions/bag-report/:month/:year?" layout = "platform_main" is_hidden = 0 == param("month"); $year = $this->param("year"); if($this["month"] == 'default'){ $this["month"] = $currentDate->month; } $reportDatas = []; //dd($reportDatas); if($year){ $bagProds = Romanah\Gokbakja\Models\SewerProduction::select('width', 'height', 'bag_gram', 'color_id') ->with('color') ->whereMonth('date', $this["month"]) ->whereYear('date', $year) ->groupBy('width') ->groupBy('height') ->groupBy('bag_gram') ->groupBy('color_id') ->orderBy('width', 'ASC') ->distinct() ->get(); for ($x = 0; $x < count($bagProds); $x++) { $action = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product') ->whereHas('product', function($qq) use($bagProds, $x, $year){ $qq->whereMonth('date', $this["month"])->whereYear('date', $year)->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->sum('amount'); $actionNow = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product') ->whereHas('product', function($qq) use($bagProds, $x, $year){ $qq->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->sum('amount'); $actionBraks = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product.color') ->whereHas('product', function($qq) use($bagProds, $x, $year){ $qq->whereMonth('date', $this["month"])->whereYear('date', $year)->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->get(); $calculateBrak = 0; $calculateBrakRepair = 0; for ($xx = 0; $xx < count($actionBraks); $xx++) { $calculateBrak += $actionBraks[$xx]->product->defective_bag_qty; $calculateBrakRepair += $actionBraks[$xx]->product->defective_repair_qty; } $reportDatas[$x]["width"] = $bagProds[$x]->width; $reportDatas[$x]["height"] = $bagProds[$x]->height; $reportDatas[$x]["color"] = $bagProds[$x]->color->name ?? ""; $reportDatas[$x]["bag_gram"] = $bagProds[$x]->bag_gram ?? 0; $reportDatas[$x]["amount"] = $action; $reportDatas[$x]["defective"] = $calculateBrak; $reportDatas[$x]["defectiveRepair"] = $calculateBrakRepair; $reportDatas[$x]["all"] = $action + $calculateBrakRepair + $calculateBrakRepair; $reportDatas[$x]["amountNow"] = $actionNow; } }else{ $bagProds = Romanah\Gokbakja\Models\SewerProduction::select('width', 'height', 'bag_gram', 'color_id') ->with('color') ->whereMonth('date', $this["month"]) ->whereYear('date', $currentDate->year) ->groupBy('width') ->groupBy('height') ->groupBy('bag_gram') ->groupBy('color_id') ->orderBy('width', 'ASC') ->distinct() ->get(); for ($x = 0; $x < count($bagProds); $x++) { $action = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product') ->whereHas('product', function($qq) use($bagProds, $x, $currentDate){ $qq->whereMonth('date', $this["month"])->whereYear('date', $currentDate->year)->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->sum('amount'); $actionNow = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product') ->whereHas('product', function($qq) use($bagProds, $x, $currentDate){ $qq->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->sum('amount'); $actionBraks = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*') ->with('product') ->whereHas('product', function($qq) use($bagProds, $x, $currentDate){ $qq->whereMonth('date', $this["month"])->whereYear('date', $currentDate->year)->where('width', $bagProds[$x]->width)->where('height', $bagProds[$x]->height)->where('bag_gram', $bagProds[$x]->bag_gram)->where('color_id', $bagProds[$x]->color_id); }) ->get(); $calculateBrak = 0; $calculateBrakRepair = 0; for ($xx = 0; $xx < count($actionBraks); $xx++) { $calculateBrak += $actionBraks[$xx]->product->defective_bag_qty; $calculateBrakRepair += $actionBraks[$xx]->product->defective_repair_qty; } $reportDatas[$x]["width"] = $bagProds[$x]->width; $reportDatas[$x]["height"] = $bagProds[$x]->height; $reportDatas[$x]["color"] = $bagProds[$x]->color->name; $reportDatas[$x]["bag_gram"] = $bagProds[$x]->bag_gram ?? 0; $reportDatas[$x]["amount"] = $action; $reportDatas[$x]["defective"] = $calculateBrak; $reportDatas[$x]["defectiveRepair"] = $calculateBrakRepair; $reportDatas[$x]["all"] = ($action + $calculateBrakRepair + $calculateBrak); $reportDatas[$x]["amountNow"] = $actionNow; } } // dd($reportDatas); $this["reportDatas"] = $reportDatas; } ?> == {% put styles %} {% endput %}

Aýlar Boýunça {{year}}

{% partial 'dataTableJs' %}