A profitcenter ütemezés felvételi űrlapján a Beszállító mező eddig minden "Mentés és új létrehozása" után kiürült, pedig a felhasználó tipikusan ugyanahhoz a beszállítóhoz vesz fel egymás után több ütemezést különböző profit center / szállítási sablon kombinációval. A Filament CreateRecord erre kész horgot ad (preserveFormDataWhenCreatingAnother()): a Beszállító mostantól megmarad a következő üres űrlapon, a Profit Center és a Szállítási sablon továbbra is ürül. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* "Mentés és új létrehozása" esetén a Beszállító mezőt megtartja, a többit üríti (EV3-432).
|
|
*
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function preserveFormDataWhenCreatingAnother(array $data): array
|
|
{
|
|
return ['supplier_id' => $data['supplier_id'] ?? null];
|
|
}
|
|
}
|