diff --git a/app/Filament/Widgets/DeliveryCalendarWidget.php b/app/Filament/Widgets/DeliveryCalendarWidget.php index b8f06dc..e443a13 100644 --- a/app/Filament/Widgets/DeliveryCalendarWidget.php +++ b/app/Filament/Widgets/DeliveryCalendarWidget.php @@ -17,6 +17,7 @@ use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\TextInput; +use Livewire\Attributes\On; class DeliveryCalendarWidget extends FullCalendarWidget { @@ -25,6 +26,10 @@ class DeliveryCalendarWidget extends FullCalendarWidget */ public Model | int | string | null $record = null; + public ?int $supplierId = null; + + public ?int $profitCenterId = null; + /** * Inaktív (nem választható) napok listája. * @@ -34,6 +39,44 @@ class DeliveryCalendarWidget extends FullCalendarWidget public function mount(): void { + $this->loadRecordFromFilter(); + } + + public function updatedSupplierId(): void + { + $this->loadRecordFromFilter(); + $this->refreshRecords(); + } + + public function updatedProfitCenterId(): void + { + $this->loadRecordFromFilter(); + $this->refreshRecords(); + } + + #[On('calendar-filter-changed')] + public function onFilterChanged(?int $supplierId, ?int $profitCenterId): void + { + $this->supplierId = $supplierId; + $this->profitCenterId = $profitCenterId; + $this->record = null; + $this->loadRecordFromFilter(); + $this->refreshRecords(); + } + + protected function loadRecordFromFilter(): void + { + if ($this->record instanceof ProfitCenterSupplierSchedule) { + return; + } + + if ($this->supplierId && $this->profitCenterId) { + $this->record = ProfitCenterSupplierSchedule::where('supplier_id', $this->supplierId) + ->where('profit_center_id', $this->profitCenterId) + ->first(); + return; + } + if (!$this->record) { $this->record = ProfitCenterSupplierSchedule::first(); } @@ -41,11 +84,12 @@ public function mount(): void public function fetchEvents(array $info): array { - if (!$this->record) { - $this->record = ProfitCenterSupplierSchedule::first(); + if (!($this->record instanceof ProfitCenterSupplierSchedule)) { + $this->loadRecordFromFilter(); } if (!$this->record) { + $this->dispatch('calendar-events-done'); return $this->getDemoEvents($info); } @@ -127,6 +171,7 @@ public function fetchEvents(array $info): array $current->addDay(); } + $this->dispatch('calendar-events-done'); return $events; }