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');