mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 05:14:38 -04:00
Increased precision for unit cost
This commit is contained in:
parent
f3b58790ab
commit
f6f9bccdb4
@ -256,7 +256,6 @@ class InvoiceItemSum
|
|||||||
//$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
//$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;
|
$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_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate1_total;
|
$item_tax += $item_tax_rate1_total;
|
||||||
|
@ -142,4 +142,61 @@ class Number
|
|||||||
return self::formatValue($value, $currency);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -306,8 +306,8 @@ trait MakesInvoiceValues
|
|||||||
|
|
||||||
//change quantity from localized number, to decimal format with no trailing zeroes 06/09/21
|
//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.'.quantity'] = rtrim($item->quantity, $locale_info['decimal_point']);
|
||||||
$data[$key][$table_type.'.unit_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::formatMoney($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);
|
$data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client);
|
||||||
|
|
||||||
|
@ -18,7 +18,11 @@ trait NumberFormatter
|
|||||||
{
|
{
|
||||||
private function formatValue($value, $precision) : string
|
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, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user