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

View File

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