diff --git a/app/Filament/Imports/ProductionPlanImporter.php b/app/Filament/Imports/ProductionPlanImporter.php index 10e6b06..95822a7 100644 --- a/app/Filament/Imports/ProductionPlanImporter.php +++ b/app/Filament/Imports/ProductionPlanImporter.php @@ -158,8 +158,20 @@ class ProductionPlanImporter extends Importer if ($productionPlan) { + $recordDate = now(); + $month = $recordDate->month; + $year = $recordDate->year; + + $previousRecord = ProductionPlan::where('plant_id', $plant->id) + ->whereMonth('created_at', $month) + ->whereYear('created_at', $year) + ->first(); + + $workingDays = $previousRecord?->working_days ?? null; + $productionPlan->update([ 'plan_quantity' => $this->data['plan_quantity'], + 'working_days' => $workingDays, 'operator_id' => $operatorName, ]); $productionPlan->save(); @@ -168,12 +180,24 @@ class ProductionPlanImporter extends Importer } } + $recordDate = now(); + $month = $recordDate->month; + $year = $recordDate->year; + + $previousRecord = ProductionPlan::where('plant_id', $plant->id) + ->whereMonth('created_at', $month) + ->whereYear('created_at', $year) + ->first(); + + $workingDays = $previousRecord?->working_days ?? null; + ProductionPlan::updateOrCreate([ 'plant_id' => $plant->id, 'line_id' => $line->id, 'item_id' => $itemAgaPlant->id, // 'shift_id' => $shift->id, 'plan_quantity' => $this->data['plan_quantity'], + 'working_days' => $workingDays, 'created_at' =>now(), 'updated_at' => now(), 'operator_id' => $operatorName,