Skip to content

Commit

Permalink
NEW Introduce a "code" into fiels to describe vat. This will allow to
Browse files Browse the repository at this point in the history
suggest different vat lines with same value with ability to
differentiate them.
  • Loading branch information
eldy committed Nov 14, 2015
1 parent 88356e2 commit 01058be
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 112 deletions.
22 changes: 11 additions & 11 deletions htdocs/admin/dict.php
Expand Up @@ -150,7 +150,7 @@
$tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, a.deductible, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays=c.rowid and c.active=1";
$tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid";
$tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
$tabsql[10]= "SELECT t.rowid, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
$tabsql[10]= "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
$tabsql[11]= "SELECT t.rowid as rowid, element, source, code, libelle, active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.fdm, c.decalage, c.active, c.sortorder FROM ".MAIN_DB_PREFIX.'c_payment_term AS c';
$tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement AS c";
Expand Down Expand Up @@ -182,7 +182,7 @@
$tabsqlsort[7] ="country ASC, code ASC, a.libelle ASC";
$tabsqlsort[8] ="country DESC, libelle ASC";
$tabsqlsort[9] ="label ASC";
$tabsqlsort[10]="country ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
$tabsqlsort[10]="country ASC, code ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
$tabsqlsort[11]="element ASC, source ASC, code ASC";
$tabsqlsort[12]="sortorder ASC, code ASC";
$tabsqlsort[13]="code ASC";
Expand Down Expand Up @@ -214,7 +214,7 @@
$tabfield[7] = "code,libelle,country,accountancy_code,deductible";
$tabfield[8] = "code,libelle,country_id,country";
$tabfield[9] = "code,label,unicode";
$tabfield[10]= "country_id,country,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[10]= "country_id,country,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[11]= "element,source,code,libelle";
$tabfield[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage,sortorder";
$tabfield[13]= "code,libelle,type,accountancy_code";
Expand Down Expand Up @@ -246,7 +246,7 @@
$tabfieldvalue[7] = "code,libelle,country,accountancy_code,deductible";
$tabfieldvalue[8] = "code,libelle,country";
$tabfieldvalue[9] = "code,label,unicode";
$tabfieldvalue[10]= "country,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[10]= "country,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[11]= "element,source,code,libelle";
$tabfieldvalue[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage,sortorder";
$tabfieldvalue[13]= "code,libelle,type,accountancy_code";
Expand Down Expand Up @@ -278,7 +278,7 @@
$tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code,deductible";
$tabfieldinsert[8] = "code,libelle,fk_country";
$tabfieldinsert[9] = "code_iso,label,unicode";
$tabfieldinsert[10]= "fk_pays,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldinsert[10]= "fk_pays,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldinsert[11]= "element,source,code,libelle";
$tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage,sortorder";
$tabfieldinsert[13]= "code,libelle,type,accountancy_code";
Expand Down Expand Up @@ -376,7 +376,7 @@
$tabhelp[7] = array('code'=>$langs->trans("EnterAnyCode"));
$tabhelp[8] = array('code'=>$langs->trans("EnterAnyCode"));
$tabhelp[9] = array('code'=>$langs->trans("EnterAnyCode"), 'unicode'=>$langs->trans("UnicodeCurrency"));
$tabhelp[10] = array('taux'=>$langs->trans("SellTaxRate"), 'recuperableonly'=>$langs->trans("RecuperableOnly"), 'localtax1_type'=>$langs->trans("LocalTaxDesc"), 'localtax2_type'=>$langs->trans("LocalTaxDesc"));
$tabhelp[10] = array('code'=>$langs->trans("EnterAnyCode"), 'taux'=>$langs->trans("SellTaxRate"), 'recuperableonly'=>$langs->trans("RecuperableOnly"), 'localtax1_type'=>$langs->trans("LocalTaxDesc"), 'localtax2_type'=>$langs->trans("LocalTaxDesc"));
$tabhelp[11] = array();
$tabhelp[12] = array('code'=>$langs->trans("EnterAnyCode"));
$tabhelp[13] = array('code'=>$langs->trans("EnterAnyCode"));
Expand Down Expand Up @@ -522,8 +522,8 @@
$ok=1;
foreach ($listfield as $f => $value)
{
if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType', 'DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
if ($value == 'color' && empty($_POST['color'])) continue;
Expand Down Expand Up @@ -1321,7 +1321,7 @@
// Can an entry be erased or disabled ?
$iserasable=1;$isdisable=1; // true by default

if (isset($obj->code))
if (isset($obj->code) && $id != 10)
{
if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $isdisable = 0; }
else if ($obj->code == 'RECEP') { $iserasable = 0; $isdisable = 0; }
Expand Down Expand Up @@ -1356,7 +1356,7 @@
print "</td>";

// Modify link
if ($iserasable) print '<td align="center"><a href="'.$url.'action=edit#'.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'">'.img_edit().'</a></td>';
if ($iserasable) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
else print '<td>&nbsp;</td>';

// Delete link
Expand Down Expand Up @@ -1479,7 +1479,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
} // For state page, we do not show the country input (we link to region, not country)
print '<td>';
$fieldname='country';
print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28);
print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth300');
print '</td>';
}
elseif ($fieldlist[$field] == 'country_id')
Expand Down
6 changes: 4 additions & 2 deletions htdocs/comm/askpricesupplier/class/askpricesupplier.class.php
Expand Up @@ -369,7 +369,8 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, '', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down Expand Up @@ -528,7 +529,8 @@ function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0,
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down
6 changes: 4 additions & 2 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -439,7 +439,8 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type);

$total_ht = $tabprice[0];
Expand Down Expand Up @@ -600,7 +601,8 @@ function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down
6 changes: 4 additions & 2 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -1220,7 +1220,8 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type,'', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down Expand Up @@ -2442,7 +2443,8 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocalt
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down
8 changes: 4 additions & 4 deletions htdocs/compta/facture.php
Expand Up @@ -1401,12 +1401,12 @@

// Margin
$fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
$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);
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);

$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc);
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc);
$info_bits = 0;
if ($tva_npr)
$info_bits |= 0x01;
Expand Down
8 changes: 5 additions & 3 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -2045,8 +2045,8 @@ function set_draft($user,$idwarehouse=-1)
* @param double $pu_ht Unit price without tax (> 0 even for credit note)
* @param double $qty Quantity
* @param double $txtva Force vat rate, -1 for auto
* @param double $txlocaltax1 Local tax 1 rate
* @param double $txlocaltax2 Local tax 2 rate
* @param double $txlocaltax1 Local tax 1 rate (deprecated)
* @param double $txlocaltax2 Local tax 2 rate (deprecated)
* @param int $fk_product Id of predefined product/service
* @param double $remise_percent Percent of discount on line
* @param int $date_start Date start of service
Expand Down Expand Up @@ -2141,6 +2141,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent);

Expand Down Expand Up @@ -2299,7 +2300,8 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $dat
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent);

$total_ht = $tabprice[0];
Expand Down
6 changes: 4 additions & 2 deletions htdocs/contrat/class/contrat.class.php
Expand Up @@ -1260,7 +1260,8 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_pr
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down Expand Up @@ -1441,7 +1442,8 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $dat
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$localtaxes_type=getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc);

$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand Down
17 changes: 11 additions & 6 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -3857,12 +3857,12 @@ function load_cache_vatrates($country_code)

dol_syslog(__METHOD__, LOG_DEBUG);

$sql = "SELECT DISTINCT t.taux, t.recuperableonly";
$sql = "SELECT DISTINCT t.code, t.taux, t.recuperableonly";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql.= " WHERE t.fk_pays = c.rowid";
$sql.= " AND t.active > 0";
$sql.= " AND c.code IN (".$country_code.")";
$sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC";
$sql.= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";

$resql=$this->db->query($sql);
if ($resql)
Expand All @@ -3873,8 +3873,9 @@ function load_cache_vatrates($country_code)
for ($i = 0; $i < $num; $i++)
{
$obj = $this->db->fetch_object($resql);
$this->cache_vatrates[$i]['code'] = $obj->code;
$this->cache_vatrates[$i]['txtva'] = $obj->taux;
$this->cache_vatrates[$i]['libtva'] = $obj->taux.'%';
$this->cache_vatrates[$i]['libtva'] = $obj->taux.'%'.($obj->code?' ('.$obj->code.')':''); // Label must contains only 0-9 , . % or *
$this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly;
}

Expand All @@ -3897,7 +3898,7 @@ function load_cache_vatrates($country_code)
* Output an HTML select vat rate.
* The name of this function should be selectVat. We keep bad name for compatibility purpose.
*
* @param string $htmlname Name of html select field
* @param string $htmlname Name of HTML select field
* @param float $selectedrate Force preselected vat rate. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
Expand All @@ -3910,10 +3911,11 @@ function load_cache_vatrates($country_code)
* Si vendeur et acheteur dans Communauté européenne et acheteur= particulier alors TVA par défaut=TVA du produit vendu. 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.
* @param bool $options_only Return options only (for ajax treatment)
* @param bool $options_only Return HTML options lines only (for ajax treatment)
* @param int $addcode Add code into key in select list
* @return string
*/
function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false)
function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false, $addcode=0)
{
global $langs,$conf,$mysoc;

Expand Down Expand Up @@ -4016,13 +4018,16 @@ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $

$return.= '<option value="'.$rate['txtva'];
$return.= $rate['nprtva'] ? '*': '';
if ($addcode && $rate['code']) $return.=' ('.$rate['code'].')';
$return.= '"';
if ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr)
{
$return.= ' selected';
}
$return.= '>'.vatrate($rate['libtva']);
//$return.=($rate['code']?' '.$rate['code']:'');
$return.= $rate['nprtva'] ? ' *': '';

$return.= '</option>';
}

Expand Down

0 comments on commit 01058be

Please sign in to comment.