FIX vat code not saved during product creation.
This commit is contained in:
parent
45004493e0
commit
1211e0d7ab
@ -4332,7 +4332,7 @@ class Form
|
|||||||
* Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle.
|
* Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle.
|
||||||
* Sinon la TVA proposee par defaut=0. Fin de regle.
|
* Sinon la TVA proposee par defaut=0. Fin de regle.
|
||||||
* @param bool $options_only Return HTML options lines only (for ajax treatment)
|
* @param bool $options_only Return HTML options lines only (for ajax treatment)
|
||||||
* @param int $mode 1=Add code into key in select list
|
* @param int $mode 0=Use vat rate as key in combo list, 1=Add VAT code after vat rate into key, -1=Use id of vat line as key
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false, $mode=0)
|
function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false, $mode=0)
|
||||||
|
|||||||
@ -239,12 +239,43 @@ if (empty($reshook))
|
|||||||
else
|
else
|
||||||
$object->price_min = GETPOST('price_min');
|
$object->price_min = GETPOST('price_min');
|
||||||
|
|
||||||
$object->tva_tx = str_replace('*','',GETPOST('tva_tx'));
|
$tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
|
||||||
$object->tva_npr = preg_match('/\*/',GETPOST('tva_tx'))?1:0;
|
|
||||||
|
|
||||||
// local taxes.
|
// We must define tva_tx, npr and local taxes
|
||||||
$object->localtax1_tx = get_localtax($object->tva_tx,1);
|
$vatratecode = '';
|
||||||
$object->localtax2_tx = get_localtax($object->tva_tx,2);
|
$tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
|
||||||
|
$npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
|
||||||
|
$localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
|
||||||
|
// If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
|
||||||
|
if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg))
|
||||||
|
{
|
||||||
|
// We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
|
||||||
|
$vatratecode=$reg[1];
|
||||||
|
// Get record from code
|
||||||
|
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
|
||||||
|
$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 = '".$mysoc->country_code."'";
|
||||||
|
$sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
|
||||||
|
$sql.= " AND t.code ='".$vatratecode."'";
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
$npr = $obj->recuperableonly;
|
||||||
|
$localtax1 = $obj->localtax1;
|
||||||
|
$localtax2 = $obj->localtax2;
|
||||||
|
$localtax1_type = $obj->localtax1_type;
|
||||||
|
$localtax2_type = $obj->localtax2_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$object->default_vat_code = $vatratecode;
|
||||||
|
$object->tva_tx = $tva_tx;
|
||||||
|
$object->tva_npr = $npr;
|
||||||
|
$object->localtax1_tx = $localtax1;
|
||||||
|
$object->localtax2_tx = $localtax2;
|
||||||
|
$object->localtax1_type = $localtax1_type;
|
||||||
|
$object->localtax2_type = $localtax2_type;
|
||||||
|
|
||||||
$object->type = $type;
|
$object->type = $type;
|
||||||
$object->status = GETPOST('statut');
|
$object->status = GETPOST('statut');
|
||||||
@ -1109,7 +1140,8 @@ else
|
|||||||
|
|
||||||
// VAT
|
// VAT
|
||||||
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
|
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
|
||||||
print $form->load_tva("tva_tx",-1,$mysoc,'');
|
$defaultva=get_default_tva($mysoc, $mysoc);
|
||||||
|
print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|||||||
@ -396,7 +396,7 @@ class Product extends CommonObject
|
|||||||
$sql = "SELECT count(*) as nb";
|
$sql = "SELECT count(*) as nb";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
||||||
$sql.= " WHERE entity IN (".getEntity('product', 1).")";
|
$sql.= " WHERE entity IN (".getEntity('product', 1).")";
|
||||||
$sql.= " AND ref = '" .$this->ref."'";
|
$sql.= " AND ref = '" .$this->db->escape($this->ref)."'";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
@ -1721,6 +1721,7 @@ class Product extends CommonObject
|
|||||||
$this->tva_tx = $obj->tva_tx;
|
$this->tva_tx = $obj->tva_tx;
|
||||||
//! French VAT NPR
|
//! French VAT NPR
|
||||||
$this->tva_npr = $obj->tva_npr;
|
$this->tva_npr = $obj->tva_npr;
|
||||||
|
$this->recuperableonly = $obj->tva_npr; // For backward compatibility
|
||||||
//! Local taxes
|
//! Local taxes
|
||||||
$this->localtax1_tx = $obj->localtax1_tx;
|
$this->localtax1_tx = $obj->localtax1_tx;
|
||||||
$this->localtax2_tx = $obj->localtax2_tx;
|
$this->localtax2_tx = $obj->localtax2_tx;
|
||||||
|
|||||||
@ -113,7 +113,7 @@ if (empty($reshook))
|
|||||||
// If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
|
// If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
|
||||||
if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg))
|
if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg))
|
||||||
{
|
{
|
||||||
// We look into database using code
|
// We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in create product.
|
||||||
$vatratecode=$reg[1];
|
$vatratecode=$reg[1];
|
||||||
// Get record from code
|
// Get record from code
|
||||||
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
|
$sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
|
||||||
@ -1819,7 +1819,10 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
|||||||
print "<td>" . "</td>";
|
print "<td>" . "</td>";
|
||||||
|
|
||||||
print '<td align="center">' . $langs->trans($object->price_base_type) . "</td>";
|
print '<td align="center">' . $langs->trans($object->price_base_type) . "</td>";
|
||||||
print '<td align="right">' . vatrate($object->tva_tx, true, $object->recuperableonly) . "</td>";
|
print '<td align="right">';
|
||||||
|
print vatrate($object->tva_tx, true, $object->recuperableonly);
|
||||||
|
print $object->default_vat_code?' ('.$object->default_vat_code.')':'';
|
||||||
|
print "</td>";
|
||||||
print '<td align="right">' . price($object->price) . "</td>";
|
print '<td align="right">' . price($object->price) . "</td>";
|
||||||
print '<td align="right">' . price($object->price_ttc) . "</td>";
|
print '<td align="right">' . price($object->price_ttc) . "</td>";
|
||||||
print '<td align="right">' . price($object->price_min) . '</td>';
|
print '<td align="right">' . price($object->price_min) . '</td>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user