Add stale gateway fee checks

This commit is contained in:
David Bomba 2024-03-25 09:42:10 +11:00
parent 1d07d48165
commit 1feff63c1b
2 changed files with 15 additions and 12 deletions

View File

@ -59,15 +59,12 @@ class CleanStaleInvoiceOrder implements ShouldQueue
Invoice::query()
->withTrashed()
->where('status_id', Invoice::STATUS_SENT)
->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(30)])
->where('created_at', '<', now()->subMinutes(30))
->where('balance', '>', 0)
->whereJsonContains('line_items', ['type_id' => '3'])
->cursor()
->each(function ($invoice) {
if (collect($invoice->line_items)->contains('type_id', 3)) {
$invoice->service()->removeUnpaidGatewayFees();
}
});
return;
@ -86,6 +83,18 @@ class CleanStaleInvoiceOrder implements ShouldQueue
$invoice->is_proforma = false;
$repo->delete($invoice);
});
Invoice::query()
->withTrashed()
->where('status_id', Invoice::STATUS_SENT)
->where('created_at', '<', now()->subMinutes(30))
->where('balance', '>', 0)
->whereJsonContains('line_items', ['type_id' => '3'])
->cursor()
->each(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees();
});
}
}

View File

@ -453,12 +453,6 @@ class InvoiceService
if ((int) $pre_count != (int) $post_count) {
$adjustment = $balance - $new_balance;
// $this->invoice
// ->client
// ->service()
// ->updateBalance($adjustment * -1)
// ->save();
$this->invoice
->ledger()
->updateInvoiceBalance($adjustment * -1, 'Adjustment for removing gateway fee');