commit21
This commit is contained in:
@@ -23,6 +23,16 @@ use Illuminate\Validation\ValidationException;
|
||||
/** Full corrective reversals; original documents and financial facts remain immutable. */
|
||||
class InventoryReversals
|
||||
{
|
||||
public function executionSourceCurrent(SupplyRecord $record): bool
|
||||
{
|
||||
return $record->kind === 'stock_reversal' && app(InventoryReviewParticipation::class)->executionSourceCurrent($record, fn (array $data) => $this->basis($data));
|
||||
}
|
||||
|
||||
public function canAct(User $actor, SupplyRecord $record, string $action): bool
|
||||
{
|
||||
return app(InventoryReviewParticipation::class)->canAct($actor, $record, 'stock_reversal', $action, fn (string $capability) => $this->allows($actor, $capability));
|
||||
}
|
||||
|
||||
public function allows(User $actor, string $action): bool
|
||||
{
|
||||
return ! app(OrganizationAccess::class)->maintenanceOnly($actor) && $actor->hasFunctions(match ($action) {
|
||||
@@ -91,8 +101,8 @@ class InventoryReversals
|
||||
$receiptSource = null;
|
||||
if ($data['source_kind'] === 'operation') {
|
||||
$operation = StockOperation::query()->whereKey($data['source_operation_id'])->firstOrFail();
|
||||
$sourceMovementIds=StockMovement::query()->where('stock_operation_id',$operation->id)->pluck('id');
|
||||
$this->check(!StockMovement::query()->where('movement_type','workshop_return_in')->whereIn('snapshot->delivery_movement_id',$sourceMovementIds)->exists(),'action','A entrega já tem devolução física de excedente. Preserve o original e confira a correcção própria.');
|
||||
$sourceMovementIds = StockMovement::query()->where('stock_operation_id', $operation->id)->pluck('id');
|
||||
$this->check(! StockMovement::query()->where('movement_type', 'workshop_return_in')->whereIn('snapshot->delivery_movement_id', $sourceMovementIds)->exists(), 'action', 'A entrega já tem devolução física de excedente. Preserve o original e confira a correcção própria.');
|
||||
$this->check(in_array($operation->kind, ['issue', 'transfer', 'adjustment', 'supplier_return', 'write_off'], true), 'data.source_operation_id', 'Seleccione uma operação física; contagens e outros estornos não são estornados por este percurso.');
|
||||
$this->check(! $this->operationReversed($operation->id), 'action', 'Esta operação já tem estorno integral.');
|
||||
$movements = StockMovement::query()->where('stock_operation_id', $operation->id)->orderBy('id')->get();
|
||||
@@ -198,7 +208,7 @@ class InventoryReversals
|
||||
$data = $old->data;
|
||||
$snapshot = $old->snapshot;
|
||||
if ($v['action'] === 'execute') {
|
||||
$this->check($old->state === 'approved' && $actor->id !== $snapshot['reviewed_by'], 'action', 'Exige aprovação actual e execução por pessoa diferente de quem aprovou.');
|
||||
$this->check($old->state === 'approved' && app(InventoryReviewParticipation::class)->independentExecutor($actor, $old), 'action', 'Exige aprovação actual e execução por pessoa diferente de quem aprovou.');
|
||||
$event = Validator::make($v['data'], ['event_on' => 'required|date_format:Y-m-d|before_or_equal:today', 'evidence' => 'required|string|min:10|max:3000'])->validate();
|
||||
$this->check($event['event_on'] >= $old->created_at->toDateString(), 'data.event_on', 'O estorno não pode anteceder a aprovação.');
|
||||
$basis = $this->basis($data);
|
||||
@@ -210,7 +220,7 @@ class InventoryReversals
|
||||
$snapshot['execution_observed'] = $basis['observed'];
|
||||
$state = 'executed';
|
||||
} else {
|
||||
$this->check(! in_array($actor->id, $snapshot['contributors'], true), 'action', 'A decisão exige pessoa independente de todos os preparadores.');
|
||||
$this->check(app(InventoryReviewParticipation::class)->independentReviewer($actor, $old), 'action', 'A decisão exige pessoa independente de todos os preparadores.');
|
||||
$this->check($v['action'] === 'return' ? in_array($old->state, ['draft', 'returned', 'approved'], true) : in_array($old->state, ['draft', 'returned'], true), 'action', 'Estado incompatível.');
|
||||
$state = $v['action'] === 'approve' ? 'approved' : 'returned';
|
||||
if ($state === 'approved') {
|
||||
|
||||
Reference in New Issue
Block a user