diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index be7ded70566..9f2c15eddbe 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1051,12 +1051,12 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='') function img_object($alt, $object) { global $conf,$langs; - + if (preg_match('/^([^@]+)@([^@]+)$/i',$object,$regs)) { return ''.dol_escape_htmltag($alt).''; } - + return ''.dol_escape_htmltag($alt).''; } @@ -2526,16 +2526,17 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) } /** - * \brief Return localtaxe rate for a particular tva - * \param tva Vat taxe - * \param local Local taxe to search and return + * \brief Return localtaxe rate for a particular tva + * \param tva Vat taxe + * \param local Local taxe to search and return + * \return int <0 if KO, localtax if found */ -function get_localtax($tva, $local=0) +function get_localtax($tva, $local) { global $db, $conf, $mysoc; $code_pays=$mysoc->pays_code; - + // Search local taxes $sql = "SELECT t.localtax1, t.localtax2"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; @@ -2550,6 +2551,8 @@ function get_localtax($tva, $local=0) if ($local==1) return $obj->localtax1; elseif ($local==2) return $obj->localtax2; } + + return -1; } /** @@ -2670,7 +2673,7 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id { if (!is_object($societe_vendeuse)) return -1; if (!is_object($societe_acheteuse)) return -1; - + if($societe_vendouse->pays_id=='ES') { if ($local=='1') //RE @@ -2678,17 +2681,17 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id // Si achatteur non assujeti a RE, localtax1 par default=0 if (is_numeric($societe_acheteuse->localtax1_assuj) && ! $societe_acheteuse->localtax1_assuj) return 0; if (! is_numeric($societe_acheteuse->localtax1_assuj) && $societe_acheteuse->localtax1_assuj=='localtax1off') return 0; - } + } elseif ($local=='2') //IRPF { // Si vendeur non assujeti a IRPF, localtax2 par default=0 if (is_numeric($societe_vendeuse->localtax2_assuj) && ! $societe_vendeuse->localtax2_assuj) return 0; if (! is_numeric($societe_vendeuse->localtax2_assuj) && $societe_vendeuse->localtax2_assuj=='localtax2off') return 0; } else return -1; - + if ($idprod) return get_product_localtax_for_country($idprod, $local, $societe_vendeuse->pays_code); - if (strlen($taux_produit) == 0) return -1; - return $taux_produit; + if (strlen($taux_produit) == 0) return -1; + return $taux_produit; } return 0; } diff --git a/htdocs/product/product.class.php b/htdocs/product/product.class.php index 3f76b4487d7..7791cced796 100644 --- a/htdocs/product/product.class.php +++ b/htdocs/product/product.class.php @@ -194,7 +194,7 @@ class Product extends CommonObject //Local taxes if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; - + if (empty($this->price)) $this->price = 0; if (empty($this->price_min)) $this->price_min = 0; if (empty($this->status)) $this->status = 0; @@ -421,7 +421,7 @@ class Product extends CommonObject //Local taxes if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; - + if (empty($this->finished)) $this->finished = 0; if (empty($this->hidden)) $this->hidden = 0; $this->accountancy_code_buy = trim($this->accountancy_code_buy); @@ -431,11 +431,11 @@ class Product extends CommonObject $sql.= " SET label = '" . addslashes($this->libelle) ."'"; $sql.= ",ref = '" . $this->ref ."'"; $sql.= ",tva_tx = " . $this->tva_tx; - + //Local taxes $sql.= ",localtax1_tx = " . $this->localtax1_tx; $sql.= ",localtax2_tx = " . $this->localtax2_tx; - + $sql.= ",envente = " . $this->status; $sql.= ",finished = " . ($this->finished<0 ? "null" : $this->finished); $sql.= ",hidden = " . ($this->hidden<0 ? "null" : $this->hidden); @@ -884,11 +884,13 @@ class Product extends CommonObject } } //print 'x'.$id.'-'.$newprice.'-'.$newpricebase.'-'.$price.'-'.$price_ttc.'-'.$price_min.'-'.$price_min_ttc; - + //Local taxes $localtax1=get_localtax($newvat,1); $localtax2=get_localtax($newvat,2); - + if (empty($localtax1)) $localtax1=0; // If = '' then = 0 + if (empty($localtax2)) $localtax2=0; // If = '' then = 0 + // Ne pas mettre de quote sur le numeriques decimaux. // Ceci provoque des stockage avec arrondis en base au lieu des valeurs exactes. $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; @@ -897,8 +899,8 @@ class Product extends CommonObject $sql.= " price_ttc=".$price_ttc.","; $sql.= " price_min=".$price_min.","; $sql.= " price_min_ttc=".$price_min_ttc.","; - $sql.= " localtax1_tx=".$localtax1.","; - $sql.= " localtax2_tx=".$localtax2.","; + $sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').","; + $sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').","; $sql.= " tva_tx='".price2num($newvat)."'"; $sql.= " WHERE rowid = " . $id; @@ -914,8 +916,8 @@ class Product extends CommonObject $this->tva_tx = $newvat; //Local taxes $this->localtax1_tx = $localtax1; - $this->localtax2_tx = $localtax2; - + $this->localtax2_tx = $localtax2; + $this->_log_price($user,$level); } else @@ -979,7 +981,7 @@ class Product extends CommonObject //Local taxes $this->localtax1_tx = $result["localtax1_tx"]; $this->localtax2_tx = $result["localtax2_tx"]; - + $this->type = $result["fk_product_type"]; $this->status = $result["envente"]; $this->finished = $result["finished"];