d2d.emegrendeles.hu/app/Filament/Pages/CalendarTest.php
2026-04-24 18:10:48 +02:00

70 lines
1.9 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Models\ProfitCenter;
use App\Models\ProfitCenterSupplierSchedule;
use App\Models\Supplier;
use Filament\Pages\Page;
class CalendarTest extends Page
{
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-calendar';
protected string $view = 'filament.pages.calendar-test';
protected static ?string $title = 'Naptár Teszt';
protected static bool $shouldRegisterNavigation = false;
public ?int $supplierId = null;
public ?int $profitCenterId = null;
public function mount(): void
{
$first = ProfitCenterSupplierSchedule::first();
if ($first) {
$this->supplierId = $first->supplier_id;
$this->profitCenterId = $first->profit_center_id;
}
}
public function getSuppliers(): array
{
return Supplier::orderBy('name')->pluck('name', 'id')->toArray();
}
public function getProfitCenters(): array
{
if (!$this->supplierId) {
return ProfitCenter::orderBy('name')->pluck('name', 'id')->toArray();
}
$pcIds = ProfitCenterSupplierSchedule::where('supplier_id', $this->supplierId)
->pluck('profit_center_id');
return ProfitCenter::whereIn('id', $pcIds)->orderBy('name')->pluck('name', 'id')->toArray();
}
public function updatedSupplierId(): void
{
$this->profitCenterId = null;
$first = ProfitCenterSupplierSchedule::where('supplier_id', $this->supplierId)->first();
if ($first) {
$this->profitCenterId = $first->profit_center_id;
}
$this->dispatch('calendar-filter-changed', supplierId: $this->supplierId, profitCenterId: $this->profitCenterId);
}
public function updatedProfitCenterId(): void
{
$this->dispatch('calendar-filter-changed', supplierId: $this->supplierId, profitCenterId: $this->profitCenterId);
}
}