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() Invoice::query()
->withTrashed() ->withTrashed()
->where('status_id', Invoice::STATUS_SENT) ->where('status_id', Invoice::STATUS_SENT)
->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(30)]) ->where('created_at', '<', now()->subMinutes(30))
->where('balance', '>', 0) ->where('balance', '>', 0)
->whereJsonContains('line_items', ['type_id' => '3'])
->cursor() ->cursor()
->each(function ($invoice) { ->each(function ($invoice) {
if (collect($invoice->line_items)->contains('type_id', 3)) {
$invoice->service()->removeUnpaidGatewayFees(); $invoice->service()->removeUnpaidGatewayFees();
}
}); });
return; return;
@ -86,6 +83,18 @@ class CleanStaleInvoiceOrder implements ShouldQueue
$invoice->is_proforma = false; $invoice->is_proforma = false;
$repo->delete($invoice); $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) { if ((int) $pre_count != (int) $post_count) {
$adjustment = $balance - $new_balance; $adjustment = $balance - $new_balance;
// $this->invoice
// ->client
// ->service()
// ->updateBalance($adjustment * -1)
// ->save();
$this->invoice $this->invoice
->ledger() ->ledger()
->updateInvoiceBalance($adjustment * -1, 'Adjustment for removing gateway fee'); ->updateInvoiceBalance($adjustment * -1, 'Adjustment for removing gateway fee');