'Machine Production', 'description' => 'Machine productions settings' ]; } public function onModalSetMachineData() { $data = post(); $machinProdId = $data["machineProdId"]; $productions = PivotSewer::whereHas("rulon_action", function($q) use($machinProdId){ $q->where('product_id', $machinProdId); })->with(["sewer_production", "rulon_action.product"])->get(); $machineProductionData = ProductionMachineModel::where('id', $machinProdId)->first(); $allBagQty = 0; $allSpent = 0; $allLeft = 0; //dd(count($productions)); if (count($productions) > 0){ $html_data = ' '; }else{ $html_data = ' '; } return [ '#modal-form' => $html_data, ]; } public function onSetFormUpdate() { $data = post(); $machinProdId = $data["machineProdId"]; $user = \Auth::user(); $production = ProductionMachineModel::where("id", $machinProdId)->first(); $colors = BagColor::get(); $types = BagType::get(); $machines = Machine::get(); $html_data = ' '; $html_data .= ''; return [ '#modal-form' => $html_data, ]; } public function onDeleteProductionMachine(){ $id = post('production_id'); $productionDelete = ProductionMachineModel::Find($id); $productionDelete->delete(); if ($productionDelete) { Flash::success("Hasabat Ustunlikli Pozuldy"); return Redirect::refresh(); } else { Flash::error("Yalnyshlyk bar!!"); return Redirect::refresh(); } } public function onRender() { $user = \Auth::user(); $html_data = ''; $crudProductionRulonq = $this->page["crudProductionRulon"]; $inboxProductionRulonq = $this->page["inboxProductionRulon"]; $currentDateFormat = Carbon::now()->format('Y-m-d'); $machineProductions = ProductionMachineModel::with(['bag_type', 'machine.building', 'employee', 'mechanic', 'color', 'shift'])->orderBy('id', 'DESC')->get(); $html_data = ''; for ($x = 0; $x < count($machineProductions); $x++) { $inStock = RulonAction::where("product_id", $machineProductions[$x]->id)->count(); $editBtn = ''; if($machineProductions[$x]->user_id != $user->id){ $editBtn = ' Size degişli däl '; }else{ if(!$inStock){ $editBtn = $crudProductionRulonq ? '   ' : ''; $editBtn .= $inboxProductionRulonq ? '' : ''; }else{ $editBtn = ' Sklada salyndy '; } } // dd($machineProductions[0]->bag_size); $html_data .= ' ' . ($x + 1) . ' #Rulon' . ($machineProductions[$x]->id) . ' ' . ($machineProductions[$x]->date == null ? "" : Carbon::parse($machineProductions[$x]->date)->format('d.m.Y')) . ' ' . ($machineProductions[$x]->shift->desc ?? ''). ' ' . $machineProductions[$x]->machine->name . ' ' . $machineProductions[$x]->width . ' ' . $machineProductions[$x]->gram . ' m2 ' . $machineProductions[$x]->bag_type->name . ' ' . ($machineProductions[$x]->color->name ?? "") . ', '. $machineProductions[$x]->layer .' gat ' . number_format($machineProductions[$x]->produced_weight, 2) . ' kg ' . number_format($machineProductions[$x]->brutto_kg, 2) . ' kg ' . number_format($machineProductions[$x]->produced_length, 2) . ' m ' . number_format($machineProductions[$x]->defective_weight, 2) . ' kg ' . $machineProductions[$x]->employee_name . ' ' . $machineProductions[$x]->note . ' '. $editBtn.' '; } return $html_data; } public function onReport() { $currentDate = Carbon::now(); $currentDateFormat = $currentDate->format('Y-m-d'); $data = post(); $machineProductions = ProductionMachineModel::with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic', 'color', 'shift']) ->orderBy('id', 'DESC'); $machineProductionsCalc = ProductionMachineModel::with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic', 'color', 'shift']) ->orderBy('id', 'DESC'); $start = Carbon::parse($data["start"])->format('Y-m-d'); $end = Carbon::parse($data["end"])->format('Y-m-d'); $machine = $data["machine_id"]; // $mechanic = $data["mechanic_id"]; $type = $data["type_id"]; $shift = $data["shift_id"]; $width = $data["width"]; $employee_name = $data["employee_name"]; $gram = $data["gram"]; $layer = $data["layer"]; // $is_finished = $data["is_finished"]; // if ($is_finished) { // $machineProductions->where("is_finished", (bool) $is_finished); // } if ($employee_name) { $machineProductions->where("employee_name", "like", "%" . $employee_name . "%"); $machineProductionsCalc->where("employee_name", "like", "%" . $employee_name . "%"); } if ($machine) { $machineProductions->where("machine_id", $machine); $machineProductionsCalc->where("machine_id", $machine); } if ($shift) { $machineProductions->where("shift_id", $shift); $machineProductionsCalc->where("shift_id", $shift); } // if ($mechanic) { // $machineProductions->where("mechanic_id", $mechanic); // $machineProductionsCalc->where("mechanic_id", $mechanic); // } if ($width) { $machineProductions->where("width", $width); $machineProductionsCalc->where("width", $width); } if ($layer) { $machineProductions->where("layer", $layer); $machineProductionsCalc->where("layer", $layer); } if ($gram) { $machineProductions->where("gram", $gram); $machineProductionsCalc->where("gram", $gram); } if ($type) { $machineProductions->where("type_id", $type); $machineProductionsCalc->where("type_id", $type); } if ($start != $currentDateFormat) { $machineProductions->whereBetween('date', [$start, $end]); $machineProductionsCalc->whereBetween('date', [$start, $end]); } $machineProductionsFiltered = $machineProductions->get(); $machineProductionsSum = $machineProductionsCalc->sum("produced_weight"); $machineProductionsBruttoSum = $machineProductionsCalc->sum("brutto_kg"); $machineProductionsDefectiveSum = $machineProductionsCalc->sum("defective_weight"); $html_data = ''; for ($x = 0; $x < count($machineProductionsFiltered); $x++) { $html_data .= ' ' . ($x + 1) . ' #Rulon' . ($machineProductionsFiltered[$x]->id) . ' ' . ($machineProductionsFiltered[$x]->date == null ? "" : Carbon::parse($machineProductionsFiltered[$x]->date)->format('d.m.Y')) . ' ' . ($machineProductionsFiltered[$x]->shift->desc ?? '') . ' ' . $machineProductionsFiltered[$x]->machine->name . ' ' . $machineProductionsFiltered[$x]->width . ' ' . $machineProductionsFiltered[$x]->gram . ' m2 ' . $machineProductionsFiltered[$x]->bag_type->name . ' ' . ($machineProductionsFiltered[$x]->color->name ?? "") . ', '. $machineProductionsFiltered[$x]->layer .' gat ' . number_format($machineProductionsFiltered[$x]->produced_weight, 2) . ' kg ' . number_format($machineProductionsFiltered[$x]->brutto_kg, 2) . ' kg ' . number_format($machineProductionsFiltered[$x]->produced_length, 2) . ' m ' . number_format($machineProductionsFiltered[$x]->defective_weight, 2) . ' kg ' . $machineProductionsFiltered[$x]->employee_name . ' ' . $machineProductionsFiltered[$x]->note . ' '; } if ($machineProductionsFiltered) { return [ '#machine_report_datas' => $html_data, '#all_amount' => '
Öndürlen Rulon: ' . count($machineProductionsFiltered) .'
Öndürlen: ' . number_format($machineProductionsSum, 2) . ' kg
Brutto Agramy: ' . number_format($machineProductionsBruttoSum, 2) . ' kg
Othod: ' . number_format($machineProductionsDefectiveSum, 2) . ' kg
', ]; } else { Flash::error("Yalnyshlyk bar!!"); } } public function onUpdateMachineProduction(){ $user = \Auth::user(); $data = post(); $oldData = ProductionMachineModel::where("id", $data["production_id"]) ->with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic', 'color']) ->first(); $updateProductionMachine = ProductionMachineModel::where("id", $data["production_id"]) ->with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic', 'color']) ->first(); $metrOfRulon = (float)((float)($data["gram"] / 100) * ($data["width"] / 100)) * (int)$data["layer"]; $metrOfAllRulon = (float) $data["produced_weight"] / $metrOfRulon; $updateProductionMachine->type_id = (int) $data["type_id"]; $updateProductionMachine->width = $data["width"]; $updateProductionMachine->gram = $data["gram"]; $updateProductionMachine->brutto_kg = $data["brutto_kg"]; $updateProductionMachine->layer = $data["layer"]; $updateProductionMachine->machine_id = (int) $data["machine_id"]; $updateProductionMachine->color_id = (int) $data["color_id"]; $updateProductionMachine->produced_weight = $data["produced_weight"]; $updateProductionMachine->produced_length = $metrOfAllRulon; $updateProductionMachine->defective_weight = $data["defective_weight"]; $updateProductionMachine->note = $data["note"]; $updateProductionMachine->date = Carbon::parse($data["date"])->format('Y-m-d'); $contentJournal = array( "old_data" => $oldData, "new_data" => $updateProductionMachine, ); $journal = new Journal(); $journal->type = "ProductionMachine"; $journal->content_id = $data["production_id"]; $journal->user_id = $user->id; $journal->data = $contentJournal; $journal->save(); $updateProductionMachine->save(); if ($updateProductionMachine && $journal) { Flash::success("Hasabat Ustunlikli Uytgedildi"); return Redirect::refresh(); } else { Flash::error("Yalnyshlyk bar!!"); return Redirect::refresh(); } } public function onCreateMachineProduction() { $user = \Auth::user(); $data = post(); if (empty($data["produced_weight"]) || $data["type_id"] == 0 || $data["machine_id"] == 0) { Flash::error("Gutulary Dolduryn!"); return [ '#validationq' => ' Gutulary Dolduryn!', ]; } else { $createProductionMachine = new ProductionMachineModel(); $metrOfRulon = (float)((float)($data["gram"] / 100) * ($data["width"] / 100)) * (int)$data["layer"]; $metrOfAllRulon = (float) $data["produced_weight"] / $metrOfRulon; $createProductionMachine->type_id = $data["type_id"]; $createProductionMachine->width = $data["width"]; $createProductionMachine->gram = $data["gram"]; $createProductionMachine->brutto_kg = $data["brutto_kg"]; $createProductionMachine->layer = $data["layer"]; $createProductionMachine->machine_id = $data["machine_id"]; $createProductionMachine->shift_id = $data["shift_id"]; $createProductionMachine->color_id = $data["color_id"]; $createProductionMachine->produced_weight = $data["produced_weight"]; $createProductionMachine->produced_length = $metrOfAllRulon; $createProductionMachine->defective_weight = $data["defective_weight"]; $createProductionMachine->employee_name = $data["employee_name"]; $createProductionMachine->mechanic_name = $data["employee_name"]; $createProductionMachine->note = $data["note"]; $createProductionMachine->date = Carbon::parse($data["date"])->format('Y-m-d'); $createProductionMachine->user_id = $user->id; $createProductionMachine->save(); $productionMachine = ProductionMachineModel::where('id', $createProductionMachine->id)->with(['machine.employee', 'machine.mechanic', 'machine.building'])->first(); // dd($productionMachine->machine->name); if ($productionMachine) { $updateResult = ProductionMachineModel::where('id', $productionMachine->id) ->update(array( 'building_name' => $productionMachine->machine->building->name, )); } if ($createProductionMachine && $updateResult) { Flash::success("Hasabat Ustunlikli Goşuldy"); return Redirect::refresh(); } else { Flash::error("Yalnyshlyk bar!!"); return Redirect::refresh(); } } } }