From 9d6d6c225491521a6aaa819ccf388edf92e52d87 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 25 Sep 2024 09:16:26 +1000 Subject: [PATCH] Minor fixes --- app/Console/Commands/CheckData.php | 26 ++++++++++++++++++- app/Jobs/Company/CompanyImport.php | 6 ++--- app/Jobs/Mail/NinjaMailerJob.php | 14 ++++++++++ app/Mail/Admin/ClientUnsubscribedObject.php | 3 ++- app/Models/VendorContact.php | 12 ++++++++- app/Services/Email/Email.php | 14 ++++++++++ .../Transformers/InvoiceTransformer.php | 22 +++++++--------- .../auth/connect/session_expired.blade.php | 13 ++++++++++ 8 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 resources/views/auth/connect/session_expired.blade.php diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 65f74b2e49b8..05ec4984cb72 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -44,6 +44,7 @@ use App\Factory\ClientContactFactory; use App\Factory\VendorContactFactory; use App\Jobs\Company\CreateCompanyToken; use App\Models\RecurringInvoiceInvitation; +use App\Utils\Traits\CleanLineItems; use Symfony\Component\Console\Input\InputOption; /* @@ -80,10 +81,12 @@ Options: */ class CheckData extends Command { + use CleanLineItems; + /** * @var string */ - protected $signature = 'ninja:check-data {--database=} {--fix=} {--portal_url=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=} {--balance_status=} {--bank_transaction=}'; + protected $signature = 'ninja:check-data {--database=} {--fix=} {--portal_url=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=} {--balance_status=} {--bank_transaction=} {--line_items=}'; /** * @var string @@ -146,6 +149,10 @@ class CheckData extends Command $this->fixBankTransactions(); } + if($this->option('line_items')) { + $this->cleanInvoiceLineItems(); + } + $this->logMessage('Done: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE)); $this->logMessage('Total execution time in seconds: ' . (microtime(true) - $time_start)); @@ -1177,4 +1184,21 @@ class CheckData extends Command }); } + + public function cleanInvoiceLineItems() + { + Invoice::withTrashed()->cursor()->each(function ($invoice) { + $invoice->line_items = $this->cleanItems($invoice->line_items); + $invoice->saveQuietly(); + }); + + Credit::withTrashed()->cursor()->each(function ($invoice) { + $invoice->line_items = $this->cleanItems($invoice->line_items); + $invoice->saveQuietly(); + }); + + + } + + } diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index ef436ab0e764..c4f8589babb6 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -354,9 +354,9 @@ class CompanyImport implements ShouldQueue unlink($tmp_file); } - if(Storage::exists($this->file_location)) { - unlink(Storage::path($this->file_location)); - } + if(Storage::exists($this->file_location)) + Storage::delete($this->file_location); + } // diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 2cf7563ea483..855751670a4d 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -154,6 +154,20 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject)) ->send(); + } catch(\Symfony\Component\Mailer\Exception\TransportException $e){ + nlog("Mailer failed with a Transport Exception {$e->getMessage()}"); + + if(Ninja::isHosted() && $this->mailer == 'smtp'){ + $settings = $this->nmo->settings; + $settings->email_sending_method = 'default'; + $this->company->settings = $settings; + $this->company->save(); + } + + $this->fail(); + $this->cleanUpMailers(); + $this->logMailError($e->getMessage(), $this->company->clients()->first()); + } catch (\Symfony\Component\Mime\Exception\RfcComplianceException $e) { nlog("Mailer failed with a Logic Exception {$e->getMessage()}"); $this->fail(); diff --git a/app/Mail/Admin/ClientUnsubscribedObject.php b/app/Mail/Admin/ClientUnsubscribedObject.php index 0d1eb20135ca..aea513a6868e 100644 --- a/app/Mail/Admin/ClientUnsubscribedObject.php +++ b/app/Mail/Admin/ClientUnsubscribedObject.php @@ -13,13 +13,14 @@ namespace App\Mail\Admin; use App\Models\ClientContact; use App\Models\Company; +use App\Models\VendorContact; use App\Utils\Ninja; use Illuminate\Support\Facades\App; class ClientUnsubscribedObject { public function __construct( - public ClientContact $contact, + public ClientContact | VendorContact$contact, public Company $company, private bool $use_react_link = false ) { diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 8ea4dc2654cd..197ebddd33b3 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -203,7 +203,6 @@ class VendorContact extends Authenticatable implements HasLocalePreference { return $this ->withTrashed() - // ->company() ->where('id', $this->decodePrimaryKey($value)) ->firstOrFail(); } @@ -219,4 +218,15 @@ class VendorContact extends Authenticatable implements HasLocalePreference return $domain.'/vendor/key_login/'.$this->contact_key; } + + public function getAdminLink($use_react_link = false): string + { + return $use_react_link ? $this->getReactLink() : config('ninja.app_url'); + } + + private function getReactLink(): string + { + return config('ninja.react_url')."/#/vendors/{$this->vendor->hashed_id}"; + } + } diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 2e21bb8b4af7..76103ddd96e5 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -291,6 +291,20 @@ class Email implements ShouldQueue LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject)) ->send(); + } catch(\Symfony\Component\Mailer\Exception\TransportException $e){ + nlog("Mailer failed with a Transport Exception {$e->getMessage()}"); + + if(Ninja::isHosted() && $this->mailer == 'smtp'){ + $settings = $this->email_object->settings; + $settings->email_sending_method = 'default'; + $this->company->settings = $settings; + $this->company->save(); + } + + $this->fail(); + $this->cleanUpMailers(); + $this->logMailError($e->getMessage(), $this->company->clients()->first()); + } catch (\Symfony\Component\Mime\Exception\RfcComplianceException $e) { nlog("Mailer failed with a Logic Exception {$e->getMessage()}"); $this->fail(); diff --git a/app/Services/Quickbooks/Transformers/InvoiceTransformer.php b/app/Services/Quickbooks/Transformers/InvoiceTransformer.php index 595a12d5f8e6..b48492e66336 100644 --- a/app/Services/Quickbooks/Transformers/InvoiceTransformer.php +++ b/app/Services/Quickbooks/Transformers/InvoiceTransformer.php @@ -46,7 +46,7 @@ class InvoiceTransformer extends BaseTransformer 'public_notes' => data_get($qb_data, 'CustomerMemo.value', false), 'due_date' => data_get($qb_data, 'DueDate', null), 'po_number' => data_get($qb_data, 'PONumber', ""), - 'partial' => data_get($qb_data, 'Deposit', 0), + 'partial' => (float)data_get($qb_data, 'Deposit', 0), 'line_items' => $this->getLineItems(data_get($qb_data, 'Line', []), data_get($qb_data, 'ApplyTaxAfterDiscount', 'true')), 'payment_ids' => $this->getPayments($qb_data), 'status_id' => Invoice::STATUS_SENT, @@ -66,10 +66,9 @@ class InvoiceTransformer extends BaseTransformer foreach(data_get($qb_data, 'Line', []) as $line) { - nlog("iterating"); + if(data_get($line, 'DetailType.value') == 'DiscountLineDetail') { - nlog("found discount"); if(!isset($this->company->custom_fields->surcharge1)) { @@ -77,8 +76,7 @@ class InvoiceTransformer extends BaseTransformer $this->company->save(); } - nlog(data_get($line, 'Amount', 0) * -1); - return data_get($line, 'Amount', 0) * -1; + return (float)data_get($line, 'Amount', 0) * -1; } } @@ -100,7 +98,7 @@ class InvoiceTransformer extends BaseTransformer $totalTaxRate += $taxRate; } - return $totalTaxRate; + return (float)$totalTaxRate; } @@ -143,13 +141,13 @@ class InvoiceTransformer extends BaseTransformer $item = new InvoiceItem; $item->product_key = data_get($qb_item, 'SalesItemLineDetail.ItemRef.name', ''); $item->notes = data_get($qb_item,'Description', ''); - $item->quantity = data_get($qb_item,'SalesItemLineDetail.Qty', 0); - $item->cost = data_get($qb_item, 'SalesItemLineDetail.UnitPrice', 0); - $item->discount = data_get($item,'DiscountRate', data_get($qb_item,'DiscountAmount', 0)); + $item->quantity = (float)data_get($qb_item,'SalesItemLineDetail.Qty', 0); + $item->cost = (float)data_get($qb_item, 'SalesItemLineDetail.UnitPrice', 0); + $item->discount = (float)data_get($item,'DiscountRate', data_get($qb_item,'DiscountAmount', 0)); $item->is_amount_discount = data_get($qb_item,'DiscountAmount', 0) > 0 ? true : false; $item->type_id = stripos(data_get($qb_item, 'ItemAccountRef.name') ?? '', 'Service') !== false ? '2' : '1'; $item->tax_id = data_get($qb_item, 'TaxCodeRef.value', '') == 'NON' ? Product::PRODUCT_TYPE_EXEMPT : $item->type_id; - $item->tax_rate1 = data_get($qb_item, 'TxnTaxDetail.TaxLine.TaxLineDetail.TaxPercent', 0); + $item->tax_rate1 = (float)data_get($qb_item, 'TxnTaxDetail.TaxLine.TaxLineDetail.TaxPercent', 0); $item->tax_name1 = $item->tax_rate1 > 0 ? "Sales Tax" : ""; $items[] = (object)$item; } @@ -161,7 +159,7 @@ class InvoiceTransformer extends BaseTransformer $item->product_key = ctrans('texts.discount'); $item->notes = ctrans('texts.discount'); $item->quantity = 1; - $item->cost = data_get($qb_item, 'Amount', 0) * -1; + $item->cost = (float)data_get($qb_item, 'Amount', 0) * -1; $item->discount = 0; $item->is_amount_discount = true; $item->type_id = '1'; @@ -171,8 +169,6 @@ class InvoiceTransformer extends BaseTransformer } } - nlog($items); - return $items; } diff --git a/resources/views/auth/connect/session_expired.blade.php b/resources/views/auth/connect/session_expired.blade.php new file mode 100644 index 000000000000..726e6a7c8fe9 --- /dev/null +++ b/resources/views/auth/connect/session_expired.blade.php @@ -0,0 +1,13 @@ +@extends('layouts.ninja') +@section('meta_title', ctrans('texts.error')) + +@section('body') +
+
+ +
+ +

Your session has expired. Connection to Stripe has been cancelled. Please try again.

+ Click here to continue. +
+@endsection