Add touchPdf() to Credit Service

This commit is contained in:
David Bomba 2022-01-19 15:32:04 +11:00
parent 8cff663d52
commit 57ea035c62
2 changed files with 37 additions and 1 deletions

View File

@ -12,6 +12,7 @@
namespace App\Services\Credit; namespace App\Services\Credit;
use App\Factory\PaymentFactory; use App\Factory\PaymentFactory;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Util\UnlinkFile; use App\Jobs\Util\UnlinkFile;
use App\Models\Credit; use App\Models\Credit;
use App\Models\Payment; use App\Models\Payment;
@ -98,6 +99,8 @@ class CreditService
if($this->credit->balance > 0) if($this->credit->balance > 0)
return $this; return $this;
$this->markSent();
$payment_repo = new PaymentRepository(new CreditRepository()); $payment_repo = new PaymentRepository(new CreditRepository());
//set credit balance to zero //set credit balance to zero
@ -132,6 +135,7 @@ class CreditService
->client ->client
->service() ->service()
->updatePaidToDate($adjustment) ->updatePaidToDate($adjustment)
->setStatus(Credit::STATUS_APPLIED)
->save(); ->save();
event('eloquent.created: App\Models\Payment', $payment); event('eloquent.created: App\Models\Payment', $payment);
@ -176,6 +180,38 @@ class CreditService
return $this; 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() public function fillDefaults()
{ {
$settings = $this->credit->client->getMergedSettings(); $settings = $this->credit->client->getMergedSettings();

View File

@ -42,7 +42,7 @@ class MarkSent
->setStatus(Credit::STATUS_SENT) ->setStatus(Credit::STATUS_SENT)
->applyNumber() ->applyNumber()
->adjustBalance($this->credit->amount) ->adjustBalance($this->credit->amount)
->deletePdf() ->touchPdf()
->save(); ->save();
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));