Suite rapport TVA

This commit is contained in:
Laurent Destailleur 2008-02-18 06:16:05 +00:00
parent 352e6c0a36
commit d0f5e7bbe1
6 changed files with 376 additions and 398 deletions

View File

@ -67,7 +67,7 @@ llxHeader();
$company_static=new Societe($db); $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='<form method="get" action="clients.php?year='.$year.'">';
$fsearch.=' <input type="hidden" name="year" value="'.$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 "<td align=\"right\">".$vatcust."</td>";
print "</tr>\n"; 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)) if (is_array($coll_list))
{ {
$var=true; $var=true;
@ -207,7 +207,7 @@ print "</tr>\n";
$company_static=new Societe($db); $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)) if (is_array($coll_list))
{ {
$var=true; $var=true;

View File

@ -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."/tva.class.php");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/product.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/fournisseur.facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/fourn/facture/paiementfourn.class.php");
$langs->load("bills"); $langs->load("bills");
$langs->load("compta"); $langs->load("compta");
@ -41,7 +43,7 @@ $langs->load("companies");
$langs->load("products"); $langs->load("products");
$year=$_GET["year"]; $year=$_GET["year"];
if ($year == 0 ) if (empty($year))
{ {
$year_current = strftime("%Y",time()); $year_current = strftime("%Y",time());
$year_start = $year_current; $year_start = $year_current;
@ -49,6 +51,7 @@ if ($year == 0 )
$year_current = $year; $year_current = $year;
$year_start = $year; $year_start = $year;
} }
$q=(! empty($_GET["q"]))?$_GET["q"]:1;
// Define modetax (0 or 1) // Define modetax (0 or 1)
$modetax = $conf->global->TAX_MODE; $modetax = $conf->global->TAX_MODE;
@ -66,16 +69,24 @@ $company_static=new Societe($db);
$invoice_customer=new Facture($db); $invoice_customer=new Facture($db);
$invoice_supplier=new FactureFournisseur($db); $invoice_supplier=new FactureFournisseur($db);
$product_static=new Product($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 // Affiche en-tête du rapport
if ($modetax==1) // Caluclate on invoice for goods and services if ($modetax==1) // Caluclate on invoice for goods and services
{ {
$nom=$langs->trans("VATReportByQuartersInDueDebtMode"); $nom=$langs->trans("VATReportByQuartersInDueDebtMode");
$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')'; $nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&q='.$q.'&modetax=0">','</a>').')';
$period=$year_start; $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)).")";
$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>":""); $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"); $description=$langs->trans("RulesVATDue");
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
$description.=$fsearch; $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 if ($modetax==0) // Invoice for goods, payment for services
{ {
$nom=$langs->trans("VATReportByQuartersInInputOutputMode"); $nom=$langs->trans("VATReportByQuartersInInputOutputMode");
$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')'; $nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&q='.$q.'&modetax=1">','</a>').')';
$period=$year_start; $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)).")";
$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>":""); $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"); $description=$langs->trans("RulesVATIn");
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
$description.=$fsearch; $description.=$fsearch;
@ -124,8 +141,7 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl
echo '<table class="noborder" width="100%">'; echo '<table class="noborder" width="100%">';
$y = $year_current; $y = $year_current;
for ($q = 1 ; $q <= 4 ; $q++ )
{
$total = 0; $subtotal = 0; $total = 0; $subtotal = 0;
$i=0; $i=0;
$subtot_coll_total = 0; $subtot_coll_total = 0;
@ -208,8 +224,8 @@ for ($q = 1 ; $q <= 4 ; $q++ )
} }
//now we have an array (x_both) indexed by rates for coll and paye //now we have an array (x_both) indexed by rates for coll and paye
//print table headers for this quadri - incomes first //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_sum = 0;
$x_coll_ht = 0; $x_coll_ht = 0;
@ -219,7 +235,7 @@ for ($q = 1 ; $q <= 4 ; $q++ )
$span=3; $span=3;
if ($modetax == 0) $span+=2; 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><td colspan="'.($span+1).'">'..')</td></tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left">'.$elementcust.'</td>'; print '<td align="left">'.$elementcust.'</td>';
@ -232,11 +248,11 @@ for ($q = 1 ; $q <= 4 ; $q++ )
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>'; print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
print '<td align="right">'.$vatcust.'</td>'; print '<td align="right">'.$vatcust.'</td>';
print '</tr>'; print '</tr>';
$var=true;
foreach(array_keys($x_coll) as $rate) foreach(array_keys($x_coll) as $rate)
{ {
if (is_array($x_both[$rate]['coll']['detail'])) if (is_array($x_both[$rate]['coll']['detail']))
{ {
$var=true;
print "<tr>"; print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>'; print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
print '</tr>'."\n"; print '</tr>'."\n";
@ -250,7 +266,7 @@ for ($q = 1 ; $q <= 4 ; $q++ )
{ {
$product_static->id=$fields['pid']; $product_static->id=$fields['pid'];
$product_static->ref=$fields['pref']; $product_static->ref=$fields['pref'];
$product_static->fk_product_type=$fields['ptype']; $product_static->type=$fields['ptype'];
print $product_static->getNomUrl(1); print $product_static->getNomUrl(1);
if ($fields['descr']) print ' - '; if ($fields['descr']) print ' - ';
} }
@ -280,6 +296,11 @@ for ($q = 1 ; $q <= 4 ; $q++ )
{ {
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
print '<td nowrap align="right">'; 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']; print $fields['payment_amount'];
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
print '</td>'; print '</td>';
@ -302,8 +323,6 @@ for ($q = 1 ; $q <= 4 ; $q++ )
$x_coll_sum += $temp_vat; $x_coll_sum += $temp_vat;
} }
} }
}
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td></td>'; print '<td></td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
@ -315,8 +334,11 @@ for ($q = 1 ; $q <= 4 ; $q++ )
print '<td align="right">'.price(price2num($subtot_coll_total,'MT')).'</td>'; print '<td align="right">'.price(price2num($subtot_coll_total,'MT')).'</td>';
print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>'; print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
print '</tr>'; print '</tr>';
}
print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
//print table headers for this quadri - expenses now //print table headers for this quadri - expenses now
//imprime les en-tete de tables pour ce quadri - maintenant les dépenses //imprime les en-tete de tables pour ce quadri - maintenant les dépenses
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -330,11 +352,11 @@ for ($q = 1 ; $q <= 4 ; $q++ )
print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>'; print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>';
print '<td align="right">'.$vatsup.'</td>'; print '<td align="right">'.$vatsup.'</td>';
print '</tr>'."\n"; print '</tr>'."\n";
$var=true;
foreach(array_keys($x_paye) as $rate) foreach(array_keys($x_paye) as $rate)
{ {
if(is_array($x_both[$rate]['paye']['detail'])) if(is_array($x_both[$rate]['paye']['detail']))
{ {
$var=true;
print "<tr>"; print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>'; print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
print '</tr>'."\n"; print '</tr>'."\n";
@ -348,7 +370,7 @@ for ($q = 1 ; $q <= 4 ; $q++ )
{ {
$product_static->id=$fields['pid']; $product_static->id=$fields['pid'];
$product_static->ref=$fields['pref']; $product_static->ref=$fields['pref'];
$product_static->fk_product_type=$fields['ptype']; $product_static->type=$fields['ptype'];
print $product_static->getNomUrl(1); print $product_static->getNomUrl(1);
if ($fields['descr']) print ' - '; if ($fields['descr']) print ' - ';
} }
@ -378,6 +400,11 @@ for ($q = 1 ; $q <= 4 ; $q++ )
{ {
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
print '<td nowrap align="right">'; 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']; print $fields['payment_amount'];
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)'; if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
print '</td>'; print '</td>';
@ -400,10 +427,9 @@ for ($q = 1 ; $q <= 4 ; $q++ )
$x_paye_sum += $temp_vat; $x_paye_sum += $temp_vat;
} }
} }
}
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td></td>'; print '<td>&nbsp;</td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0) if ($modetax == 0)
{ {
@ -413,6 +439,7 @@ for ($q = 1 ; $q <= 4 ; $q++ )
print '<td align="right">'.price(price2num($subtot_paye_total,'MT')).'</td>'; print '<td align="right">'.price(price2num($subtot_paye_total,'MT')).'</td>';
print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>'; print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
print '</tr>'; print '</tr>';
}
print '<tr>'; print '<tr>';
print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'</td>'; print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'</td>';
@ -429,7 +456,6 @@ for ($q = 1 ; $q <= 4 ; $q++ )
print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>'."\n"; print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>'."\n";
$i++; $i++;
}
echo '</table>'; echo '</table>';

View File

@ -404,7 +404,7 @@ class Facture extends CommonObject
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$lien.$this->ref.$lienfin; if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
return $result; return $result;
} }

View File

@ -16,17 +16,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/fourn/facture/paiementfourn.class.php \file htdocs/fourn/facture/paiementfourn.class.php
\ingroup fournisseur, facture \ingroup fournisseur, facture
\brief Page de cr<EFBFBD>ation de paiement factures fournisseurs \brief Classe paiement fournisseur
\remarks Cette classe est presque identique <EFBFBD> paiement.class.php \remarks Cette classe est presque identique a paiement.class.php
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
@ -455,5 +452,27 @@ class PaiementFourn
} }
return $langs->trans('Unknown'); 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;
}
} }
?> ?>

View File

@ -30,12 +30,30 @@
* \param db Database handle * \param db Database handle
* \param y Year * \param y Year
* \param modetax 0 or 1 (option vat on debit) * \param modetax 0 or 1 (option vat on debit)
* \param direction 'sell' or 'buy'
* \return array List of customers third parties with vat * \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; 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 // Define sql request
$sql=''; $sql='';
if ($modetax == 1) if ($modetax == 1)
@ -52,13 +70,13 @@ function vat_received_by_customer($db, $y, $modetax)
if ($conf->global->MAIN_MODULE_COMPTABILITE) if ($conf->global->MAIN_MODULE_COMPTABILITE)
{ {
$sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; $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.= " 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.= " WHERE ";
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) $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 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"; $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) // Tva sur factures payés (should be on payment)
/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; /* $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.= " 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.= " WHERE ";
$sql.= " f.fk_statut in (2)"; // Payed (partially or completely) $sql.= " f.fk_statut in (2)"; // Payed (partially or completely)
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $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"; $sql.= " GROUP BY s.rowid";
*/ */
} }
@ -91,16 +109,15 @@ function vat_received_by_customer($db, $y, $modetax)
if ($sql) if ($sql)
{ {
dolibarr_syslog("Client::tva_coll sql=".$sql); dolibarr_syslog("Client::vat_by_customer sql=".$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$list = array();
while($assoc = $db->fetch_array($resql)) while($assoc = $db->fetch_array($resql))
{ {
$list[] = $assoc; $list[] = $assoc;
} }
$db->free(); $db->free($resql);
return $list; return $list;
} }
else 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 * \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 * 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'; $invoicetable='facture';
$invoicedettable='facturedet'; $invoicedettable='facturedet';
$fk_facture='fk_facture'; $fk_facture='fk_facture';
$fk_facture2='fk_facture';
$fk_payment='fk_paiement';
$total_tva='total_tva'; $total_tva='total_tva';
$paymenttable='paiement';
$paymentfacturetable='paiement_facture';
} }
if ($direction == 'buy') if ($direction == 'buy')
{ {
$invoicetable='facture_fourn'; $invoicetable='facture_fourn';
$invoicedettable='facture_fourn_det'; $invoicedettable='facture_fourn_det';
$fk_facture='fk_facture_fourn'; $fk_facture='fk_facture_fourn';
$fk_facture2='fk_facturefourn';
$fk_payment='fk_paiementfourn';
$total_tva='tva'; $total_tva='tva';
$paymenttable='paiementfourn';
$paymentfacturetable='paiementfourn_facturefourn';
} }
// CAS DES BIENS // 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 = "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.= " 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.= " 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.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX."paiement_facture as pf,"; $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
$sql.= " ".MAIN_DB_PREFIX."paiement as pa,"; $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE "; $sql.= " WHERE ";
$sql.= " f.fk_statut in (1,2)"; // Payed (partially or completely) $sql.= " f.fk_statut in (1,2)"; // Payed (partially or completely)
$sql.= " AND f.rowid = d.".$fk_facture;; $sql.= " AND f.rowid = d.".$fk_facture;;
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.".$fk_facture2." = f.rowid";
$sql.= " AND pa.rowid = pa.fk_paiement"; $sql.= " AND pa.rowid = pf.".$fk_payment;
$sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'"; $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 (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 $sql.= " AND d.product_type = 1"; // Limit to services

View File

@ -410,7 +410,7 @@ class Paiement
/** /**
* \brief Renvoie nom clicable (avec eventuellement le picto) * \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 * \param option Sur quoi pointe le lien
* \return string Chaine avec URL * \return string Chaine avec URL
*/ */
@ -423,8 +423,9 @@ class Paiement
$lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$this->rowid.'">'; $lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$this->rowid.'">';
$lienfin='</a>'; $lienfin='</a>';
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin.' '); if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin);
$result.=$lien.$this->rowid.$lienfin; if ($withpicto && $withpicto != 2) $result.=' ';
if ($withpicto != 2) $result.=$lien.$this->rowid.$lienfin;
return $result; return $result;
} }