Fix: Solve phpunit regression.

Include an option to support local tax of type 7 (need more time to
validate this type).
This commit is contained in:
Laurent Destailleur 2012-12-19 18:51:49 +01:00
parent e9d7a4adc6
commit 78a1354a52
13 changed files with 82 additions and 76 deletions

View File

@ -1483,8 +1483,8 @@ abstract class CommonObject
$fieldlocaltax2='total_localtax2';
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='tva';
$sql = 'SELECT qty, total_ht, '.$fieldtva.' as total_tva, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2, total_ttc,';
$sql.= ' tva_tx as vatrate';
$sql = 'SELECT qty, total_ht, '.$fieldtva.' as total_tva, total_ttc, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2,';
$sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
if ($exclspec)
@ -1518,49 +1518,48 @@ abstract class CommonObject
$this->total_localtax2 += $obj->total_localtax2;
$this->total_ttc += $obj->total_ttc;
// Check if global invoice tax for this vat rate
if (! empty($obj->vatrate))
// Check if there is a global invoice tax for this vat rate
// FIXME: We should have no database access into this function. Also localtax 7 seems to have problem so i add condition to avoid it into standard usage without loosing it.
if (! empty($conf->global->MAIN_USE_LOCALTAX_TYPE_7))
{
if ($this->total_localtax1 == 0)
if ($this->total_localtax1 == 0)
{
// Search local taxes
$sql = "SELECT t.localtax1, t.localtax1_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->client->country_code."'";
$sql .= " AND t.taux = ".$obj->vatrate." AND t.active = 1";
// Search to know if there is a localtax of type 7
// TODO : store local taxes types into object lines and remove this. We should use here $obj->localtax1_type but it is not yet filled into database, so we search into table of vat rate
global $mysoc;
$localtax1_array=getLocalTaxesFromRate($vatrate,1,$mysoc);
if (empty($obj->localtax1_type))
{
$obj->localtax1_type = $localtax1_array[0];
$obj->localtax1_tx = $localtax1_array[1];
}
//end TODO
dol_syslog("get_localtax sql=".$sql);
$resqlt=$this->db->query($sql);
if ($resqlt)
if ($obj->localtax1_type == '7')
{
$objt = $this->db->fetch_object($resqlt);
if ($objt->localtax1_type == '7')
{
$this->total_localtax1 += $objt->localtax1;
$this->total_ttc += $objt->localtax1;
}
$this->total_localtax1 += $obj->localtax1_tx;
$this->total_ttc += $obj->localtax1_tx;
}
}
if ($this->total_localtax2 == 0)
{
// Search local taxes
$sql = "SELECT t.localtax2, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->client->country_code."'";
$sql .= " AND t.taux = ".$obj->vatrate." AND t.active = 1";
// Search to know if there is a localtax of type 7
// TODO : store local taxes types into object lines and remove this. We should use here $obj->localtax1_type but it is not yet filled into database, so we search into table of vat rate
global $mysoc;
$localtax2_array=getLocalTaxesFromRate($vatrate,2,$mysoc);
if (empty($obj->localtax2_type))
{
$obj->localtax2_type = $localtax2_array[0];
$obj->localtax2_tx = $localtax2_array[1];
}
//end TODO
dol_syslog("get_localtax sql=".$sql);
$resqlt=$this->db->query($sql);
if ($resqlt)
if ($obj->localtax2_type == '7')
{
$objt = $this->db->fetch_object($resqlt);
if ($objt->localtax2_type == '7')
{
$this->total_localtax2 += $objt->localtax2;
$this->total_ttc += $objt->localtax2;
}
$this->total_localtax2 += $obj->localtax2_tx;
$this->total_ttc += $obj->localtax2_tx;
}
}
}
}
$i++;

View File

@ -2674,7 +2674,7 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
* @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
* @return int 0 if not found, localtax if found
* @return mixed 0 if not found, localtax if found
* @see get_default_tva
*/
function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
@ -2683,10 +2683,10 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
if (empty($thirdparty_seller) || ! is_object($thirdparty_seller)) $thirdparty_seller=$mysoc;
dol_syslog("get_localtax tva=".$tva." local=".$local." thirdparty_buyer=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')." thirdparty_seller=".$thirdparty_seller->id);
dol_syslog("get_localtax tva=".$tva." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')." thirdparty_seller id=".$thirdparty_seller->id);
// Some test to guess with no need to make database access
if ($mysoc->country_code == 'ES') // For spain, localtaxes are qualified if both supplier and seller use local taxe
if ($mysoc->country_code == 'ES') // For spain and localtaxes 1, tax is qualified if buyer use local taxe
{
if ($local == 1 && ! $thirdparty_buyer->localtax1_assuj) return 0;
if ($local == 2 && ! $thirdparty_seller->localtax2_assuj) return 0;
@ -2699,7 +2699,6 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
//if ($local == 0 && ! $thirdparty_seller->localtax1_assuj && ! $thirdparty_seller->localtax2_assuj) return array('localtax1'=>0,'localtax2'=>0);
$code_country=$thirdparty_seller->country_code;
if (is_object($thirdparty_buyer))
{
if ($code_country != $thirdparty_buyer->country_code) return 0;
@ -2723,6 +2722,38 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
return 0;
}
/**
* Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
*
* @param real $vatrate VAT Rate
* @param int $local Number of localtax (1 / 2)
* @param int $thirdparty company object
* @return array array(Type of local tax (1 to 7 / 0 if not found), rate or amount of localtax)
* @deprecated TODO We should remove this function by storing rate and type into detail lines.
*/
function getLocalTaxesFromRate($vatrate, $local, $thirdparty)
{
global $db;
dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local." thirdparty id=".(is_object($thirdparty)?$thirdparty->id:''));
// Search local taxes
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$thirdparty->country_code."'";
$sql .= " AND t.taux = ".$vatrate." AND t.active = 1";
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($local == 1) return array($obj->localtax1_type, $obj->localtax1);
elseif ($local == 2) return array($obj->localtax2_type, $obj->localtax2);
}
return 0;
}
/**
* Return vat rate of a product in a particular selling country or default country vat if product is unknown
*
@ -4201,35 +4232,7 @@ function getCurrencySymbol($currency_code)
return $currency_sign;
}
/**
* Get type of one localtax
*
* @param int $vatrate VAT Rate
* @param int $number Number of localtax (1 / 2)
* @param int $thirdparty company object
* @return array array(Type of local tax (1 to 7 / 0 if not found), rate or amount of localtax)
*/
function getTypeOfLocalTaxFromRate($vatrate, $number, $thirdparty)
{
global $db;
// Search local taxes
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$thirdparty->country_code."'";
$sql .= " AND t.taux = ".$vatrate." AND t.active = 1";
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($number == 1) return array($obj->localtax1_type, $obj->localtax1);
elseif ($number == 2) return array($obj->localtax2_type, $obj->localtax2);
}
return 0;
}
if (! function_exists('getmypid'))
{

View File

@ -118,6 +118,8 @@ class pdf_einstein extends ModelePDFCommandes
}
$this->tva=array();
$this->localtax1=array();
$this->localtax2=array();
$this->atleastoneratenotnull=0;
$this->atleastonediscount=0;
}
@ -374,8 +376,8 @@ class pdf_einstein extends ModelePDFCommandes
$vatrate=(string) $object->lines[$i]->tva_tx;
// TODO : store local taxes types into object lines and remove this
$localtax1_array=getTypeOfLocalTaxFromRate($vatrate,1,$mysoc);
$localtax2_array=getTypeOfLocalTaxFromRate($vatrate,2,$mysoc);
$localtax1_array=getLocalTaxesFromRate($vatrate,1,$mysoc);
$localtax2_array=getLocalTaxesFromRate($vatrate,2,$mysoc);
if (empty($localtax1_type))
$localtax1_type = $localtax1_array[0];
if (empty($localtax2_type))

View File

@ -378,8 +378,8 @@ class pdf_crabe extends ModelePDFFactures
$vatrate=(string) $object->lines[$i]->tva_tx;
// TODO : store local taxes types into object lines and remove this
$localtax1_array=getTypeOfLocalTaxFromRate($vatrate,1,$mysoc);
$localtax2_array=getTypeOfLocalTaxFromRate($vatrate,2,$mysoc);
$localtax1_array=getLocalTaxesFromRate($vatrate,1,$mysoc);
$localtax2_array=getLocalTaxesFromRate($vatrate,2,$mysoc);
if (empty($localtax1_type))
$localtax1_type = $localtax1_array[0];
if (empty($localtax2_type))

View File

@ -117,6 +117,8 @@ class pdf_azur extends ModelePDFPropales
}
$this->tva=array();
$this->localtax1=array();
$this->localtax2=array();
$this->atleastoneratenotnull=0;
$this->atleastonediscount=0;
}
@ -371,8 +373,8 @@ class pdf_azur extends ModelePDFPropales
$vatrate=(string) $object->lines[$i]->tva_tx;
// TODO : store local taxes types into object lines and remove this
$localtax1_array=getTypeOfLocalTaxFromRate($vatrate,1,$mysoc);
$localtax2_array=getTypeOfLocalTaxFromRate($vatrate,2,$mysoc);
$localtax1_array=getLocalTaxesFromRate($vatrate,1,$mysoc);
$localtax2_array=getLocalTaxesFromRate($vatrate,2,$mysoc);
if (empty($localtax1_type))
$localtax1_type = $localtax1_array[0];
if (empty($localtax2_type))

View File

@ -350,6 +350,7 @@ TextLong=Text llarg
Int=numèric enter
Float=Decimal
DateAndTime=Data i hora
LocalTaxDesc=Alguns països apliquen 2 o 3 taxes a cada línia de factura. Si és el cas, escolliu el tipus de la segona i tercera taxa i el seu valor. Els possibles tipus són: <br> 1: taxa local aplicable a productes i serveis sense IVA (IVA no s'aplica a la taxa local) <br> 2: taxa local s'aplica a productes i serveis abans de l'IVA (IVA es calcula sobre import + taxa local) <br> 3: taxa local s'aplica a productes sense IVA (IVA no s'aplica a la taxa local) <br> 4: taxa local s'aplica a productes abans de l'IVA (IVA es calcula sobre l'import + taxa local) <br> 5: taxa local s'aplica a serveis sense IVA (IVA no s'aplica a la taxa local) <br> 6: taxa local s'aplica a serveis abans de l'IVA (IVA es calcula sobre import + taxa local)
# Modules
Module0Name=Usuaris y grups

View File

@ -251,7 +251,6 @@ MonthOfDay=Mes del dia
HourShort=H
Rate=Tipus
UseLocalTax=Incloure taxes
LocalTaxDesc=Alguns països apliquen 2 o 3 taxes a cada línia de factura. Si és el cas, escolliu el tipus de la segona i tercera taxa i el seu valor. Els possibles tipus són: <br> 1: taxa local aplicable a productes i serveis sense IVA (IVA no s'aplica a la taxa local) <br> 2: taxa local s'aplica a productes i serveis abans de l'IVA (IVA es calcula sobre import + taxa local) <br> 3: taxa local s'aplica a productes sense IVA (IVA no s'aplica a la taxa local) <br> 4: taxa local s'aplica a productes abans de l'IVA (IVA es calcula sobre l'import + taxa local) <br> 5: taxa local s'aplica a serveis sense IVA (IVA no s'aplica a la taxa local) <br> 6: taxa local s'aplica a serveis abans de l'IVA (IVA es calcula sobre import + taxa local) <br> 7: la taxa local és un import fix aplicat al total de la factura
Bytes=Bytes
KiloBytes=Kilobytes
MegaBytes=Megabytes

View File

@ -347,6 +347,7 @@ Float=Float
DateAndTime=Date and hour
LibraryToBuildPDF=Library used to build PDF
WarningUsingFPDF=Warning: Your <b>conf.php</b> contains directive <b>dolibarr_pdf_force_fpdf=1</b>. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.<br>To solve this and have a full support of PDF generation, please download <a href="http://www.tcpdf.org/" target="_blank">TCPDF library</a>, then comment or remove the line <b>$dolibarr_pdf_force_fpdf=1</b>, and add instead <b>$dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir'</b>
LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:<br>1 : local tax apply on products and services without vat (vat is not applied on local tax)<br>2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)<br>3 : local tax apply on products without vat (vat is not applied on local tax)<br>4 : local tax apply on products before vat (vat is calculated on amount + localtax)<br>5 : local tax apply on services without vat (vat is not applied on local tax)<br>6 : local tax apply on services before vat (vat is calculated on amount + localtax)
# Modules
Module0Name=Users & groups

View File

@ -248,7 +248,6 @@ MonthOfDay=Month of the day
HourShort=H
Rate=Rate
UseLocalTax=Include tax
LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:<br>1 : local tax apply on products and services without vat (vat is not applied on local tax)<br>2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)<br>3 : local tax apply on products without vat (vat is not applied on local tax)<br>4 : local tax apply on products before vat (vat is calculated on amount + localtax)<br>5 : local tax apply on services without vat (vat is not applied on local tax)<br>6 : local tax apply on services before vat (vat is calculated on amount + localtax)<br>7 : local tax is a fix amount applied on global invoice
Bytes=Bytes
KiloBytes=Kilobytes
MegaBytes=Megabytes

View File

@ -352,6 +352,7 @@ Int=Numérico entero
Float=Decimal
DateAndTime=Fecha y hora
Unique=Único
LocalTaxDesc=Algunos países aplican 2 o 3 tasas a cada línea de factura. Si es el caso, escoja el tipo de la segunda y tercera tasa y su valor. Los posibles tipos son:<br>1 : tasa local aplicable a productos y servicios sin IVA (IVA no se aplica en la tasa local)<br>2 : tasa local se aplica a productos y servicios antes del IVA (IVA se calcula sobre importe+tasa local)<br>3 : tasa local se aplica a productos sin IVA (IVA no se aplica en la tasa local)<br>4 : tasa local se aplica a productos antes del IVA (IVA se calcula sobre el importe+tasa local)<br>5 : tasa local se aplica a servicios sin IVA (IVA no se aplica a la tasa local)<br>6 : tasa local se aplica a servicios antes del IVA (IVA se calcula sobre importe + tasa local)
# Modules
Module0Name=Usuarios y grupos

View File

@ -251,7 +251,6 @@ MonthOfDay=Mes del día
HourShort=H
Rate=Tipo
UseLocalTax=Incluir tasas
LocalTaxDesc=Algunos países aplican 2 o 3 tasas a cada línea de factura. Si es el caso, escoja el tipo de la segunda y tercera tasa y su valor. Los posibles tipos son:<br>1 : tasa local aplicable a productos y servicios sin IVA (IVA no se aplica en la tasa local)<br>2 : tasa local se aplica a productos y servicios antes del IVA (IVA se calcula sobre importe+tasa local)<br>3 : tasa local se aplica a productos sin IVA (IVA no se aplica en la tasa local)<br>4 : tasa local se aplica a productos antes del IVA (IVA se calcula sobre el importe+tasa local)<br>5 : tasa local se aplica a servicios sin IVA (IVA no se aplica a la tasa local)<br>6 : tasa local se aplica a servicios antes del IVA (IVA se calcula sobre importe + tasa local)<br>7 : la tasa local es un importe fijo aplicado al total de la factura
Bytes=Bytes
KiloBytes=Kilobytes
MegaBytes=Megabytes

View File

@ -349,6 +349,7 @@ Float=Décimal
DateAndTime=Date et heure
LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF
WarningUsingFPDF=Attention: Votre fichier <b>conf.php</b> contient la directive <b>dolibarr_pdf_force_fpdf=1</b>. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.<br>Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la <a href="http://www.tcpdf.org/" target="_blank">librairie TCPDF</a> puis commenter ou supprimer la ligne <b>$dolibarr_pdf_force_fpdf=1</b>, et ajouter à la place <b>$dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF'</b>
LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:<br>1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)<br>3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)<br>4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)<br>5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale)
# Modules= undefined
Module0Name= Utilisateurs & groupes

View File

@ -250,7 +250,6 @@ MonthOfDay=Mois du jour
HourShort=H
Rate=Taux
UseLocalTax=Inclure taxe
LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:<br>1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)<br>3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)<br>4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)<br>5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale)<br>7 : la taxe locale est un montant fixe ajouté au total de la facture
Bytes=Octets
KiloBytes=Kilooctets
MegaBytes=Mégaoctets