2
0
forked from Wavyzz/dolibarr

Fix a lot of fixes to have the french vat npr working better

This commit is contained in:
Laurent Destailleur
2016-02-27 11:32:49 +01:00
parent 4ed53edee8
commit c86a1a30d5
16 changed files with 68 additions and 45 deletions

View File

@@ -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)

View File

@@ -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,6 +272,7 @@ 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;
}

View File

@@ -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;

View File

@@ -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];

View File

@@ -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)

View File

@@ -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,

View File

@@ -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'];

View File

@@ -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.

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;

View File

@@ -425,6 +425,8 @@ 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>';
@@ -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
{

View File

@@ -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,6 +574,7 @@ 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;

View File

@@ -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)