@@ -82,6 +82,7 @@ class OrderCancellationWorkflow
|
||||
private function enabled(): void
|
||||
{
|
||||
abort_unless(config('order_cancellation.enabled') && Schema::hasTable('order_cancellations'), 503, 'Cancelamento de ordens não activado.');
|
||||
app(OrderCancellationRuntime::class)->assertReady();
|
||||
}
|
||||
|
||||
public function state(PurchaseOrder $order): string
|
||||
@@ -198,11 +199,12 @@ class OrderCancellationWorkflow
|
||||
if (! empty($order->snapshot['budget_control']) && ! DB::table('budget_entries')->where('tenant_id', $actor->tenant_id)->where('requisition_id', $request->id)->exists()) {
|
||||
throw ValidationException::withMessages(['budget' => 'A ordem indica controlo orçamental, mas o compromisso não está disponível.']);
|
||||
}
|
||||
$path = base_path('packages/order-cancellation/src/CommitmentReversal.php');
|
||||
abort_unless(is_file($path) && hash_file('sha256', $path) === config('order_cancellation.reversal_sha256'), 503, 'Capacidade de reversão indisponível.');
|
||||
require_once $path;
|
||||
$cycles = app(OrderCancellationRuntime::class)->load($request->id);
|
||||
$context = $cycles
|
||||
? (new \ReflectionClass(BudgetContext::class))->newInstanceArgs([$actor->id, ['tenant_id' => (int) $actor->tenant_id], (int) now()->year, 'MZN', RequisitionExpiry::orderCycles($order)])
|
||||
: new BudgetContext($actor->id, ['tenant_id' => (int) $actor->tenant_id], (int) now()->year, 'MZN');
|
||||
try {
|
||||
$entry = (new CommitmentReversal)->reverse(DB::connection(), new BudgetContext($actor->id, ['tenant_id' => (int) $actor->tenant_id], (int) now()->year, 'MZN'), $request->id, $order->id);
|
||||
$entry = (new CommitmentReversal)->reverse(DB::connection(), $context, $request->id, $order->id);
|
||||
} catch (\LogicException $error) {
|
||||
throw ValidationException::withMessages(['budget' => 'O compromisso não está integralmente disponível para reversão ou a sua base é inconsistente. Reveja o controlo orçamental.']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user