@@ -3,6 +3,7 @@
|
||||
use App\Models\Requisition;
|
||||
use App\Models\User;
|
||||
use App\Services\ExpenseAllocations;
|
||||
use App\Services\RequisitionExpiry;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Database\Connection;
|
||||
@@ -23,6 +24,7 @@ if (! $app->environment('testing') || $db->getDriverName() !== 'pgsql' || $db->g
|
||||
}
|
||||
config(['requisition-expiry.qa_enabled' => true]);
|
||||
$expenses = ($argv[2] ?? '') === 'recover-expenses';
|
||||
$urgent = ($argv[2] ?? '') === 'recover-urgent';
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
receiptFixture();
|
||||
$fingerprint = static function (Connection $connection): array {
|
||||
@@ -51,7 +53,7 @@ $pg = static function (string $binary, array $arguments) use ($connectionConfig)
|
||||
$preDump = $directory.'/before.dump';
|
||||
$postDump = $directory.'/after.dump';
|
||||
$pg('pg_dump', ['--format=custom', '--file='.$preDump, '--dbname='.$database]);
|
||||
$prepare = new Process([PHP_BINARY, __DIR__.'/requisition-cycle-worker.php', $database, 'prepare'], dirname(__DIR__, 2), timeout: 30);
|
||||
$prepare = new Process([PHP_BINARY, __DIR__.'/requisition-cycle-worker.php', $database, 'prepare', ...($urgent ? ['urgent'] : [])], dirname(__DIR__, 2), timeout: 30);
|
||||
$prepare->mustRun();
|
||||
$input = json_decode($prepare->getOutput(), true, 32, JSON_THROW_ON_ERROR);
|
||||
Carbon::setTestNow($input['clock']);
|
||||
@@ -62,7 +64,7 @@ $workflow = app(RequisitionWorkflow::class);
|
||||
$workflow->expire($owner, $request, $input['basis'], $input['operation'], $input['version']);
|
||||
$request->refresh();
|
||||
$request = $workflow->save($owner, ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version,
|
||||
'cost_center_id' => $request->cost_center_id, 'priority' => 'normal', 'needed_by' => today()->addWeek()->toDateString(),
|
||||
'cost_center_id' => $request->cost_center_id, 'priority' => $urgent ? 'urgent' : 'normal', 'needed_by' => today()->addWeek()->toDateString(),
|
||||
'justification' => 'Synthetic revised request retained through recovery',
|
||||
'items' => [['description' => 'Synthetic revised item', 'category' => 'Material', 'purchase_type' => 'consumable', 'quantity' => '1.000', 'unit' => 'un', 'unit_price' => '120.00', 'tax_rate' => '0.00']]], $request);
|
||||
$submission = (string) Str::uuid();
|
||||
@@ -105,6 +107,15 @@ try {
|
||||
|| $restored->table('approval_steps')->where('requisition_id', $request->id)->where('decision', 'expired')->count() !== 1) {
|
||||
throw new RuntimeException('Restored native expiry/submission replay changed history or reservation.');
|
||||
}
|
||||
if ($urgent) {
|
||||
$deadline = app(RequisitionExpiry::class)->deadline($request->fresh());
|
||||
if (($deadline['timing'] ?? null) !== 'urgent_override'
|
||||
|| Carbon::parse($deadline['started_at'])->diffInSeconds(Carbon::parse($deadline['expires_at'])) != 300
|
||||
|| $request->fresh()->approval_snapshot['approval_expiry']['request_priority'] !== 'urgent') {
|
||||
throw new RuntimeException('Restored urgent submission lost its explicit frozen timing.');
|
||||
}
|
||||
echo json_encode(['urgent_policy_frozen_restored' => true, 'urgent_expire_seconds_restored' => 300], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
}
|
||||
if ($expenses) {
|
||||
$expenseActor = User::query()->whereKey($expenseFixture['f']['validator']->id)->firstOrFail();
|
||||
auth()->guard()->setUser($expenseActor);
|
||||
|
||||
Reference in New Issue
Block a user