2020-03-26 04:23:57 +01:00
|
|
|
<?php
|
2022-09-09 01:12:43 +02:00
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-03-26 04:23:57 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-03-26 04:23:57 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-03-26 04:23:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
use App\DataMapper\EmailTemplateDefaults;
|
2022-10-27 11:17:31 +02:00
|
|
|
use App\Mail\Engine\PaymentEmailEngine;
|
2020-10-01 23:29:11 +02:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceInvitation;
|
2022-10-27 11:17:31 +02:00
|
|
|
use App\Models\Payment;
|
2022-06-30 08:40:31 +02:00
|
|
|
use App\Models\PurchaseOrder;
|
|
|
|
use App\Models\PurchaseOrderInvitation;
|
2021-11-08 04:09:06 +01:00
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Models\QuoteInvitation;
|
2022-06-30 08:40:31 +02:00
|
|
|
use App\Models\Vendor;
|
|
|
|
use App\Models\VendorContact;
|
2021-04-13 16:43:35 +02:00
|
|
|
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
|
2021-04-16 08:22:42 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-03-26 04:23:57 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
|
|
use App\Utils\Traits\MakesTemplateData;
|
2022-06-30 11:41:44 +02:00
|
|
|
use App\Utils\VendorHtmlEngine;
|
2020-10-28 11:10:49 +01:00
|
|
|
use DB;
|
2021-04-16 08:22:42 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Illuminate\Support\Facades\Lang;
|
2022-06-30 08:40:31 +02:00
|
|
|
use Illuminate\Support\Str;
|
2020-03-26 04:23:57 +01:00
|
|
|
use League\CommonMark\CommonMarkConverter;
|
2021-04-13 16:43:35 +02:00
|
|
|
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
class TemplateEngine
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use MakesTemplateData;
|
|
|
|
use MakesInvoiceHtml;
|
|
|
|
|
|
|
|
public $body;
|
|
|
|
|
|
|
|
public $subject;
|
|
|
|
|
|
|
|
public $entity;
|
|
|
|
|
|
|
|
public $entity_id;
|
|
|
|
|
|
|
|
public $template;
|
|
|
|
|
|
|
|
private $entity_obj;
|
|
|
|
|
|
|
|
private $settings_entity;
|
|
|
|
|
2020-09-18 14:27:20 +02:00
|
|
|
private $settings;
|
|
|
|
|
2021-01-19 01:46:00 +01:00
|
|
|
private $raw_body;
|
|
|
|
|
|
|
|
private $raw_subject;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-04-22 12:29:00 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $labels_and_values;
|
2021-01-19 01:46:00 +01:00
|
|
|
|
2020-03-26 09:25:44 +01:00
|
|
|
public function __construct($body, $subject, $entity, $entity_id, $template)
|
2020-03-26 04:23:57 +01:00
|
|
|
{
|
|
|
|
$this->body = $body;
|
|
|
|
|
|
|
|
$this->subject = $subject;
|
|
|
|
|
|
|
|
$this->entity = $entity;
|
|
|
|
|
|
|
|
$this->entity_id = $entity_id;
|
|
|
|
|
|
|
|
$this->template = $template;
|
|
|
|
|
|
|
|
$this->entity_obj = null;
|
|
|
|
|
|
|
|
$this->settings_entity = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function build()
|
|
|
|
{
|
2022-07-01 10:35:52 +02:00
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
return $this->setEntity()
|
2022-09-09 01:12:43 +02:00
|
|
|
->setSettingsObject()
|
|
|
|
->setTemplates()
|
|
|
|
->replaceValues()
|
|
|
|
->renderTemplate();
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function setEntity()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (strlen($this->entity) > 1 && strlen($this->entity_id) > 1) {
|
2022-09-09 01:12:43 +02:00
|
|
|
$class = 'App\Models\\' . ucfirst(Str::camel($this->entity));
|
2021-02-26 12:20:17 +01:00
|
|
|
$this->entity_obj = $class::withTrashed()->where('id', $this->decodePrimaryKey($this->entity_id))->company()->first();
|
2020-11-25 15:19:52 +01:00
|
|
|
} else {
|
2020-10-01 23:29:11 +02:00
|
|
|
$this->mockEntity();
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function setSettingsObject()
|
|
|
|
{
|
2022-09-09 01:12:43 +02:00
|
|
|
if ($this->entity == 'purchaseOrder' || $this->entity == 'purchase_order') {
|
2022-06-30 08:40:31 +02:00
|
|
|
$this->settings_entity = auth()->user()->company();
|
|
|
|
$this->settings = $this->settings_entity->settings;
|
2022-09-09 01:12:43 +02:00
|
|
|
} elseif ($this->entity_obj->client()->exists()) {
|
2020-03-26 04:23:57 +01:00
|
|
|
$this->settings_entity = $this->entity_obj->client;
|
2020-09-18 14:27:20 +02:00
|
|
|
$this->settings = $this->settings_entity->getMergedSettings();
|
2020-03-26 04:23:57 +01:00
|
|
|
} else {
|
|
|
|
$this->settings_entity = auth()->user()->company();
|
2020-09-18 14:27:20 +02:00
|
|
|
$this->settings = $this->settings_entity->settings;
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
2021-04-16 08:22:42 +02:00
|
|
|
App::forgetInstance('translator');
|
2021-05-31 12:40:34 +02:00
|
|
|
$t = app('translator');
|
|
|
|
$t->replace(Ninja::transformTranslations($this->settings));
|
2021-04-16 08:22:42 +02:00
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the body / subject are not populated we need to get the defaults */
|
|
|
|
private function setTemplates()
|
|
|
|
{
|
2020-03-26 09:25:44 +01:00
|
|
|
if (strlen($this->subject) == 0 && strlen($this->template) > 1) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$subject_template = str_replace('template', 'subject', $this->template);
|
2020-09-17 00:22:23 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (strlen($this->settings_entity->getSetting($subject_template)) > 1) {
|
2020-09-17 00:22:23 +02:00
|
|
|
$this->subject = $this->settings_entity->getSetting($subject_template);
|
2020-11-25 15:19:52 +01:00
|
|
|
} else {
|
2020-09-17 00:22:23 +02:00
|
|
|
$this->subject = EmailTemplateDefaults::getDefaultTemplate($subject_template, $this->settings_entity->locale());
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 09:25:44 +01:00
|
|
|
if (strlen($this->body) == 0 && strlen($this->template) > 1) {
|
2020-11-25 15:19:52 +01:00
|
|
|
if (strlen($this->settings_entity->getSetting($this->template)) > 1) {
|
2020-09-17 00:22:23 +02:00
|
|
|
$this->body = $this->settings_entity->getSetting($this->template);
|
2020-11-25 15:19:52 +01:00
|
|
|
} else {
|
2020-09-17 00:22:23 +02:00
|
|
|
$this->body = EmailTemplateDefaults::getDefaultTemplate($this->template, $this->settings_entity->locale());
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2021-04-20 13:31:21 +02:00
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function replaceValues()
|
|
|
|
{
|
2021-01-19 01:46:00 +01:00
|
|
|
$this->raw_body = $this->body;
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->raw_subject = $this->subject;
|
2021-01-19 01:46:00 +01:00
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
if ($this->entity_obj->client()->exists()) {
|
2020-04-16 10:41:25 +02:00
|
|
|
$this->entityValues($this->entity_obj->client->primary_contact()->first());
|
2022-09-09 01:12:43 +02:00
|
|
|
} elseif ($this->entity_obj->vendor()->exists()) {
|
|
|
|
$this->entityValues($this->entity_obj->vendor->primary_contact()->first());
|
|
|
|
} else {
|
2020-03-26 04:23:57 +01:00
|
|
|
$this->fakerValues();
|
2020-03-26 09:25:44 +01:00
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function fakerValues()
|
|
|
|
{
|
|
|
|
$labels = $this->makeFakerLabels();
|
|
|
|
$values = $this->makeFakerValues();
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
$this->body = strtr($this->body, $labels);
|
|
|
|
$this->body = strtr($this->body, $values);
|
|
|
|
|
|
|
|
$this->subject = strtr($this->subject, $labels);
|
|
|
|
$this->subject = strtr($this->subject, $values);
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
|
|
|
|
2022-07-04 06:41:16 +02:00
|
|
|
$this->body = $converter->convert($this->body)->getContent();
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
private function entityValues($contact)
|
2020-03-26 04:23:57 +01:00
|
|
|
{
|
2022-09-09 01:12:43 +02:00
|
|
|
if (in_array($this->entity, ['purchaseOrder', 'purchase_order']))
|
2022-06-30 11:41:44 +02:00
|
|
|
$this->labels_and_values = (new VendorHtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues();
|
2022-10-27 11:17:31 +02:00
|
|
|
elseif($this->entity == 'payment')
|
|
|
|
$this->labels_and_values = (new PaymentEmailEngine($this->entity_obj, $this->entity_obj->client->contacts->first()))->generateLabelsAndValues();
|
2022-06-30 11:41:44 +02:00
|
|
|
else
|
|
|
|
$this->labels_and_values = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues();
|
2020-10-28 06:50:06 +01:00
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
|
2021-04-22 12:29:00 +02:00
|
|
|
$this->body = strtr($this->body, $this->labels_and_values['labels']);
|
|
|
|
$this->body = strtr($this->body, $this->labels_and_values['values']);
|
2021-01-19 01:46:00 +01:00
|
|
|
|
2021-04-22 12:29:00 +02:00
|
|
|
$this->subject = strtr($this->subject, $this->labels_and_values['labels']);
|
|
|
|
$this->subject = strtr($this->subject, $this->labels_and_values['values']);
|
|
|
|
|
|
|
|
$email_style = $this->settings_entity->getSetting('email_style');
|
|
|
|
|
|
|
|
if ($email_style !== 'custom') {
|
|
|
|
$this->body = DesignHelpers::parseMarkdownToHtml($this->body);
|
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTemplate()
|
|
|
|
{
|
|
|
|
/* wrapper */
|
|
|
|
$email_style = $this->settings_entity->getSetting('email_style');
|
|
|
|
|
|
|
|
$data['title'] = '';
|
|
|
|
$data['body'] = '$body';
|
|
|
|
$data['footer'] = '';
|
2021-06-15 15:42:37 +02:00
|
|
|
$data['logo'] = auth()->user()->company()->present()->logo();
|
2020-10-28 11:10:49 +01:00
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
if ($this->entity_obj->client()->exists())
|
2022-06-30 08:40:31 +02:00
|
|
|
$data = array_merge($data, Helpers::sharedEmailVariables($this->entity_obj->client));
|
2022-09-09 01:12:43 +02:00
|
|
|
else {
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
$data['signature'] = $this->settings->email_signature;
|
|
|
|
$data['settings'] = $this->settings;
|
|
|
|
$data['whitelabel'] = $this->entity_obj ? $this->entity_obj->company->account->isPaid() : true;
|
|
|
|
$data['company'] = $this->entity_obj ? $this->entity_obj->company : '';
|
|
|
|
$data['settings'] = $this->settings;
|
|
|
|
}
|
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
if ($email_style == 'custom') {
|
|
|
|
$wrapper = $this->settings_entity->getSetting('email_style_custom');
|
2020-03-28 12:34:04 +01:00
|
|
|
|
2021-04-22 12:29:00 +02:00
|
|
|
// In order to parse variables such as $signature in the body,
|
|
|
|
// we need to replace strings with the values from HTMLEngine.
|
|
|
|
$wrapper = strtr($wrapper, $this->labels_and_values['values']);
|
|
|
|
|
2020-03-28 12:34:04 +01:00
|
|
|
/*If no custom design exists, send back a blank!*/
|
2020-04-04 12:32:42 +02:00
|
|
|
if (strlen($wrapper) > 1) {
|
2020-03-28 12:34:04 +01:00
|
|
|
$wrapper = $this->renderView($wrapper, $data);
|
2020-04-04 12:32:42 +02:00
|
|
|
} else {
|
2020-03-28 12:34:04 +01:00
|
|
|
$wrapper = '';
|
2020-04-04 12:32:42 +02:00
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif ($email_style == 'plain') {
|
2020-03-26 04:23:57 +01:00
|
|
|
$wrapper = view($this->getTemplatePath($email_style), $data)->render();
|
2021-01-20 13:18:17 +01:00
|
|
|
$injection = '';
|
2020-09-06 11:38:10 +02:00
|
|
|
$wrapper = str_replace('<head>', $injection, $wrapper);
|
2022-06-21 11:57:17 +02:00
|
|
|
} else {
|
2021-06-15 15:42:37 +02:00
|
|
|
$wrapper = view($this->getTemplatePath('client'), $data)->render();
|
|
|
|
$injection = '';
|
|
|
|
$wrapper = str_replace('<head>', $injection, $wrapper);
|
|
|
|
}
|
2020-03-26 04:23:57 +01:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'subject' => $this->subject,
|
2021-06-23 10:46:51 +02:00
|
|
|
'body' => $this->body,
|
2020-03-26 04:23:57 +01:00
|
|
|
'wrapper' => $wrapper,
|
2021-01-19 01:46:00 +01:00
|
|
|
'raw_body' => $this->raw_body,
|
2022-06-21 11:57:17 +02:00
|
|
|
'raw_subject' => $this->raw_subject,
|
2020-03-26 04:23:57 +01:00
|
|
|
];
|
2021-01-20 13:18:17 +01:00
|
|
|
|
2020-10-01 23:29:11 +02:00
|
|
|
$this->tearDown();
|
|
|
|
|
2020-03-26 04:23:57 +01:00
|
|
|
return $data;
|
|
|
|
}
|
2020-10-01 23:29:11 +02:00
|
|
|
|
|
|
|
private function mockEntity()
|
|
|
|
{
|
2022-09-09 01:12:43 +02:00
|
|
|
if (!$this->entity && $this->template && str_contains($this->template, 'purchase_order'))
|
2022-07-01 10:11:04 +02:00
|
|
|
$this->entity = 'purchaseOrder';
|
2022-10-27 11:17:31 +02:00
|
|
|
elseif(str_contains($this->template, 'payment'))
|
|
|
|
$this->entity = 'payment';
|
2022-06-30 11:41:44 +02:00
|
|
|
|
2021-06-24 13:52:02 +02:00
|
|
|
DB::connection(config('database.default'))->beginTransaction();
|
2020-10-01 23:29:11 +02:00
|
|
|
|
2022-06-30 08:40:31 +02:00
|
|
|
$vendor = false;
|
|
|
|
|
2020-10-01 23:29:11 +02:00
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
]);
|
2020-10-01 23:29:11 +02:00
|
|
|
|
|
|
|
$contact = ClientContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
'send_email' => true,
|
|
|
|
]);
|
|
|
|
|
2022-10-27 11:17:31 +02:00
|
|
|
if ($this->entity == 'payment') {
|
|
|
|
|
|
|
|
|
|
|
|
$this->entity_obj = Payment::factory()->create([
|
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'applied' => 10,
|
|
|
|
'refunded' => 5,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = Invoice::factory()->create([
|
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'balance' => 10,
|
|
|
|
'number' => rand(1,10000)
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invitation = InvoiceInvitation::factory()->create([
|
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'invoice_id' => $invoice->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->entity_obj->invoices()->attach($invoice->id, [
|
|
|
|
'amount' => 10,
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
if (!$this->entity || $this->entity == 'invoice') {
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->entity_obj = Invoice::factory()->create([
|
2020-10-01 23:29:11 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
]);
|
|
|
|
|
2021-11-08 04:09:06 +01:00
|
|
|
$invitation = InvoiceInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'invoice_id' => $this->entity_obj->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
2021-11-08 04:09:06 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->entity == 'quote') {
|
2021-11-08 04:09:06 +01:00
|
|
|
$this->entity_obj = Quote::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
]);
|
2021-11-08 04:09:06 +01:00
|
|
|
|
|
|
|
$invitation = QuoteInvitation::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'quote_id' => $this->entity_obj->id,
|
|
|
|
'client_contact_id' => $contact->id,
|
2021-11-08 04:09:06 +01:00
|
|
|
]);
|
|
|
|
}
|
2020-10-01 23:29:11 +02:00
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
if ($this->entity == 'purchaseOrder') {
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
$vendor = Vendor::factory()->create([
|
2022-09-09 01:12:43 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
]);
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
$contact = VendorContact::factory()->create([
|
2022-09-09 01:12:43 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'vendor_id' => $vendor->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
'send_email' => true,
|
|
|
|
]);
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
$this->entity_obj = PurchaseOrder::factory()->create([
|
2022-09-09 01:12:43 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'vendor_id' => $vendor->id,
|
|
|
|
]);
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
$invitation = PurchaseOrderInvitation::factory()->create([
|
2022-09-09 01:12:43 +02:00
|
|
|
'user_id' => auth()->user()->id,
|
|
|
|
'company_id' => auth()->user()->company()->id,
|
|
|
|
'purchase_order_id' => $this->entity_obj->id,
|
|
|
|
'vendor_contact_id' => $contact->id,
|
2022-06-30 08:40:31 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-09 01:12:43 +02:00
|
|
|
if ($vendor) {
|
2022-06-30 08:40:31 +02:00
|
|
|
|
|
|
|
$this->entity_obj->setRelation('invitations', $invitation);
|
|
|
|
$this->entity_obj->setRelation('vendor', $vendor);
|
|
|
|
$this->entity_obj->setRelation('company', auth()->user()->company());
|
|
|
|
$this->entity_obj->load('vendor');
|
|
|
|
$vendor->setRelation('company', auth()->user()->company());
|
|
|
|
$vendor->load('company');
|
2022-09-09 01:12:43 +02:00
|
|
|
} else {
|
2022-06-30 08:40:31 +02:00
|
|
|
$this->entity_obj->setRelation('invitations', $invitation);
|
|
|
|
$this->entity_obj->setRelation('client', $client);
|
|
|
|
$this->entity_obj->setRelation('company', auth()->user()->company());
|
|
|
|
$this->entity_obj->load('client');
|
|
|
|
$client->setRelation('company', auth()->user()->company());
|
|
|
|
$client->load('company');
|
|
|
|
}
|
2020-10-01 23:29:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function tearDown()
|
|
|
|
{
|
2021-06-24 13:52:02 +02:00
|
|
|
DB::connection(config('database.default'))->rollBack();
|
2020-10-01 23:29:11 +02:00
|
|
|
}
|
2020-03-26 09:25:44 +01:00
|
|
|
}
|