From 57ea035c62318600e964a06859e29340cf0a2785 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Jan 2022 15:32:04 +1100 Subject: [PATCH] Add touchPdf() to Credit Service --- app/Services/Credit/CreditService.php | 36 +++++++++++++++++++++++++++ app/Services/Credit/MarkSent.php | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 22bd94a56448..465fd522f524 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -12,6 +12,7 @@ namespace App\Services\Credit; use App\Factory\PaymentFactory; +use App\Jobs\Entity\CreateEntityPdf; use App\Jobs\Util\UnlinkFile; use App\Models\Credit; use App\Models\Payment; @@ -98,6 +99,8 @@ class CreditService if($this->credit->balance > 0) return $this; + $this->markSent(); + $payment_repo = new PaymentRepository(new CreditRepository()); //set credit balance to zero @@ -132,6 +135,7 @@ class CreditService ->client ->service() ->updatePaidToDate($adjustment) + ->setStatus(Credit::STATUS_APPLIED) ->save(); event('eloquent.created: App\Models\Payment', $payment); @@ -176,6 +180,38 @@ class CreditService return $this; } + /** + * Sometimes we need to refresh the + * PDF when it is updated etc. + * @return InvoiceService + */ + public function touchPdf($force = false) + { + try { + + if($force){ + + $this->credit->invitations->each(function ($invitation) { + CreateEntityPdf::dispatchNow($invitation); + }); + + return $this; + } + + $this->credit->invitations->each(function ($invitation) { + CreateEntityPdf::dispatch($invitation); + }); + + } + catch(\Exception $e){ + + nlog("failed creating invoices in Touch PDF"); + + } + + return $this; + } + public function fillDefaults() { $settings = $this->credit->client->getMergedSettings(); diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index b02e85e50dec..1a39b3960c91 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -42,7 +42,7 @@ class MarkSent ->setStatus(Credit::STATUS_SENT) ->applyNumber() ->adjustBalance($this->credit->amount) - ->deletePdf() + ->touchPdf() ->save(); event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));