'Machine Production',
'description' => 'Machine productions settings'
];
}
public function onRender()
{
$html_data = '';
$currentDateFormat = Carbon::now()->format('Y-m-d');
$machineProductions = ProductionMachineModel::with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic'])->orderBy('id', 'DESC')->whereDate('created_at', date($currentDateFormat))->get();
$html_data = '';
for ($x = 0; $x < count($machineProductions); $x++) {
// dd($machineProductions[0]->bag_size);
$html_data .= '
| ' . ($x + 1) . ' |
' . $machineProductions[$x]->building_name . ' |
' . $machineProductions[$x]->machine->name . ' |
' . $machineProductions[$x]->bag_size->name . ' |
' . $machineProductions[$x]->bag_type->name . ' |
' . number_format($machineProductions[$x]->produced_weight) . ' kg
|
' . $machineProductions[$x]->employee_name . ' |
' . $machineProductions[$x]->mechanic_name . ' |
' . $machineProductions[$x]->note . ' |
';
}
return $html_data;
}
public function onReport()
{
$currentDate = Carbon::now()->timezone('UTC +05:00');
$currentDateFormat = $currentDate->format('Y-m-d');
$data = post();
$machineProductions = ProductionMachineModel::with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic'])->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"];
$size = $data["size_id"];
$type = $data["type_id"];
if ($machine) {
$machineProductions->where("machine_id", $machine);
}
if ($mechanic) {
$machineProductions->where("mechanic_id", $mechanic);
}
if ($size) {
$machineProductions->where("size_id", $size);
}
if ($type) {
$machineProductions->where("type_id", $type);
}
if ($start != $currentDateFormat){
$machineProductions->whereBetween('created_at', [$start, $end]);
}
$machineProductionsFiltered = $machineProductions->get();
$machineProductionsSum = $machineProductions->sum("produced_weight");
$html_data = '';
for ($x = 0; $x < count($machineProductionsFiltered); $x++) {
$html_data .= '
| ' . ($x + 1) . ' |
' . $machineProductionsFiltered[$x]->created_at->format("d.m.Y") . ' |
' . $machineProductionsFiltered[$x]->building_name . ' |
' . $machineProductionsFiltered[$x]->machine->name . ' |
' . $machineProductionsFiltered[$x]->bag_size->name . ' |
' . $machineProductionsFiltered[$x]->bag_type->name . ' |
' . number_format($machineProductionsFiltered[$x]->produced_weight) . ' kg
|
' . $machineProductionsFiltered[$x]->employee_name . ' |
' . $machineProductionsFiltered[$x]->mechanic_name . ' |
' . $machineProductionsFiltered[$x]->note . ' |
';
}
if ($machineProductionsFiltered) {
return [
'#machine_report_datas' => $html_data,
'#all_amount' => '
Jemi Öndürlen Önüm: '.number_format($machineProductionsSum).' kg
',
];
} else {
Flash::error("Yalnyshlyk bar!!");
}
}
public function onCreateMachineProduction()
{
$user = \Auth::user();
$data = post();
if (empty($data["produced_weight"]) || $data["type_id"] == 0 || $data["size_id"] == 0 || $data["machine_id"] == 0) {
Flash::error("Gutulary Dolduryn!");
return [
'#validationq' => ' Gutulary Dolduryn!',
];
} else {
$createProductionMachine = new ProductionMachineModel();
$createProductionMachine->type_id = $data["type_id"];
$createProductionMachine->size_id = $data["size_id"];
$createProductionMachine->machine_id = $data["machine_id"];
$createProductionMachine->produced_weight = $data["produced_weight"];
$createProductionMachine->note = $data["note"];
$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(
'employee_id' => $productionMachine->machine->employee->id,
'mechanic_id' => $productionMachine->machine->mechanic->id,
'employee_name' => $productionMachine->machine->employee->name,
'mechanic_name' => $productionMachine->machine->mechanic->name,
'building_name' => $productionMachine->machine->building->name,
));
}
$currentDateFormat = Carbon::now()->format('Y-m-d');
$machineProductions = ProductionMachineModel::with(['bag_type', 'bag_size', 'machine.building', 'employee', 'mechanic'])->whereDate('created_at', date($currentDateFormat))->orderBy('id', 'DESC')->get();
$html_data = '';
for ($x = 0; $x < count($machineProductions); $x++) {
$html_data .= '
| ' . ($x + 1) . ' |
' . $machineProductions[$x]->building_name . ' |
' . $machineProductions[$x]->machine->name . ' |
' . $machineProductions[$x]->bag_size->name . ' |
' . $machineProductions[$x]->bag_type->name . ' |
' . number_format($machineProductions[$x]->produced_weight) . ' kg
|
' . $machineProductions[$x]->employee_name . ' |
' . $machineProductions[$x]->mechanic_name . ' |
' . $machineProductions[$x]->note . ' |
';
}
if ($createProductionMachine && $updateResult) {
Flash::success("Hasabat Ustunlikli Goşuldy");
return [
'#machine_datas' => $html_data,
];
} else {
Flash::error("Yalnyshlyk bar!!");
}
}
}
}