From ee785ca209940869429f0eb4abd80f0162114b66 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 28 Nov 2021 21:19:34 +1100 Subject: [PATCH 01/29] Minor fixes --- app/Http/Controllers/ClientPortal/NinjaPlanController.php | 3 ++- .../ClientPortal/Subscriptions/ShowPlanSwitchRequest.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index c9047f7ba6..ba817d4b57 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -71,7 +71,8 @@ class NinjaPlanController extends Controller { //harvest the current plan $data = []; - + $data['late_invoice'] = false; + if(MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); diff --git a/app/Http/Requests/ClientPortal/Subscriptions/ShowPlanSwitchRequest.php b/app/Http/Requests/ClientPortal/Subscriptions/ShowPlanSwitchRequest.php index 4c05a0fbab..0764ad47ee 100644 --- a/app/Http/Requests/ClientPortal/Subscriptions/ShowPlanSwitchRequest.php +++ b/app/Http/Requests/ClientPortal/Subscriptions/ShowPlanSwitchRequest.php @@ -17,6 +17,7 @@ class ShowPlanSwitchRequest extends FormRequest */ public function authorize() { + return (bool)$this->recurring_invoice->subscription->allow_plan_changes; } From 5060b39773112da472c78f73eecc99faace70358 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 28 Nov 2021 21:23:35 +1100 Subject: [PATCH 02/29] Uncomment pdf logging --- app/Jobs/Entity/CreateEntityPdf.php | 20 -------------------- app/Jobs/Entity/CreateRawPdf.php | 4 ++-- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index b7660e7bcb..41f788111f 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -115,9 +115,6 @@ class CreateEntityPdf implements ShouldQueue /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->client->getMergedSettings())); - $translate = microtime(true); - // nlog("Translate ". $translate - $start); - if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { return (new Phantom)->generate($this->invitation); } @@ -142,9 +139,6 @@ class CreateEntityPdf implements ShouldQueue $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->client->getSetting($entity_design_id)); - // if(!$this->company->account->hasFeature(Account::FEATURE_DIFFERENT_DESIGNS)) - // $entity_design_id = 2; - $design = Design::find($entity_design_id); /* Catch all in case migration doesn't pass back a valid design */ @@ -153,9 +147,6 @@ class CreateEntityPdf implements ShouldQueue $html = new HtmlEngine($this->invitation); - $design_time = microtime(true); - // nlog("Design ". $design_time - $translate); - if ($design->is_custom) { $options = [ 'custom_partials' => json_decode(json_encode($design->design), true) @@ -167,9 +158,6 @@ class CreateEntityPdf implements ShouldQueue $variables = $html->generateLabelsAndValues(); - $labels_time = microtime(true); - // nlog("Labels ". $labels_time - $design_time); - $state = [ 'template' => $template->elements([ 'client' => $this->client, @@ -192,10 +180,6 @@ class CreateEntityPdf implements ShouldQueue ->design($template) ->build(); - - $template_time = microtime(true); - // nlog("Template Build ". $template_time - $labels_time); - $pdf = null; try { @@ -215,10 +199,6 @@ class CreateEntityPdf implements ShouldQueue info($maker->getCompiledHTML()); } - - $pdf_time = microtime(true); - // nlog("PDF time " . $pdf_time - $template_time); - if ($pdf) { try{ diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index c2c28b0c23..585deb9dbe 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -188,9 +188,9 @@ class CreateRawPdf implements ShouldQueue nlog(print_r($e->getMessage(), 1)); } - // if (config('ninja.log_pdf_html')) { + if (config('ninja.log_pdf_html')) { info($maker->getCompiledHTML()); - // } + } if ($pdf) return $pdf; From fddd06ae9aec3be1e5cea4240ca8c69fdec70450 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 29 Nov 2021 07:43:54 +1100 Subject: [PATCH 03/29] Minor fixes for Required client info + Payment Failed Mailer --- app/Http/Livewire/RequiredClientInfo.php | 2 +- app/Jobs/Mail/PaymentFailedMailer.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php index 71f0ac4f57..06d3915fc8 100644 --- a/app/Http/Livewire/RequiredClientInfo.php +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -60,7 +60,7 @@ class RequiredClientInfo extends Component 'contact_first_name' => 'first_name', 'contact_last_name' => 'last_name', - // 'contact_email' => 'email', + 'contact_email' => 'email', // 'contact_phone' => 'phone', ]; diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php index da316645ae..dc053ef9b3 100644 --- a/app/Jobs/Mail/PaymentFailedMailer.php +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -23,6 +23,7 @@ use App\Models\Company; use App\Models\Invoice; use App\Models\PaymentHash; use App\Models\User; +use App\Utils\Traits\MakesHash; use App\Utils\Traits\Notifications\UserNotifies; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -35,7 +36,7 @@ use Illuminate\Support\Facades\Mail; class PaymentFailedMailer implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies; + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies, MakesHash; public ?PaymentHash $payment_hash; From a4da2b0428b1a2c4b94f5c19b00d7dcfc888abc3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 29 Nov 2021 15:57:22 +1100 Subject: [PATCH 04/29] Fixes for payment failure mailer --- app/Jobs/Mail/PaymentFailedMailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php index dc053ef9b3..9bdeafd638 100644 --- a/app/Jobs/Mail/PaymentFailedMailer.php +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -81,7 +81,7 @@ class PaymentFailedMailer implements ShouldQueue if($this->payment_hash){ $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); } //iterate through company_users From b8697863a6417388cd2ed5e4febcbd3795527fe5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 29 Nov 2021 21:59:48 +1100 Subject: [PATCH 05/29] Return payment if it exists --- app/PaymentDrivers/BaseDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index bd29febe30..6c1460a9f8 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -226,7 +226,7 @@ class BaseDriver extends AbstractPaymentDriver $_payment = Payment::where('transaction_reference', $data['transaction_reference']) ->where('client_id', $this->client->id) - ->exists(); + ->first(); if($_payment) return $_payment; From 5af0ad72e9ff952a6bdc15b50f39bf47b695910b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 30 Nov 2021 16:05:15 +1100 Subject: [PATCH 06/29] Fixes for recurring invoices where auto_email_invoice not set --- app/Jobs/Entity/EmailEntity.php | 6 ++++-- app/Mail/Engine/QuoteEmailEngine.php | 3 +-- app/Services/Invoice/InvoiceService.php | 4 ++++ app/Services/Quote/TriggeredActions.php | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index e2683196f5..53d4dfbd9e 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -112,6 +112,9 @@ class EmailEntity implements ShouldQueue App::setLocale($this->invitation->contact->preferredLocale()); $t->replace(Ninja::transformTranslations($this->settings)); + /* Mark entity sent */ + $this->entity->service()->markSent()->save(); + $nmo = new NinjaMailerObject; $nmo->mailable = new TemplateEmail($this->email_entity_builder, $this->invitation->contact, $this->invitation); $nmo->company = $this->company; @@ -124,8 +127,7 @@ class EmailEntity implements ShouldQueue NinjaMailerJob::dispatchNow($nmo); - /* Mark entity sent */ - $this->entity->service()->markSent()->save(); + } private function resolveEntityString() :string diff --git a/app/Mail/Engine/QuoteEmailEngine.php b/app/Mail/Engine/QuoteEmailEngine.php index 2d33077210..39342f8f60 100644 --- a/app/Mail/Engine/QuoteEmailEngine.php +++ b/app/Mail/Engine/QuoteEmailEngine.php @@ -64,7 +64,7 @@ class QuoteEmailEngine extends BaseEmailEngine [ 'quote' => $this->quote->number, 'company' => $this->quote->company->present()->name(), - 'amount' => Number::formatMoney($this->quote->balance, $this->client), + 'amount' => Number::formatMoney($this->quote->amount, $this->client), ], null, $this->client->locale() @@ -99,7 +99,6 @@ class QuoteEmailEngine extends BaseEmailEngine ->setViewText(ctrans('texts.view_quote')) ->setInvitation($this->invitation); - if ($this->client->getSetting('pdf_email_attachment') !== false && $this->quote->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { if(Ninja::isHosted()) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 153e5fd0bf..a310c635d3 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -483,6 +483,10 @@ class InvoiceService if(!isset($this->invoice->exchange_rate) && $this->invoice->client->currency()->id != (int) $this->invoice->company->settings->currency_id) $this->invoice->exchange_rate = $this->invoice->client->currency()->exchange_rate; + if($settings->counter_number_applied == 'when_saved'){ + $this->invoice->service()->applyNumber()->save(); + } + return $this; } diff --git a/app/Services/Quote/TriggeredActions.php b/app/Services/Quote/TriggeredActions.php index e1ec9a37a0..14d69b63fe 100644 --- a/app/Services/Quote/TriggeredActions.php +++ b/app/Services/Quote/TriggeredActions.php @@ -57,7 +57,10 @@ class TriggeredActions extends AbstractService { $reminder_template = $this->quote->calculateTemplate('quote'); - //$reminder_template = 'payment'; + // $reminder_template = 'email_template_quote'; + +// nlog($reminder_template); + $this->quote->invitations->load('contact.client.country', 'quote.client.country', 'quote.company')->each(function ($invitation) use ($reminder_template) { EmailEntity::dispatch($invitation, $this->quote->company, $reminder_template); From 5798efc0be4c1d5c86c3eecdb7da4a1e0744b4ea Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 30 Nov 2021 17:28:07 +1100 Subject: [PATCH 07/29] Remove expenses from documents in Client Portal --- app/Http/Livewire/DocumentsTable.php | 2 +- .../ninja2020/components/livewire/documents-table.blade.php | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/Http/Livewire/DocumentsTable.php b/app/Http/Livewire/DocumentsTable.php index 73fee5be01..6fb8bd644e 100644 --- a/app/Http/Livewire/DocumentsTable.php +++ b/app/Http/Livewire/DocumentsTable.php @@ -74,7 +74,7 @@ class DocumentsTable extends Component break; case 'expenses': - $this->query = $this->expenses(); + // $this->query = $this->expenses(); break; case 'invoices': diff --git a/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php b/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php index 3e5b8970eb..61beb2645a 100644 --- a/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php @@ -12,12 +12,6 @@ {{ ctrans('texts.credits') }} - -