Improve extended quaterly VAT report

This commit is contained in:
Yannick Warnier 2015-06-28 12:52:34 -05:00
parent 0cfd513b8c
commit c3bb76340f
2 changed files with 246 additions and 193 deletions

View File

@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
$langs->load("main");
$langs->load("bills"); $langs->load("bills");
$langs->load("compta"); $langs->load("compta");
$langs->load("companies"); $langs->load("companies");
@ -104,7 +105,9 @@ if (empty($modetax)) {
// Security check // Security check
$socid = GETPOST('socid','int'); $socid = GETPOST('socid','int');
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) {
$socid=$user->societe_id;
}
$result = restrictedArea($user, 'tax', '', '', 'charges'); $result = restrictedArea($user, 'tax', '', '', 'charges');
@ -178,6 +181,7 @@ if ($modetax==1) { // Calculate on invoice for goods and services
$productcust=$langs->trans("ProductOrService"); $productcust=$langs->trans("ProductOrService");
$amountcust=$langs->trans("AmountHT"); $amountcust=$langs->trans("AmountHT");
$vatcust=$langs->trans("VATReceived"); $vatcust=$langs->trans("VATReceived");
$namecust=$langs->trans("Name");
if ($mysoc->tva_assuj) { if ($mysoc->tva_assuj) {
$vatcust.=' ('.$langs->trans("ToPay").')'; $vatcust.=' ('.$langs->trans("ToPay").')';
} }
@ -185,6 +189,7 @@ if ($modetax==1) { // Calculate on invoice for goods and services
$productsup=$langs->trans("ProductOrService"); $productsup=$langs->trans("ProductOrService");
$amountsup=$langs->trans("AmountHT"); $amountsup=$langs->trans("AmountHT");
$vatsup=$langs->trans("VATPaid"); $vatsup=$langs->trans("VATPaid");
$namesup=$namecust;
if ($mysoc->tva_assuj) { if ($mysoc->tva_assuj) {
$vatsup.=' ('.$langs->trans("ToGetBack").')'; $vatsup.=' ('.$langs->trans("ToGetBack").')';
} }
@ -226,12 +231,20 @@ if ($modetax==0) { // Invoice for goods, payment for services
$productcust=$langs->trans("ProductOrService"); $productcust=$langs->trans("ProductOrService");
$amountcust=$langs->trans("AmountHT"); $amountcust=$langs->trans("AmountHT");
$vatcust=$langs->trans("VATReceived"); $vatcust=$langs->trans("VATReceived");
if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')'; $datecust=$langs->trans("ValidatePayment");
$namecust=$langs->trans("Name");
if ($mysoc->tva_assuj) {
$vatcust.=' ('.$langs->trans("ToPay").')';
}
$elementsup=$langs->trans("SuppliersInvoices"); $elementsup=$langs->trans("SuppliersInvoices");
$productsup=$langs->trans("ProductOrService"); $productsup=$productcust;
$amountsup=$langs->trans("AmountHT"); $amountsup=$amountcust;
$vatsup=$langs->trans("VATPaid"); $vatsup=$langs->trans("VATPaid");
if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')'; $datesup=$datecust;
$namesup=$namecust;
if ($mysoc->tva_assuj) {
$vatsup.=' ('.$langs->trans("ToGetBack").')';
}
} }
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
@ -275,6 +288,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
$x_both[$my_coll_rate]['coll']['detail'][] = array( $x_both[$my_coll_rate]['coll']['detail'][] = array(
'id' =>$x_coll[$my_coll_rate]['facid'][$id], 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
'descr' =>$x_coll[$my_coll_rate]['descr'][$id], 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
@ -286,6 +300,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
'company_link'=>$company_static->getNomUrl(1,'',20),
'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id], 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
@ -309,6 +325,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
$x_both[$my_paye_rate]['paye']['detail'][] = array( $x_both[$my_paye_rate]['paye']['detail'][] = array(
'id' =>$x_paye[$my_paye_rate]['facid'][$id], 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
'descr' =>$x_paye[$my_paye_rate]['descr'][$id], 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
@ -320,6 +337,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
'company_link'=>$company_static->getNomUrl(1,'',20),
'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id], 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
@ -338,7 +357,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$x_paye_sum = 0; $x_paye_sum = 0;
$x_paye_ht = 0; $x_paye_ht = 0;
$span=3; $span=$columns-3;
if ($modetax == 0) $span+=2; if ($modetax == 0) $span+=2;
//print '<tr><td colspan="'.($span+1).'">'..')</td></tr>'; //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
@ -346,6 +365,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
// Customers invoices // Customers invoices
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left">'.$elementcust.'</td>'; print '<td align="left">'.$elementcust.'</td>';
print '<td align="left">'.$datecust.'</td>';
print '<td align="left">'.$namecust.'</td>';
print '<td align="left">'.$productcust.'</td>'; print '<td align="left">'.$productcust.'</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td align="right">'.$amountcust.'</td>'; print '<td align="right">'.$amountcust.'</td>';
@ -393,6 +414,11 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
// Ref // Ref
print '<td class="nowrap" align="left">'.$fields['link'].'</td>'; print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
// Invoice date
print '<td align="left">' . $fields['datef'] . '</td>';
// Company name
print '<td align="left">' . $fields['company_link'] . '</td>';
// Description // Description
print '<td align="left">'; print '<td align="left">';
if ($fields['pid']) { if ($fields['pid']) {
@ -400,7 +426,9 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$product_static->ref=$fields['pref']; $product_static->ref=$fields['pref'];
$product_static->type=$fields['ptype']; $product_static->type=$fields['ptype'];
print $product_static->getNomUrl(1); print $product_static->getNomUrl(1);
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); if (dol_string_nohtmltag($fields['descr'])) {
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
}
} else { } else {
if ($type) { if ($type) {
$text = img_object($langs->trans('Service'),'service'); $text = img_object($langs->trans('Service'),'service');
@ -408,9 +436,13 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$text = img_object($langs->trans('Product'),'product'); $text = img_object($langs->trans('Product'),'product');
} }
if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) { if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) {
if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit'); if ($reg[1]=='DEPOSIT') {
elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote'); $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]); } elseif ($reg[1]=='CREDIT_NOTE') {
$fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
} else {
$fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
}
} }
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
@ -481,7 +513,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
} }
// Total customers for this vat rate // Total customers for this vat rate
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td></td>'; print '<td colspan="'.$span.'"></td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td class="nowrap" align="right">&nbsp;</td>'; print '<td class="nowrap" align="right">&nbsp;</td>';
@ -494,7 +526,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
if (count($x_coll) == 0) { // Show a total ine if nothing shown if (count($x_coll) == 0) { // Show a total ine if nothing shown
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td>&nbsp;</td>'; print '<td colspan="'.$span.'"></td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td class="nowrap" align="right">&nbsp;</td>'; print '<td class="nowrap" align="right">&nbsp;</td>';
@ -512,6 +544,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
//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">';
print '<td align="left">'.$elementsup.'</td>'; print '<td align="left">'.$elementsup.'</td>';
print '<td align="left">'.$datesup.'</td>';
print '<td align="left">'.$namesup.'</td>';
print '<td align="left">'.$productsup.'</td>'; print '<td align="left">'.$productsup.'</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td align="right">'.$amountsup.'</td>'; print '<td align="right">'.$amountsup.'</td>';
@ -530,6 +564,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
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";
foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) { foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
// Define type // Define type
$type=($fields['dtype']?$fields['dtype']:$fields['ptype']); $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
@ -547,6 +582,10 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
// Ref // Ref
print '<td class="nowrap" align="left">'.$fields['link'].'</td>'; print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
// Invoice date
print '<td align="left">' . $fields['datef'] . '</td>';
// Company name
print '<td align="left">' . $fields['company_link'] . '</td>';
// Description // Description
print '<td align="left">'; print '<td align="left">';
@ -632,7 +671,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
} }
// Total suppliers for this vat rate // Total suppliers for this vat rate
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td>&nbsp;</td>'; print '<td colspan="'.$span.'"></td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td class="nowrap" align="right">&nbsp;</td>'; print '<td class="nowrap" align="right">&nbsp;</td>';
@ -645,7 +684,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
if (count($x_paye) == 0) { // Show a total ine if nothing shown if (count($x_paye) == 0) { // Show a total ine if nothing shown
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td>&nbsp;</td>'; print '<td colspan="'.$span.'"></td>';
print '<td align="right">'.$langs->trans("Total").':</td>'; print '<td align="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0) { if ($modetax == 0) {
print '<td class="nowrap" align="right">&nbsp;</td>'; print '<td class="nowrap" align="right">&nbsp;</td>';

View File

@ -280,10 +280,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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_tx 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
$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.= " 0 as payment_id, 0 as payment_amount"; $sql.= " 0 as payment_id, 0 as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
$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 f.entity = " . $conf->entity; $sql.= " WHERE f.entity = " . $conf->entity;
@ -291,6 +292,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
else $sql.= " AND f.type IN (0,1,2,3,5)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.rowid = d.".$fk_facture;
$sql.= " AND s.rowid = f.fk_soc";
if ($y && $m) if ($y && $m)
{ {
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@ -325,10 +327,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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_tx 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef as date_f, s.nom as company_name, s.rowid as company_id,";
$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.= " 0 as payment_id, 0 as payment_amount"; $sql.= " 0 as payment_id, 0 as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
$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 f.entity = " . $conf->entity; $sql.= " WHERE f.entity = " . $conf->entity;
@ -336,6 +339,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
else $sql.= " AND f.type IN (0,1,2,3,5)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.rowid = d.".$fk_facture;
$sql.= " AND s.rowid = f.fk_soc";
if ($y && $m) if ($y && $m)
{ {
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@ -384,6 +388,9 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
} }
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
$list[$assoc['rate']]['dtype'][] = $assoc['dtype']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
$list[$assoc['rate']]['datef'][] = $assoc['datef'];
$list[$assoc['rate']]['company_name'][] = $assoc['company_name'];
$list[$assoc['rate']]['company_id'][] = $assoc['company_id'];
$list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
$list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
@ -438,10 +445,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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_tx 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
$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.= " 0 as payment_id, 0 as payment_amount"; $sql.= " 0 as payment_id, 0 as payment_amount";
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
$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 f.entity = " . $conf->entity; $sql.= " WHERE f.entity = " . $conf->entity;
@ -449,6 +457,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
else $sql.= " AND f.type IN (0,1,2,3,5)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.rowid = d.".$fk_facture;
$sql.= " AND s.rowid = f.fk_soc";
if ($y && $m) if ($y && $m)
{ {
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@ -484,12 +493,13 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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_tx 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,"; $sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,"; $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
$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_payment." 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.$paymentfacturetable." as pf,"; $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
$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 f.entity = " . $conf->entity; $sql.= " WHERE f.entity = " . $conf->entity;
@ -497,6 +507,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
else $sql.= " AND f.type IN (0,1,2,3,5)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.rowid = d.".$fk_facture; $sql.= " AND f.rowid = d.".$fk_facture;
$sql.= " AND s.rowid = f.fk_soc";
$sql.= " AND pf.".$fk_facture2." = f.rowid"; $sql.= " AND pf.".$fk_facture2." = f.rowid";
$sql.= " AND pa.rowid = pf.".$fk_payment; $sql.= " AND pa.rowid = pf.".$fk_payment;
if ($y && $m) if ($y && $m)
@ -548,6 +559,9 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
} }
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
$list[$assoc['rate']]['dtype'][] = $assoc['dtype']; $list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
$list[$assoc['rate']]['datef'][] = $assoc['datef'];
$list[$assoc['rate']]['company_name'][] = $assoc['company_name'];
$list[$assoc['rate']]['company_id'][] = $assoc['company_id'];
$list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
$list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);