From 264a4df13b58d38a7874c6ed3a1623986ca1ba92 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 24 Nov 2022 16:49:03 +1100 Subject: [PATCH] Adjustments for handling invoice deletion --- app/Jobs/Util/ReminderJob.php | 8 +++++--- app/Services/Credit/ApplyPayment.php | 2 +- app/Services/Invoice/ApplyPayment.php | 2 +- app/Services/Invoice/InvoiceService.php | 6 ++++-- tests/Feature/SubscriptionApiTest.php | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 8b8a4610d543..23875c3f6c9a 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -71,6 +71,8 @@ class ReminderJob implements ShouldQueue { nlog('Sending invoice reminders '.now()->format('Y-m-d h:i:s')); + set_time_limit(0); + Invoice::query() ->where('is_deleted', 0) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) @@ -90,7 +92,7 @@ class ReminderJob implements ShouldQueue nlog("reminder template = {$reminder_template}"); $invoice = $this->calcLateFee($invoice, $reminder_template); $invoice->service()->touchReminder($reminder_template)->save(); - $invoice->service()->touchPdf(); + $invoice->service()->touchPdf(true); //20-04-2022 fixes for endless reminders - generic template naming was wrong $enabled_reminder = 'enable_'.$reminder_template; @@ -107,7 +109,7 @@ class ReminderJob implements ShouldQueue (Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) { $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { - EmailEntity::dispatchSync($invitation, $invitation->company, $reminder_template); + EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); }); @@ -206,7 +208,7 @@ class ReminderJob implements ShouldQueue /**Refresh Invoice values*/ $invoice->calc()->getInvoice()->save(); $invoice->fresh(); - $invoice->service()->deletePdf(); + // $invoice->service()->deletePdf(); 24-11-2022 no need to delete here because we regenerate later anyway /* Refresh the client here to ensure the balance is fresh */ $client = $invoice->client; diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index a80264c7ecb4..b5df4be9e60f 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -147,7 +147,7 @@ class ApplyPayment event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); if ((int) $this->invoice->balance == 0) { - $this->invoice->service()->deletePdf(); + $this->invoice->service()->touchPdf(); $this->invoice = $this->invoice->fresh(); event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); } diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index d124c7f821d5..1c873aa11a22 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -103,7 +103,7 @@ class ApplyPayment extends AbstractService } }); - $this->invoice->service()->applyNumber()->workFlow()->save(); + $this->invoice->service()->applyNumber()->workFlow()->touchPdf()->save(); $transaction = [ 'invoice' => $this->invoice->transaction_event(), diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 6ee15254ccba..0717804d7048 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -112,10 +112,12 @@ class InvoiceService * @param Payment $payment The Payment * @param float $payment_amount The Payment amount * @return InvoiceService Parent class object + * @deprecated 24-11-2022 - cannot find any references to this method anywhere */ public function applyPayment(Payment $payment, float $payment_amount) { - $this->deletePdf(); + // $this->deletePdf(); + $this->invoice = $this->markSent(); $this->invoice = (new ApplyPayment($this->invoice, $payment, $payment_amount))->run(); @@ -218,7 +220,7 @@ class InvoiceService public function markDeleted() { $this->removeUnpaidGatewayFees(); - $this->deletePdf(); + // $this->deletePdf(); $this->invoice = (new MarkInvoiceDeleted($this->invoice))->run(); diff --git a/tests/Feature/SubscriptionApiTest.php b/tests/Feature/SubscriptionApiTest.php index 8cf835f9767f..86360680e510 100644 --- a/tests/Feature/SubscriptionApiTest.php +++ b/tests/Feature/SubscriptionApiTest.php @@ -83,7 +83,7 @@ class SubscriptionApiTest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true, 'name' => Str::random(5)]); + ])->post('/api/v1/subscriptions', ['product_ids' => $product->hashed_id, 'allow_cancellation' => true, 'name' => Str::random(5)]); // nlog($response); $response->assertStatus(200); @@ -98,7 +98,7 @@ class SubscriptionApiTest extends TestCase $response1 = $this ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token]) - ->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'name' => Str::random(5)]) + ->post('/api/v1/subscriptions', ['product_ids' => $product->hashed_id, 'name' => Str::random(5)]) ->assertStatus(200) ->json();