From f6f9bccdb467db3182408fd523bc4715b4cd7da5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 8 Jan 2022 20:16:21 +1100 Subject: [PATCH 1/6] Increased precision for unit cost --- app/Helpers/Invoice/InvoiceItemSum.php | 1 - app/Utils/Number.php | 57 +++++++++++++++++++++++++ app/Utils/Traits/MakesInvoiceValues.php | 4 +- app/Utils/Traits/NumberFormatter.php | 6 ++- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index ba20fb2712b1..8866b99ae0b5 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -256,7 +256,6 @@ class InvoiceItemSum //$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)); $amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0; - $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); $item_tax += $item_tax_rate1_total; diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 8e956a7bf66f..69383dbb8384 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -142,4 +142,61 @@ class Number return self::formatValue($value, $currency); } } + +/** + * Formats a given value based on the clients currency AND country. + * + * @param floatval $value The number to be formatted + * @param $entity + * @return string The formatted value + */ + public static function formatMoneyNoRounding($value, $entity) :string + { + $currency = $entity->currency(); + + $thousand = $currency->thousand_separator; + $decimal = $currency->decimal_separator; + $precision = $currency->precision; + $code = $currency->code; + $swapSymbol = $currency->swap_currency_symbol; + + if ($entity instanceof Company) { + $country = $entity->country(); + } else { + $country = $entity->country; + } + + /* Country settings override client settings */ + if (isset($country->thousand_separator) && strlen($country->thousand_separator) >= 1) { + $thousand = $country->thousand_separator; + } + + if (isset($country->decimal_separator) && strlen($country->decimal_separator) >= 1) { + $decimal = $country->decimal_separator; + } + + if (isset($country->swap_currency_symbol) && strlen($country->swap_currency_symbol) >= 1) { + $swapSymbol = $country->swap_currency_symbol; + } + + /* 08-01-2022 allow increased precision for unit price*/ + $v = rtrim(sprintf('%f', $value),"0"); + $precision = strlen(substr(strrchr($v, $decimal), 1)); + + $value = number_format($v, $precision, $decimal, $thousand); + $symbol = $currency->symbol; + + if ($entity->getSetting('show_currency_code') === true && $currency->code == 'CHF') { + return "{$code} {$value}"; + } elseif ($entity->getSetting('show_currency_code') === true) { + return "{$value} {$code}"; + } elseif ($swapSymbol) { + return "{$value} ".trim($symbol); + } elseif ($entity->getSetting('show_currency_code') === false) { + return "{$symbol}{$value}"; + } else { + return self::formatValue($value, $currency); + } + } + } diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index f284bcae9458..8ba43416d1fe 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -306,8 +306,8 @@ trait MakesInvoiceValues //change quantity from localized number, to decimal format with no trailing zeroes 06/09/21 $data[$key][$table_type.'.quantity'] = rtrim($item->quantity, $locale_info['decimal_point']); - $data[$key][$table_type.'.unit_cost'] = Number::formatMoney($item->cost, $this->client); - $data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client); + $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->client); + $data[$key][$table_type.'.cost'] = Number::formatMoneyNoRounding($item->cost, $this->client); $data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client); diff --git a/app/Utils/Traits/NumberFormatter.php b/app/Utils/Traits/NumberFormatter.php index 9b58d80af2a0..3cb14bf6ddb7 100644 --- a/app/Utils/Traits/NumberFormatter.php +++ b/app/Utils/Traits/NumberFormatter.php @@ -18,7 +18,11 @@ trait NumberFormatter { private function formatValue($value, $precision) : string { - return number_format($this->parseFloat($value), $precision, '.', ''); + /* 08-01-2022 allow increased precision means we need to transform from scientific notation to a regular string */ + + return number_format($this->parseFloat(rtrim(sprintf('%f', $value),"0")), $precision, '.', ''); + + // return number_format($this->parseFloat($value), $precision, '.', ''); } /** From 762f6d4b2ec6123f60b1f42f719dc40c7ba31efe Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 9 Jan 2022 13:34:23 +1100 Subject: [PATCH 2/6] Minor adjustments for mollie payment driver --- app/Http/Requests/Payments/PaymentWebhookRequest.php | 9 +++++++-- app/PaymentDrivers/MolliePaymentDriver.php | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index ef805d1367bd..eb6bf11a5b8c 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -27,8 +27,6 @@ class PaymentWebhookRequest extends Request public function authorize() { - MultiDB::findAndSetDbByCompanyKey($this->company_key); - return true; } @@ -47,6 +45,8 @@ class PaymentWebhookRequest extends Request */ public function getCompanyGateway() { + MultiDB::findAndSetDbByCompanyKey($this->company_key); + return CompanyGateway::withTrashed()->findOrFail($this->decodePrimaryKey($this->company_gateway_id)); } @@ -59,6 +59,9 @@ class PaymentWebhookRequest extends Request public function getPaymentHash() { if ($this->query('hash')) { + + MultiDB::findAndSetDbByCompanyKey($this->company_key); + return PaymentHash::where('hash', $this->query('hash'))->firstOrFail(); } @@ -72,6 +75,8 @@ class PaymentWebhookRequest extends Request */ public function getCompany(): ?Company { + MultiDB::findAndSetDbByCompanyKey($this->company_key); + return Company::where('company_key', $this->company_key)->firstOrFail(); } } diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index f13c747e9480..bab3adcf2e59 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -304,6 +304,8 @@ class MolliePaymentDriver extends BaseDriver 'paid' => Payment::STATUS_COMPLETED, ]; + nlog($request->id); + try { $payment = $this->gateway->payments->get($request->id); $record = Payment::withTrashed()->where('transaction_reference', $request->id)->first(); From 8ee1e8ca9d93e7b1d55df2f6c9ab70756faebad7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 9 Jan 2022 13:53:27 +1100 Subject: [PATCH 3/6] Ensure PDFs are created when sending recurring invoices --- app/Jobs/RecurringInvoice/SendRecurring.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 8db0d968c122..f688ec47dcd2 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -93,6 +93,9 @@ class SendRecurring implements ShouldQueue } $invoice = $this->createRecurringInvitations($invoice); + + /* 09-01-2022 ensure we create the PDFs at this point in time! */ + $invoice->service()->touchPdf(); nlog("updating recurring invoice dates"); /* Set next date here to prevent a recurring loop forming */ From 406d6b8d087d70be06ca22e19fd85bfee71726be Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 9 Jan 2022 15:59:14 +1100 Subject: [PATCH 4/6] Fixes for endless reminders --- app/Jobs/Util/ReminderJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 947d12cccf4c..93c61e7482cd 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -81,7 +81,7 @@ class ReminderJob implements ShouldQueue $invoice = $this->calcLateFee($invoice, $reminder_template); //check if this reminder needs to be emailed - if(in_array($reminder_template, ['reminder1','reminder2','reminder3']) && $invoice->client->getSetting("enable_".$reminder_template)) + if(in_array($reminder_template, ['reminder1','reminder2','reminder3','reminder_endless']) && $invoice->client->getSetting("enable_".$reminder_template)) { $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); From ab6a941080b8d26761e028e56aa96873c26e33c9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 9 Jan 2022 16:00:06 +1100 Subject: [PATCH 5/6] v5.3.43 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 93a75a086973..bb5c61465643 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.42 \ No newline at end of file +5.3.43 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index c3656dce7023..01e71b7bf538 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.42', - 'app_tag' => '5.3.42', + 'app_version' => '5.3.43', + 'app_tag' => '5.3.43', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), From d914738128a24a4e848f77550592e999c0fa3167 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 9 Jan 2022 16:02:04 +1100 Subject: [PATCH 6/6] Minor fixes for postmark message query --- app/Http/Controllers/PostMarkController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PostMarkController.php b/app/Http/Controllers/PostMarkController.php index 5401808119a0..6646f1724327 100644 --- a/app/Http/Controllers/PostMarkController.php +++ b/app/Http/Controllers/PostMarkController.php @@ -231,13 +231,13 @@ class PostMarkController extends BaseController { $invitation = false; - if($invitation = InvoiceInvitation::whereRaw('BINARY `message_id`= ?', [$message_id])->first()) + if($invitation = InvoiceInvitation::where('message_id', $message_id)->first()) return $invitation; - elseif($invitation = QuoteInvitation::whereRaw('BINARY `message_id`= ?', [$message_id])->first()) + elseif($invitation = QuoteInvitation::where('message_id', $message_id)->first()) return $invitation; - elseif($invitation = RecurringInvoiceInvitation::whereRaw('BINARY `message_id`= ?', [$message_id])->first()) + elseif($invitation = RecurringInvoiceInvitation::where('message_id', $message_id)->first()) return $invitation; - elseif($invitation = CreditInvitation::whereRaw('BINARY `message_id`= ?', [$message_id])->first()) + elseif($invitation = CreditInvitation::where('message_id', $message_id)->first()) return $invitation; else return $invitation;