<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi All,<br>
<br>
Here is a small modification of <b>....\include\fields\CurrencyField.php</b><br>
<br>
It would be useful, if the parameter $numberOfDecimal could be set
up from settings panel.<br>
<br>
Due to actual state of economics and inflation in Hungary we are not
using anymore cents only whole Forints. Even now we are using only 0
or 5 end integers for the prices and currency values because so we
should round all prices:<br>
Numbers with end ...xxx1 , ...xxx2, ...xxx8 and ...xxx9 to the
..xxx0 and <br>
numbers with end ...xxx3 , ...xxx4, ...xxx6 and ...xxx7 to the
..xxx5 <br>
<br>
There are a var $numberOfDecimal = 3; in this file.<br>
<br>
If this var set <b>$numberOfDecimal = 0;</b><br>
<br>
and adding and/or changing the blue lines in the <b>function </b>_formatCurrencyValue($value),
the numbers will round well in the PDF Invoice.<br>
<tt><br>
/**<br>
* Function that formats the Number based on the User
configured Pattern, Currency separator and Decimal separator<br>
* @param Number $value<br>
* @return Formatted Currency<br>
*/<br>
private function _formatCurrencyValue($value) {<br>
<br>
$currencyPattern = $this->currencyFormat;<br>
$currencySeparator = $this->currencySeparator;<br>
$decimalSeparator = $this->decimalSeparator;<br>
if(empty($currencySeparator)) $currencySeparator = ' ';<br>
if(empty($decimalSeparator)) $decimalSeparator = ' ';<br>
<b><font color="#000099"> // Rounding value to the given
decimals<br>
$value = round($value, $this->numberOfDecimal);</font></b><br>
<br>
if($currencyPattern == $this->CURRENCY_PATTERN_PLAIN) {<br>
// Replace '.' with Decimal Separator<br>
$number = str_replace('.', $decimalSeparator, $value);<br>
return $number;<br>
}<br>
if($currencyPattern ==
$this->CURRENCY_PATTERN_SINGLE_GROUPING) {<br>
// Separate the numeric and decimal parts<br>
$numericParts = explode('.', $value);<br>
$wholeNumber = $numericParts[0];<br>
// First part of the number which remains intact<br>
if(strlen($wholeNumber) > 3) {<br>
$wholeNumberFirstPart =
substr($wholeNumber,0,strlen($wholeNumber)-3);<br>
}<br>
// Second Part of the number (last 3 digits) which
should be separated from the First part using Currency Separator<br>
$wholeNumberLastPart = substr($wholeNumber,-3);<br>
// Re-create the whole number with user's configured
currency separator<br>
if(!empty($wholeNumberFirstPart)) {<br>
$numericParts[0] =
$wholeNumberFirstPart.$currencySeparator.$wholeNumberLastPart;<br>
} else {<br>
$numericParts[0] = $wholeNumberLastPart;<br>
}<br>
<b><font color="#000099"> // Handling number rounding<br>
if ( $this->numberOfDecimal == 0) {<br>
//No decimal parts: No $decimalSeparator and
No $numericParts[1]<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = $numericParts[0]; <br>
}<br>
else {<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = implode($decimalSeparator,
$numericParts);<br>
}</font></b><br>
return $number;<br>
}<br>
if($currencyPattern ==
$this->CURRENCY_PATTERN_THOUSAND_GROUPING) {<br>
// Separate the numeric and decimal parts<br>
$numericParts = explode('.', $value);<br>
$wholeNumber = $numericParts[0];<br>
// Pad the rest of the length in the number string
with Leading 0, to get it to the multiples of 3<br>
$numberLength = strlen($wholeNumber);<br>
// First grouping digits length<br>
$OddGroupLength = $numberLength%3;<br>
$gapsToBeFilled = 0;<br>
if($OddGroupLength > 0) $gapsToBeFilled = 3 -
$OddGroupLength;<br>
$wholeNumber = str_pad($wholeNumber,
$numberLength+$gapsToBeFilled, '0', STR_PAD_LEFT);<br>
// Split the whole number into chunks of 3 digits<br>
$wholeNumberParts = str_split($wholeNumber,3);<br>
// Re-create the whole number with user's configured
currency separator<br>
$numericParts[0] = $wholeNumber =
implode($currencySeparator, $wholeNumberParts);<br>
if($wholeNumber > 0) {<br>
$numericParts[0] = ltrim($wholeNumber, '0');<br>
} else {<br>
$numericParts[0] = 0;<br>
}<br>
<font color="#000099"><b> // Handling number rounding<br>
if ( $this->numberOfDecimal == 0) {<br>
//No decimal parts: No $decimalSeparator and
No $numericParts[1]<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = $numericParts[0]; <br>
}<br>
else {<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = implode($decimalSeparator,
$numericParts);<br>
}</b></font><br>
return $number;<br>
}<br>
if($currencyPattern ==
$this->CURRENCY_PATTERN_MIXED_GROUPING) {<br>
// Separate the numeric and decimal parts<br>
$numericParts = explode('.', $value);<br>
$wholeNumber = $numericParts[0];<br>
// First part of the number which needs separate
division<br>
if(strlen($wholeNumber) > 3) {<br>
$wholeNumberFirstPart =
substr($wholeNumber,0,strlen($wholeNumber)-3);<br>
}<br>
// Second Part of the number (last 3 digits) which
should be separated from the First part using Currency Separator<br>
$wholeNumberLastPart = substr($wholeNumber,-3);<br>
if(!empty($wholeNumberFirstPart)) {<br>
// Pad the rest of the length in the number string
with Leading 0, to get it to the multiples of 2<br>
$numberLength = strlen($wholeNumberFirstPart);<br>
// First grouping digits length<br>
$OddGroupLength = $numberLength%2;<br>
$gapsToBeFilled = 0;<br>
if($OddGroupLength > 0) $gapsToBeFilled = 2 -
$OddGroupLength;<br>
$wholeNumberFirstPart =
str_pad($wholeNumberFirstPart, $numberLength+$gapsToBeFilled, '0',
STR_PAD_LEFT);<br>
// Split the first part of tne number into chunks
of 2 digits<br>
$wholeNumberFirstPartElements =
str_split($wholeNumberFirstPart,2);<br>
$wholeNumberFirstPart =
ltrim(implode($currencySeparator, $wholeNumberFirstPartElements),
'0');<br>
$wholeNumberFirstPart =
implode($currencySeparator, $wholeNumberFirstPartElements);<br>
if($wholeNumberFirstPart > 0) {<br>
$wholeNumberFirstPart =
ltrim($wholeNumberFirstPart, '0');<br>
} else {<br>
$wholeNumberFirstPart = 0;<br>
}<br>
// Re-create the whole number with user's
configured currency separator<br>
$numericParts[0] =
$wholeNumberFirstPart.$currencySeparator.$wholeNumberLastPart;<br>
} else {<br>
$numericParts[0] = $wholeNumberLastPart;<br>
}<br>
<font color="#000099"><b> // Handling number rounding<br>
if ( $this->numberOfDecimal == 0) {<br>
//No decimal parts: No $decimalSeparator and
No $numericParts[1]<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = $numericParts[0]; <br>
}<br>
else {<br>
// Re-create the currency value combining the
whole number and the decimal part using Decimal separator<br>
$number = implode($decimalSeparator,
$numericParts);<br>
}</b></font><br>
return $number;<br>
}<br>
return $number;<br>
}</tt><br>
<br>
---------------------------------------------------<br>
Plus we should change the <b>....\include\InventoryPDFController.php</b>
a little also.<br>
<br>
About line 135 - 140: <br>
<br>
Change:<tt><br>
$contentModel->set('Quantity', $quantity);</tt><br>
Into:<br>
<tt> <b>$contentModel->set('Quantity',
round($quantity,0));</b></tt><br>
<br>
and<br>
<br>
Change:<br>
<tt> $contentModel->set('Discount',
$this->formatPrice($discount)."\n ($discountPercentage%)");</tt><br>
Into:<br>
<b><tt> </tt><tt> $contentModel->set('Discount',
$this->formatPrice($discount)."\n
(".round($discountPercentage,1)."%)");</tt><br>
</b><br>
<br>
Also should be changed 2 lines about lines: 210-214<br>
<tt><br>
$summaryModel->set(getTranslatedString("Shipping &
Handling Tax:", $this->moduleName)."($sh_tax_percent%)",
$this->formatPrice($final_details['shtax_totalamount']));<br>
<br>
$summaryModel->set(getTranslatedString("Grand Total :
(in $currencySymbol)", $this->moduleName),
$this->formatPrice($final_details['grandTotal']));</tt><br>
<br>
Into the:<br>
<b><br>
</b><tt><b>
$summaryModel->set(getTranslatedString("Shipping &
Handling Tax", $this->moduleName)." ($sh_tax_percent%):",
$this->formatPrice($final_details['shtax_totalamount']));<br>
<br>
$summaryModel->set(getTranslatedString("Grand Total",
$this->moduleName)." ($currencySymbol):",
$this->formatPrice($final_details['grandTotal']));</b><br>
</tt><br>
The first line for the better look, but the second line for the
availability to translate.<br>
The original version consists a variable in the
getTranslatedString("<b>argument</b>", $this->moduleName) - so it
very hard to translate.<br>
<br>
<br>
Best regards:<br>
<br>
<div class="moz-signature">-- <br>
<br>
Holbok István<br>
telefon: +3670-342-0900<br>
e-mail: <a href="mailto:holbok@gmail.com">holbok@gmail.com</a><br>
<br>
<br>
<br>
</div>
</body>
</html>