@@ -12,6 +12,8 @@ use App\Services\CommonPaymentFacts;
|
||||
use App\Services\ExpenseAllocations;
|
||||
use App\Services\GeneralLedger;
|
||||
use App\Services\InvoiceWorkflow;
|
||||
use App\Services\OrderCancellationRuntime;
|
||||
use App\Services\OrderCancellationWorkflow;
|
||||
use App\Services\ProcurementPaymentInsights;
|
||||
use App\Services\RequisitionAccountAssignments;
|
||||
use App\Services\RequisitionExpiry;
|
||||
@@ -27,10 +29,13 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tempo\Finance\Budget\BudgetContext;
|
||||
use Tempo\Finance\Budget\BudgetFailure;
|
||||
use Tempo\Finance\OrderCancellation\CommitmentReversal;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/PaymentFixture.php';
|
||||
require_once __DIR__.'/../Support/IssuedOrderCancellationFixture.php';
|
||||
|
||||
beforeEach(function () {
|
||||
if (getenv('COMPRAS_STANDALONE_BUSINESS_QA') !== '1') {
|
||||
@@ -84,6 +89,38 @@ test('standalone candidate preserves explicit line account attribution without a
|
||||
expect(DB::table('supply_records')->where('kind', 'req_account')->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('issued order cancellation reverses the current resubmission cycle and preserves the closed reservation history', function (int $cycle) {
|
||||
issuedOrderCancellationFixture($this, $cycle);
|
||||
$origin = $this->f['r']->id;
|
||||
$first = DB::table('budget_entries')->where('requisition_id', $origin)->where('requisition_cycle', '<', $cycle)->orderBy('id')->get()->toJson();
|
||||
$workflow = app(OrderCancellationWorkflow::class);
|
||||
$this->actingAs($this->buyer);
|
||||
$record = $workflow->request($this->buyer, $this->f['order'], $this->data);
|
||||
$this->actingAs($this->finance);
|
||||
$workflow->decide($this->finance, $record, 'approved', 'Independent synthetic cancellation after request resubmission');
|
||||
$workflow->decide($this->finance, $record, 'approved', 'Independent synthetic cancellation after request resubmission');
|
||||
$reversal = DB::table('budget_entries')->where('requisition_id', $origin)->where('kind', 'order-cancel-'.$this->f['order']->id)->sole();
|
||||
expect((int) $reversal->requisition_cycle)->toBe($cycle)
|
||||
->and(DB::table('budget_entries')->where('requisition_id', $origin)->where('requisition_cycle', '<', $cycle)->orderBy('id')->get()->toJson())->toBe($first)
|
||||
->and((int) DB::table('budget_entries')->where('requisition_id', $origin)->where('requisition_cycle', $cycle)->sum('committed_minor'))->toBe(0)
|
||||
->and($this->f['r']->fresh()->status)->toBe('cancelled');
|
||||
})->with([1, 2]);
|
||||
|
||||
test('cycle-aware cancellation refuses a stale or missing cycle map without appending a reversal', function () {
|
||||
issuedOrderCancellationFixture($this, 2);
|
||||
$origin = $this->f['r']->id;
|
||||
$before = DB::table('budget_entries')->orderBy('id')->get()->toJson();
|
||||
app(OrderCancellationRuntime::class)->load($origin);
|
||||
foreach ([[], [$origin => 1]] as $cycles) {
|
||||
$context = (new ReflectionClass(BudgetContext::class))->newInstanceArgs([
|
||||
$this->finance->id, ['tenant_id' => $this->finance->tenant_id], (int) now()->year, 'MZN', $cycles,
|
||||
]);
|
||||
expect(fn () => DB::transaction(fn () => (new CommitmentReversal)->reverse(DB::connection(), $context, $origin, $this->f['order']->id)))->toThrow(LogicException::class);
|
||||
}
|
||||
expect(DB::table('budget_entries')->orderBy('id')->get()->toJson())->toBe($before)
|
||||
->and($this->f['r']->fresh()->status)->toBe('approved');
|
||||
});
|
||||
|
||||
test('standalone candidate closes an old reservation cycle and reserves a revised amount once without rewriting history', function () {
|
||||
$finance = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id,
|
||||
'purchasing_role' => PurchasingRole::Finance]);
|
||||
|
||||
Reference in New Issue
Block a user