Suite rapport TVA
This commit is contained in:
parent
352e6c0a36
commit
d0f5e7bbe1
@ -67,7 +67,7 @@ llxHeader();
|
||||
|
||||
$company_static=new Societe($db);
|
||||
|
||||
print_fiche_titre($langs->trans("VAT"),"");
|
||||
//print_fiche_titre($langs->trans("VAT"),"");
|
||||
|
||||
$fsearch='<form method="get" action="clients.php?year='.$year.'">';
|
||||
$fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
|
||||
@ -140,7 +140,7 @@ print "<td align=\"right\">".$langs->trans("SalesTurnover")." ".$langs->trans("H
|
||||
print "<td align=\"right\">".$vatcust."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$coll_list = vat_received_by_customer($db,$year_current,$modetax);
|
||||
$coll_list = vat_by_thirdparty($db,$year_current,$modetax,'sell');
|
||||
if (is_array($coll_list))
|
||||
{
|
||||
$var=true;
|
||||
@ -207,7 +207,7 @@ print "</tr>\n";
|
||||
|
||||
$company_static=new Societe($db);
|
||||
|
||||
$coll_list = vat_payed_by_supplier($db,$year_current,$modetax);
|
||||
$coll_list = vat_by_thirdparty($db,$year_current,$modetax,'buy');
|
||||
if (is_array($coll_list))
|
||||
{
|
||||
$var=true;
|
||||
|
||||
@ -33,7 +33,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/tva.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.facture.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/fourn/facture/paiementfourn.class.php");
|
||||
|
||||
$langs->load("bills");
|
||||
$langs->load("compta");
|
||||
@ -41,14 +43,15 @@ $langs->load("companies");
|
||||
$langs->load("products");
|
||||
|
||||
$year=$_GET["year"];
|
||||
if ($year == 0 )
|
||||
if (empty($year))
|
||||
{
|
||||
$year_current = strftime("%Y",time());
|
||||
$year_start = $year_current;
|
||||
$year_current = strftime("%Y",time());
|
||||
$year_start = $year_current;
|
||||
} else {
|
||||
$year_current = $year;
|
||||
$year_start = $year;
|
||||
$year_current = $year;
|
||||
$year_start = $year;
|
||||
}
|
||||
$q=(! empty($_GET["q"]))?$_GET["q"]:1;
|
||||
|
||||
// Define modetax (0 or 1)
|
||||
$modetax = $conf->global->TAX_MODE;
|
||||
@ -66,16 +69,24 @@ $company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
|
||||
print_fiche_titre($langs->trans("VAT"),"");
|
||||
//print_fiche_titre($langs->trans("VAT"),"");
|
||||
|
||||
// Affiche en-tête du rapport
|
||||
if ($modetax==1) // Caluclate on invoice for goods and services
|
||||
{
|
||||
$nom=$langs->trans("VATReportByQuartersInDueDebtMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&q='.$q.'&modetax=0">','</a>').')';
|
||||
$period=$year_start.' - '.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$year_start)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$year_start)).")";
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) $prevquarter--;
|
||||
else { $prevquarter=4; $prevyear--; }
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) $nextquarter++;
|
||||
else { $nextquarter=1; $nextyear++; }
|
||||
$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATDue");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
@ -96,9 +107,15 @@ if ($modetax==1) // Caluclate on invoice for goods and services
|
||||
if ($modetax==0) // Invoice for goods, payment for services
|
||||
{
|
||||
$nom=$langs->trans("VATReportByQuartersInInputOutputMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&q='.$q.'&modetax=1">','</a>').')';
|
||||
$period=$year_start.' - '.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$year_start)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$year_start)).")";
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) $prevquarter--;
|
||||
else { $prevquarter=4; $prevyear--; }
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) $nextquarter++;
|
||||
else { $nextquarter=1; $nextyear++; }
|
||||
$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATIn");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
@ -124,186 +141,188 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl
|
||||
echo '<table class="noborder" width="100%">';
|
||||
|
||||
$y = $year_current;
|
||||
for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
|
||||
$total = 0; $subtotal = 0;
|
||||
$i=0;
|
||||
$subtot_coll_total = 0;
|
||||
$subtot_coll_vat = 0;
|
||||
$subtot_paye_total = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
|
||||
$x_coll = vat_by_quarter($db, $y, $q, $modetax, 'sell');
|
||||
$x_paye = vat_by_quarter($db, $y, $q, $modetax, 'buy');
|
||||
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
$total = 0; $subtotal = 0;
|
||||
$i=0;
|
||||
$subtot_coll_total = 0;
|
||||
$subtot_coll_vat = 0;
|
||||
$subtot_paye_total = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
|
||||
$x_coll = vat_by_quarter($db, $y, $q, $modetax, 'sell');
|
||||
$x_paye = vat_by_quarter($db, $y, $q, $modetax, 'buy');
|
||||
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
//print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
break;
|
||||
}
|
||||
|
||||
$x_both = array();
|
||||
//now, from these two arrays, get another array with one rate per line
|
||||
foreach(array_keys($x_coll) as $my_coll_rate)
|
||||
{
|
||||
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
|
||||
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
|
||||
$x_both[$my_coll_rate]['paye']['totalht'] = 0;
|
||||
$x_both[$my_coll_rate]['paye']['vat'] = 0;
|
||||
$x_both[$my_coll_rate]['coll']['links'] = '';
|
||||
$x_both[$my_coll_rate]['coll']['detail'] = array();
|
||||
foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
|
||||
{
|
||||
$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
|
||||
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
|
||||
$x_both[$my_coll_rate]['coll']['detail'][] = array(
|
||||
'id' =>$x_coll[$my_coll_rate]['facid'][$id],
|
||||
'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
|
||||
'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
|
||||
'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
|
||||
'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
|
||||
'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_customer->getNomUrl(1));
|
||||
//$x_both[$my_coll_rate]['coll']['links'] .= '<a href="../facture.php?facid='.$x_coll[$my_coll_rate]['facid'][$id].'" title="'.$x_coll[$my_coll_rate]['facnum'][$id].'">..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
}
|
||||
// tva payed
|
||||
foreach(array_keys($x_paye) as $my_paye_rate){
|
||||
$x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
|
||||
$x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
|
||||
if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
|
||||
$x_both[$my_paye_rate]['coll']['totalht'] = 0;
|
||||
$x_both[$my_paye_rate]['coll']['vat'] = 0;
|
||||
}
|
||||
$x_both[$my_paye_rate]['paye']['links'] = '';
|
||||
$x_both[$my_paye_rate]['paye']['detail'] = array();
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
//print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
break;
|
||||
}
|
||||
|
||||
foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
|
||||
{
|
||||
$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
|
||||
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
|
||||
$x_both[$my_paye_rate]['paye']['detail'][] = array(
|
||||
'id' =>$x_paye[$my_paye_rate]['facid'][$id],
|
||||
'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
|
||||
'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
|
||||
'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
|
||||
'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
|
||||
'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_supplier->getNomUrl(1));
|
||||
//$x_both[$my_paye_rate]['paye']['links'] .= '<a href="../../fourn/facture/fiche.php?facid='.$x_paye[$my_paye_rate]['facid'][$id].'" title="'.$x_paye[$my_paye_rate]['facnum'][$id].'">..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
}
|
||||
//now we have an array (x_both) indexed by rates for coll and paye
|
||||
|
||||
//print table headers for this quadri - incomes first
|
||||
//imprime les en-tete de tables pour ce quadri - d'abord les revenus
|
||||
|
||||
$x_coll_sum = 0;
|
||||
$x_coll_ht = 0;
|
||||
$x_paye_sum = 0;
|
||||
$x_paye_ht = 0;
|
||||
|
||||
$span=3;
|
||||
if ($modetax == 0) $span+=2;
|
||||
|
||||
print '<tr><td colspan="'.($span+1).'">'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$y)).')</td></tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementcust.'</td>';
|
||||
print '<td align="left">'.$productcust.'</td>';
|
||||
if ($modetax == 0)
|
||||
$x_both = array();
|
||||
//now, from these two arrays, get another array with one rate per line
|
||||
foreach(array_keys($x_coll) as $my_coll_rate)
|
||||
{
|
||||
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
|
||||
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
|
||||
$x_both[$my_coll_rate]['paye']['totalht'] = 0;
|
||||
$x_both[$my_coll_rate]['paye']['vat'] = 0;
|
||||
$x_both[$my_coll_rate]['coll']['links'] = '';
|
||||
$x_both[$my_coll_rate]['coll']['detail'] = array();
|
||||
foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
|
||||
{
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
|
||||
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
|
||||
$x_both[$my_coll_rate]['coll']['detail'][] = array(
|
||||
'id' =>$x_coll[$my_coll_rate]['facid'][$id],
|
||||
'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
|
||||
'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
|
||||
'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
|
||||
'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
|
||||
'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_customer->getNomUrl(1));
|
||||
//$x_both[$my_coll_rate]['coll']['links'] .= '<a href="../facture.php?facid='.$x_coll[$my_coll_rate]['facid'][$id].'" title="'.$x_coll[$my_coll_rate]['facnum'][$id].'">..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
|
||||
print '<td align="right">'.$vatcust.'</td>';
|
||||
print '</tr>';
|
||||
$var=true;
|
||||
foreach(array_keys($x_coll) as $rate)
|
||||
}
|
||||
// tva payed
|
||||
foreach(array_keys($x_paye) as $my_paye_rate){
|
||||
$x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
|
||||
$x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
|
||||
if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
|
||||
$x_both[$my_paye_rate]['coll']['totalht'] = 0;
|
||||
$x_both[$my_paye_rate]['coll']['vat'] = 0;
|
||||
}
|
||||
$x_both[$my_paye_rate]['paye']['links'] = '';
|
||||
$x_both[$my_paye_rate]['paye']['detail'] = array();
|
||||
|
||||
foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
|
||||
{
|
||||
if (is_array($x_both[$rate]['coll']['detail']))
|
||||
$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
|
||||
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
|
||||
$x_both[$my_paye_rate]['paye']['detail'][] = array(
|
||||
'id' =>$x_paye[$my_paye_rate]['facid'][$id],
|
||||
'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
|
||||
'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
|
||||
'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
|
||||
'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
|
||||
'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_supplier->getNomUrl(1));
|
||||
//$x_both[$my_paye_rate]['paye']['links'] .= '<a href="../../fourn/facture/fiche.php?facid='.$x_paye[$my_paye_rate]['facid'][$id].'" title="'.$x_paye[$my_paye_rate]['facnum'][$id].'">..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
}
|
||||
//now we have an array (x_both) indexed by rates for coll and paye
|
||||
|
||||
|
||||
//print table headers for this quadri - incomes first
|
||||
|
||||
$x_coll_sum = 0;
|
||||
$x_coll_ht = 0;
|
||||
$x_paye_sum = 0;
|
||||
$x_paye_ht = 0;
|
||||
|
||||
$span=3;
|
||||
if ($modetax == 0) $span+=2;
|
||||
|
||||
//print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementcust.'</td>';
|
||||
print '<td align="left">'.$productcust.'</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
|
||||
print '<td align="right">'.$vatcust.'</td>';
|
||||
print '</tr>';
|
||||
foreach(array_keys($x_coll) as $rate)
|
||||
{
|
||||
if (is_array($x_both[$rate]['coll']['detail']))
|
||||
{
|
||||
$var=true;
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->fk_product_type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$payment_static->rowid=$fields['payment_id'];
|
||||
print $payment_static->getNomUrl(2);
|
||||
}
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
@ -315,95 +334,102 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
print '<td align="right">'.price(price2num($subtot_coll_total,'MT')).'</td>';
|
||||
print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
|
||||
//print table headers for this quadri - expenses now
|
||||
//imprime les en-tete de tables pour ce quadri - maintenant les dépenses
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementsup.'</td>';
|
||||
print '<td align="left">'.$productsup.'</td>';
|
||||
if ($modetax == 0)
|
||||
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>';
|
||||
|
||||
//print table headers for this quadri - expenses now
|
||||
//imprime les en-tete de tables pour ce quadri - maintenant les dépenses
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementsup.'</td>';
|
||||
print '<td align="left">'.$productsup.'</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>';
|
||||
print '<td align="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\n";
|
||||
foreach(array_keys($x_paye) as $rate)
|
||||
{
|
||||
if(is_array($x_both[$rate]['paye']['detail']))
|
||||
{
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>';
|
||||
print '<td align="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\n";
|
||||
$var=true;
|
||||
foreach(array_keys($x_paye) as $rate)
|
||||
{
|
||||
if(is_array($x_both[$rate]['paye']['detail']))
|
||||
$var=true;
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->fk_product_type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$paymentfourn_static->rowid=$fields['payment_id'];
|
||||
print $paymentfourn_static->getNomUrl(2);
|
||||
}
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
@ -413,23 +439,23 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
print '<td align="right">'.price(price2num($subtot_paye_total,'MT')).'</td>';
|
||||
print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '<tr>';
|
||||
print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'</td>';
|
||||
print '</tr>'."\n";
|
||||
print '<tr>';
|
||||
print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
$diff = $x_coll_sum - $x_paye_sum;
|
||||
//$total = $total + $diff;
|
||||
//$subtotal = $subtotal + $diff;
|
||||
print "<tr>";
|
||||
print '<td colspan="'.$span.'"></td>';
|
||||
print '<td nowrap align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
$diff = $x_coll_sum - $x_paye_sum;
|
||||
//$total = $total + $diff;
|
||||
//$subtotal = $subtotal + $diff;
|
||||
print "<tr>";
|
||||
print '<td colspan="'.$span.'"></td>';
|
||||
print '<td nowrap align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>'."\n";
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>'."\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
$i++;
|
||||
|
||||
echo '</table>';
|
||||
|
||||
|
||||
@ -404,7 +404,7 @@ class Facture extends CommonObject
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
$result.=$lien.$this->ref.$lienfin;
|
||||
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@ -16,17 +16,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/fourn/facture/paiementfourn.class.php
|
||||
\ingroup fournisseur, facture
|
||||
\brief Page de cr<EFBFBD>ation de paiement factures fournisseurs
|
||||
\remarks Cette classe est presque identique <EFBFBD> paiement.class.php
|
||||
\version $Revision$
|
||||
\brief Classe paiement fournisseur
|
||||
\remarks Cette classe est presque identique a paiement.class.php
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
|
||||
@ -455,5 +452,27 @@ class PaiementFourn
|
||||
}
|
||||
return $langs->trans('Unknown');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
||||
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
||||
* \param option Sur quoi pointe le lien
|
||||
* \return string Chaine avec URL
|
||||
*/
|
||||
function getNomUrl($withpicto=0,$option='')
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
|
||||
$lien = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$this->rowid.'">';
|
||||
$lienfin='</a>';
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$lien.$this->rowid.$lienfin;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -30,12 +30,30 @@
|
||||
* \param db Database handle
|
||||
* \param y Year
|
||||
* \param modetax 0 or 1 (option vat on debit)
|
||||
* \param direction 'sell' or 'buy'
|
||||
* \return array List of customers third parties with vat
|
||||
*/
|
||||
function vat_received_by_customer($db, $y, $modetax)
|
||||
function vat_by_thirdparty($db, $y, $modetax, $direction)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$list=array();
|
||||
|
||||
if ($direction == 'sell')
|
||||
{
|
||||
$invoicetable='facture';
|
||||
$invoicedettable='facturedet';
|
||||
$fk_facture='fk_facture';
|
||||
$total_tva='total_tva';
|
||||
}
|
||||
if ($direction == 'buy')
|
||||
{
|
||||
$invoicetable='facture_fourn';
|
||||
$invoicedettable='facture_fourn_det';
|
||||
$fk_facture='fk_facture_fourn';
|
||||
$total_tva='tva';
|
||||
}
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
@ -52,13 +70,13 @@ function vat_received_by_customer($db, $y, $modetax)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicedettable." as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
}
|
||||
}
|
||||
@ -77,13 +95,13 @@ function vat_received_by_customer($db, $y, $modetax)
|
||||
{
|
||||
// Tva sur factures payés (should be on payment)
|
||||
/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (2)"; // Payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
*/
|
||||
}
|
||||
@ -91,16 +109,15 @@ function vat_received_by_customer($db, $y, $modetax)
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::tva_coll sql=".$sql);
|
||||
dolibarr_syslog("Client::vat_by_customer sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$list = array();
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
$list[] = $assoc;
|
||||
}
|
||||
$db->free();
|
||||
$db->free($resql);
|
||||
return $list;
|
||||
}
|
||||
else
|
||||
@ -116,99 +133,6 @@ function vat_received_by_customer($db, $y, $modetax)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get payable VAT
|
||||
* \param resource Database handle
|
||||
* \param y Year
|
||||
* \param modetax 0 or 1 (option vat on debit)
|
||||
* \return array List of suppliers third parties with vat
|
||||
*/
|
||||
function vat_payed_by_supplier($db, $y, $modetax)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
{
|
||||
// If vat payed on due invoices (non draft)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si on paye la tva sur les payments
|
||||
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// Tva sur factures payés
|
||||
/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
//$sql.= " f.fk_statut in (2)"; // Payed (partially or completely)
|
||||
$sql.= " f.paye in (1)"; // Payed (completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::tva_paye sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$list = array();
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
$list[] = $assoc;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Gets VAT to collect for the given month of the given year
|
||||
* The function gets the VAT in split results, as the VAT declaration asks
|
||||
@ -232,14 +156,22 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
|
||||
$invoicetable='facture';
|
||||
$invoicedettable='facturedet';
|
||||
$fk_facture='fk_facture';
|
||||
$fk_facture2='fk_facture';
|
||||
$fk_payment='fk_paiement';
|
||||
$total_tva='total_tva';
|
||||
$paymenttable='paiement';
|
||||
$paymentfacturetable='paiement_facture';
|
||||
}
|
||||
if ($direction == 'buy')
|
||||
{
|
||||
$invoicetable='facture_fourn';
|
||||
$invoicedettable='facture_fourn_det';
|
||||
$fk_facture='fk_facture_fourn';
|
||||
$fk_facture2='fk_facturefourn';
|
||||
$fk_payment='fk_paiementfourn';
|
||||
$total_tva='tva';
|
||||
$paymenttable='paiementfourn';
|
||||
$paymentfacturetable='paiementfourn_facturefourn';
|
||||
}
|
||||
|
||||
// CAS DES BIENS
|
||||
@ -405,17 +337,17 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
|
||||
$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " pf.fk_paiement as payment_id, pf.amount as payment_amount";
|
||||
$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."paiement_facture as pf,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."paiement as pa,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Payed (partially or completely)
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;;
|
||||
$sql.= " AND pf.fk_facture = f.rowid";
|
||||
$sql.= " AND pa.rowid = pa.fk_paiement";
|
||||
$sql.= " AND pf.".$fk_facture2." = f.rowid";
|
||||
$sql.= " AND pa.rowid = pf.".$fk_payment;
|
||||
$sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'";
|
||||
$sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
|
||||
$sql.= " AND d.product_type = 1"; // Limit to services
|
||||
|
||||
@ -410,7 +410,7 @@ class Paiement
|
||||
|
||||
/**
|
||||
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
||||
* \param withpicto Inclut le picto dans le lien
|
||||
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
||||
* \param option Sur quoi pointe le lien
|
||||
* \return string Chaine avec URL
|
||||
*/
|
||||
@ -423,8 +423,9 @@ class Paiement
|
||||
$lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$this->rowid.'">';
|
||||
$lienfin='</a>';
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin.' ');
|
||||
$result.=$lien.$this->rowid.$lienfin;
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$lien.$this->rowid.$lienfin;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user