diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 99803ef0ce59..710fdfa76131 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -216,7 +216,7 @@ class PreviewController extends BaseController if(!$request->has('entity_id')) $entity_obj->service()->fillDefaults()->save(); - $entity_obj->load('client'); + $entity_obj->load('client.contacts','company'); App::forgetInstance('translator'); $t = app('translator'); diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 97d32bba5cf5..6fe7f9bb88f2 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -74,12 +74,15 @@ class EmailPayment implements ShouldQueue MultiDB::setDb($this->company->db); + $this->payment->load('invoices'); + $this->contact->load('client'); + $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); $invitation = null; - if($this->payment->invoices()->exists()) - $invitation = $this->payment->invoices()->first()->invitations()->first(); + if($this->payment->invoices && $this->payment->invoices->count() >=1) + $invitation = $this->payment->invoices->first()->invitations()->first(); $nmo = new NinjaMailerObject; $nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation); diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index ed36c8ae321f..7f4805e4185b 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -47,6 +47,7 @@ class PaymentEmailEngine extends BaseEmailEngine $this->company = $payment->company; $this->client = $payment->client; $this->contact = $contact ?: $this->client->primary_contact()->first(); + $this->contact->load('client.company'); $this->settings = $this->client->getMergedSettings(); $this->template_data = $template_data; $this->helpers = new Helpers(); diff --git a/app/Models/Client.php b/app/Models/Client.php index dfbba29ed506..5b1216e1178e 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -84,12 +84,12 @@ class Client extends BaseModel implements HasLocalePreference ]; protected $with = [ - 'gateway_tokens', - 'documents', - 'contacts.company', + // 'gateway_tokens', + // 'documents', + // 'contacts.company', // 'currency', // 'primary_contact', - 'country', + // 'country', // 'contacts', // 'shipping_country', // 'company', diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index f125d8fc7eb2..7812ad52af46 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -64,6 +64,10 @@ class Subscription extends BaseModel 'deleted_at' => 'timestamp', ]; + protected $with = [ + 'company', + ]; + public function service(): SubscriptionService { return new SubscriptionService($this);