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

@ -20,8 +20,8 @@
*/ */
/** /**
* \file htdocs/compta/tva/quadri_detail.php * \file htdocs/compta/tva/quadri_detail.php
* \ingroup tax * \ingroup tax
* \brief Trimestrial page - detailed version * \brief Trimestrial page - detailed version
* TODO Deal with recurrent invoices as well * TODO Deal with recurrent invoices as well
*/ */
@ -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");
@ -59,52 +60,54 @@ if (empty($date_start) || empty($date_end)) { // We define date_start and date_e
$q=GETPOST('q', 'int'); $q=GETPOST('q', 'int');
if (empty($q)) { if (empty($q)) {
if (isset($_REQUEST["month"])) { if (isset($_REQUEST["month"])) {
$date_start=dol_get_first_day($year_start,$_REQUEST["month"],false); $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false);
$date_end=dol_get_last_day($year_start,$_REQUEST["month"],false); $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false);
} else { } else {
$month_current = strftime("%m",dol_now()); $month_current = strftime("%m",dol_now());
if ($month_current >= 10) $q=4; if ($month_current >= 10) $q=4;
elseif ($month_current >= 7) $q=3; elseif ($month_current >= 7) $q=3;
elseif ($month_current >= 4) $q=2; elseif ($month_current >= 4) $q=2;
else $q=1; else $q=1;
} }
} }
if ($q==1) { if ($q==1) {
$date_start=dol_get_first_day($year_start,1,false); $date_start=dol_get_first_day($year_start,1,false);
$date_end=dol_get_last_day($year_start,3,false); $date_end=dol_get_last_day($year_start,3,false);
} }
if ($q==2) { if ($q==2) {
$date_start=dol_get_first_day($year_start,4,false); $date_start=dol_get_first_day($year_start,4,false);
$date_end=dol_get_last_day($year_start,6,false); $date_end=dol_get_last_day($year_start,6,false);
} }
if ($q==3) { if ($q==3) {
$date_start=dol_get_first_day($year_start,7,false); $date_start=dol_get_first_day($year_start,7,false);
$date_end=dol_get_last_day($year_start,9,false); $date_end=dol_get_last_day($year_start,9,false);
} }
if ($q==4) { if ($q==4) {
$date_start=dol_get_first_day($year_start,10,false); $date_start=dol_get_first_day($year_start,10,false);
$date_end=dol_get_last_day($year_start,12,false); $date_end=dol_get_last_day($year_start,12,false);
} }
} }
$min = GETPOST("min"); $min = GETPOST("min");
if (empty($min)) { if (empty($min)) {
$min = 0; $min = 0;
} }
// Define modetax (0 or 1) // Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit // 0=normal, 1=option vat for services is on debit
$modetax = $conf->global->TAX_MODE; $modetax = $conf->global->TAX_MODE;
if (isset($_REQUEST["modetax"])) { if (isset($_REQUEST["modetax"])) {
$modetax=$_REQUEST["modetax"]; $modetax=$_REQUEST["modetax"];
} }
if (empty($modetax)) { if (empty($modetax)) {
$modetax=0; $modetax=0;
} }
// 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');
@ -117,8 +120,8 @@ $morequerystring='';
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday'); $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
foreach ($listofparams as $param) { foreach ($listofparams as $param) {
if (GETPOST($param)!='') { if (GETPOST($param)!='') {
$morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param); $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
} }
} }
llxHeader('','','','',0,0,'','',$morequerystring); llxHeader('','','','',0,0,'','',$morequerystring);
@ -143,95 +146,105 @@ $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
// Affiche en-tete du rapport // Affiche en-tete du rapport
if ($modetax==1) { // Calculate on invoice for goods and services if ($modetax==1) { // Calculate on invoice for goods and services
$nom=$langs->trans("VATReportByQuartersInDueDebtMode"); $nom=$langs->trans("VATReportByQuartersInDueDebtMode");
$calcmode=$langs->trans("CalcModeVATDebt"); $calcmode=$langs->trans("CalcModeVATDebt");
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
$prevyear=$year_start; $prevquarter=$q; $prevyear=$year_start; $prevquarter=$q;
if ($prevquarter > 1) { if ($prevquarter > 1) {
$prevquarter--; $prevquarter--;
} else { } else {
$prevquarter=4; $prevyear--; $prevquarter=4; $prevyear--;
} }
$nextyear=$year_start; $nextquarter=$q; $nextyear=$year_start; $nextquarter=$q;
if ($nextquarter < 4) { if ($nextquarter < 4) {
$nextquarter++; $nextquarter++;
} else { } else {
$nextquarter=1; $nextyear++; $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>":""); //$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("RulesVATDueServices"); $description=$langs->trans("RulesVATDueServices");
$description.='<br>'; $description.='<br>';
$description.=$langs->trans("RulesVATDueProducts"); $description.=$langs->trans("RulesVATDueProducts");
//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded"); //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.='<br>'.$langs->trans("DepositsAreNotIncluded"); $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
} else { } else {
$description.='<br>'.$langs->trans("DepositsAreIncluded"); $description.='<br>'.$langs->trans("DepositsAreIncluded");
} }
$description.=$fsearch; $description.=$fsearch;
$builddate=time(); $builddate=time();
//$exportlink=$langs->trans("NotYetAvailable"); //$exportlink=$langs->trans("NotYetAvailable");
$elementcust=$langs->trans("CustomersInvoices"); $elementcust=$langs->trans("CustomersInvoices");
$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").')';
} }
$elementsup=$langs->trans("SuppliersInvoices"); $elementsup=$langs->trans("SuppliersInvoices");
$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").')';
} }
} }
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");
$calcmode=$langs->trans("CalcModeVATEngagement"); $calcmode=$langs->trans("CalcModeVATEngagement");
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
$prevyear=$year_start; $prevquarter=$q; $prevyear=$year_start; $prevquarter=$q;
if ($prevquarter > 1) { if ($prevquarter > 1) {
$prevquarter--; $prevquarter--;
} else { } else {
$prevquarter=4; $prevyear--; $prevquarter=4; $prevyear--;
} }
$nextyear=$year_start; $nextquarter=$q; $nextyear=$year_start; $nextquarter=$q;
if ($nextquarter < 4) { if ($nextquarter < 4) {
$nextquarter++; $nextquarter++;
} else { } else {
$nextquarter=1; $nextyear++; $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>":""); //$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("RulesVATInServices"); $description=$langs->trans("RulesVATInServices");
$description.=' '.$langs->trans("DepositsAreIncluded"); $description.=' '.$langs->trans("DepositsAreIncluded");
$description.='<br>'; $description.='<br>';
$description.=$langs->trans("RulesVATInProducts"); $description.=$langs->trans("RulesVATInProducts");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.=' '.$langs->trans("DepositsAreNotIncluded"); $description.=' '.$langs->trans("DepositsAreNotIncluded");
} else { } else {
$description.=' '.$langs->trans("DepositsAreIncluded"); $description.=' '.$langs->trans("DepositsAreIncluded");
} }
//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite'); //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded"); //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
$description.=$fsearch; $description.=$fsearch;
$builddate=time(); $builddate=time();
//$exportlink=$langs->trans("NotYetAvailable"); //$exportlink=$langs->trans("NotYetAvailable");
$elementcust=$langs->trans("CustomersInvoices"); $elementcust=$langs->trans("CustomersInvoices");
$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);
@ -255,18 +268,18 @@ $x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
if (!is_array($x_coll) || !is_array($x_paye)) { if (!is_array($x_coll) || !is_array($x_paye)) {
$langs->load("errors"); $langs->load("errors");
if ($x_coll == -1) { if ($x_coll == -1) {
print '<tr><td colspan="' . $columns . '">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>'; print '<tr><td colspan="' . $columns . '">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
} else if ($x_coll == -2) { } else if ($x_coll == -2) {
print '<tr><td colspan="' . $columns . '">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>'; print '<tr><td colspan="' . $columns . '">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
} else { } else {
print '<tr><td colspan="' . $columns . '">' . $langs->trans("Error") . '</td></tr>'; print '<tr><td colspan="' . $columns . '">' . $langs->trans("Error") . '</td></tr>';
} }
} else { } else {
$x_both = array(); $x_both = array();
//now, from these two arrays, get another array with one rate per line //now, from these two arrays, get another array with one rate per line
foreach(array_keys($x_coll) as $my_coll_rate) { 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']['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]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
$x_both[$my_coll_rate]['paye']['totalht'] = 0; $x_both[$my_coll_rate]['paye']['totalht'] = 0;
$x_both[$my_coll_rate]['paye']['vat'] = 0; $x_both[$my_coll_rate]['paye']['vat'] = 0;
$x_both[$my_coll_rate]['coll']['links'] = ''; $x_both[$my_coll_rate]['coll']['links'] = '';
@ -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,12 +300,14 @@ 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],
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
'link' =>$invoice_customer->getNomUrl(1,'',12) 'link' =>$invoice_customer->getNomUrl(1,'',12)
); );
} }
} }
// tva paid // tva paid
@ -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,12 +337,14 @@ 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]),
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
'link' =>$invoice_supplier->getNomUrl(1,'',12) 'link' =>$invoice_supplier->getNomUrl(1,'',12)
); );
} }
} }
//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
@ -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>';
@ -381,11 +402,11 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
// Try to enhance type detection using date_start and date_end for free lines where type // Try to enhance type detection using date_start and date_end for free lines where type
// was not saved. // was not saved.
if (!empty($fields['ddate_start'])) { if (!empty($fields['ddate_start'])) {
$type=1; $type=1;
} }
if (!empty($fields['ddate_end'])) { if (!empty($fields['ddate_end'])) {
$type=1; $type=1;
} }
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -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,18 +426,24 @@ 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');
} else { } else {
$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);
// Show range // Show range
@ -435,8 +467,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$ratiopaymentinvoice=1; $ratiopaymentinvoice=1;
if ($modetax == 0) { if ($modetax == 0) {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
} }
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
//print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
if ($fields['payment_amount'] && $fields['ftotal_ttc']) { if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
@ -448,8 +480,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
} else { } else {
print $fields['payment_amount']; print $fields['payment_amount'];
if (isset($fields['payment_amount'])) { if (isset($fields['payment_amount'])) {
print ' ('.round($ratiopaymentinvoice*100,2).'%)'; print ' ('.round($ratiopaymentinvoice*100,2).'%)';
} }
} }
print '</td>'; print '</td>';
} }
@ -458,8 +490,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
$temp_ht=$fields['totalht']; $temp_ht=$fields['totalht'];
if ($type == 1) { if ($type == 1) {
$temp_ht=$fields['totalht']*$ratiopaymentinvoice; $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
} }
print price(price2num($temp_ht,'MT'),1); print price(price2num($temp_ht,'MT'),1);
print '</td>'; print '</td>';
@ -467,8 +499,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
$temp_vat=$fields['vat']; $temp_vat=$fields['vat'];
if ($type == 1) { if ($type == 1) {
$temp_vat=$fields['vat']*$ratiopaymentinvoice; $temp_vat=$fields['vat']*$ratiopaymentinvoice;
} }
print price(price2num($temp_vat,'MT'),1); print price(price2num($temp_vat,'MT'),1);
//print price($fields['vat']); //print price($fields['vat']);
print '</td>'; print '</td>';
@ -479,39 +511,41 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$x_coll_sum += $temp_vat; $x_coll_sum += $temp_vat;
} }
} }
// 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>';
print '<td align="right">&nbsp;</td>'; print '<td align="right">&nbsp;</td>';
} }
print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>'; print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>'; print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
print '</tr>'; print '</tr>';
} }
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>';
print '<td align="right">&nbsp;</td>'; print '<td align="right">&nbsp;</td>';
} }
print '<td align="right">'.price(price2num(0,'MT')).'</td>'; print '<td align="right">'.price(price2num(0,'MT')).'</td>';
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>'; print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
print '</tr>'; print '</tr>';
} }
// Blank line // Blank line
print '<tr><td colspan="'.($span+1).'">&nbsp;</td></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">';
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,23 +564,28 @@ 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']);
// Try to enhance type detection using date_start and date_end for free lines where type // Try to enhance type detection using date_start and date_end for free lines where type
// was not saved. // was not saved.
if (!empty($fields['ddate_start'])) { if (!empty($fields['ddate_start'])) {
$type=1; $type=1;
} }
if (!empty($fields['ddate_end'])) { if (!empty($fields['ddate_end'])) {
$type=1; $type=1;
} }
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
// 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">';
@ -556,14 +595,14 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$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'])) { if (dol_string_nohtmltag($fields['descr'])) {
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); 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');
} else { } else {
$text = img_object($langs->trans('Product'),'product'); $text = img_object($langs->trans('Product'),'product');
} }
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16); print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
// Show range // Show range
@ -587,8 +626,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
$ratiopaymentinvoice=1; $ratiopaymentinvoice=1;
if ($modetax == 0) { if ($modetax == 0) {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
} }
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
if ($fields['payment_amount'] && $fields['ftotal_ttc']) { if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
$paymentfourn_static->id=$fields['payment_id']; $paymentfourn_static->id=$fields['payment_id'];
@ -599,8 +638,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
} else { } else {
print $fields['payment_amount']; print $fields['payment_amount'];
if (isset($fields['payment_amount'])) { if (isset($fields['payment_amount'])) {
print ' ('.round($ratiopaymentinvoice*100,2).'%)'; print ' ('.round($ratiopaymentinvoice*100,2).'%)';
} }
} }
print '</td>'; print '</td>';
} }
@ -609,8 +648,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
$temp_ht=$fields['totalht']; $temp_ht=$fields['totalht'];
if ($type == 1) { if ($type == 1) {
$temp_ht=$fields['totalht']*$ratiopaymentinvoice; $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
} }
print price(price2num($temp_ht,'MT'),1); print price(price2num($temp_ht,'MT'),1);
print '</td>'; print '</td>';
@ -618,50 +657,50 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
print '<td class="nowrap" align="right">'; print '<td class="nowrap" align="right">';
$temp_vat=$fields['vat']; $temp_vat=$fields['vat'];
if ($type == 1) { if ($type == 1) {
$temp_vat=$fields['vat']*$ratiopaymentinvoice; $temp_vat=$fields['vat']*$ratiopaymentinvoice;
} }
print price(price2num($temp_vat,'MT'),1); print price(price2num($temp_vat,'MT'),1);
//print price($fields['vat']); //print price($fields['vat']);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
$subtot_paye_total_ht += $temp_ht; $subtot_paye_total_ht += $temp_ht;
$subtot_paye_vat += $temp_vat; $subtot_paye_vat += $temp_vat;
$x_paye_sum += $temp_vat; $x_paye_sum += $temp_vat;
} }
} }
// 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>';
print '<td align="right">&nbsp;</td>'; print '<td align="right">&nbsp;</td>';
} }
print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>'; print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>'; print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
print '</tr>'; print '</tr>';
} }
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>';
print '<td align="right">&nbsp;</td>'; print '<td align="right">&nbsp;</td>';
} }
print '<td align="right">'.price(price2num(0,'MT')).'</td>'; print '<td align="right">'.price(price2num(0,'MT')).'</td>';
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>'; print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
print '</tr>'; print '</tr>';
} }
print '</table>'; print '</table>';
// Total to pay // Total to pay
print '<br><br>'; print '<br><br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$diff = $x_coll_sum - $x_paye_sum; $diff = $x_coll_sum - $x_paye_sum;
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>'; print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n"; print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";

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']);