Minor enhancement on vat report

This commit is contained in:
Laurent Destailleur 2009-03-05 20:14:13 +00:00
parent d287b92a96
commit 33ff5c61f2
7 changed files with 90 additions and 39 deletions

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2007 Yannick Warnier <ywarnier@beeznest.org>
*
* This program is free software; you can redistribute it and/or modify
@ -181,6 +181,7 @@ else
{
$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$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],
@ -194,7 +195,7 @@ else
'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));
'link' =>$invoice_customer->getNomUrl(1,'',12));
//$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> ';
}
}
@ -213,6 +214,7 @@ else
{
$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$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],
@ -226,7 +228,7 @@ else
'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));
'link' =>$invoice_supplier->getNomUrl(1,'',12));
//$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> ';
}
}
@ -245,6 +247,7 @@ else
//print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
// Customers invoices
print '<tr class="liste_titre">';
print '<td align="left">'.$elementcust.'</td>';
print '<td align="left">'.$productcust.'</td>';
@ -256,6 +259,7 @@ else
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
print '<td align="right">'.$vatcust.'</td>';
print '</tr>';
foreach(array_keys($x_coll) as $rate)
{
$subtot_coll_total_ht = 0;
@ -263,16 +267,20 @@ else
if (is_array($x_both[$rate]['coll']['detail']))
{
// VAT Rate
$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)
{
$var=!$var;
print '<tr '.$bc[$var].'>';
// Ref
print '<td nowrap align="left">'.$fields['link'].'</td>';
//Description
print '<td align="left">';
if ($fields['pid'])
@ -289,8 +297,10 @@ else
else $text = img_object($langs->trans('Product'),'product');
print $text.' ';
}
print dol_trunc($fields['descr'],16).'</td>';
// Amount line
print dol_trunc(dol_string_nohtmltag($fields['descr']),16);
print '</td>';
// Total HT
if ($modetax == 0)
{
print '<td nowrap align="right">';
@ -303,26 +313,35 @@ else
}
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['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
{
$payment_static->rowid=$fields['payment_id'];
print $payment_static->getNomUrl(2);
}
print $fields['payment_amount'];
if ($fields['ptype'] == 0)
{
print $langs->trans("NotUsedForGoods");
}
else print $fields['payment_amount'];
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
print '</td>';
}
// Total collected
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;
@ -365,6 +384,7 @@ else
print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>';
print '<td align="right">'.$vatsup.'</td>';
print '</tr>'."\n";
foreach(array_keys($x_paye) as $rate)
{
$subtot_paye_total_ht = 0;
@ -380,7 +400,11 @@ else
{
$var=!$var;
print '<tr '.$bc[$var].'>';
// Ref
print '<td nowrap align="left">'.$fields['link'].'</td>';
//Description
print '<td align="left">';
if ($fields['pid'])
{
@ -397,7 +421,8 @@ else
print $text.' ';
}
print dol_trunc($fields['descr'],24).'</td>';
// Amount line
// Total HT
if ($modetax == 0)
{
print '<td nowrap align="right">';
@ -410,6 +435,7 @@ else
}
print '</td>';
}
// Payment
$ratiopaymentinvoice=1;
if ($modetax == 0)
@ -421,15 +447,22 @@ else
$paymentfourn_static->rowid=$fields['payment_id'];
print $paymentfourn_static->getNomUrl(2);
}
print $fields['payment_amount'];
if ($fields['ptype'] == 0)
{
print $langs->trans("NotUsedForGoods");
}
else print $fields['payment_amount'];
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
print '</td>';
}
// VAT payed
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;
@ -460,7 +493,7 @@ else
print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
print '<tr>';
print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").' '.$q.':</td>';
print '<td colspan="'.($span-1).'"></td><td align="right" colspan="2">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").' '.$q.':</td>';
print '</tr>'."\n";
$diff = $x_coll_sum - $x_paye_sum;

View File

@ -451,9 +451,10 @@ class Facture extends CommonObject
* \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 ('', 'withdraw')
* \param max Max length of shown ref
* \return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$option='')
function getNomUrl($withpicto=0,$option='',$max=0)
{
global $langs;
@ -482,7 +483,7 @@ class Facture extends CommonObject
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' ';
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
if ($withpicto != 2) $result.=$lien.($max?dol_trunc($this->ref,$max):$this->ref).$lienfin;
return $result;
}

View File

@ -705,9 +705,10 @@ class FactureFournisseur extends Facture
* \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
* \param max Max length of shown ref
* \return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$option='')
function getNomUrl($withpicto=0,$option='',$max=0)
{
global $langs;
@ -716,8 +717,10 @@ class FactureFournisseur extends Facture
$lien = '<a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$this->id.'">';
$lienfin='</a>';
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowInvoice"),'bill').$lienfin.' ');
$result.=$lien.$this->ref.$lienfin;
$label=$langs->trans("ShowInvoice").': '.$this->ref;
if ($withpicto) $result.=($lien.img_object($label,'bill').$lienfin.' ');
$result.=$lien.($max?dol_trunc($this->ref,$max):$this->ref).$lienfin;
return $result;
}

View File

@ -109,6 +109,7 @@ RulesVATIn=For services, the report includes the VAT regulations actually receiv
RulesVATDue=For services, the report includes VAT invoices due, paid or not, based on the date of validation of these bills.<br>- For material assets, it includes the VAT invoices, based on the date of validation of the invoice.
OptionVatInfoModuleComptabilite=Note: For material assets, it should use the date of delivery to be more fair.
PercentOfInvoice=%%/invoice
NotUsedForGoods=Not used on goods
Dispatch=Dispatching
Dispatched=Dispatched
ToDispatch=To dispatch

View File

@ -109,6 +109,7 @@ RulesVATIn=- Pour les services, le rapport inclut les TVA des réglements effect
RulesVATDue=- Pour les services, le rapport inclut les TVA des factures dues, payées ou non en se basant sur la date de validation de ces factures.<br>- Pour les biens matériels, il inclut les TVA des factures en se basant sur la date de validation de la facture.
OptionVatInfoModuleComptabilite=Remarque : Pour les biens matériels, il faudrait utiliser la date de livraison pour être plus juste.
PercentOfInvoice=%%/facture
NotUsedForGoods=Non utilisé pour les biens
OrderStats=Statistiques sur les commandes
Dispatch=Ventilation
Dispatched=Ventilés

View File

@ -44,7 +44,7 @@ NameNotDefined=Le nom n'est pas défini.
ListOfUsers=Liste des utilisateurs
Administrator=Administrateur
DefaultRights=Permissions par défaut
DefaultRightsDesc=Définissez ici les permissions par défaut, c'est-à-dire les permissions qui seront attribuées automatiquement à un nouvel utilisateur lors de sa création.
DefaultRightsDesc=Définissez ici les permissions <b>par défaut</b>, c'est-à-dire les permissions qui seront attribuées automatiquement à un nouvel utilisateur lors de sa création.
DolibarrUsers=Utilisateurs Dolibarr
LastName=Nom
FirstName=Prénom

View File

@ -41,14 +41,14 @@ function vat_by_thirdparty($db, $y, $modetax, $direction)
//print "xx".$conf->global->MAIN_MODULE_COMPTABILITEEXPERT;
//print "xx".$conf->global->MAIN_MODULE_COMPTABILITE;
if ($direction == 'sell')
if ($direction == 'sell')
{
$invoicetable='facture';
$invoicedettable='facturedet';
$fk_facture='fk_facture';
$total_tva='total_tva';
}
if ($direction == 'buy')
if ($direction == 'buy')
{
$invoicetable='facture_fourn';
$invoicedettable='facture_fourn_det';
@ -154,7 +154,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$list=array();
if ($direction == 'sell')
if ($direction == 'sell')
{
$invoicetable='facture';
$invoicedettable='facturedet';
@ -165,7 +165,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$paymenttable='paiement';
$paymentfacturetable='paiement_facture';
}
if ($direction == 'buy')
if ($direction == 'buy')
{
$invoicetable='facture_fourn';
$invoicedettable='facture_fourn_det';
@ -176,12 +176,12 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$paymenttable='paiementfourn';
$paymentfacturetable='paiementfourn_facturefourn';
}
// CAS DES BIENS
// Define sql request
$sql='';
if ($modetax == 1)
if ($modetax == 1) // Option vat on debit
{
// If vat payed on due invoices (non draft)
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
@ -196,9 +196,10 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
if ($conf->global->MAIN_MODULE_COMPTABILITE)
{
$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.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,";
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql.= " 0 as payment_id, 0 as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE ";
@ -210,7 +211,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
}
}
else
else // Option vat on payments
{
// If vat payed on payments
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
@ -224,16 +225,24 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
}
if ($conf->global->MAIN_MODULE_COMPTABILITE)
{
// Tva sur factures payés (should be on payment)
// Tva sur factures payés (should be on shipment, done on payment instead !)
$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.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,";
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql.= " 0 as payment_id, 0 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.$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)"; // Validated or payed (partially or completely)
$sql.= " AND f.rowid = d.".$fk_facture;
// $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 f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
$sql.= " AND d.product_type = 0"; // Limit to products
@ -267,6 +276,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
$list[$assoc['rate']]['type'][] = $assoc['type'];
$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
$list[$assoc['rate']]['descr'][] = $assoc['descr'];
@ -279,7 +289,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
$rate = $assoc['rate'];
}
}
@ -292,7 +302,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
// CAS DES SERVICES
// Define sql request
$sql='';
if ($modetax == 1) // Option vat on debit
@ -310,8 +320,9 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
if ($conf->global->MAIN_MODULE_COMPTABILITE)
{
$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.= " f.facnumber as facnum, f.type, f.total_ttc as ftotal_ttc,";
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql.= " 0 as payment_id, 0 as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
@ -324,7 +335,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
}
}
else
else // Option vat on payments
{
// If vat payed on payments
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
@ -332,7 +343,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
// \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
// (Il faut quand un paiement a lieu, stocker en plus du montant du paiement le
// detail part tva et part ht).
$sql='TODO';
}
@ -340,7 +351,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
{
// Tva sur factures payés (should be on payment)
$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.type, f.total_ttc as ftotal_ttc,";
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
@ -383,9 +394,10 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
}
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
$list[$assoc['rate']]['type'][] = $assoc['type'];
$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
$list[$assoc['rate']]['descr'][] = $assoc['descr'];
@ -408,7 +420,7 @@ function vat_by_quarter($db, $y, $q, $modetax, $direction)
return -3;
}
}
return $list;
}