Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,25 @@ public function reject(BankMatch $match): RedirectResponse
'reviewed_at' => now(),
]);

$match->transaction?->update([
'matching_status' => 'rejected',
'matching_reason' => __('bank-payments::imports.rejected'),
'matched_at' => now(),
]);
// Rejecting a candidate says this invoice is not the one; the money
// still arrived. The transfer stays in the queue with the candidates
// left, or with none for staff to assign by hand. Removing the
// transfer itself is the separate dismiss action.
$transaction = $match->transaction;

if ($transaction) {
$remaining = $transaction->matches()->where('status', 'proposed')->count();

$transaction->update([
'matching_status' => match (true) {
$remaining > 1 => 'ambiguous',
$remaining === 1 => 'review',
default => 'unmatched',
},
'matching_reason' => __('bank-payments::imports.rejected'),
'matched_at' => now(),
]);
}

return back()->with('success', __('bank-payments::imports.rejected'));
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/BankPayments/BankAssignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,36 @@ function bankAssignmentInvoice(): array
->and($transactions->where('source', 'csv'))->toHaveCount(1);
});

it('rejects one candidate invoice and keeps the transfer in the queue', function () {
bankAssignmentBoot();
$this->actingAs(Admin::factory()->create(), 'admin');
[, $first] = bankAssignmentInvoice();
[, $second] = bankAssignmentInvoice();
$transaction = bankAssignmentTransaction();

app(InvoiceMatcher::class)->match($transaction);

expect($transaction->fresh()->matching_status)->toBe('ambiguous');

$wrong = BankMatch::where('bank_transaction_id', $transaction->id)->where('invoice_id', $first->id)->firstOrFail();

$this->post(route('admin.bank-payments.matches.reject', $wrong))->assertSessionHas('success');

expect($wrong->fresh()->status)->toBe('rejected')
->and(BankMatch::where('invoice_id', $second->id)->value('status'))->toBe('proposed')
->and($transaction->fresh()->matching_status)->toBe('review');

$this->get(route('admin.bank-payments.matches.index'))
->assertOk()
->assertSee($second->invoice_num);

$last = BankMatch::where('bank_transaction_id', $transaction->id)->where('invoice_id', $second->id)->firstOrFail();

$this->post(route('admin.bank-payments.matches.reject', $last))->assertSessionHas('success');

expect($transaction->fresh()->matching_status)->toBe('unmatched');
});

it('restores a rejected transfer to the matching queue', function () {
bankAssignmentBoot();
$this->actingAs(Admin::factory()->create(), 'admin');
Expand Down
Loading