@@ -34,7 +34,12 @@ final class ImportEstimates
|
||||
return null;
|
||||
}
|
||||
|
||||
return SupplyRecord::query()->where('kind', 'import_estimate')->where('data->requisition_id', $request->id)->latest('version')->first();
|
||||
$cycle = (int) ($request->getAttribute('approval_cycle') ?? 1);
|
||||
|
||||
return SupplyRecord::query()->where('kind', 'import_estimate')->where('data->requisition_id', $request->id)
|
||||
->when($cycle > 1, fn ($q) => $q->where('data->requisition_cycle', $cycle),
|
||||
fn ($q) => $q->where(fn ($first) => $first->whereNull('data->requisition_cycle')->orWhere('data->requisition_cycle', 1)))
|
||||
->latest('version')->first();
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
@@ -95,7 +100,7 @@ final class ImportEstimates
|
||||
$record = $this->current($request);
|
||||
abort_unless($record !== null, 409);
|
||||
$adapter = app(CommonBudget::class);
|
||||
$engine = $adapter->for($actor);
|
||||
$engine = $adapter->for($actor, RequisitionExpiry::cycles($request));
|
||||
abort_unless(in_array('reserveImportEstimate', get_class_methods($engine), true), 503, 'Motor sem reserva pré-documental.');
|
||||
$adapter->execute(fn () => (new \ReflectionMethod($engine, 'reserveImportEstimate'))->invoke($engine, $record->record_key, $record->version, $record->data['budget_id'],
|
||||
$request->id, $record->snapshot['plan']['goods'], $record->data['components'], $record->operation_key));
|
||||
@@ -110,7 +115,7 @@ final class ImportEstimates
|
||||
}
|
||||
abort_unless($this->ready(), 503, 'Preserve o motor das estimativas reservadas.');
|
||||
$adapter = app(CommonBudget::class);
|
||||
$engine = $adapter->for($actor);
|
||||
$engine = $adapter->for($actor, RequisitionExpiry::cycles($request));
|
||||
abort_unless(in_array('releaseImportEstimate', get_class_methods($engine), true), 503);
|
||||
$adapter->execute(fn () => (new \ReflectionMethod($engine, 'releaseImportEstimate'))->invoke($engine, $estimate['record_key'], $estimate['version'],
|
||||
$estimate['plan']['fingerprint'], (string) Str::uuid()));
|
||||
@@ -267,7 +272,8 @@ final class ImportEstimates
|
||||
$record = SupplyRecord::query()->create(['tenant_id' => $actor->tenant_id, 'kind' => 'import_estimate',
|
||||
'record_key' => $old->record_key ?? (string) Str::uuid(), 'version' => ($old->version ?? 0) + 1,
|
||||
'state' => $plan['complete'] ? 'prepared' : 'incomplete', 'created_by' => $actor->id,
|
||||
'data' => ['requisition_id' => $request->id, 'budget_id' => $budget->id, 'components' => $data['components']],
|
||||
'data' => ['requisition_id' => $request->id, 'budget_id' => $budget->id, 'components' => $data['components'],
|
||||
...((int) ($request->getAttribute('approval_cycle') ?? 1) > 1 ? ['requisition_cycle' => $request->getAttribute('approval_cycle')] : [])],
|
||||
'snapshot' => ['native' => $native, 'plan' => $plan, 'budget' => $budget->only(['id', 'cost_center_id', 'year', 'kind', 'includes_tax']), 'legal_sources' => $legalSources],
|
||||
'reason' => $data['reason'], 'operation_key' => $data['operation_key'], 'input_hash' => $hash, 'created_at' => now()]);
|
||||
app(RequisitionWorkflow::class)->audit($actor, 'import.estimate_prepared', $request, null,
|
||||
|
||||
Reference in New Issue
Block a user