Skip to content

Commit

Permalink
Merge pull request #7270 from atm-florian/6.0_fix
Browse files Browse the repository at this point in the history
6.0 fix
  • Loading branch information
eldy committed Aug 22, 2017
2 parents 9be342b + 874d61b commit ca3b3b9
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions htdocs/core/class/commondocgenerator.class.php
Expand Up @@ -374,13 +374,12 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
$array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
$array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
$array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
$array_key.'_total_discount_ht_locale' => price($object->getTotalDiscount(), 0, $outputlangs),

$array_key.'_total_ht'=>price2num($object->total_ht),
$array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)),
$array_key.'_total_localtax1'=>price2num($object->total_localtax1),
$array_key.'_total_localtax2'=>price2num($object->total_localtax2),
$array_key.'_total_ttc'=>price2num($object->total_ttc),
$array_key.'_total_discount_ht' => price2num($object->getTotalDiscount()),

$array_key.'_multicurrency_code' => price2num($object->multicurrency_code),
$array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
Expand Down Expand Up @@ -411,18 +410,29 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
$array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT')
);

if (method_exists($object, 'getTotalDiscount')) {
$resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
$resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
} else {
$resarray[$array_key.'_total_discount_ht_locale'] = '';
$resarray[$array_key.'_total_discount_ht'] = '';
}

// Add vat by rates
foreach ($object->lines as $line)
if (is_array($object->lines) && count($object->lines)>0)
{
// $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0;
$resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
$resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
// $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
$vatformated=vatrate($line->tva_tx);
if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0;
$resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva;
$resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]);
foreach ($object->lines as $line)
{
// $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0;
$resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
$resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
// $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
$vatformated=vatrate($line->tva_tx);
if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0;
$resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva;
$resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]);
}
}
// Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options))
Expand Down

0 comments on commit ca3b3b9

Please sign in to comment.