From aae986333a4b6dcbcc487ef03f5a2f43f0e8b5a2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 Mar 2023 11:51:07 +1100 Subject: [PATCH] Updates for migration vendors --- app/Jobs/Util/Import.php | 4 ++ app/Mail/Engine/PaymentEmailEngine.php | 6 +-- app/Utils/HtmlEngine.php | 2 - app/Utils/TemplateEngine.php | 55 +++++++++++++++++--------- app/Utils/VendorHtmlEngine.php | 2 +- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 4d12e8948d14..ecfb43a5f96c 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -811,6 +811,10 @@ class Import implements ShouldQueue $modified['updated_at'] = Carbon::parse($modified['updated_at']); } + if(!array_key_exists('currency_id', $modified) || !$modified['currency_id']) { + $modified['currency_id'] = $this->company->settings->currency_id; + } + $vendor = $vendor_repository->save( $modified, VendorFactory::create( diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 353dfbfb810d..1b274fca2353 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -362,10 +362,10 @@ class PaymentEmailEngine extends BaseEmailEngine /** * generateLabelsAndValues - * - * @return void + * + * @return array */ - public function generateLabelsAndValues() + public function generateLabelsAndValues(): array { $data = []; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 3872ef95666e..c889bd675f58 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -683,8 +683,6 @@ class HtmlEngine $data['labels'][$key.'_label'] = $value['label']; } - // nlog($data); - return $data; } diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index ca10200a882e..778a0083fcfc 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -12,27 +12,28 @@ namespace App\Utils; -use App\DataMapper\EmailTemplateDefaults; -use App\Mail\Engine\PaymentEmailEngine; -use App\Models\Client; -use App\Models\ClientContact; -use App\Models\Invoice; -use App\Models\InvoiceInvitation; -use App\Models\Payment; -use App\Models\PurchaseOrder; -use App\Models\PurchaseOrderInvitation; -use App\Models\Quote; -use App\Models\QuoteInvitation; -use App\Models\Vendor; -use App\Models\VendorContact; -use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; -use App\Utils\Traits\MakesHash; -use App\Utils\Traits\MakesInvoiceHtml; -use App\Utils\Traits\MakesTemplateData; use DB; -use Illuminate\Support\Facades\App; +use App\Models\Quote; +use App\Models\Client; +use App\Models\Vendor; +use App\Models\Invoice; +use App\Models\Payment; use Illuminate\Support\Str; +use App\Models\ClientContact; +use App\Models\PurchaseOrder; +use App\Models\VendorContact; +use App\Services\Pdf\PdfMock; +use App\Models\QuoteInvitation; +use App\Utils\Traits\MakesHash; +use App\Models\InvoiceInvitation; +use Illuminate\Support\Facades\App; +use App\Utils\Traits\MakesInvoiceHtml; +use App\Mail\Engine\PaymentEmailEngine; +use App\Models\PurchaseOrderInvitation; +use App\Utils\Traits\MakesTemplateData; +use App\DataMapper\EmailTemplateDefaults; use League\CommonMark\CommonMarkConverter; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; class TemplateEngine { @@ -96,7 +97,19 @@ class TemplateEngine if (strlen($this->entity) > 1 && strlen($this->entity_id) > 1) { $class = 'App\Models\\' . ucfirst(Str::camel($this->entity)); $this->entity_obj = $class::withTrashed()->where('id', $this->decodePrimaryKey($this->entity_id))->company()->first(); - } else { + } + elseif(stripos($this->template, 'quote') !== false && $quote = Quote::whereHas('invitations')->withTrashed()->company()->first()){ + $this->entity = 'quote'; + $this->entity_obj = $quote; + } + elseif(stripos($this->template, 'purchase') !== false && $purchase_order = PurchaseOrder::whereHas('invitations')->withTrashed()->company()->first()){ + $this->entity = 'purchase_order'; + $this->entity_obj = $purchase_order; + } + elseif ($invoice = Invoice::whereHas('invitations')->withTrashed()->company()->first()){ + $this->entity_obj = $invoice; + } + else { $this->mockEntity(); } @@ -183,6 +196,7 @@ class TemplateEngine private function entityValues($contact) { + if (in_array($this->entity, ['purchaseOrder', 'purchase_order'])) { $this->labels_and_values = (new VendorHtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues(); } elseif ($this->entity == 'payment') { @@ -323,6 +337,8 @@ class TemplateEngine 'user_id' => auth()->user()->id, 'company_id' => auth()->user()->company()->id, 'client_id' => $client->id, + 'amount' => '10', + 'balance' => '10', ]); $invitation = InvoiceInvitation::factory()->create([ @@ -391,6 +407,7 @@ class TemplateEngine $this->entity_obj->load('client'); $client->setRelation('company', auth()->user()->company()); $client->load('company'); + } } diff --git a/app/Utils/VendorHtmlEngine.php b/app/Utils/VendorHtmlEngine.php index 4eac57ac59bc..aab9b9fb3302 100644 --- a/app/Utils/VendorHtmlEngine.php +++ b/app/Utils/VendorHtmlEngine.php @@ -511,7 +511,7 @@ class VendorHtmlEngine $data['values'][$key] = $value['value']; $data['labels'][$key.'_label'] = $value['label']; } -nlog($data); + return $data; }