44 lines
2.4 KiB
PHP
44 lines
2.4 KiB
PHP
<?php
|
|
|
|
use App\Enums\PurchasingRole;
|
|
use App\Models\Budget;
|
|
use App\Models\User;
|
|
use App\Services\BudgetWorkflow;
|
|
use App\Services\OrderCancellationPolicyWorkflow;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
|
|
|
function issuedOrderCancellationFixture(object $test): void
|
|
{
|
|
config(['order_cancellation.enabled' => true]);
|
|
$test->f = receiptFixture();
|
|
$base = ['tenant_id' => $test->f['tenant']->id, 'department_id' => $test->f['department']->id];
|
|
$test->buyer = User::factory()->create([...$base, 'purchasing_role' => PurchasingRole::Procurement]);
|
|
$test->finance = User::factory()->create([...$base, 'purchasing_role' => PurchasingRole::Finance]);
|
|
$test->admins = [];
|
|
foreach (range(1, 3) as $index) {
|
|
$test->admins[] = User::factory()->create([...$base, 'purchasing_role' => PurchasingRole::Admin]);
|
|
}
|
|
$test->actingAs($test->admins[0]);
|
|
$flow = app(OrderCancellationPolicyWorkflow::class);
|
|
$test->policy = $flow->propose($test->admins[0], ['previous_id' => 0, 'mode' => 'issued_order', 'enabled' => true,
|
|
'valid_from' => today()->toDateString(), 'valid_until' => today()->addWeek()->toDateString(), 'reason' => 'Política exclusivamente fictícia para o circuito de testes.']);
|
|
foreach ([$test->admins[1], $test->admins[2]] as $admin) {
|
|
$test->actingAs($admin);
|
|
$flow->review($admin, $test->policy, 'approved', 'Conferência independente da política fictícia.');
|
|
}
|
|
$test->actingAs($test->finance);
|
|
$test->budget = Budget::query()->create(['tenant_id' => $test->f['tenant']->id, 'cost_center_id' => $test->f['r']->cost_center_id, 'year' => now()->year,
|
|
'amount_minor' => 20000, 'includes_tax' => true, 'reason' => 'Dotação fictícia para ensaio da reversão.', 'created_by' => $test->finance->id,
|
|
'approved_by' => $test->admins[0]->id, 'approved_at' => now()]);
|
|
DB::transaction(function () use ($test) {
|
|
foreach (['reserve', 'award', 'commit'] as $kind) {
|
|
app(BudgetWorkflow::class)->record($test->finance, $test->f['r'], $kind, 10000, 10000);
|
|
}
|
|
});
|
|
$test->data = ['operation_key' => (string) Str::uuid(), 'reason' => 'Cancelamento integral fictício antes de qualquer execução.', 'evidence' => 'Referência documental fictícia do fundamento do cancelamento.'];
|
|
$test->actingAs($test->buyer);
|
|
}
|