Fixes for recurring

This commit is contained in:
David Bomba 2021-04-30 09:01:56 +10:00
parent 6d1605f746
commit aba280d9ab
4 changed files with 33 additions and 2 deletions

View File

@ -60,6 +60,8 @@ class EmailEntity implements ShouldQueue
public $template_data; //The data to be merged into the template public $template_data; //The data to be merged into the template
public $tries = 1;
/** /**
* EmailEntity constructor. * EmailEntity constructor.
* *

View File

@ -94,7 +94,14 @@ class SendRecurring implements ShouldQueue
$invoice->invitations->each(function ($invitation) use ($invoice) { $invoice->invitations->each(function ($invitation) use ($invoice) {
if ($invitation->contact && strlen($invitation->contact->email) >=1) { if ($invitation->contact && strlen($invitation->contact->email) >=1) {
try{
EmailEntity::dispatch($invitation, $invoice->company); EmailEntity::dispatch($invitation, $invoice->company);
}
catch(\Exception $e) {
nlog($e->getMessage());
}
nlog("Firing email for invoice {$invoice->number}"); nlog("Firing email for invoice {$invoice->number}");
} }
}); });

View File

@ -395,9 +395,19 @@ class Invoice extends BaseModel
public function pdf_file_path($invitation = null, string $type = 'url') public function pdf_file_path($invitation = null, string $type = 'url')
{ {
if (! $invitation) { if (! $invitation) {
$invitation = $this->invitations->first();
if($this->invitations()->exists())
$invitation = $this->invitations()->first();
else{
$this->service()->createInvitations();
$invitation = $this->invitations()->first();
} }
}
if(!$invitation)
throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?');
$storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf'); $storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf');
if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) { if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) {

View File

@ -55,6 +55,16 @@ class CreateInvitations extends AbstractService
} }
}); });
if($this->invoice->invitations()->count() == 0) {
$contact = $this->createBlankContact();
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
$ii->invoice_id = $this->invoice->id;
$ii->client_contact_id = $contact->id;
$ii->save();
}
return $this->invoice; return $this->invoice;
} }
@ -65,5 +75,7 @@ class CreateInvitations extends AbstractService
$new_contact->contact_key = Str::random(40); $new_contact->contact_key = Str::random(40);
$new_contact->is_primary = true; $new_contact->is_primary = true;
$new_contact->save(); $new_contact->save();
return $new_contact;
} }
} }