From 3376d35eaaf78ac73d3d12890d567adb9bfacdd4 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 16 Feb 2026 11:14:03 +0530 Subject: [PATCH] Added Production Calendar screen page --- app/Filament/Pages/ProductionCalender.php | 163 ++++++++++++++++++ .../pages/production-calender.blade.php | 13 ++ resources/views/forms/calendar.blade.php | 151 ++++++++++++++++ resources/views/forms/save.php | 9 + 4 files changed, 336 insertions(+) create mode 100644 app/Filament/Pages/ProductionCalender.php create mode 100644 resources/views/filament/pages/production-calender.blade.php create mode 100644 resources/views/forms/calendar.blade.php create mode 100644 resources/views/forms/save.php diff --git a/app/Filament/Pages/ProductionCalender.php b/app/Filament/Pages/ProductionCalender.php new file mode 100644 index 0000000..ef4ea37 --- /dev/null +++ b/app/Filament/Pages/ProductionCalender.php @@ -0,0 +1,163 @@ +form->fill([ + 'working_days' => $days ?? 0, + ]); + } + + public function form(Form $form): Form + { + return $form + ->statePath('filters') + ->schema([ + Section::make('') + ->schema([ + Select::make('plant_id') + ->label('Plant') + ->reactive() + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) + ->columnSpan(['default' => 10, 'sm' => 7]) + ->required() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('working_days', null); + }), + TextInput::make('working_days') + ->label('No. of Working Days') + ->numeric() + ->readOnly() + ->columnSpan(['default' => 10, 'sm' => 2]) + ->required() + ->minValue(0) + ->maxValue(31) + ->placeholder('Enter working days') + ->id('working_days'), + + Hidden::make('month') + ->label('Month') + ->id('month'), + + Hidden::make('year') + ->label('Year') + ->id('year'), + + Hidden::make('selected_dates') + ->label('Selected Dates') + ->id('selected_dates'), + + ViewField::make('save') + ->view('forms.save') + ->columnSpan(['default' => 10, 'sm' => 1]), + + ViewField::make('calendar') + ->view('forms.calendar') + ->columnspan(10), + ]) + ->columns(10) + ]); + } + + public function saveWorkingDays(){ + $plantId = $this->filters['plant_id'] ?? null; + $workingDays = $this->filters['working_days'] ?? null; + $month = $this->filters['month'] ?? null; + $year = $this->filters['year'] ?? null; + $dates = $this->filters['selected_dates'] ?? null; + + if (!$plantId) { + Notification::make() + ->title('Unknown Plant') + ->body("Please select a plant first!") + ->danger() + ->send(); + return; + } + else if (!$workingDays) { + Notification::make() + ->title('Unknown Working Days') + ->body("Working days can't be empty!") + ->danger() + ->send(); + return; + } + else if (!$month) { + Notification::make() + ->title('Unknown Month') + ->body("month can't be empty!") + ->danger() + ->send(); + return; + } + else if (!$year) { + Notification::make() + ->title('Unknown Year') + ->body("Year can't be empty!") + ->danger() + ->send(); + return; + } + + $updated = ProductionPlan::where('plant_id', $plantId) + ->whereMonth('created_at', $month) + ->whereYear('created_at', $year) + ->update([ + 'working_days' => $workingDays, + 'leave_dates' => $dates, + 'updated_at' => now(), + ]); + + if ($updated) { + Notification::make() + ->title('Success') + ->body("Working days updated successfully!") + ->success() + ->send(); + } else { + Notification::make() + ->title('No Records Updated') + ->body("No production plans found for this plant and month.") + ->warning() + ->send(); + } + } + +} diff --git a/resources/views/filament/pages/production-calender.blade.php b/resources/views/filament/pages/production-calender.blade.php new file mode 100644 index 0000000..915fe0e --- /dev/null +++ b/resources/views/filament/pages/production-calender.blade.php @@ -0,0 +1,13 @@ + + +
+ + {{-- Render the Select form fields --}} +
+ {{ $this->form }} +
+ + +
+ +
diff --git a/resources/views/forms/calendar.blade.php b/resources/views/forms/calendar.blade.php new file mode 100644 index 0000000..113f799 --- /dev/null +++ b/resources/views/forms/calendar.blade.php @@ -0,0 +1,151 @@ + + + +
+ + + + + + + + diff --git a/resources/views/forms/save.php b/resources/views/forms/save.php new file mode 100644 index 0000000..bb8c6c0 --- /dev/null +++ b/resources/views/forms/save.php @@ -0,0 +1,9 @@ +
+ +