@@ -13,6 +13,7 @@ use App\Models\Supplier;
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Models\User;
|
||||
use App\Models\Warehouse;
|
||||
use App\Services\AgreementOrderLimits;
|
||||
use App\Services\InventoryReversals;
|
||||
use App\Services\OrganizationAccess;
|
||||
use App\Services\ReceiptWorkflow;
|
||||
@@ -52,7 +53,10 @@ class SupplyPlanningController extends Controller
|
||||
private function page(Request $request, SupplyPlanning $planning, User $actor): HttpResponse
|
||||
{
|
||||
Inertia::encryptHistory();
|
||||
$view = $request->validate(['view' => 'nullable|in:agreements,calendar,imports,alternatives,reservations,deliveries,suggestions,history'])['view'] ?? 'agreements';
|
||||
$view = $request->validate(['view' => 'nullable|in:contracts,agreements,calendar,imports,alternatives,reservations,deliveries,suggestions,history'])['view'] ?? 'agreements';
|
||||
if ($view === 'contracts') {
|
||||
abort_unless(app(AgreementOrderLimits::class)->ready(), 503);
|
||||
}
|
||||
if ($view === 'history') {
|
||||
return $this->privateResponse($request, $this->history($request, $actor, $planning));
|
||||
}
|
||||
@@ -66,7 +70,7 @@ class SupplyPlanningController extends Controller
|
||||
$capabilities = $import ? ['import_read', 'import_prepare', 'import_customs'] : ['supply_read', 'supply_prepare', 'supply_review'];
|
||||
abort_unless(collect($capabilities)->contains(fn ($p) => $planning->allows($actor, $p)), 403);
|
||||
$ready = Schema::hasTable('supply_records');
|
||||
$kind = $import ? 'import' : ($view === 'calendar' ? 'policy' : 'agreement');
|
||||
$kind = $import ? 'import' : ($view === 'calendar' ? 'policy' : ($view === 'contracts' ? 'contract' : 'agreement'));
|
||||
$focus = $this->focusedRecord($request, $actor, $kind);
|
||||
[$records, $page] = $this->recordPage($request, $planning, $ready, $kind, $focus);
|
||||
$projections = [];
|
||||
@@ -98,7 +102,15 @@ class SupplyPlanningController extends Controller
|
||||
'agreement_form_key' => 'nullable|string|max:80',
|
||||
]) : [];
|
||||
|
||||
$contractFilters = $request->validate(['contract_search' => 'nullable|string|max:100', 'selected_contract_key' => 'nullable|uuid']);
|
||||
|
||||
return $this->privateResponse($request, Inertia::render('supply/index', ['view' => $view, 'kind' => $kind, 'ready' => $ready,
|
||||
'contractSearch' => $contractFilters['contract_search'] ?? '',
|
||||
'contracts' => $ready && $prepare && $kind === 'agreement' && app(AgreementOrderLimits::class)->ready()
|
||||
? $this->approvedOptions($planning, 'contract', $records->pluck('data.contract_key')->push($contractFilters['selected_contract_key'] ?? null), ['agreement_search' => $contractFilters['contract_search'] ?? ''])->map(fn ($r) => $r->only(['record_key', 'version', 'data', 'snapshot'])) : [],
|
||||
'orderLimitsReady' => app(AgreementOrderLimits::class)->ready(),
|
||||
'linkedAgreementKey' => $kind === 'policy' ? $request->query('linked_agreement_key') : null,
|
||||
'linkedContractKey' => $kind === 'agreement' ? $request->query('linked_contract_key') : null,
|
||||
'agreementSearch' => $agreementFilters['agreement_search'] ?? '', 'agreementFormKey' => $agreementFilters['agreement_form_key'] ?? null,
|
||||
'recordPagination' => $this->pagination($page),
|
||||
'focusRecordId' => $focus->id ?? null, 'focusChanged' => $focus !== null && $records->first()?->id !== $focus->id,
|
||||
@@ -143,6 +155,18 @@ class SupplyPlanningController extends Controller
|
||||
return [collect(), null];
|
||||
}
|
||||
$query = $planning->latest($kind)->latest('id');
|
||||
if ($kind === 'agreement') {
|
||||
$linked = $request->validate(['linked_contract_key' => 'nullable|uuid']);
|
||||
if (! empty($linked['linked_contract_key'])) {
|
||||
$query->where('data->contract_key', $linked['linked_contract_key']);
|
||||
}
|
||||
}
|
||||
if ($kind === 'policy') {
|
||||
$linked = $request->validate(['linked_agreement_key' => 'nullable|uuid']);
|
||||
if (! empty($linked['linked_agreement_key'])) {
|
||||
$query->where('data->agreement_key', $linked['linked_agreement_key']);
|
||||
}
|
||||
}
|
||||
if ($focus !== null) {
|
||||
return [$query->where('record_key', $focus->record_key)->get(), null];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user