Skip to content
Permalink
Browse files

Added new calculation fields for the doc generator

- object_total_up  : Sum of all lines (subprice * qty)
- object_total_up_locale : Localized sum of all lines (subprice * qty)
- object_total_discount : Total discount in percent
- object_total_discount_locale : Localized total discount in percent
- line_total_up : Total sum of a line (subprice * qty)
- line_total_up_locale : Localized Total sum of a line (subprice * qty)
  • Loading branch information...
Gerhard Stephan
Gerhard Stephan committed Jan 24, 2019
1 parent af46f89 commit a78e406e76d3616b8e523694ef8cbf8e973742b0
Showing with 17 additions and 0 deletions.
  1. +17 −0 htdocs/core/class/commondocgenerator.class.php
@@ -445,6 +445,7 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
// Add vat by rates
if (is_array($object->lines) && count($object->lines)>0)
{
$totalUp = 0;
foreach ($object->lines as $line)
{
// $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
@@ -456,8 +457,20 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
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]);
$totalUp += $line->subprice * $line->qty;
}
// @GS: Calculate total up and total discount percentage
$resarray['object_total_up'] = $totalUp;
$resarray['object_total_up_locale'] = price($resarray['object_total_up'], 0, $outputlangs);
if (method_exists($object, 'getTotalDiscount')) {
$resarray['object_total_discount'] = round(100 / $totalUp * $object->getTotalDiscount(), 2);
$resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs);
}
}
// Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options))
{
@@ -470,6 +483,7 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
$resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs);
}
return $resarray;
}
@@ -493,6 +507,8 @@ function get_substitutionarray_lines($line,$outputlangs)
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
'line_up'=>price2num($line->subprice),
'line_up_locale'=>price($line->subprice, 0, $outputlangs),
'line_total_up'=>price2num($line->subprice * $line->qty),
'line_total_up_locale'=>price($line->subprice * $line->qty, 0, $outputlangs),
'line_qty'=>$line->qty,
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
'line_price_ht'=>price2num($line->total_ht),
@@ -629,6 +645,7 @@ function get_substitutionarray_shipment_lines($line, $outputlangs)
'line_desc'=>$line->desc,
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
'line_up'=>price($line->subprice),
'line_total_up'=>price($line->subprice * $line->qty),
'line_qty'=>$line->qty,
'line_qty_shipped'=>$line->qty_shipped,
'line_qty_asked'=>$line->qty_asked,

0 comments on commit a78e406

Please sign in to comment.
You can’t perform that action at this time.