2
0
forked from Wavyzz/dolibarr

New: price function can show price with currency symbol.

This commit is contained in:
Laurent Destailleur
2013-03-15 15:59:51 +01:00
parent fbdf438351
commit a86c6ac39d
2 changed files with 24 additions and 21 deletions

View File

@@ -3018,29 +3018,23 @@ else if ($id > 0 || ! empty($ref))
// Amount // Amount
print '<tr><td>'.$langs->trans('AmountHT').'</td>'; print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2" nowrap>'.price($object->total_ht).'</td>'; print '<td align="right" colspan="3" nowrap>'.price($object->total_ht,1,'',1,-1,-1,$conf->currency).'</td></tr>';
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>'; print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right" colspan="3" nowrap>'.price($object->total_tva,1,'',1,-1,-1,$conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right" colspan="2" nowrap>'.price($object->total_tva).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td>';
print '</tr>'; print '</tr>';
// Amount Local Taxes // Amount Local Taxes
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{ {
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>'; print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
print '<td align="right" colspan="2" nowrap>'.price($object->total_localtax1).'</td>'; print '<td align="right" colspan="3" nowrap>'.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).'</td></tr>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
} }
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{ {
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>'; print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
print '<td align="right" colspan="2" nowrap>'.price($object->total_localtax2).'</td>'; print '<td align="right" colspan="3" nowrap>'.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).'</td></tr>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
} }
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2" nowrap>'.price($object->total_ttc).'</td>'; print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right" colspan="3" nowrap>'.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).'</td></tr>';
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
// Statut // Statut
print '<tr><td>'.$langs->trans('Status').'</td>'; print '<tr><td>'.$langs->trans('Status').'</td>';

View File

@@ -2554,20 +2554,21 @@ function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
/** /**
* Fonction qui formate un montant pour visualisation * Function to format a value into an amount for visual output
* Fonction utilisee dans les pdf et les pages html * Function used into PDF and HTML pages
* *
* @param float $amount Montant a formater * @param float $amount Amount to format
* @param string $form Type de formatage, html ou pas (par defaut) * @param string $form Type of format, HTML or not (not by default)
* @param Translate $outlangs Objet langs pour formatage text * @param Translate $outlangs Object langs for output
* @param int $trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage * @param int $trunc 1=Truncate if there is too much decimals (default), 0=Does not truncate
* @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 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 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 * @return string Chaine avec montant formate
* *
* @see price2num Revert function of price * @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; global $langs,$conf;
@@ -2623,7 +2624,15 @@ function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerou
{ {
$output=number_format($amount, $nbdecimal, $dec, $thousand); $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; return $output;
} }