diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php index 95672410ef15..c127d6f6e26e 100644 --- a/app/Models/SystemLog.php +++ b/app/Models/SystemLog.php @@ -104,7 +104,7 @@ class SystemLog extends Model public function resolveRouteBinding($value, $field = null) { if (is_numeric($value)) { - throw new ModelNotFoundException("Record with value {$value} not found"); + throw new \Illuminate\Database\Eloquent\ModelNotFoundException("Record with value {$value} not found"); } return $this diff --git a/app/Utils/Number.php b/app/Utils/Number.php index af7fb8f8b50e..87b99a80225a 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -49,6 +49,25 @@ class Number return number_format($value, $precision, $decimal, $thousand); } + /** + * Formats a given value based on the clients currency. + * + * @param float $value The number to be formatted + * @param object $currency The client currency object + * + * @return string The formatted value + */ + public static function formatValueNoTrailingZeroes($value, $currency) :string + { + $value = floatval($value); + + $thousand = $currency->thousand_separator; + $decimal = $currency->decimal_separator; + $precision = $currency->precision; + + return rtrim(rtrim(number_format($value, $precision, $decimal, $thousand), "0"),$decimal); + } + /** * Formats a given value based on the clients currency * BACK to a float. diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 7bfc420e8821..1cdb2f97b4a9 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -303,15 +303,10 @@ trait MakesInvoiceValues $data[$key][$table_type . ".{$_table_type}4"] = $helpers->formatCustomFieldValue($this->client->company->custom_fields, "{$_table_type}4", $item->custom_value4, $this->client); // 08-02-2022 - fix for regression below - $data[$key][$table_type.'.quantity'] = Number::formatValue($item->quantity, $this->client->currency()); + // $data[$key][$table_type.'.quantity'] = Number::formatValue($item->quantity, $this->client->currency()); + + $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $this->client->currency()); - //change quantity from localized number, to decimal format with no trailing zeroes 06/09/21 - - //30-01-2022 - improve rounding display for Unit quantity - // $data[$key][$table_type.'.quantity'] = $item->quantity >=1 ? rtrim(number_format($item->quantity, $this->client->currency()->precision), $locale_info['decimal_point']) : rtrim(number_format($item->quantity,15), 0); - // $data[$key][$table_type.'.quantity'] = rtrim($item->quantity, $locale_info['decimal_point']); - - //30-01-2022 - improve rounding display for Unit Cost $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->client); $data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client);