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:
@@ -547,7 +547,7 @@ if ($action == 'edit' || $action == 'updateedit')
|
||||
/*
|
||||
* Local Taxes
|
||||
*/
|
||||
if ($mysoc->country_code=='ES')
|
||||
if ($mysoc->hasLocalTax(1))
|
||||
{
|
||||
// Local Tax 1
|
||||
print '<br>';
|
||||
@@ -576,7 +576,9 @@ if ($action == 'edit' || $action == 'updateedit')
|
||||
print "</table>";
|
||||
print "</td></tr>\n";
|
||||
print "</table>";
|
||||
|
||||
}
|
||||
if ($mysoc->hasLocalTax(2))
|
||||
{
|
||||
// Local Tax 2
|
||||
print '<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
@@ -921,7 +923,7 @@ else
|
||||
/*
|
||||
* Local Taxes
|
||||
*/
|
||||
if ($mysoc->country_code=='ES')
|
||||
if ($mysoc->hasLocalTax(1))
|
||||
{
|
||||
// Local Tax 1
|
||||
print '<br>';
|
||||
@@ -951,7 +953,9 @@ else
|
||||
print "</td></tr>\n";
|
||||
|
||||
print "</table>";
|
||||
|
||||
}
|
||||
if ($mysoc->hasLocalTax(2))
|
||||
{
|
||||
// Local Tax 2
|
||||
print '<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
@@ -1565,21 +1565,19 @@ print '<td align="right" nowrap>'.price($object->total_tva).'</td>';
|
||||
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
|
||||
// Amount Local Taxes
|
||||
if ($mysoc->country_code=='ES')
|
||||
{
|
||||
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
|
||||
if ($mysoc->localtax1_assuj=="1") //Localtax1
|
||||
{
|
||||
print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
|
||||
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
|
||||
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
|
||||
print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';
|
||||
|
||||
@@ -1581,8 +1581,6 @@ 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('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>";
|
||||
if ($mysoc->country_code=='ES')
|
||||
{
|
||||
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>";
|
||||
@@ -1592,7 +1590,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
{
|
||||
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>";
|
||||
}
|
||||
else
|
||||
@@ -1814,11 +1812,8 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
if (! empty($conf->projet->enabled)) $nbrow++;
|
||||
|
||||
//Local taxes
|
||||
if ($mysoc->country_code=='ES')
|
||||
{
|
||||
if($mysoc->localtax1_assuj=="1") $nbrow++;
|
||||
if($mysoc->localtax2_assuj=="1") $nbrow++;
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
@@ -2075,8 +2070,6 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
|
||||
|
||||
// Amount Local Taxes
|
||||
if ($mysoc->country_code=='ES')
|
||||
{
|
||||
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
|
||||
{
|
||||
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
|
||||
@@ -2089,7 +2082,6 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
print '<td align="right">'.price($object->total_localtax2).'</td>';
|
||||
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// Total TTC
|
||||
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($object->total_ttc).'</td>';
|
||||
|
||||
@@ -1518,27 +1518,49 @@ abstract class CommonObject
|
||||
$this->total_localtax2 += $obj->total_localtax2;
|
||||
$this->total_ttc += $obj->total_ttc;
|
||||
|
||||
// Define vatrates with totals for each line and for all lines
|
||||
// TODO $vatrates and $vatrates_alllines not used ?
|
||||
if (! empty($this->vatrate))
|
||||
// Check if global invoice tax for this vat rate
|
||||
if (! empty($obj->vatrate))
|
||||
{
|
||||
$vatrates[$this->vatrate][]=array(
|
||||
'total_ht' =>$obj->total_ht,
|
||||
'total_tva' =>$obj->total_tva,
|
||||
'total_ttc' =>$obj->total_ttc,
|
||||
'total_localtax1'=>$obj->total_localtax1,
|
||||
'total_localtax2'=>$obj->total_localtax2
|
||||
);
|
||||
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;
|
||||
if (! isset($vatrates_alllines[$this->vatrate]['total_localtax1'])) $vatrates_alllines[$this->vatrate]['total_localtax1']=0;
|
||||
if (! isset($vatrates_alllines[$this->vatrate]['total_localtax2'])) $vatrates_alllines[$this->vatrate]['total_localtax2']=0;
|
||||
if (! isset($vatrates_alllines[$this->vatrate]['total_ttc'])) $vatrates_alllines[$this->vatrate]['total_ttc']=0;
|
||||
$vatrates_alllines[$this->vatrate]['total_ht'] +=$obj->total_ht;
|
||||
$vatrates_alllines[$this->vatrate]['total_tva'] +=$obj->total_tva;
|
||||
$vatrates_alllines[$this->vatrate]['total_localtax1']+=$obj->total_localtax1;
|
||||
$vatrates_alllines[$this->vatrate]['total_localtax2']+=$obj->total_localtax2;
|
||||
$vatrates_alllines[$this->vatrate]['total_ttc'] +=$obj->total_ttc;
|
||||
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";
|
||||
|
||||
dol_syslog("get_localtax sql=".$sql);
|
||||
$resqlt=$this->db->query($sql);
|
||||
if ($resqlt)
|
||||
{
|
||||
$objt = $this->db->fetch_object($resqlt);
|
||||
if ($objt->localtax1_type == '7')
|
||||
{
|
||||
$this->total_localtax1 += $objt->localtax1;
|
||||
$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++;
|
||||
@@ -1546,21 +1568,6 @@ abstract class CommonObject
|
||||
|
||||
$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
|
||||
$fieldht='total_ht';
|
||||
$fieldtva='tva';
|
||||
|
||||
@@ -2721,7 +2721,7 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
|
||||
}
|
||||
|
||||
// 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 .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_country."'";
|
||||
$sql .= " AND t.taux = ".$tva." AND t.active = 1";
|
||||
@@ -2731,9 +2731,8 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($local==1) return $obj->localtax1;
|
||||
elseif ($local==2) return $obj->localtax2;
|
||||
//else return array($obj->localtax1,$obj->localtax2);
|
||||
if ($local==1 && $obj->localtax1_type != '7') return $obj->localtax1;
|
||||
elseif ($local==2 && $obj->localtax2_type != '7') return $obj->localtax2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -119,6 +119,8 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
$this->tva=array();
|
||||
$this->localtax1=array();
|
||||
$this->localtax2=array();
|
||||
$this->localtax1_type=array();
|
||||
$this->localtax2_type=array();
|
||||
$this->atleastoneratenotnull=0;
|
||||
$this->atleastonediscount=0;
|
||||
}
|
||||
@@ -370,16 +372,24 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
|
||||
|
||||
$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 (! 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->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
|
||||
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
|
||||
@@ -701,6 +711,84 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
}
|
||||
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)
|
||||
{
|
||||
if ($tvakey > 0) // On affiche pas taux 0
|
||||
@@ -724,71 +812,65 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
|
||||
}
|
||||
}
|
||||
if (! $this->atleastoneratenotnull) // If no vat at all
|
||||
{
|
||||
$index++;
|
||||
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
|
||||
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
|
||||
|
||||
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
|
||||
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
|
||||
|
||||
// Total LocalTax1
|
||||
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
|
||||
//Local tax 1 after VAT
|
||||
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
|
||||
{
|
||||
$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);
|
||||
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) {
|
||||
switch ($localtax_type) {
|
||||
case '2':
|
||||
case '4':
|
||||
case '6':
|
||||
continue 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// Total LocalTax2
|
||||
if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
|
||||
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);
|
||||
$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);
|
||||
|
||||
$tvacompl='';
|
||||
if (preg_match('/\*/',$tvakey))
|
||||
{
|
||||
$tvakey=str_replace('*','',$tvakey);
|
||||
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
|
||||
}
|
||||
$totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
|
||||
if ($localtax_type == '7') { // amount on order
|
||||
$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
|
||||
{
|
||||
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
|
||||
{
|
||||
//$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->country_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 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++;
|
||||
|
||||
@@ -801,7 +883,15 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
$tvakey=str_replace('*','',$tvakey);
|
||||
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
|
||||
}
|
||||
$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' ';
|
||||
$totalvat = $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
|
||||
|
||||
if ($localtax_type == '7') { // amount on order
|
||||
$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);
|
||||
|
||||
@@ -811,6 +901,7 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Total TTC
|
||||
$index++;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
||||
* 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
|
||||
* 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->localtax1=array();
|
||||
$this->localtax2=array();
|
||||
$this->localtax1_type=array();
|
||||
$this->localtax2_type=array();
|
||||
$this->atleastoneratenotnull=0;
|
||||
$this->atleastonediscount=0;
|
||||
}
|
||||
@@ -368,16 +371,24 @@ class pdf_azur extends ModelePDFPropales
|
||||
if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
|
||||
|
||||
$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 (! 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->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
|
||||
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
|
||||
@@ -735,6 +746,84 @@ class pdf_azur extends ModelePDFPropales
|
||||
}
|
||||
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)
|
||||
{
|
||||
if ($tvakey > 0) // On affiche pas taux 0
|
||||
@@ -759,71 +848,64 @@ 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++;
|
||||
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
|
||||
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
|
||||
|
||||
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
|
||||
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
|
||||
|
||||
// Total LocalTax1
|
||||
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
|
||||
{
|
||||
$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);
|
||||
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) {
|
||||
switch ($localtax_type) {
|
||||
case '2':
|
||||
case '4':
|
||||
case '6':
|
||||
continue 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// Total LocalTax2
|
||||
if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
|
||||
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);
|
||||
$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);
|
||||
|
||||
$tvacompl='';
|
||||
if (preg_match('/\*/',$tvakey))
|
||||
{
|
||||
$tvakey=str_replace('*','',$tvakey);
|
||||
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
|
||||
}
|
||||
$totalvat = $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
|
||||
if ($localtax_type == '7') { // amount on order
|
||||
$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
|
||||
{
|
||||
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
|
||||
{
|
||||
//$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->country_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 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++;
|
||||
|
||||
@@ -836,13 +918,21 @@ class pdf_azur extends ModelePDFPropales
|
||||
$tvakey=str_replace('*','',$tvakey);
|
||||
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
|
||||
}
|
||||
$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' ';
|
||||
$totalvat = $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
|
||||
|
||||
if ($localtax_type == '7') { // amount on order
|
||||
$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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2570,6 +2570,43 @@ class Societe extends CommonObject
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -907,31 +907,27 @@ 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>';
|
||||
|
||||
// Local Taxes
|
||||
// TODO add specific function by country
|
||||
if($mysoc->country_code=='ES')
|
||||
{
|
||||
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
|
||||
print '<tr><td>'.$langs->trans("LocalTax1IsUsed").'</td><td>';
|
||||
print $form->selectyesno('localtax1assuj_value',0,1);
|
||||
print '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
|
||||
print '</td><td>'.$langs->trans("LocalTax2IsUsed").'</td><td>';
|
||||
print $form->selectyesno('localtax2assuj_value',0,1);
|
||||
print '</td></tr>';
|
||||
|
||||
}
|
||||
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 '</td><tr>';
|
||||
}
|
||||
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 '</td><tr>';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||
{
|
||||
@@ -1322,9 +1318,6 @@ else
|
||||
print '</tr>';
|
||||
|
||||
// Local Taxes
|
||||
// TODO add specific function by country
|
||||
if($mysoc->country_code=='ES')
|
||||
{
|
||||
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
|
||||
@@ -1347,7 +1340,6 @@ else
|
||||
print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// Type - Size
|
||||
print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
|
||||
@@ -1642,9 +1634,6 @@ else
|
||||
print '</tr>';
|
||||
|
||||
// Local Taxes
|
||||
// TODO add specific function by country
|
||||
if($mysoc->country_code=='ES')
|
||||
{
|
||||
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
|
||||
@@ -1666,7 +1655,6 @@ else
|
||||
print yn($object->localtax2_assuj);
|
||||
print '</td><tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// Type + Staff
|
||||
$arr = $formcompany->typent_array(1);
|
||||
|
||||
Reference in New Issue
Block a user