NEW: VAT report - Optimisation & collapse by rate

This commit is contained in:
Alexandre SPANGARO 2021-02-16 04:28:55 +01:00
parent 9e16cd5b77
commit 8079105aaf
4 changed files with 804 additions and 706 deletions

View File

@ -41,11 +41,56 @@ $now = dol_now();
$current_date = dol_getdate($now); $current_date = dol_getdate($now);
if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1; if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
$refresh = GETPOSTISSET('submit') ? true : false;
if ($refresh === false) {
$year_current = intval(strftime('%Y', $now));
$month_current = intval(strftime('%m', $now));
// 1 : Monthly (by default)
// 2 : Quarterly
// 3 : Annual
if ($conf->global->MAIN_INFO_VAT_RETURN == 2) {
// quarterly
$year = $year_current;
if ($month_current >= 7 && $month_current <= 9) {
$month_start = 4;
$month_end = 6;
} elseif ($month_current >= 10 && $month_current <= 12) {
$month_start = 7;
$month_end = 9;
} elseif ($month_current >= 1 && $month_current <= 3) {
$month_start = 10;
$month_end = 12;
$year--;
} else {
$month_start = 1;
$month_end = 3;
}
$date_start = dol_get_first_day($year, $month_start);
$date_end = dol_get_last_day($year, $month_end);
}
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
// annual
$date_start = dol_get_first_day($year_current, 1);
$date_end = dol_get_last_day($year_current, 12);
} else {
// monthly by default
$year = $year_current;
$month_last = $month_current - 1;
if ($month_last <= 0) {
$month_last = $month_last + 12;
$year--;
}
$date_start = dol_get_first_day($year, $month_last);
$date_end = dol_get_last_day($year, $month_last);
}
} else {
// Date range // Date range
$year = GETPOST("year", "int"); $year = GETPOST("year", "int");
if (empty($year)) if (empty($year)) {
{ $year_current = strftime("%Y", dol_now());
$year_current = $current_date['year']; if ($conf->global->SOCIETE_FISCAL_MONTH_START > date('m')) $year_current--;
$year_start = $year_current; $year_start = $year_current;
} else { } else {
$year_current = $year; $year_current = $year;
@ -53,43 +98,36 @@ if (empty($year))
} }
$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Set default period if not defined
if (empty($date_start) || empty($date_end)) // We define date_start and date_end if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{ {
$q = GETPOST("q", "int"); $q = GETPOST("q", "int");
if (empty($q)) if (empty($q)) {
{ if (GETPOST("month", "int")) {
if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false);
else { $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter
$date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm');
$date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
}
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat
if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) {
if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year
$year_start--;
}
} else { } else {
if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year
$year_start--;
}
}
$date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false);
$date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
} }
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month } else {
$date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); if ($q == 1) {
$date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; $date_start = dol_get_first_day($year_start, 1, false);
$date_end = dol_get_last_day($year_start, 3, false);
}
if ($q == 2) {
$date_start = dol_get_first_day($year_start, 4, false);
$date_end = dol_get_last_day($year_start, 6, false);
}
if ($q == 3) {
$date_start = dol_get_first_day($year_start, 7, false);
$date_end = dol_get_last_day($year_start, 9, false);
}
if ($q == 4) {
$date_start = dol_get_first_day($year_start, 10, false);
$date_end = dol_get_last_day($year_start, 12, false);
} }
} }
} }
else {
if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
}
} }
// Define modetax (0 or 1) // Define modetax (0 or 1)
@ -261,6 +299,7 @@ report_header($name, '', $period, $periodlink, $description, $builddate, $export
print '<br>'; print '<br>';
if ($refresh === true) {
print '<div class="fichecenter"><div class="fichethirdleft">'; print '<div class="fichecenter"><div class="fichethirdleft">';
print load_fiche_titre($langs->trans("VATSummary"), '', ''); print load_fiche_titre($langs->trans("VATSummary"), '', '');
@ -281,8 +320,12 @@ $tmp = dol_getdate($date_end);
$yend = $tmp['year']; $yend = $tmp['year'];
$mend = $tmp['mon']; $mend = $tmp['mon'];
//var_dump($m); //var_dump($m);
$total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; $total = 0;
$i = 0; $mcursor = 0; $subtotalcoll = 0;
$subtotalpaye = 0;
$subtotal = 0;
$i = 0;
$mcursor = 0;
while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
{ {
@ -296,8 +339,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$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;
@ -343,11 +385,9 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$x_both[$my_paye_rate]['paye']['links'] = ''; $x_both[$my_paye_rate]['paye']['links'] = '';
$x_both[$my_paye_rate]['paye']['detail'] = array(); $x_both[$my_paye_rate]['paye']['detail'] = array();
foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
{
// ExpenseReport // ExpenseReport
if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
{
//$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id]; //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
//$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id]; //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
//$expensereport->type=$x_paye[$my_paye_rate]['type'][$id]; //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
@ -369,8 +409,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
'vat' => $x_paye[$my_paye_rate]['vat_list'][$id], 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
//'link' =>$expensereport->getNomUrl(1) //'link' =>$expensereport->getNomUrl(1)
); );
} } else {
else {
//$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];
@ -411,14 +450,12 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$hookmanager->initHooks(array('externalbalance')); $hookmanager->initHooks(array('externalbalance'));
$reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (!is_array($x_coll) && $coll_listbuy == -1) if (!is_array($x_coll) && $coll_listbuy == -1) {
{
$langs->load("errors"); $langs->load("errors");
print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>'; print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
break; break;
} }
if (!is_array($x_paye) && $coll_listbuy == -2) if (!is_array($x_paye) && $coll_listbuy == -2) {
{
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>'; print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
break; break;
} }
@ -428,17 +465,14 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print '<td class="nowrap"><a href="' . DOL_URL_ROOT . '/compta/tva/quadri_detail.php?leftmenu=tax_vat&month=' . $m . '&year=' . $y . '">' . dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y") . '</a></td>'; print '<td class="nowrap"><a href="' . DOL_URL_ROOT . '/compta/tva/quadri_detail.php?leftmenu=tax_vat&month=' . $m . '&year=' . $y . '">' . dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y") . '</a></td>';
$x_coll_sum = 0; $x_coll_sum = 0;
foreach (array_keys($x_coll) as $rate) foreach (array_keys($x_coll) as $rate) {
{
$subtot_coll_total_ht = 0; $subtot_coll_total_ht = 0;
$subtot_coll_vat = 0; $subtot_coll_vat = 0;
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
{
// Payment // Payment
$ratiopaymentinvoice = 1; $ratiopaymentinvoice = 1;
if ($modetax != 1) if ($modetax != 1) {
{
// Define type // Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
@ -452,8 +486,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
} }
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
{
//print $langs->trans("NA"); //print $langs->trans("NA");
} else { } else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@ -472,17 +505,14 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print '<td class="nowrap right">' . price(price2num($x_coll_sum, 'MT')) . '</td>'; print '<td class="nowrap right">' . price(price2num($x_coll_sum, 'MT')) . '</td>';
$x_paye_sum = 0; $x_paye_sum = 0;
foreach (array_keys($x_paye) as $rate) foreach (array_keys($x_paye) as $rate) {
{
$subtot_paye_total_ht = 0; $subtot_paye_total_ht = 0;
$subtot_paye_vat = 0; $subtot_paye_vat = 0;
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
{
// Payment // Payment
$ratiopaymentinvoice = 1; $ratiopaymentinvoice = 1;
if ($modetax != 1) if ($modetax != 1) {
{
// Define type // Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
@ -496,8 +526,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
} }
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
{
//print $langs->trans("NA"); //print $langs->trans("NA");
} else { } else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@ -526,9 +555,9 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print "<td>&nbsp;</td>\n"; print "<td>&nbsp;</td>\n";
print "</tr>\n"; print "</tr>\n";
$i++; $m++; $i++;
if ($i > 2) $m++;
{ if ($i > 2) {
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) . '&year=' . $y . '">' . $langs->trans("SubTotal") . '</a>:</td>'; print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) . '&year=' . $y . '">' . $langs->trans("SubTotal") . '</a>:</td>';
print '<td class="nowrap right">' . price(price2num($subtotalcoll, 'MT')) . '</td>'; print '<td class="nowrap right">' . price(price2num($subtotalcoll, 'MT')) . '</td>';
@ -536,7 +565,9 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print '<td class="nowrap right">' . price(price2num($subtotal, 'MT')) . '</td>'; print '<td class="nowrap right">' . price(price2num($subtotal, 'MT')) . '</td>';
print '<td>&nbsp;</td></tr>'; print '<td>&nbsp;</td></tr>';
$i = 0; $i = 0;
$subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; $subtotalcoll = 0;
$subtotalpaye = 0;
$subtotal = 0;
} }
} }
print '<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans("TotalToPay") . ':</td><td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>'; print '<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans("TotalToPay") . ':</td><td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>';
@ -549,7 +580,6 @@ print '</table>';
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">'; print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
/* /*
* Paid * Paid
*/ */
@ -579,8 +609,7 @@ $sql .= " ORDER BY dm ASC, mode ASC";
pt($db, $sql, $langs->trans("Month")); pt($db, $sql, $langs->trans("Month"));
if (!empty($conf->global->MAIN_FEATURES_LEVEL)) if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
{
print '<br>'; print '<br>';
/* /*
@ -621,6 +650,7 @@ if (!empty($conf->global->MAIN_FEATURES_LEVEL))
} }
print '</div></div>'; print '</div></div>';
}
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@ -45,55 +45,58 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.
$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin")); $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
$now = dol_now(); $now = dol_now();
$current_date = dol_getdate($now); $refresh = GETPOSTISSET('submit') ? true : false;
if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1; $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : '';
$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1;
// Date range $year_current = GETPOSTISSET('year') ? GETPOST('year', 'int') : intval(strftime('%Y', $now));
$year = GETPOST("year", "int");
if (empty($year))
{
$year_current = $current_date['year'];
$year_start = $year_current; $year_start = $year_current;
$month_current = GETPOSTISSET('month') ? GETPOST('month', 'int') : intval(strftime('%m', $now));
$month_start = $month_current;
if ($refresh===false) {
$date_start = dol_get_first_day($year_start, $month_start);
$date_end = dol_get_last_day($year_start, $month_start);
} else { } else {
$year_current = $year; // Date range
$year_start = $year; //$year=GETPOST("year", "int");
} //if (empty($year))
//{
// $year_current = strftime("%Y", dol_now());
// $year_start = $year_current;
//} else {
// $year_current = $year;
// $year_start = $year;
//}
$date_start=dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); $date_start=dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end=dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); $date_end=dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Set default period if not defined // Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{ {
$q=GETPOST("q", "int"); $q=GETPOST("q", "int");
if (empty($q)) if (empty($q))
{ {
if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else { if (GETPOST("month", "int")) { $date_start=dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end=dol_get_last_day($year_start, GETPOST("month", "int"), false); }
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter else
$date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); {
$date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; $date_start=dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false);
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end=dol_time_plus_duree($date_start, 3, 'm') - 1;
if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1;
if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end=dol_time_plus_duree($date_start, 1, 'm') - 1;
$year_start--;
}
} else {
if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year
$year_start--;
} }
} }
$date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); else
$date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; {
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month
$date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm');
$date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
}
}
} else {
if ($q==1) { $date_start=dol_get_first_day($year_start, 1, false); $date_end=dol_get_last_day($year_start, 3, false); } if ($q==1) { $date_start=dol_get_first_day($year_start, 1, false); $date_end=dol_get_last_day($year_start, 3, false); }
if ($q==2) { $date_start=dol_get_first_day($year_start, 4, false); $date_end=dol_get_last_day($year_start, 6, false); } if ($q==2) { $date_start=dol_get_first_day($year_start, 4, false); $date_end=dol_get_last_day($year_start, 6, false); }
if ($q==3) { $date_start=dol_get_first_day($year_start, 7, false); $date_end=dol_get_last_day($year_start, 9, false); } if ($q==3) { $date_start=dol_get_first_day($year_start, 7, false); $date_end=dol_get_last_day($year_start, 9, false); }
if ($q==4) { $date_start=dol_get_first_day($year_start, 10, false); $date_end=dol_get_last_day($year_start, 12, false); } if ($q==4) { $date_start=dol_get_first_day($year_start, 10, false); $date_end=dol_get_last_day($year_start, 12, false); }
} }
} }
}
$month_start = strftime('%m', $date_start);
$year_start = strftime('%Y', $date_start);
$min = price2num(GETPOST("min", "alpha")); $min = price2num(GETPOST("min", "alpha"));
if (empty($min)) $min = 0; if (empty($min)) $min = 0;
@ -389,7 +392,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
{ {
// VAT Rate // VAT Rate
print "<tr>"; print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>'; print '<td class="tax_rate" colspan="' . ($span+1) . '">';
print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
print ' - <a href="' . dol_buildpath('/compta/tva/quadri_detail.php', 1) . '?invoice_type=customer&amp;vat_rate_show=' . $rate . '&amp;year=' . $year_start . '&amp;month=' . $month_start . '">' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '</a>';
print '</td>';
print '</tr>'."\n"; print '</tr>'."\n";
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
@ -405,6 +411,48 @@ if (!is_array($x_coll) || !is_array($x_paye))
$type = 1; $type = 1;
} }
// Payment
$ratiopaymentinvoice=1;
if ($modetax != 1)
{
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
{
} else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
}
}
}
// Total collected
$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
// VAT
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
$subtot_coll_total_ht += $temp_ht;
$subtot_coll_vat += $temp_vat;
$x_coll_sum += $temp_vat;
}
}
if ($invoice_type == 'customer' && $vat_rate_show == $rate) {
if (is_array($x_both[$rate]['coll']['detail'])) {
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
// Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) {
$type = 1;
}
if (!empty($fields['ddate_end'])) {
$type = 1;
}
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -423,8 +471,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Description // Description
print '<td class="left">'; print '<td class="left">';
if ($fields['pid']) if ($fields['pid']) {
{
$product_static->id = $fields['pid']; $product_static->id = $fields['pid'];
$product_static->ref = $fields['pref']; $product_static->ref = $fields['pref'];
$product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
@ -455,12 +502,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</td>'; print '</td>';
// Total HT // Total HT
if ($modetax != 1) if ($modetax != 1) {
{
print '<td class="nowrap right">'; print '<td class="nowrap right">';
print price($fields['totalht']); print price($fields['totalht']);
if (price2num($fields['ftotal_ttc'])) if (price2num($fields['ftotal_ttc'])) {
{
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
//print ' ('.round($ratiolineinvoice*100,2).'%)'; //print ' ('.round($ratiolineinvoice*100,2).'%)';
@ -470,18 +515,15 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment // Payment
$ratiopaymentinvoice = 1; $ratiopaymentinvoice = 1;
if ($modetax != 1) if ($modetax != 1) {
{
print '<td class="nowrap right">'; print '<td class="nowrap 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']) {
{
$payment_static->id = $fields['payment_id']; $payment_static->id = $fields['payment_id'];
print $payment_static->getNomUrl(2); print $payment_static->getNomUrl(2);
} }
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
{
print $langs->trans("NA"); print $langs->trans("NA");
} else { } else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@ -509,9 +551,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
$subtot_coll_total_ht += $temp_ht; //$subtot_coll_total_ht += $temp_ht;
$subtot_coll_vat += $temp_vat; //$subtot_coll_vat += $temp_vat;
$x_coll_sum += $temp_vat; //$x_coll_sum += $temp_vat;
}
} }
} }
// Total customers for this vat rate // Total customers for this vat rate
@ -568,7 +611,9 @@ if (!is_array($x_coll) || !is_array($x_paye))
if (is_array($x_both[$rate]['paye']['detail'])) if (is_array($x_both[$rate]['paye']['detail']))
{ {
print "<tr>"; print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>'; print '<td class="tax_rate">';
print '<a href="' . dol_buildpath('/compta/tva/quadri_detail.php', 1) . '?invoice_type=supplier&amp;vat_rate_show=' . $rate . '&amp;year=' . $year_start . '&amp;month=' . $month_start . '" title="' . $langs->trans('VATReportShowByRateDetails') . '">' . $langs->trans('Rate') . ' : ' . vatrate($rate) . '%' . '</a>';
print '</td><td colspan="' . ($span+1) . '"></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) {
@ -584,6 +629,44 @@ if (!is_array($x_coll) || !is_array($x_paye))
$type = 1; $type = 1;
} }
// Payment
$ratiopaymentinvoice = 1;
if ($modetax != 1) {
if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
} else {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
$ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
}
}
}
// VAT paid
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
// VAT
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
$subtot_paye_total_ht += $temp_ht;
$subtot_paye_vat += $temp_vat;
$x_paye_sum += $temp_vat;
}
if ($invoice_type == 'supplier' && $vat_rate_show == $rate) {
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
// Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) {
$type = 1;
}
if (!empty($fields['ddate_end'])) {
$type = 1;
}
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -602,8 +685,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Description // Description
print '<td class="left">'; print '<td class="left">';
if ($fields['pid']) if ($fields['pid']) {
{
$product_static->id = $fields['pid']; $product_static->id = $fields['pid'];
$product_static->ref = $fields['pref']; $product_static->ref = $fields['pref'];
$product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
@ -634,12 +716,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</td>'; print '</td>';
// Total HT // Total HT
if ($modetax != 1) if ($modetax != 1) {
{
print '<td class="nowrap right">'; print '<td class="nowrap right">';
print price($fields['totalht']); print price($fields['totalht']);
if (price2num($fields['ftotal_ttc'])) if (price2num($fields['ftotal_ttc'])) {
{
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
//print ' ('.round($ratiolineinvoice*100,2).'%)'; //print ' ('.round($ratiolineinvoice*100,2).'%)';
@ -649,18 +729,15 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment // Payment
$ratiopaymentinvoice = 1; $ratiopaymentinvoice = 1;
if ($modetax != 1) if ($modetax != 1) {
{
print '<td class="nowrap right">'; print '<td class="nowrap 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'];
print $paymentfourn_static->getNomUrl(2); print $paymentfourn_static->getNomUrl(2);
} }
if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
{
print $langs->trans("NA"); print $langs->trans("NA");
} else { } else {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
@ -688,11 +765,13 @@ if (!is_array($x_coll) || !is_array($x_paye))
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 colspan="4"></td>'; print '<td colspan="4"></td>';

View File

@ -599,16 +599,14 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$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 .= " 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 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture."=f.rowid";
$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 IN (".getEntity($invoicetable).")"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
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 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))."'";
@ -633,20 +631,16 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$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 .= " pa.datep as datep"; $sql .= " pa.datep as datep";
$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
$sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";;
$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
$sql .= " ".MAIN_DB_PREFIX."societe as s,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid";
$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 IN (".getEntity($invoicetable).")"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
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 s.rowid = f.fk_soc";
$sql .= " AND pf.".$fk_facture2." = f.rowid";
$sql .= " AND pa.rowid = pf.".$fk_payment;
if ($y && $m) if ($y && $m)
{ {
$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
@ -741,16 +735,14 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$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 .= " 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 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid";
$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 IN (".getEntity($invoicetable).")"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
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 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))."'";
@ -775,20 +767,16 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$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 .= " pa.datep as datep"; $sql .= " pa.datep as datep";
$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
$sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";
$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
$sql .= " ".MAIN_DB_PREFIX."societe as s,"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid";
$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 IN (".getEntity($invoicetable).")"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
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 s.rowid = f.fk_soc";
$sql .= " AND pf.".$fk_facture2." = f.rowid";
$sql .= " AND pa.rowid = pf.".$fk_payment;
if ($y && $m) if ($y && $m)
{ {
$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";

View File

@ -191,6 +191,7 @@ VATReportByThirdParties=Sale tax report by third parties
VATReportByCustomers=Sale tax report by customer VATReportByCustomers=Sale tax report by customer
VATReportByCustomersInInputOutputMode=Report by the customer VAT collected and paid VATReportByCustomersInInputOutputMode=Report by the customer VAT collected and paid
VATReportByQuartersInInputOutputMode=Report by Sale tax rate of the tax collected and paid VATReportByQuartersInInputOutputMode=Report by Sale tax rate of the tax collected and paid
VATReportShowByRateDetails=Show details of this rate
LT1ReportByQuarters=Report tax 2 by rate LT1ReportByQuarters=Report tax 2 by rate
LT2ReportByQuarters=Report tax 3 by rate LT2ReportByQuarters=Report tax 3 by rate
LT1ReportByQuartersES=Report by RE rate LT1ReportByQuartersES=Report by RE rate