Browse Source

FIX tag object_total_vat_x need x to be a string with unknown decimal
lenght. Now use for x the real vat real with no more decimal (x = 20 or
x = 8.5 or x = 5.99, ...)

Laurent Destailleur 9 years ago
parent
commit
a01a85c3f6
1 changed files with 6 additions and 1 deletions
  1. 6 1
      htdocs/core/class/commondocgenerator.class.php

+ 6 - 1
htdocs/core/class/commondocgenerator.class.php

@@ -388,11 +388,16 @@ abstract class CommonDocGenerator
 		// Add vat by rates
 		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))
 		{