'Production', 'description' => 'productions settings' ]; } public function onReportProduction() { $currentDate = Carbon::now(); $currentDateFormat = $currentDate->format('Y-m-d'); $data = post(); $productions = ProductionModel::with(['pivot_production', 'excruiter', 'shift', 'pivot_production_calculation'])->orderBy('date', 'DESC')->orderBy('time', 'DESC'); $productionsCalc = ProductionModel::orderBy('id', 'DESC'); $productionsCalcPivot = ProductionCalculateModel::orderBy('id', 'DESC'); $start = Carbon::parse($data["start"])->format('Y-m-d'); $end = Carbon::parse($data["end"])->format('Y-m-d'); if ($start == $currentDateFormat) { Flash::error("Sene Saylan!"); } else { $startView = Carbon::parse($data["start"])->format('d.m.Y'); $endView = Carbon::parse($data["end"])->format('d.m.Y'); $excruiter = $data["excruiter_id"]; $shiftId = $data["shift_id"]; if ($excruiter) { $productions->where("excruiter_id", $excruiter); $productionsCalc->where("excruiter_id", $excruiter); $productionsCalcPivot->where("excruiter_id", $excruiter); } if ($shiftId) { $productions->where("shift_id", $shiftId); $productionsCalc->where("shift_id", $shiftId); $productionsCalcPivot->where("shift_id", $shiftId); } if ($start != $currentDateFormat) { $productions->whereBetween('date', [$start, $end]); $calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time')) ->whereBetween('date', [$start, $end])->first(); $diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time); $calcTimeDiff = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut'; $productionsCalcPivot->whereBetween('date', [$start, $end]); // dd($max); // $min = $productions->select(DB::raw("MIN(id)")); } $productionsFiltered = $productions->get(); //$calculationAmount = $productionsCalcPivot->sum("amount_calc"); $calculationAmountqq = $productions->where('id', '!=', $productionsFiltered[0]->id)->get()->pluck('id')->toArray(); $pivotIds = PivotProductionModel::whereIn('production_id', $calculationAmountqq)->get()->pluck('id')->toArray(); $calculationAmount = ProductionCalculateModel::whereIn('prev_pivot_id', $pivotIds)->sum("amount_calc"); //dd($pivotIds); $html_data = ''; for ($x = 0; $x < count($productionsFiltered); $x++) { $date = ""; if($productionsFiltered[$x]->date != null){ $date = Carbon::parse($productionsFiltered[$x]->date)->format('d.m.Y').' | '.$productionsFiltered[$x]->time; }else{ $date = ""; } // dd($productionsFiltered[0]->shift->desc); $html_data .= ' ' . ($x + 1) . ' ' . $date . ' ' . $productionsFiltered[$x]->shift->desc . ' ' . $productionsFiltered[$x]->excruiter->name . ' ' . number_format($productionsFiltered[$x]->all_amount) . ' kg '; for ($i = 0; $i < count($productionsFiltered[$x]->pivot_production); $i++) { $html_data .= ' ' . number_format($productionsFiltered[$x]->pivot_production[$i]->amount_percentage, 2) . '% '; } $html_data .= '' . $productionsFiltered[$x]->note . ' '; } if ($productionsFiltered) { return [ '#production_report_datas' => $html_data, // '#exampleModalFullscreenLabel' => ''. $startView .' - '. $endView .' seneleri aralygynda güni jemi', '#report_dynamic' => '

Çig Mallar Boýunça Umumy

Hasabat

Sarp Edilen Wagt: ' . $calcTimeDiff . ' sany
Sarp Edilen Çig mal: ' . number_format($calculationAmount) . ' kg
' ]; } else { Flash::error("Yalnyshlyk bar!!"); } } } public function onCalculateReportDaily() { $currentDate = Carbon::now(); $currentDateFormat = $currentDate->format('Y-m-d'); $data = post(); $excruiter = $this->param("excruiter"); $currentExcrutier = ExcruiterModel::where("id", $excruiter)->first(); $productionsCalc = ProductionModel::orderBy('id', 'DESC'); $calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time')) ->whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->first(); $diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time); $timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut'; $countDailyChanges = ProductionModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->get(); $products = ProductModel::where('report', 'simple')->get(); // dd(count($countDailyChanges)); $dailyCalculated = ProductionCalculateModel::whereDate("date", date($currentDateFormat))->where("excruiter_id", $excruiter)->sum("amount_calc"); if ((count($countDailyChanges) > 0) && ($dailyCalculated)) { $dailyCalculated = ProductionCalculateModel::whereDate("date", date($currentDateFormat))->where("excruiter_id", $excruiter)->sum("amount_calc"); //sagatda ortacaha hasaplama $html_data2 = ''; // gunluk hasabat $html_data = '
'; $html_data .= '

JEMI IŞLENEN ÇIG MAL (ekstrudor: ' . $currentExcrutier->name . ')

'; $html_data .= '
' . $timeCalc . '

JEMI IŞLENEN: ' . $dailyCalculated . ' kg

'; //sagatda ortacaha hasaplama $html_data2 .= '
'; $html_data2 .= '

SAGATDA ORTAÇA (ekstrudor: ' . $currentExcrutier->name . ')

'; $html_data2 .= ''; for ($x = 0; $x < count($products); $x++) { $productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->where("product_id", $products[$x]->id)->sum('amount_calc'); $productCalcPercentage = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiter)->where("product_id", $products[$x]->id)->orderBy('id', 'DESC')->first(); // $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount; // $diffPerc = ($diff * 100) / $producedAll; $html_data .= ''; $html_data2 .= ''; } $html_data .= '
'; $html_data2 .= '
'; //ekstrudorlar b-ca $excruiters = ExcruiterModel::get(); $html_data3 = '
'; for ($x = 0; $x < count($excruiters); $x++) { $productionsCalc = ProductionModel::orderBy('id', 'DESC'); $calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time')) ->whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->first(); $diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time); $timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut'; $productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->sum('amount_calc'); $html_data3 .= '

JEMI IŞLENEN ÇIG MAL (ekstrudor: ' . $excruiters[$x]->name . ')

'; $html_data3 .= '
' . $timeCalc . '

JEMI IŞLENEN: ' . number_format($dailyCalculated, 2) . ' kg

'; for ($i = 0; $i < count($products); $i++) { $productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->where("product_id", $products[$i]->id)->sum('amount_calc'); $productCalcPercentage = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('excruiter_id', $excruiters[$x]->id)->where("product_id", $products[$i]->id)->orderBy('id', 'DESC')->first(); $html_data3 .= '
' . (number_format($productCalc, 2)) . ' kg

' . $products[$i]->code . ' : ' . ($productCalcPercentage->amount_percentage ?? 0) . ' %

'; } } $html_data3 .= '
'; //smenlar boyuncha $shifts = ShiftModel::get(); $html_data4 = '

SMENLAR BOÝUNÇA

'; $html_data4 .= '
'; $html_data4 .= ''; $html_data4 .= ''; $sumTimeDiffs = 0; $productAllCalc = 0; for ($i = 0; $i < count($shifts); $i++) { $productionsCalc = ProductionModel::orderBy('id', 'DESC'); $calc = $productionsCalc->select(DB::raw('MAX(time) AS max_time'), DB::raw('MIN(time) AS min_time')) ->whereDate('date', date($currentDateFormat))->where('shift_id', $shifts[$i]->id)->first(); $diffMinutes = Carbon::parse($calc->max_time)->diffInMinutes($calc->min_time); $sumTimeDiffs += $diffMinutes; $timeCalc = floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut'; $productCalc = ProductionCalculateModel::whereDate('date', date($currentDateFormat))->where('shift_id', $shifts[$i]->id)->sum('amount_calc'); $productAllCalc += $productCalc; $html_data4 .= ''; $html_data4 .= ''; } $timeAllCalc = floor($sumTimeDiffs / 60) . ' sagat ' . ($sumTimeDiffs - floor($sumTimeDiffs / 60) * 60) . ' minut'; $html_data4 .= ''; $html_data4 .= ''; $html_data4 .= '
# Smen Wagty Jemi
' . ($i + 1) . ' ' . $shifts[$i]->desc . '(' . $shifts[$i]->start . ' - ' . $shifts[$i]->end . ') ' . $timeCalc . ' ' . $productCalc . ' kg
JEMI ' . $timeAllCalc . ' ' . $productAllCalc . ' kg
'; return [ '#calculation_of_day' => $html_data, '#avg_of_day' => $html_data2, '#excruiter_daily_report' => $html_data3, '#shift_daily_report' => $html_data4 ]; } else { return [ '#calculation_of_day' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!', '#excruiter_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!', '#shift_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!' ]; } } function onCalculateAvg() { $currentDate = Carbon::now(); $currentDateFormat = $currentDate->format('Y-m-d'); $excruiter = $this->param("excruiter"); $data = post(); $enteredDate = Carbon::parse($data["date"])->format('Y-m-d'); $todayProductionsCount = ProductionModel::whereDate('date', date($enteredDate))->where("excruiter_id", $excruiter)->count(); if ($todayProductionsCount > 0) { $todayProductionsGet = ProductionModel::whereDate('date', date($enteredDate))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->first(); $productionPivot = PivotProductionModel::where('production_id', $todayProductionsGet->id)->where("product_id", $data["prod_id"])->first(); if(!$productionPivot){ $amountPERC = 0; }else{ $amountPERC = $productionPivot->amount_percentage; } $diffAllAMount = ((float) $data["all_amount"] - (float) $todayProductionsGet->all_amount) ?? 0; $calculatedAmount = (float)(((float) $data["field_value"] ?? 0) / 100) * ((float) $diffAllAMount); $allData = array( "product_name" => $productionPivot->product_code ?? "Haryt yok", "avg_percentage" => number_format($amountPERC, 2), "avg_amount" => number_format($calculatedAmount, 2), "headerq" => "Çig Mallar Boýunça (Soňky üýtgeşme: " . $diffAllAMount . " kg)" ); } else { $allData = array( // "product_name" => $productionPivot->product_name, "avg_percentage" => number_format(0, 2), "avg_amount" => number_format(0, 2) ); } return $allData; } public function onUpdatePivotProduction() { $user = \Auth::user(); $currentDate = Carbon::now(); // $this["currentMonth"] = $currentDate->format('m'); $data = post(); // dd($data); $updatePivotProduction = PivotProductionModel::where("id", $data["product_id"])->first(); $production = ProductionModel::where("id", $updatePivotProduction->production_id)->first(); $fieldName = "product_" . $data["product_id"]; $updatePivotProduction->amount_percentage = (float) $data[$fieldName] ?? 0; $updatePivotProduction->amount = (((float) $data[$fieldName] ?? 0) / 100) * ((float) $production->all_amount); $updatePivotProduction->save(); $productionCalulate = ProductionCalculateModel::where("production_id", $updatePivotProduction->production_id)->where("prev_pivot_id", $updatePivotProduction->id)->first(); // dd($production); if ($productionCalulate != null) { $diffCalc = (float) ((float) $productionCalulate->amount_calc * 100) / (float) $productionCalulate->amount_percentage; $productionCalulate->amount_calc = (float)(((float) $data[$fieldName] ?? 0) / 100) * ((float) $diffCalc); $productionCalulate->amount_percentage = (float) $data[$fieldName] ?? 0; $productionCalulate->save(); } if ($updatePivotProduction) { Flash::success("Hasabat Ustunlikli Üýtgedildi"); return Redirect::refresh(); } } public function onCreateProduction() { $user = \Auth::user(); $currentDate = Carbon::now(); // $this["currentMonth"] = $currentDate->format('m'); $data = post(); $excruiter = $this->param("excruiter"); if ($excruiter == 0) { Flash::error("Ekstrudor Saýla!"); return Redirect::refresh(); } else { $createProduction = new ProductionModel(); $createProduction->all_amount = $data["all_amount"]; $createProduction->note = $data["note"]; $createProduction->user_id = $user->id; $createProduction->date = Carbon::parse($data["date"])->format('Y-m-d'); $createProduction->time = Carbon::parse($data["time"])->format('H:i:s'); $createProduction->excruiter_id = $excruiter; $createProduction->shift_id = $data["shift_id"]; $createProduction->save(); $products = ProductModel::where("report", "simple")->orderBy('order', 'ASC')->get(); for ($x = 0; $x < count($products); $x++) { $fieldName = "product_" . $products[$x]->id; $createPivotProduction = new PivotProductionModel(); $createPivotProduction->production_id = $createProduction->id; $createPivotProduction->product_id = $products[$x]->id; $createPivotProduction->amount_percentage = (float) $data[$fieldName] ?? 0; $createPivotProduction->product_name = $products[$x]->name; $createPivotProduction->product_code = $products[$x]->code; $createProduction->excruiter_id = $excruiter; $createPivotProduction->amount = (float)(((float) $data[$fieldName] ?? 0) / 100) * ((float) $createProduction->all_amount); $createPivotProduction->date = Carbon::parse($data["date"])->format('Y-m-d'); $createPivotProduction->time = Carbon::parse($data["time"])->format('H:i:s'); $createPivotProduction->save(); } $todayProductionsCount = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->count(); if ($todayProductionsCount > 1) { // $todayProductionsGetLast = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->first(); $todayProductionsGet = ProductionModel::whereDate('date', date($createProduction->date))->where("excruiter_id", $excruiter)->orderBy("id", "DESC")->skip(1)->first(); $productionPivots = PivotProductionModel::where('production_id', $todayProductionsGet->id)->get(); $diffAllAmount = ($createProduction->all_amount - $todayProductionsGet->all_amount); for ($x = 0; $x < count($productionPivots); $x++) { $currentPivot = PivotProductionModel::where("production_id", $createProduction->id)->where("product_id", $productionPivots[$x]->product_id)->first(); $createCalculate = new ProductionCalculateModel(); $createCalculate->production_id = $todayProductionsGet->id; $createCalculate->product_id = $productionPivots[$x]->product_id; $createCalculate->amount_calc = (float)(((float) $productionPivots[$x]->amount_percentage ?? 0) / 100) * ((float) $diffAllAmount); $createCalculate->excruiter_id = $todayProductionsGet->excruiter_id; $createCalculate->shift_id = $todayProductionsGet->shift_id; $createCalculate->amount_percentage = $productionPivots[$x]->amount_percentage; $createCalculate->current_pivot_id = $currentPivot->id; $createCalculate->prev_pivot_id = $productionPivots[$x]->id; $createCalculate->date = $productionPivots[$x]->date; $createCalculate->time = $productionPivots[$x]->time; $createCalculate->save(); } } if ($createProduction && $createPivotProduction) { Flash::success("Hasabat Ustunlikli Goşuldy"); return Redirect::refresh(); } } } public function onUpdateProduction() { $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"], 'note' => $data["note"], 'transport_no' => $data["transport_no"], 'driver' => $data["driver"], 'user_id' => $user->id, )); // $createResult = DollorModel::create([]); // dd($data); if ($updateResult) { Flash::success("Action Ustunlikli Uytgedildi"); return Redirect::refresh(); } } public function onGetProduction() { $id = post('id'); return ActionModel::where('id', $id)->first(); } public function onDeleteProduction() { $id = post('id'); $item = ProductionModel::Find($id); $item->delete(); if ($item) { Flash::success("Hasabat Ustunlikli Pozuldy"); return Redirect::refresh(); } } }