mod EV3-442 Profitcenter ütemezés 2.

This commit is contained in:
E98Developer 2026-07-16 08:53:09 +02:00
parent 558a99970a
commit 5477b953a8
5 changed files with 81 additions and 9 deletions

View File

@ -3,9 +3,33 @@
namespace App\Filament\Resources\ProfitCenterSupplierSchedules\Pages;
use App\Filament\Resources\ProfitCenterSupplierSchedules\ProfitCenterSupplierScheduleResource;
use App\Models\ProfitCenterSupplierSchedule;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
class CreateProfitCenterSupplierSchedule extends CreateRecord
{
protected static string $resource = ProfitCenterSupplierScheduleResource::class;
/**
* Több profit center esetén minden egyes profit centerhez külön rekordot hoz létre.
*
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
$profitCenterIds = (array) $data['profit_center_id'];
$lastRecord = null;
foreach ($profitCenterIds as $profitCenterId) {
$lastRecord = ProfitCenterSupplierSchedule::create([
'profit_center_id' => $profitCenterId,
'supplier_id' => $data['supplier_id'],
'delivery_schedule_id' => $data['delivery_schedule_id'],
]);
}
return $lastRecord;
}
}

View File

@ -6,12 +6,38 @@
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Forms\Components\Select;
use Filament\Resources\Pages\EditRecord;
use Filament\Schemas\Schema;
class EditProfitCenterSupplierSchedule extends EditRecord
{
protected static string $resource = ProfitCenterSupplierScheduleResource::class;
public function form(Schema $schema): Schema
{
return $schema
->components([
Select::make('profit_center_id')
->label('Profit Center')
->relationship('profitCenter', 'name')
->searchable()
->required(),
Select::make('supplier_id')
->label('Beszállító')
->relationship('supplier', 'name')
->searchable()
->required(),
Select::make('delivery_schedule_id')
->label('Szállítási sablon')
->relationship('deliverySchedule', 'name')
->searchable()
->live()
->afterStateUpdated(fn ($state, $livewire) => $livewire->dispatch('delivery-schedule-changed', deliveryScheduleId: $state))
->required(),
]);
}
protected function getHeaderActions(): array
{
return [

View File

@ -2,6 +2,7 @@
namespace App\Filament\Resources\ProfitCenterSupplierSchedules\Schemas;
use App\Models\ProfitCenter;
use Filament\Forms\Components\Select;
use Filament\Schemas\Schema;
@ -13,8 +14,9 @@ public static function configure(Schema $schema): Schema
->components([
Select::make('profit_center_id')
->label('Profit Center')
->relationship('profitCenter', 'name')
->options(ProfitCenter::orderBy('name')->pluck('name', 'id'))
->searchable()
->multiple()
->required(),
Select::make('supplier_id')
->label('Beszállító')

View File

@ -33,6 +33,9 @@ class DeliveryCalendarWidget extends FullCalendarWidget
/** Következő szállítási nap dátuma (YYYY-MM-DD formátum), kék kiemeléshez. */
public ?string $nextDeliveryDate = null;
/** Előnézeti szállítási sablon ID (edit oldalon, mentés előtti változás). */
public ?int $previewDeliveryScheduleId = null;
/**
* Inaktív (nem választható) napok listája.
*
@ -74,6 +77,13 @@ public function onNextDeliveryDateChanged(?string $date): void
$this->refreshRecords();
}
#[On('delivery-schedule-changed')]
public function onDeliveryScheduleChanged(?int $deliveryScheduleId): void
{
$this->previewDeliveryScheduleId = $deliveryScheduleId;
$this->refreshRecords();
}
protected function loadRecordFromFilter(): void
{
if ($this->record instanceof ProfitCenterSupplierSchedule) {
@ -114,11 +124,19 @@ public function fetchEvents(array $info): array
$events = [];
// 1. Szállítási napok zöld háttér
$assignment = $this->record;
if ($this->previewDeliveryScheduleId && $this->previewDeliveryScheduleId !== $this->record->delivery_schedule_id) {
$assignment = clone $this->record;
$assignment->delivery_schedule_id = $this->previewDeliveryScheduleId;
$assignment->setRelation('deliverySchedule', \App\Models\DeliverySchedule::find($this->previewDeliveryScheduleId));
}
$deliveryDates = $service->getAvailableDeliveryDates(
$this->record->profitCenter,
$this->record->supplier,
$start,
$end
$end,
$assignment
);
foreach ($deliveryDates as $date) {

View File

@ -26,7 +26,7 @@ public function __construct(
* 3. Általános override (az összes PC-re vonatkozó)
* Ha egyetlen szinten sem található override, folytatódik a normál kiértékelés.
*/
public function isDeliveryDay(ProfitCenter $pc, Supplier $supplier, Carbon $date): bool
public function isDeliveryDay(ProfitCenter $pc, Supplier $supplier, Carbon $date, ?ProfitCenterSupplierSchedule $assignment = null): bool
{
$date = $date->startOfDay();
@ -42,10 +42,12 @@ public function isDeliveryDay(ProfitCenter $pc, Supplier $supplier, Carbon $date
}
// PC-hez rendelt szállítási sablon lekérése (2. és 5. prioritáshoz egyaránt szükséges)
$assignment = ProfitCenterSupplierSchedule::where('profit_center_id', $pc->id)
->where('supplier_id', $supplier->id)
->with('deliverySchedule')
->first();
if ($assignment === null) {
$assignment = ProfitCenterSupplierSchedule::where('profit_center_id', $pc->id)
->where('supplier_id', $supplier->id)
->with('deliverySchedule')
->first();
}
// 2. Prioritás: DeliverySchedule-specifikus felülbírálás (a PC-hez rendelt szállítási sablon alapján)
if ($assignment && $assignment->delivery_schedule_id) {
@ -91,14 +93,14 @@ public function isDeliveryDay(ProfitCenter $pc, Supplier $supplier, Carbon $date
*
* @return Collection<Carbon>
*/
public function getAvailableDeliveryDates(ProfitCenter $pc, Supplier $supplier, Carbon $start, Carbon $end): Collection
public function getAvailableDeliveryDates(ProfitCenter $pc, Supplier $supplier, Carbon $start, Carbon $end, ?ProfitCenterSupplierSchedule $assignment = null): Collection
{
$dates = collect();
$current = $start->copy()->startOfDay();
$end = $end->copy()->startOfDay();
while ($current <= $end) {
if ($this->isDeliveryDay($pc, $supplier, $current)) {
if ($this->isDeliveryDay($pc, $supplier, $current, $assignment)) {
$dates->push($current->copy());
}
$current->addDay();