2
0
forked from Wavyzz/dolibarr

Merge pull request #495 from cbattarel/develop

[ task #204 ] Manage canadian, spain and other country double VAT with a generic system. various updates for local taxes
This commit is contained in:
Laurent Destailleur
2012-11-28 02:08:07 -08:00
9 changed files with 1556 additions and 1350 deletions

View File

@@ -547,7 +547,7 @@ if ($action == 'edit' || $action == 'updateedit')
/* /*
* Local Taxes * Local Taxes
*/ */
if ($mysoc->country_code=='ES') if ($mysoc->hasLocalTax(1))
{ {
// Local Tax 1 // Local Tax 1
print '<br>'; print '<br>';
@@ -576,7 +576,9 @@ if ($action == 'edit' || $action == 'updateedit')
print "</table>"; print "</table>";
print "</td></tr>\n"; print "</td></tr>\n";
print "</table>"; print "</table>";
}
if ($mysoc->hasLocalTax(2))
{
// Local Tax 2 // Local Tax 2
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
@@ -921,7 +923,7 @@ else
/* /*
* Local Taxes * Local Taxes
*/ */
if ($mysoc->country_code=='ES') if ($mysoc->hasLocalTax(1))
{ {
// Local Tax 1 // Local Tax 1
print '<br>'; print '<br>';
@@ -951,7 +953,9 @@ else
print "</td></tr>\n"; print "</td></tr>\n";
print "</table>"; print "</table>";
}
if ($mysoc->hasLocalTax(2))
{
// Local Tax 2 // Local Tax 2
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';

View File

@@ -1565,21 +1565,19 @@ print '<td align="right" nowrap>'.price($object->total_tva).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
// Amount Local Taxes // Amount Local Taxes
if ($mysoc->country_code=='ES') if ($mysoc->localtax1_assuj=="1") //Localtax1
{ {
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
{ print '<td align="right" nowrap>'.price($object->total_localtax1).'</td>';
print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>'; print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<td align="right" nowrap>'.price($object->total_localtax1).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
}
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{
print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
print '<td align="right" nowrap>'.price($object->total_localtax2).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
}
} }
if ($mysoc->localtax2_assuj=="1") //Localtax2
{
print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
print '<td align="right" nowrap>'.price($object->total_localtax2).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
}
// Amount TTC // Amount TTC
print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>'; print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';

View File

@@ -1581,18 +1581,16 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>'; print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>'; print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>"; print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
if ($mysoc->country_code=='ES') if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{ {
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
{
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
}
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
}
} }
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
}
print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>"; print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
} }
else else
@@ -1814,11 +1812,8 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
if (! empty($conf->projet->enabled)) $nbrow++; if (! empty($conf->projet->enabled)) $nbrow++;
//Local taxes //Local taxes
if ($mysoc->country_code=='ES') if($mysoc->localtax1_assuj=="1") $nbrow++;
{ if($mysoc->localtax2_assuj=="1") $nbrow++;
if($mysoc->localtax1_assuj=="1") $nbrow++;
if($mysoc->localtax2_assuj=="1") $nbrow++;
}
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@@ -2075,20 +2070,17 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>'; print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
// Amount Local Taxes // Amount Local Taxes
if ($mysoc->country_code=='ES') if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{ {
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
{ print '<td align="right">'.price($object->total_localtax1).'</td>';
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>'; print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<td align="right">'.price($object->total_localtax1).'</td>'; }
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>'; if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
} {
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
{ print '<td align="right">'.price($object->total_localtax2).'</td>';
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>'; print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<td align="right">'.price($object->total_localtax2).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
}
} }
// Total TTC // Total TTC

View File

@@ -1518,27 +1518,49 @@ abstract class CommonObject
$this->total_localtax2 += $obj->total_localtax2; $this->total_localtax2 += $obj->total_localtax2;
$this->total_ttc += $obj->total_ttc; $this->total_ttc += $obj->total_ttc;
// Define vatrates with totals for each line and for all lines // Check if global invoice tax for this vat rate
// TODO $vatrates and $vatrates_alllines not used ? if (! empty($obj->vatrate))
if (! empty($this->vatrate))
{ {
$vatrates[$this->vatrate][]=array( if ($this->total_localtax1 == 0)
'total_ht' =>$obj->total_ht, {
'total_tva' =>$obj->total_tva, // Search local taxes
'total_ttc' =>$obj->total_ttc, $sql = "SELECT t.localtax1, t.localtax1_type";
'total_localtax1'=>$obj->total_localtax1, $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
'total_localtax2'=>$obj->total_localtax2 $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->client->country_code."'";
); $sql .= " AND t.taux = ".$obj->vatrate." AND t.active = 1";
if (! isset($vatrates_alllines[$this->vatrate]['total_ht'])) $vatrates_alllines[$this->vatrate]['total_ht']=0;
if (! isset($vatrates_alllines[$this->vatrate]['total_tva'])) $vatrates_alllines[$this->vatrate]['total_tva']=0; dol_syslog("get_localtax sql=".$sql);
if (! isset($vatrates_alllines[$this->vatrate]['total_localtax1'])) $vatrates_alllines[$this->vatrate]['total_localtax1']=0; $resqlt=$this->db->query($sql);
if (! isset($vatrates_alllines[$this->vatrate]['total_localtax2'])) $vatrates_alllines[$this->vatrate]['total_localtax2']=0; if ($resqlt)
if (! isset($vatrates_alllines[$this->vatrate]['total_ttc'])) $vatrates_alllines[$this->vatrate]['total_ttc']=0; {
$vatrates_alllines[$this->vatrate]['total_ht'] +=$obj->total_ht; $objt = $this->db->fetch_object($resqlt);
$vatrates_alllines[$this->vatrate]['total_tva'] +=$obj->total_tva; if ($objt->localtax1_type == '7')
$vatrates_alllines[$this->vatrate]['total_localtax1']+=$obj->total_localtax1; {
$vatrates_alllines[$this->vatrate]['total_localtax2']+=$obj->total_localtax2; $this->total_localtax1 += $objt->localtax1;
$vatrates_alllines[$this->vatrate]['total_ttc'] +=$obj->total_ttc; $this->total_ttc += $objt->localtax1;
}
}
}
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";
dol_syslog("get_localtax sql=".$sql);
$resqlt=$this->db->query($sql);
if ($resqlt)
{
$objt = $this->db->fetch_object($resqlt);
if ($objt->localtax2_type == '7')
{
$this->total_localtax2 += $objt->localtax2;
$this->total_ttc += $objt->localtax2;
}
}
}
} }
$i++; $i++;
@@ -1546,21 +1568,6 @@ abstract class CommonObject
$this->db->free($resql); $this->db->free($resql);
// TODO
if ($roundingadjust)
{
// For each vatrate, calculate if two method of calculation differs
// If it differs
if (1==2)
{
// Adjust a line and update it
}
}
// Now update global field total_ht, total_ttc and tva // Now update global field total_ht, total_ttc and tva
$fieldht='total_ht'; $fieldht='total_ht';
$fieldtva='tva'; $fieldtva='tva';
@@ -3037,4 +3044,4 @@ abstract class CommonObject
} }
} }
?> ?>

View File

@@ -2721,7 +2721,7 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
} }
// Search local taxes // Search local taxes
$sql = "SELECT t.localtax1, t.localtax2"; $sql = "SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; $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 = '".$code_country."'"; $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_country."'";
$sql .= " AND t.taux = ".$tva." AND t.active = 1"; $sql .= " AND t.taux = ".$tva." AND t.active = 1";
@@ -2731,9 +2731,8 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
if ($resql) if ($resql)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($local==1) return $obj->localtax1; if ($local==1 && $obj->localtax1_type != '7') return $obj->localtax1;
elseif ($local==2) return $obj->localtax2; elseif ($local==2 && $obj->localtax2_type != '7') return $obj->localtax2;
//else return array($obj->localtax1,$obj->localtax2);
} }
return 0; return 0;

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr> * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -118,6 +119,8 @@ class pdf_azur extends ModelePDFPropales
$this->tva=array(); $this->tva=array();
$this->localtax1=array(); $this->localtax1=array();
$this->localtax2=array(); $this->localtax2=array();
$this->localtax1_type=array();
$this->localtax2_type=array();
$this->atleastoneratenotnull=0; $this->atleastoneratenotnull=0;
$this->atleastonediscount=0; $this->atleastonediscount=0;
} }
@@ -368,16 +371,24 @@ class pdf_azur extends ModelePDFPropales
if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
$vatrate=(string) $object->lines[$i]->tva_tx; $vatrate=(string) $object->lines[$i]->tva_tx;
$localtax1rate=(string) $object->lines[$i]->localtax1_tx;
$localtax2rate=(string) $object->lines[$i]->localtax2_tx;
if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=''; if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]='';
if (! isset($this->localtax1[$localtax1rate])) $this->localtax1[$localtax1rate]='';
if (! isset($this->localtax2[$localtax2rate])) $this->localtax2[$localtax2rate]='';
$this->tva[$vatrate] += $tvaligne; $this->tva[$vatrate] += $tvaligne;
$this->localtax1[$localtax1rate]+=$localtax1ligne;
$this->localtax2[$localtax2rate]+=$localtax2ligne; // 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 = '".$object->client->country_code."'";
$sql .= " AND t.taux = ".$vatrate." AND t.active = 1";
$resqlt=$this->db->query($sql);
if ($resqlt)
{
$objt = $this->db->fetch_object($resqlt);
$this->localtax1[$objt->localtax1_type][$objt->localtax1]+=$localtax1ligne;
$this->localtax2[$objt->localtax2_type][$objt->localtax2]+=$localtax2ligne;
}
// Add line // Add line
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
@@ -735,6 +746,84 @@ class pdf_azur extends ModelePDFPropales
} }
else else
{ {
//Local tax 1 before VAT
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
{
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) {
switch ($localtax_type) {
case '1':
case '3':
case '5':
case '7':
continue 2;
break;
}
foreach( $localtax_rate as $tvakey => $tvaval )
{
if ($tvakey>0) // On affiche pas taux 0
{
//$this->atleastoneratenotnull++;
$index++;
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$tvacompl='';
if (preg_match('/\*/',$tvakey))
{
$tvakey=str_replace('*','',$tvakey);
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
}
$totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
$totalvat.=vatrate($tvakey,1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
}
}
}
}
//Local tax 2 before VAT
if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
{
foreach( $this->localtax2 as $localtax_type => $localtax_rate ) {
switch ($localtax_type) {
case '1':
case '3':
case '5':
case '7':
continue 2;
break;
}
foreach( $localtax_rate as $tvakey => $tvaval )
{
if ($tvakey>0) // On affiche pas taux 0
{
//$this->atleastoneratenotnull++;
$index++;
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$tvacompl='';
if (preg_match('/\*/',$tvakey))
{
$tvakey=str_replace('*','',$tvakey);
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
}
$totalvat = $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
$totalvat.=vatrate($tvakey,1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
}
}
}
}
// VAT
foreach($this->tva as $tvakey => $tvaval) foreach($this->tva as $tvakey => $tvaval)
{ {
if ($tvakey > 0) // On affiche pas taux 0 if ($tvakey > 0) // On affiche pas taux 0
@@ -759,48 +848,25 @@ class pdf_azur extends ModelePDFPropales
} }
} }
if (! $this->atleastoneratenotnull) // If no vat at all //Local tax 1 after VAT
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
{ {
$index++; foreach( $this->localtax1 as $localtax_type => $localtax_rate ) {
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); switch ($localtax_type) {
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1); case '2':
case '4':
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); case '6':
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1); continue 2;
break;
// Total LocalTax1 }
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0) foreach( $localtax_rate as $tvakey => $tvaval )
{
$index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
}
// Total LocalTax2
if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
{
$index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
}
}
else
{
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
{
//Local tax 1
foreach($this->localtax1 as $tvakey => $tvaval)
{ {
if ($tvakey!=0) // On affiche pas taux 0 if ($tvakey>0) // On affiche pas taux 0
{ {
//$this->atleastoneratenotnull++; //$this->atleastoneratenotnull++;
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$tvacompl=''; $tvacompl='';
if (preg_match('/\*/',$tvakey)) if (preg_match('/\*/',$tvakey))
@@ -808,27 +874,43 @@ class pdf_azur extends ModelePDFPropales
$tvakey=str_replace('*','',$tvakey); $tvakey=str_replace('*','',$tvakey);
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
} }
$totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' '; $totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
$totalvat.=vatrate($tvakey,1).$tvacompl; if ($localtax_type == '7') { // amount on order
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($tvakey), 0, 'R', 1);
}
else
{
$totalvat.=vatrate($tvakey,1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
}
} }
} }
} }
}
if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') //Local tax 2 after VAT
{ if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
//Local tax 2 {
foreach($this->localtax2 as $tvakey => $tvaval) foreach( $this->localtax2 as $localtax_type => $localtax_rate ) {
switch ($localtax_type) {
case '2':
case '4':
case '6':
continue 2;
break;
}
foreach( $localtax_rate as $tvakey => $tvaval )
{ {
if ($tvakey!=0) // On affiche pas taux 0 if ($tvakey>0) // On affiche pas taux 0
{ {
//$this->atleastoneratenotnull++; //$this->atleastoneratenotnull++;
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$tvacompl=''; $tvacompl='';
if (preg_match('/\*/',$tvakey)) if (preg_match('/\*/',$tvakey))
@@ -836,13 +918,21 @@ class pdf_azur extends ModelePDFPropales
$tvakey=str_replace('*','',$tvakey); $tvakey=str_replace('*','',$tvakey);
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
} }
$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' '; $totalvat = $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
$totalvat.=vatrate($tvakey,1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); if ($localtax_type == '7') { // amount on order
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvakey), 0, 'R', 1);
}
else
{
$totalvat.=vatrate($tvakey,1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
}
} }
} }
} }

View File

@@ -2569,6 +2569,43 @@ class Societe extends CommonObject
$this->idprof5='idprof5'; $this->idprof5='idprof5';
$this->idprof6='idprof6'; $this->idprof6='idprof6';
} }
/**
* Check if localtax define for company
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @param localTaxNum $localTaxNum 1 or 2
* @return boolean true / false
*/
function hasLocalTax($localTaxNum) {
global $user,$langs,$conf;
// check parameter
if ($localTaxNum != 1 && $localTaxNum != 2)
return false;
// 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";
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->country_code."'";
$sql .= " AND t.active = 1";
if ($localTaxNum == 1)
$sql .= " AND t.localtax1 <> 0";
elseif ($localTaxNum == 2)
$sql .= " AND t.localtax2 <> 0";
dol_syslog("get_localtax sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return ($this->db->num_rows($resql) > 0);
}
else
return false;
}
} }

View File

@@ -907,30 +907,26 @@ else
print '<tr><td>'.$langs->trans('Capital').'</td><td colspan="3"><input type="text" name="capital" size="10" value="'.$object->capital.'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>'; print '<tr><td>'.$langs->trans('Capital').'</td><td colspan="3"><input type="text" name="capital" size="10" value="'.$object->capital.'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
// Local Taxes // Local Taxes
// TODO add specific function by country if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
if($mysoc->country_code=='ES')
{ {
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") print '<tr><td>'.$langs->trans("LocalTax1IsUsed").'</td><td>';
{ print $form->selectyesno('localtax1assuj_value',0,1);
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>'; print '</td><td>'.$langs->trans("LocalTax2IsUsed").'</td><td>';
print $form->selectyesno('localtax1assuj_value',0,1); print $form->selectyesno('localtax2assuj_value',0,1);
print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>'; print '</td></tr>';
print $form->selectyesno('localtax2assuj_value',0,1);
print '</td></tr>';
} }
elseif($mysoc->localtax1_assuj=="1") elseif($mysoc->localtax1_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax1IsUsed").'</td><td colspan="3">';
print $form->selectyesno('localtax1assuj_value',0,1); print $form->selectyesno('localtax1assuj_value',0,1);
print '</td><tr>'; print '</td><tr>';
} }
elseif($mysoc->localtax2_assuj=="1") elseif($mysoc->localtax2_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax2IsUsed").'</td><td colspan="3">';
print $form->selectyesno('localtax2assuj_value',0,1); print $form->selectyesno('localtax2assuj_value',0,1);
print '</td><tr>'; print '</td><tr>';
}
} }
if (! empty($conf->global->MAIN_MULTILANGS)) if (! empty($conf->global->MAIN_MULTILANGS))
@@ -1322,31 +1318,27 @@ else
print '</tr>'; print '</tr>';
// Local Taxes // Local Taxes
// TODO add specific function by country if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
if($mysoc->country_code=='ES')
{ {
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
{ print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>'; print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1); print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>'; print '</td></tr>';
print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
print '</td></tr>';
} }
elseif($mysoc->localtax1_assuj=="1") elseif($mysoc->localtax1_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1); print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
print '</td></tr>'; print '</td></tr>';
} }
elseif($mysoc->localtax2_assuj=="1") elseif($mysoc->localtax2_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1); print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
print '</td></tr>'; print '</td></tr>';
}
} }
// Type - Size // Type - Size
@@ -1642,30 +1634,26 @@ else
print '</tr>'; print '</tr>';
// Local Taxes // Local Taxes
// TODO add specific function by country if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
if($mysoc->country_code=='ES')
{ {
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
{ print yn($object->localtax1_assuj);
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>'; print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
print yn($object->localtax1_assuj); print yn($object->localtax2_assuj);
print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>'; print '</td></tr>';
print yn($object->localtax2_assuj);
print '</td></tr>';
} }
elseif($mysoc->localtax1_assuj=="1") elseif($mysoc->localtax1_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
print yn($object->localtax1_assuj); print yn($object->localtax1_assuj);
print '</td><tr>'; print '</td><tr>';
} }
elseif($mysoc->localtax2_assuj=="1") elseif($mysoc->localtax2_assuj=="1")
{ {
print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
print yn($object->localtax2_assuj); print yn($object->localtax2_assuj);
print '</td><tr>'; print '</td><tr>';
}
} }
// Type + Staff // Type + Staff