diff --git a/app/Filament/Pages/ProductionCalender.php b/app/Filament/Pages/ProductionCalender.php index 8abe8c45..376911f6 100644 --- a/app/Filament/Pages/ProductionCalender.php +++ b/app/Filament/Pages/ProductionCalender.php @@ -4,6 +4,7 @@ namespace App\Filament\Pages; use App\Models\CustomerPoMaster; use App\Models\Plant; +use App\Models\ProductionCalendar; use App\Models\ProductionPlan; use App\Models\WireMasterPacking; use Filament\Facades\Filament; @@ -139,27 +140,36 @@ class ProductionCalender extends Page return; } - $updated = ProductionPlan::where('plant_id', $plantId) + $updated = ProductionCalendar::where('plant_id', $plantId) ->whereMonth('created_at', $month) ->whereYear('created_at', $year) - ->update([ - 'working_days' => $workingDays, - 'leave_dates' => $dates, - 'updated_at' => now(), - ]); + ->first(); if ($updated) { + $updated->update([ + 'working_days' => $workingDays, + 'leave_dates' => $dates, + ]); Notification::make() ->title('Success') ->body("Working days updated successfully!") ->success() ->send(); + return; } else { + + ProductionCalendar::create([ + 'plant_id' => $plantId, + 'working_days' => $workingDays, + 'leave_dates' => $dates, + ]); + Notification::make() - ->title('No Records Updated') - ->body("No production plans found for this plant and month.") - ->warning() + ->title('Record Created Successfully') + ->body("Production calendar plans created for this plant and month.") + ->success() ->send(); + return; } }