From 1feff63c1be8c0a135be26fdb7522bc102e5431a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 25 Mar 2024 09:42:10 +1100 Subject: [PATCH] Add stale gateway fee checks --- .../Subscription/CleanStaleInvoiceOrder.php | 21 +++++++++++++------ app/Services/Invoice/InvoiceService.php | 6 ------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Jobs/Subscription/CleanStaleInvoiceOrder.php b/app/Jobs/Subscription/CleanStaleInvoiceOrder.php index aacd7b32d03a..d7ba6fc3b691 100644 --- a/app/Jobs/Subscription/CleanStaleInvoiceOrder.php +++ b/app/Jobs/Subscription/CleanStaleInvoiceOrder.php @@ -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(); - } - + $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(); + }); + } } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index c89c246a49da..9378593f1208 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -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');