Browse Source

FIX Bad cleaning of VAT rate when numbers are into code

Laurent Destailleur 4 years ago
parent
commit
fd4dab495f

+ 4 - 1
htdocs/comm/propal/class/propal.class.php

@@ -602,6 +602,7 @@ class Propal extends CommonObject
 
 			// Clean vat code
 			$vat_src_code = '';
+			$reg = array();
 			if (preg_match('/\((.*)\)/', $txtva, $reg))
 			{
 				$vat_src_code = $reg[1];
@@ -779,7 +780,9 @@ class Propal extends CommonObject
 		$qty = price2num($qty);
 		$pu = price2num($pu);
 		$pu_ht_devise = price2num($pu_ht_devise);
-		$txtva = price2num($txtva);
+		if (!preg_match('/\((.*)\)/', $txtva)) {
+			$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+		}
 		$txlocaltax1 = price2num($txlocaltax1);
 		$txlocaltax2 = price2num($txlocaltax2);
 		$pa_ht = price2num($pa_ht);

+ 3 - 1
htdocs/commande/class/commande.class.php

@@ -3120,7 +3120,9 @@ class Commande extends CommonOrder
 			$pu = price2num($pu);
 			$pa_ht = price2num($pa_ht);
 			$pu_ht_devise = price2num($pu_ht_devise);
-			$txtva = price2num($txtva);
+			if (!preg_match('/\((.*)\)/', $txtva)) {
+				$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+			}
 			$txlocaltax1 = price2num($txlocaltax1);
 			$txlocaltax2 = price2num($txlocaltax2);
 

+ 8 - 3
htdocs/compta/facture/class/facture-rec.class.php

@@ -849,7 +849,9 @@ class FactureRec extends CommonInvoice
 			$qty = price2num($qty);
 			$pu_ht = price2num($pu_ht);
 			$pu_ttc = price2num($pu_ttc);
-			$txtva = price2num($txtva);
+			if (!preg_match('/\((.*)\)/', $txtva)) {
+				$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+			}
 			$txlocaltax1 = price2num($txlocaltax1);
 			$txlocaltax2 = price2num($txlocaltax2);
 			if (empty($txtva)) $txtva = 0;
@@ -1031,8 +1033,10 @@ class FactureRec extends CommonInvoice
 	        $pu_ht          = price2num($pu_ht);
 	        $pu_ttc         = price2num($pu_ttc);
 	        $pu_ht_devise = price2num($pu_ht_devise);
-	        $txtva = price2num($txtva);
-		    $txlocaltax1	= price2num($txlocaltax1);
+	        if (!preg_match('/\((.*)\)/', $txtva)) {
+	        	$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+	        }
+	        $txlocaltax1	= price2num($txlocaltax1);
 		    $txlocaltax2	= price2num($txlocaltax2);
 		    if (empty($txlocaltax1)) $txlocaltax1 = 0;
 		    if (empty($txlocaltax2)) $txlocaltax2 = 0;
@@ -1059,6 +1063,7 @@ class FactureRec extends CommonInvoice
 
 	        // Clean vat code
 	        $vat_src_code = '';
+	        $reg = array();
 	        if (preg_match('/\((.*)\)/', $txtva, $reg))
 	        {
 	        	$vat_src_code = $reg[1];

+ 3 - 1
htdocs/compta/facture/class/facture.class.php

@@ -3311,7 +3311,9 @@ class Facture extends CommonInvoice
 			$pu 			= price2num($pu);
         	$pu_ht_devise = price2num($pu_ht_devise);
 			$pa_ht			= price2num($pa_ht);
-			$txtva			= price2num($txtva);
+			if (!preg_match('/\((.*)\)/', $txtva)) {
+				$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+			}
 			$txlocaltax1	= price2num($txlocaltax1);
 			$txlocaltax2	= price2num($txlocaltax2);
 

+ 0 - 1
htdocs/contrat/class/contrat.class.php

@@ -1502,7 +1502,6 @@ class Contrat extends CommonObject
 				$vat_src_code = $reg[1];
 				$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
 			}
-
 			$txtva = price2num($txtva);
 			$txlocaltax1 = price2num($txlocaltax1);
 			$txlocaltax2 = price2num($txlocaltax2);

+ 3 - 1
htdocs/fichinter/class/fichinterrec.class.php

@@ -473,7 +473,9 @@ class FichinterRec extends Fichinter
             if (!$info_bits) $info_bits = 0;
             $pu_ht = price2num($pu_ht);
             $pu_ttc = price2num($pu_ttc);
-            $txtva = price2num($txtva);
+            if (!preg_match('/\((.*)\)/', $txtva)) {
+            	$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+            }
 
             if ($price_base_type == 'HT') {
                 $pu = $pu_ht;

+ 3 - 1
htdocs/fourn/class/fournisseur.commande.class.php

@@ -2633,7 +2633,9 @@ class CommandeFournisseur extends CommonOrder
             if (!$qty) $qty = 1;
             $pu = price2num($pu);
         	$pu_ht_devise = price2num($pu_ht_devise);
-        	$txtva = price2num($txtva);
+        	if (!preg_match('/\((.*)\)/', $txtva)) {
+        		$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+        	}
         	$txlocaltax1 = price2num($txlocaltax1);
         	$txlocaltax2 = price2num($txlocaltax2);
 

+ 8 - 3
htdocs/supplier_proposal/class/supplier_proposal.class.php

@@ -423,10 +423,13 @@ class SupplierProposal extends CommonObject
         $qty = price2num($qty);
         $pu_ht = price2num($pu_ht);
         $pu_ttc = price2num($pu_ttc);
-        $txtva = price2num($txtva);
+        if (!preg_match('/\((.*)\)/', $txtva)) {
+        	$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+        }
         $txlocaltax1 = price2num($txlocaltax1);
         $txlocaltax2 = price2num($txlocaltax2);
-            $pa_ht = price2num($pa_ht);
+
+        $pa_ht = price2num($pa_ht);
         if ($price_base_type == 'HT')
         {
             $pu = $pu_ht;
@@ -682,7 +685,9 @@ class SupplierProposal extends CommonObject
         $remise_percent = price2num($remise_percent);
         $qty = price2num($qty);
         $pu = price2num($pu);
-        $txtva = price2num($txtva);
+        if (!preg_match('/\((.*)\)/', $txtva)) {
+        	$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+        }
         $txlocaltax1 = price2num($txlocaltax1);
         $txlocaltax2 = price2num($txlocaltax2);
         $pa_ht = price2num($pa_ht);