From c86a1a30d5055ecce80a907da6a0ae61e66c1396 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sat, 27 Feb 2016 11:32:49 +0100
Subject: [PATCH] Fix a lot of fixes to have the french vat npr working better

---
 htdocs/comm/propal.php                             | 10 +++++-----
 htdocs/comm/propal/class/propal.class.php          | 10 ++++++----
 htdocs/commande/card.php                           |  2 ++
 htdocs/commande/class/commande.class.php           |  7 +++++--
 htdocs/compta/facture.php                          |  8 ++++++--
 htdocs/compta/facture/class/facture.class.php      |  8 +++++---
 htdocs/contrat/card.php                            |  6 ++++--
 htdocs/core/class/html.form.class.php              |  1 +
 htdocs/core/lib/functions.lib.php                  |  8 +++++---
 htdocs/fourn/class/fournisseur.product.class.php   |  1 -
 htdocs/fourn/commande/card.php                     | 13 +++++++------
 htdocs/fourn/facture/card.php                      | 14 +++++++-------
 htdocs/product/card.php                            |  6 ++++--
 htdocs/product/fournisseurs.php                    |  5 ++++-
 htdocs/supplier_proposal/card.php                  |  7 +++----
 .../class/supplier_proposal.class.php              |  7 ++++---
 16 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 07c51e76916..7d85567f480 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -467,9 +467,7 @@ if (empty($reshook))
 											$array_options = $lines[$i]->array_options;
 										}
 
-										$tva_tx=get_default_tva($mysoc, $object->thirdparty);
-
-										$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
+										$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
 
 										if ($result > 0) {
 											$lineid = $result;
@@ -753,6 +751,8 @@ if (empty($reshook))
 				// If prices fields are update
 					$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
 					$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
+					if (empty($tva_tx)) $tva_npr=0;
+					
 					$pu_ht = $prod->price;
 					$pu_ttc = $prod->price_ttc;
 					$price_min = $prod->price_min;
@@ -873,8 +873,8 @@ if (empty($reshook))
 			$date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
 
 			// Local Taxes
-			$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
-			$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
+			$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
+			$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
 
 			$info_bits = 0;
 			if ($tva_npr)
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 922f24cb8b6..7905af12030 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -248,9 +248,10 @@ class Propal extends CommonObject
             $productdesc = $prod->description;
 
             $tva_tx = get_default_tva($mysoc,$this->client,$prod->id);
-            // local taxes
-            $localtax1_tx = get_default_localtax($mysoc,$this->client,1,$prod->tva_tx);
-            $localtax2_tx = get_default_localtax($mysoc,$this->client,2,$prod->tva_tx);
+            $tva_npr = get_default_npr($mysoc,$this->client,$prod->id);
+            if (empty($tva_tx)) $tva_npr=0;
+            $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->client,$tva_npr);
+            $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->client,$tva_npr);
 
             // multiprix
             if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level)
@@ -271,7 +272,8 @@ class Propal extends CommonObject
             $line->remise_percent=$remise_percent;
             $line->tva_tx=$tva_tx;
 	        $line->fk_unit=$prod->fk_unit;
-
+			if ($tva_npr) $line->info_bits = 1;
+			
             $this->lines[]=$line;
         }
     }
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index c58516f4fea..e63e3b9a5dc 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -680,6 +680,8 @@ if (empty($reshook))
 				// Update if prices fields are defined
 					$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
 					$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
+					if (empty($tva_tx)) $tva_npr=0;
+					
 					$pu_ht = $prod->price;
 					$pu_ttc = $prod->price_ttc;
 					$price_min = $prod->price_min;
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index eb240c852fc..8f8edcf15a3 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1421,8 +1421,11 @@ class Commande extends CommonOrder
             $prod->fetch($idproduct);
 
             $tva_tx = get_default_tva($mysoc,$this->client,$prod->id);
-            $localtax1_tx=get_localtax($tva_tx,1,$this->client);
-            $localtax2_tx=get_localtax($tva_tx,2,$this->client);
+            $tva_npr = get_default_npr($mysoc,$this->client,$prod->id);
+            if (empty($tva_tx)) $tva_npr=0;
+            $localtax1_tx=get_localtax($tva_tx,1,$this->client,$mysoc,$tva_npr);
+            $localtax2_tx=get_localtax($tva_tx,2,$this->client,$mysoc,$tva_npr);
+            
             // multiprix
             if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level)
             $price = $prod->multiprices[$this->client->price_level];
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 28c4694412f..1288278c32d 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1356,6 +1356,8 @@ if (empty($reshook))
 				// Update if prices fields are defined
 					$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
 					$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
+					if (empty($tva_tx)) $tva_npr=0;
+					
 					$pu_ht = $prod->price;
 					$pu_ttc = $prod->price_ttc;
 					$price_min = $prod->price_min;
@@ -1372,6 +1374,7 @@ if (empty($reshook))
 						{
                             if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
                             if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
+							if (empty($tva_tx)) $tva_npr=0;
 						}
 					}
 					elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
@@ -1455,6 +1458,7 @@ if (empty($reshook))
 				$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
 				$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
 				$tva_tx = str_replace('*', '', $tva_tx);
+				if (empty($tva_tx)) $tva_npr=0;
 				$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
 				$desc = $product_desc;
 				$type = GETPOST('type');
@@ -1466,8 +1470,8 @@ if (empty($reshook))
 			$buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : '');    // If buying_price is '0', we must keep this value
 
 			// Local Taxes
-			$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc);
-			$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc);
+			$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
+			$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
 			
 			$info_bits = 0;
 			if ($tva_npr)
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 0b34c42cbad..95356149622 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -539,8 +539,10 @@ class Facture extends CommonInvoice
 						$res=$prod->fetch($_facrec->lines[$i]->fk_product);
 					}
 					$tva_tx = get_default_tva($mysoc,$soc,$prod->id);
-					$localtax1_tx=get_localtax($tva_tx,1,$soc);
-					$localtax2_tx=get_localtax($tva_tx,2,$soc);
+					$tva_npr = get_default_npr($mysoc,$soc,$prod->id);
+					if (empty($tva_tx)) $tva_npr=0;
+					$localtax1_tx=get_localtax($tva_tx,1,$soc,$mysoc,$tva_npr);
+					$localtax2_tx=get_localtax($tva_tx,2,$soc,$mysoc,$tva_npr);
 
 					$result_insert = $this->addline(
 						$_facrec->lines[$i]->desc,
@@ -551,7 +553,7 @@ class Facture extends CommonInvoice
 						$localtax2_tx,
 						$_facrec->lines[$i]->fk_product,
 						$_facrec->lines[$i]->remise_percent,
-						'','',0,0,'','HT',0,
+						'','',0,$tva_npr,'','HT',0,
 						$_facrec->lines[$i]->product_type,
 						$_facrec->lines[$i]->rang,
 						$_facrec->lines[$i]->special_code,
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index d910ebb6a79..c8504a186d4 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -492,6 +492,8 @@ if (empty($reshook))
 	
 	            $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id);
 	            $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id);
+	            if (empty($tva_tx)) $tva_npr=0;
+	            
 	            $pu_ht = $prod->price;
 	            $pu_ttc = $prod->price_ttc;
 	            $price_min = $prod->price_min;
@@ -552,8 +554,8 @@ if (empty($reshook))
 				$fk_unit= GETPOST('units', 'alpha');
 	        }
 	
-	        $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty);
-	        $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty);
+	        $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty,$mysoc,$tva_npr);
+	        $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty,$mysoc,$tva_npr);
 	
 			// ajout prix achat
 			$fk_fournprice = $_POST['fournprice'];
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index df2041cc070..1f18d1ac26c 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -4201,6 +4201,7 @@ class Form
         	{
         		$defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$idprod);
         		$defaultnpr=get_default_npr($societe_vendeuse,$societe_acheteuse,$idprod);
+        		if (empty($defaulttx)) $defaultnpr=0;
         	}
 
         	// Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index d7575cc6ab5..d70719c4d4f 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3452,14 +3452,15 @@ function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs)
  *	Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller
  *  Note: This function applies same rules than get_default_tva
  *
- * 	@param	float		$vatrate		        Vat rate. Can be '8.5' or '8.5 (8.5NPR)' for example
+ * 	@param	float		$vatrate		        Vat rate. Can be '8.5' or '8.5 (VATCODEX)' for example
  * 	@param  int			$local		         	Local tax to search and return (1 or 2 return only tax rate 1 or tax rate 2)
  *  @param  Societe		$thirdparty_buyer    	Object of buying third party
  *  @param	Societe		$thirdparty_seller		Object of selling third party
+ *  @param	int			$vatnpr					If vat rate is NPR or not
  * 	@return	mixed			   					0 if not found, localtax rate if found
  *  @see get_default_tva
  */
-function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="")
+function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
 {
 	global $db, $conf, $mysoc;
 
@@ -3568,7 +3569,8 @@ function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller
    	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
    	$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
    	$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
-   	if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
+   	if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";		// If we have the code, we use it in priority
+   	else $sql.= " AND t.recuperableonly ='".$npr."'";
    	dol_syslog("get_localtax", LOG_DEBUG);
    	$resql=$db->query($sql);
 
diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php
index 0bf0492b411..63b3e833a4c 100644
--- a/htdocs/fourn/class/fournisseur.product.class.php
+++ b/htdocs/fourn/class/fournisseur.product.class.php
@@ -191,7 +191,6 @@ class ProductFournisseur extends Product
         if ($delivery_time_days != '' && ! is_numeric($delivery_time_days)) $delivery_time_days = '';
         if ($price_base_type == 'TTC')
 		{
-			//$ttx = get_default_tva($fourn,$mysoc,$this->id);	// We must use the VAT rate defined by user and not calculate it
 			$ttx = $tva_tx;
 			$buyprice = $buyprice/(1+($ttx/100));
 		}
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index a53bcb78d80..922e0d61d38 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -350,12 +350,13 @@ if (empty($reshook))
 	    		$desc = $productsupplier->description;
 	    		if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
 
-	    		$tva_tx	= get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
 	    		$type = $productsupplier->type;
-
-	    		// Local Taxes
-	    		$localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
-	    		$localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
+	    		
+	    		$tva_tx	= get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
+	    		$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
+				if (empty($tva_tx)) $tva_npr=0;
+	    		$localtax1_tx= get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
+	    		$localtax2_tx= get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
 
 	    		$result=$object->addline(
 	    			$desc,
@@ -371,7 +372,7 @@ if (empty($reshook))
 	    			'HT',
 	    			$pu_ttc,
 	    			$type,
-	    			'',
+	    			$tva_npr,
 	    			'',
 	    			$date_start,
 	    			$date_end,
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 73def71adc1..1409cb94266 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -726,17 +726,17 @@ if (empty($reshook))
 	            $desc = $productsupplier->description;
 	            if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
 
-	            $tvatx=get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
-	            $npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
-
-	            $localtax1_tx= get_localtax($tvatx, 1, $mysoc,$object->thirdparty);
-	            $localtax2_tx= get_localtax($tvatx, 2, $mysoc,$object->thirdparty);
+	            $tva_tx=get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
+	            $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
+				if (empty($tva_tx)) $tva_npr=0;
+	            $localtax1_tx= get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
+	            $localtax2_tx= get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
 
 	            $type = $productsupplier->type;
 	            $price_base_type = 'HT';
 
 	            // TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first)
-	            $result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, $date_start, $date_end, 0, $npr, $price_base_type, $type, -1, 0, $array_options, $productsupplier->fk_unit);
+	            $result=$object->addline($desc, $productsupplier->fourn_pu, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $productsupplier->fk_unit);
 	        }
 	    	if ($idprod == -2 || $idprod == 0)
 	        {
@@ -783,7 +783,7 @@ if (empty($reshook))
 	            $price_base_type = 'HT';
 	        }
 
-			$result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit);
+			$result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit);
 	    }
 
 	    //print "xx".$tva_tx; exit;
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 987754a36ae..ef126a85b52 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -620,8 +620,10 @@ if (empty($reshook))
             $desc = $object->description;
 
             $tva_tx = get_default_tva($mysoc, $soc, $object->id);
-            $localtax1_tx = get_localtax($tva_tx, 1, $soc);
-            $localtax2_tx = get_localtax($tva_tx, 2, $soc);
+            $tva_npr = get_default_npr($mysoc, $soc, $object->id);
+            if (empty($tva_tx)) $tva_npr=0;
+            $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr);
+            $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr);
 
             $pu_ht = $object->price;
             $pu_ttc = $object->price_ttc;
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index d825a1f2c66..96020e81ada 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -425,7 +425,9 @@ if ($id > 0 || $ref)
 				$mysoc2->name='Fictive seller with same country';
 				$mysoc2->tva_assuj=1;
 				$default_vat=get_default_tva($mysoc2, $mysoc, $object->id, 0);
-
+				$default_npr=get_default_npr($mysoc2, $mysoc, $object->id, 0);
+				if (empty($default_vat)) $default_npr=$default_vat;
+				
 				print '<tr><td class="fieldrequired">'.$langs->trans("VATRateForSupplierProduct").'</td>';
 				print '<td>';
 				//print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc);    // Do not use list here as it may be any vat rates for any country
@@ -434,6 +436,7 @@ if ($id > 0 || $ref)
 				    $tmpproductsupplier=new ProductFournisseur($db);
 				    $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1);
 					$default_vat=$tmpproductsupplier->fourn_tva_tx;
+					$default_npr=$tmpproductsupplier->fourn_tva_npr;
 				}
 				else
 				{
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index e0ba1c18dd5..a66c849bf3a 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -351,9 +351,7 @@ if (empty($reshook))
 										$array_option = $lines[$i]->array_options;
 									}
 
-									$tva_tx=get_default_tva($mysoc, $object->thirdparty);
-
-									$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_option);
+									$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_option);
 
 									if ($result > 0) {
 										$lineid = $result;
@@ -576,7 +574,8 @@ if (empty($reshook))
 				// If prices fields are update
 					$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
 					$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
-
+					if (empty($tva_tx)) $tva_npr=0;
+					
 					//On garde le prix indiqué dans l'input pour la demande de prix fournisseur
 					//$pu_ht = $prod->price;
 					$pu_ht = price2num($price_ht, 'MU');
diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php
index abbaed6d5f4..b5319210fc7 100644
--- a/htdocs/supplier_proposal/class/supplier_proposal.class.php
+++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php
@@ -199,9 +199,10 @@ class SupplierProposal extends CommonObject
             $productdesc = $prod->description;
 
             $tva_tx = get_default_tva($mysoc,$this->client,$prod->id);
-            // local taxes
-            $localtax1_tx = get_default_localtax($mysoc,$this->client,1,$prod->tva_tx);
-            $localtax2_tx = get_default_localtax($mysoc,$this->client,2,$prod->tva_tx);
+            $tva_npr = get_default_npr($mysoc,$this->client,$prod->id);
+            if (empty($tva_tx)) $tva_npr=0;
+            $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->client,$tva_npr);
+            $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->client,$tva_npr);
 
             // multiprix
             if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level)
-- 
GitLab