This commit is contained in:
2026-11-03 11:51:44 +02:00
parent badaada043
commit e753f7a0a4
309 changed files with 14537 additions and 529 deletions
+18 -1
View File
@@ -18,6 +18,23 @@ use Illuminate\Validation\ValidationException;
class SupplyHistory
{
public function independentReviewer(User $actor, SupplyRecord $record): bool
{
return $actor->tenant_id === $record->tenant_id && app(SupplyPlanning::class)->allows($actor, 'supply_history_review')
&& ! in_array($actor->id, $record->snapshot['contributors'] ?? [$record->created_by], true);
}
/** Eligibility to confer; approval still checks ledger, scope and source changes. */
public function canReview(User $actor, SupplyRecord $record, string $action = 'approve'): bool
{
if ($record->kind !== 'history' || ! in_array($action, ['approve', 'return', 'suspend'], true) || ! $this->independentReviewer($actor, $record)) {
return false;
}
$latest = app(SupplyPlanning::class)->latest('history')->where('record_key', $record->record_key)->first();
return $latest?->id === $record->id && ($action === 'suspend' ? $record->state === 'approved' : in_array($record->state, ['draft', 'returned'], true));
}
/** @param array<string,mixed> $input */
public function save(User $actor, array $input): SupplyRecord
{
@@ -58,7 +75,7 @@ class SupplyHistory
$this->require($old !== null, 'action', 'Prepare primeiro a análise.');
$data = $old->data;
$snapshot = $old->snapshot;
$this->require(! in_array($actor->id, $snapshot['contributors'], true), 'action', 'A conferência exige independência de todos os preparadores.');
$this->require($this->independentReviewer($actor, $old), 'action', 'A conferência exige independência de todos os preparadores.');
$this->require($v['action'] === 'suspend' ? $old->state === 'approved' : in_array($old->state, ['draft', 'returned'], true), 'action', 'Estado incompatível com esta decisão.');
if ($v['action'] === 'approve') {
$confirm = Validator::make($v['data'], ['confirm_scope' => 'required|accepted'])->validate();