From a86c6ac39d98ba85779e7eaa365d970226ec3bb9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 15 Mar 2013 15:59:51 +0100 Subject: [PATCH] New: price function can show price with currency symbol. --- htdocs/compta/facture.php | 16 +++++----------- htdocs/core/lib/functions.lib.php | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 17947e6e3ed..6b0cd0dfb93 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3018,29 +3018,23 @@ else if ($id > 0 || ! empty($ref)) // Amount print ''.$langs->trans('AmountHT').''; - print ''.price($object->total_ht).''; - print ''.$langs->trans('Currency'.$conf->currency).''; - print ''.$langs->trans('AmountVAT').''.price($object->total_tva).''; - print ''.$langs->trans('Currency'.$conf->currency).''; - + print ''.price($object->total_ht,1,'',1,-1,-1,$conf->currency).''; + print ''.$langs->trans('AmountVAT').''.price($object->total_tva,1,'',1,-1,-1,$conf->currency).''; print ''; // Amount Local Taxes if ($mysoc->localtax1_assuj=="1") //Localtax1 RE { print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).''; - print ''.price($object->total_localtax1).''; - print ''.$langs->trans("Currency".$conf->currency).''; + print ''.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).''; } if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF { print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).''; - print ''.price($object->total_localtax2).''; - print ''.$langs->trans("Currency".$conf->currency).''; + print ''.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).''; } - print ''.$langs->trans('AmountTTC').''.price($object->total_ttc).''; - print ''.$langs->trans('Currency'.$conf->currency).''; + print ''.$langs->trans('AmountTTC').''.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).''; // Statut print ''.$langs->trans('Status').''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a610a184321..ab504a52b37 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2554,20 +2554,21 @@ function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0) /** - * Fonction qui formate un montant pour visualisation - * Fonction utilisee dans les pdf et les pages html + * Function to format a value into an amount for visual output + * Function used into PDF and HTML pages * - * @param float $amount Montant a formater - * @param string $form Type de formatage, html ou pas (par defaut) - * @param Translate $outlangs Objet langs pour formatage text - * @param int $trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage - * @param int $rounding Minimum number of decimal. If not defined we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOTAL) + * @param float $amount Amount to format + * @param string $form Type of format, HTML or not (not by default) + * @param Translate $outlangs Object langs for output + * @param int $trunc 1=Truncate if there is too much decimals (default), 0=Does not truncate + * @param int $rounding Minimum number of decimal to show. If not defined we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOTAL) * @param int $forcerounding Force the number of decimal + * @param string $currency_code To add currency symbol (''=add nothing, 'XXX'=add currency symbols for XXX currency) * @return string Chaine avec montant formate * * @see price2num Revert function of price */ -function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1) +function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='') { global $langs,$conf; @@ -2623,8 +2624,16 @@ function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerou { $output=number_format($amount, $nbdecimal, $dec, $thousand); } - $output.=$end; - + // Add symbol of currency if requested + $cursymbolbefore=$cursymbolafter=''; + if ($currency_code) + { + $listofcurrenciesbefore=array('USD'); + if (in_array($currency_code,$listofcurrenciesbefore)) $cursymbolbefore.=$outlangs->getCurrencySymbol($currency_code); + else $cursymbolafter.=$outlangs->getCurrencySymbol($currency_code); + } + $output.=$cursymbolbefore.$end.$cursymbolafter; + return $output; }