diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php
index 081023cd2e8..ec62f28d32a 100644
--- a/htdocs/compta/tva/index.php
+++ b/htdocs/compta/tva/index.php
@@ -41,55 +41,93 @@ $now = dol_now();
$current_date = dol_getdate($now);
if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
-// Date range
-$year = GETPOST("year", "int");
-if (empty($year))
-{
- $year_current = $current_date['year'];
- $year_start = $year_current;
+$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 {
- $year_current = $year;
- $year_start = $year;
-}
-$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"));
-// Set default period if not defined
-if (empty($date_start) || empty($date_end)) // We define date_start and date_end
-{
- $q = GETPOST("q", "int");
- if (empty($q))
+ // Date range
+ $year = GETPOST("year", "int");
+ if (empty($year)) {
+ $year_current = strftime("%Y", dol_now());
+ if ($conf->global->SOCIETE_FISCAL_MONTH_START > date('m')) $year_current--;
+ $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_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
+ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
- 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 (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 {
- 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--;
- }
- }
+ $q = GETPOST("q", "int");
+ 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 {
$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;
}
- 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 == 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)
@@ -261,366 +299,358 @@ report_header($name, '', $period, $periodlink, $description, $builddate, $export
print '
';
-print '
';
+if ($refresh === true) {
+ print '
';
-print load_fiche_titre($langs->trans("VATSummary"), '', '');
+ print load_fiche_titre($langs->trans("VATSummary"), '', '');
-print '
';
-print '';
-print '| '.$langs->trans("Year")." ".$y.' | ';
-print ''.$langs->trans("VATToPay").' | ';
-print ''.$langs->trans("VATToCollect").' | ';
-print ''.$langs->trans("Balance").' | ';
-print ' | '."\n";
-print '
'."\n";
+ print '';
+ print '';
+ print '| ' . $langs->trans("Year") . " " . $y . ' | ';
+ print '' . $langs->trans("VATToPay") . ' | ';
+ print '' . $langs->trans("VATToCollect") . ' | ';
+ print '' . $langs->trans("Balance") . ' | ';
+ print ' | ' . "\n";
+ print '
' . "\n";
-$tmp = dol_getdate($date_start);
-$y = $tmp['year'];
-$m = $tmp['mon'];
-$tmp = dol_getdate($date_end);
-$yend = $tmp['year'];
-$mend = $tmp['mon'];
+ $tmp = dol_getdate($date_start);
+ $y = $tmp['year'];
+ $m = $tmp['mon'];
+ $tmp = dol_getdate($date_end);
+ $yend = $tmp['year'];
+ $mend = $tmp['mon'];
//var_dump($m);
-$total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
-$i = 0; $mcursor = 0;
+ $total = 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
-{
- //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
- if ($m == 13) $y++;
- if ($m > 12) $m -= 12;
- $mcursor++;
-
- $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
- $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
-
- $x_both = array();
- //now, from these two arrays, get another array with one rate per line
- foreach (array_keys($x_coll) as $my_coll_rate)
+ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
{
- $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]['paye']['totalht'] = 0;
- $x_both[$my_coll_rate]['paye']['vat'] = 0;
- $x_both[$my_coll_rate]['coll']['links'] = '';
- $x_both[$my_coll_rate]['coll']['detail'] = array();
- foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
- //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
- //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
- //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
- //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
- $x_both[$my_coll_rate]['coll']['detail'][] = array(
- 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
- 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
- 'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
- 'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
- 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
- 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
- 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
- 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
- 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
- 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
- 'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
- 'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
- //'company_link'=>$company_static->getNomUrl(1,'',20),
- 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
- 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
- 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
- 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
- //'link' =>$invoice_customer->getNomUrl(1,'',12)
- );
- }
- }
+ //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
+ if ($m == 13) $y++;
+ if ($m > 12) $m -= 12;
+ $mcursor++;
- // tva paid
- foreach (array_keys($x_paye) as $my_paye_rate) {
- $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
- $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
- if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
- $x_both[$my_paye_rate]['coll']['totalht'] = 0;
- $x_both[$my_paye_rate]['coll']['vat'] = 0;
- }
- $x_both[$my_paye_rate]['paye']['links'] = '';
- $x_both[$my_paye_rate]['paye']['detail'] = array();
+ $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
+ $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
- foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
- {
- // ExpenseReport
- if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
- {
- //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
- //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
- //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
-
- $x_both[$my_paye_rate]['paye']['detail'][] = array(
- 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
- 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
- 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
- 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
- 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
- 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
- 'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
- 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
- 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
- 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
- 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
- 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
- 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
- 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
- //'link' =>$expensereport->getNomUrl(1)
- );
- }
- else {
- //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
- //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
- //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
- //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
- $x_both[$my_paye_rate]['paye']['detail'][] = array(
- 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
- 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
- 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
- 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
- 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
- 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
- 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
- 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
- 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
- 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
- 'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
- 'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
- //'company_link'=>$company_static->getNomUrl(1,'',20),
- 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
- 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
- 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
- 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
- //'link' =>$invoice_supplier->getNomUrl(1,'',12)
+ $x_both = array();
+ //now, from these two arrays, get another array with one rate per line
+ 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']['vat'] = $x_coll[$my_coll_rate]['vat'];
+ $x_both[$my_coll_rate]['paye']['totalht'] = 0;
+ $x_both[$my_coll_rate]['paye']['vat'] = 0;
+ $x_both[$my_coll_rate]['coll']['links'] = '';
+ $x_both[$my_coll_rate]['coll']['detail'] = array();
+ foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
+ //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
+ //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
+ //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
+ //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
+ $x_both[$my_coll_rate]['coll']['detail'][] = array(
+ 'id' => $x_coll[$my_coll_rate]['facid'][$id],
+ 'descr' => $x_coll[$my_coll_rate]['descr'][$id],
+ 'pid' => $x_coll[$my_coll_rate]['pid'][$id],
+ 'pref' => $x_coll[$my_coll_rate]['pref'][$id],
+ 'ptype' => $x_coll[$my_coll_rate]['ptype'][$id],
+ 'payment_id' => $x_coll[$my_coll_rate]['payment_id'][$id],
+ 'payment_amount' => $x_coll[$my_coll_rate]['payment_amount'][$id],
+ 'ftotal_ttc' => $x_coll[$my_coll_rate]['ftotal_ttc'][$id],
+ 'dtotal_ttc' => $x_coll[$my_coll_rate]['dtotal_ttc'][$id],
+ 'dtype' => $x_coll[$my_coll_rate]['dtype'][$id],
+ 'datef' => $x_coll[$my_coll_rate]['datef'][$id],
+ 'datep' => $x_coll[$my_coll_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start' => $x_coll[$my_coll_rate]['ddate_start'][$id],
+ 'ddate_end' => $x_coll[$my_coll_rate]['ddate_end'][$id],
+ 'totalht' => $x_coll[$my_coll_rate]['totalht_list'][$id],
+ 'vat' => $x_coll[$my_coll_rate]['vat_list'][$id],
+ //'link' =>$invoice_customer->getNomUrl(1,'',12)
);
}
}
+
+ // tva paid
+ foreach (array_keys($x_paye) as $my_paye_rate) {
+ $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
+ $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
+ if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
+ $x_both[$my_paye_rate]['coll']['totalht'] = 0;
+ $x_both[$my_paye_rate]['coll']['vat'] = 0;
+ }
+ $x_both[$my_paye_rate]['paye']['links'] = '';
+ $x_both[$my_paye_rate]['paye']['detail'] = array();
+
+ foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
+ // ExpenseReport
+ if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
+ //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
+
+ $x_both[$my_paye_rate]['paye']['detail'][] = array(
+ 'id' => $x_paye[$my_paye_rate]['facid'][$id],
+ 'descr' => $x_paye[$my_paye_rate]['descr'][$id],
+ 'pid' => $x_paye[$my_paye_rate]['pid'][$id],
+ 'pref' => $x_paye[$my_paye_rate]['pref'][$id],
+ 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
+ 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
+ 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
+ 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
+ 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
+ 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
+ //'link' =>$expensereport->getNomUrl(1)
+ );
+ } else {
+ //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
+ //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
+ $x_both[$my_paye_rate]['paye']['detail'][] = array(
+ 'id' => $x_paye[$my_paye_rate]['facid'][$id],
+ 'descr' => $x_paye[$my_paye_rate]['descr'][$id],
+ 'pid' => $x_paye[$my_paye_rate]['pid'][$id],
+ 'pref' => $x_paye[$my_paye_rate]['pref'][$id],
+ 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
+ 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
+ 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
+ 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
+ 'datef' => $x_paye[$my_paye_rate]['datef'][$id],
+ 'datep' => $x_paye[$my_paye_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
+ 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
+ //'link' =>$invoice_supplier->getNomUrl(1,'',12)
+ );
+ }
+ }
+ }
+ //now we have an array (x_both) indexed by rates for coll and paye
+
+ $action = "tva";
+ $object = array(&$x_coll, &$x_paye, &$x_both);
+ $parameters["mode"] = $modetax;
+ $parameters["year"] = $y;
+ $parameters["month"] = $m;
+ $parameters["type"] = 'vat';
+
+ // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
+ $hookmanager->initHooks(array('externalbalance'));
+ $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) {
+ $langs->load("errors");
+ print '| ' . $langs->trans("ErrorNoAccountancyModuleLoaded") . ' |
';
+ break;
+ }
+ if (!is_array($x_paye) && $coll_listbuy == -2) {
+ print '| ' . $langs->trans("FeatureNotYetAvailable") . ' |
';
+ break;
+ }
+
+
+ print '';
+ print '| ' . dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y") . ' | ';
+
+ $x_coll_sum = 0;
+ foreach (array_keys($x_coll) as $rate) {
+ $subtot_coll_total_ht = 0;
+ $subtot_coll_vat = 0;
+
+ foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
+ // Payment
+ $ratiopaymentinvoice = 1;
+ if ($modetax != 1) {
+ // 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;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
+ $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
+ $subtot_coll_total_ht += $temp_ht;
+ $subtot_coll_vat += $temp_vat;
+ $x_coll_sum += $temp_vat;
+ }
+ }
+ print '' . price(price2num($x_coll_sum, 'MT')) . ' | ';
+
+ $x_paye_sum = 0;
+ foreach (array_keys($x_paye) as $rate) {
+ $subtot_paye_total_ht = 0;
+ $subtot_paye_vat = 0;
+
+ foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
+ // Payment
+ $ratiopaymentinvoice = 1;
+ if ($modetax != 1) {
+ // 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;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
+ $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
+ $subtot_paye_total_ht += $temp_ht;
+ $subtot_paye_vat += $temp_vat;
+ $x_paye_sum += $temp_vat;
+ }
+ }
+ print '' . price(price2num($x_paye_sum, 'MT')) . ' | ';
+
+ $subtotalcoll = $subtotalcoll + $x_coll_sum;
+ $subtotalpaye = $subtotalpaye + $x_paye_sum;
+
+ $diff = $x_coll_sum - $x_paye_sum;
+ $total = $total + $diff;
+ $subtotal = price2num($subtotal + $diff, 'MT');
+
+ print '' . price(price2num($diff, 'MT')) . ' | ' . "\n";
+ print " | \n";
+ print "
\n";
+
+ $i++;
+ $m++;
+ if ($i > 2) {
+ print '';
+ print '| ' . $langs->trans("SubTotal") . ': | ';
+ print '' . price(price2num($subtotalcoll, 'MT')) . ' | ';
+ print '' . price(price2num($subtotalpaye, 'MT')) . ' | ';
+ print '' . price(price2num($subtotal, 'MT')) . ' | ';
+ print ' |
';
+ $i = 0;
+ $subtotalcoll = 0;
+ $subtotalpaye = 0;
+ $subtotal = 0;
+ }
}
- //now we have an array (x_both) indexed by rates for coll and paye
+ print '| ' . $langs->trans("TotalToPay") . ': | ' . price(price2num($total, 'MT')) . ' | ';
+ print " | \n";
+ print '
';
- $action = "tva";
- $object = array(&$x_coll, &$x_paye, &$x_both);
- $parameters["mode"] = $modetax;
- $parameters["year"] = $y;
- $parameters["month"] = $m;
- $parameters["type"] = 'vat';
-
- // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
- $hookmanager->initHooks(array('externalbalance'));
- $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)
- {
- $langs->load("errors");
- print '| '.$langs->trans("ErrorNoAccountancyModuleLoaded").' |
';
- break;
- }
- if (!is_array($x_paye) && $coll_listbuy == -2)
- {
- print '| '.$langs->trans("FeatureNotYetAvailable").' |
';
- break;
- }
+ print '
';
- print '';
- print '| '.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").' | ';
+ print '';
- $x_coll_sum = 0;
- foreach (array_keys($x_coll) as $rate)
- {
- $subtot_coll_total_ht = 0;
- $subtot_coll_vat = 0;
-
- foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
- {
- // Payment
- $ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
- // 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;
- }
-
- if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
- {
- //print $langs->trans("NA");
- } else {
- if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
- $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
- }
- }
- }
- //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
- $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
- $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
- $subtot_coll_total_ht += $temp_ht;
- $subtot_coll_vat += $temp_vat;
- $x_coll_sum += $temp_vat;
- }
- }
- print '
'.price(price2num($x_coll_sum, 'MT')).' | ';
-
- $x_paye_sum = 0;
- foreach (array_keys($x_paye) as $rate)
- {
- $subtot_paye_total_ht = 0;
- $subtot_paye_vat = 0;
-
- foreach ($x_both[$rate]['paye']['detail'] as $index => $fields)
- {
- // Payment
- $ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
- // 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;
- }
-
- if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
- {
- //print $langs->trans("NA");
- } else {
- if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
- $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
- }
- }
- }
- //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
- $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
- $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
- $subtot_paye_total_ht += $temp_ht;
- $subtot_paye_vat += $temp_vat;
- $x_paye_sum += $temp_vat;
- }
- }
- print ''.price(price2num($x_paye_sum, 'MT')).' | ';
-
- $subtotalcoll = $subtotalcoll + $x_coll_sum;
- $subtotalpaye = $subtotalpaye + $x_paye_sum;
-
- $diff = $x_coll_sum - $x_paye_sum;
- $total = $total + $diff;
- $subtotal = price2num($subtotal + $diff, 'MT');
-
- print ''.price(price2num($diff, 'MT')).' | '."\n";
- print " | \n";
- print "
\n";
-
- $i++; $m++;
- if ($i > 2)
- {
- print '';
- print '| '.$langs->trans("SubTotal").': | ';
- print ''.price(price2num($subtotalcoll, 'MT')).' | ';
- print ''.price(price2num($subtotalpaye, 'MT')).' | ';
- print ''.price(price2num($subtotal, 'MT')).' | ';
- print ' |
';
- $i = 0;
- $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
- }
-}
-print '| '.$langs->trans("TotalToPay").': | '.price(price2num($total, 'MT')).' | ';
-print " | \n";
-print '
';
-
-print '
';
-
-
-print '
';
-
-
-
-/*
- * Paid
- */
-
-print load_fiche_titre($langs->trans("VATPaid"), '', '');
-
-$sql = '';
-
-$sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
-$sql .= " FROM ".MAIN_DB_PREFIX."tva as tva";
-$sql .= " WHERE tva.entity = ".$conf->entity;
-$sql .= " AND (tva.datev >= '".$db->idate($date_start)."' AND tva.datev <= '".$db->idate($date_end)."')";
-$sql .= " GROUP BY dm";
-
-$sql .= " UNION ";
-
-$sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
-$sql .= " FROM ".MAIN_DB_PREFIX."tva as tva";
-$sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
-$sql .= " WHERE tva.entity = ".$conf->entity;
-$sql .= " AND (tva.datev >= '".$db->idate($date_start)."' AND tva.datev <= '".$db->idate($date_end)."')";
-$sql .= " GROUP BY dm";
-
-$sql .= " ORDER BY dm ASC, mode ASC";
-//print $sql;
-
-pt($db, $sql, $langs->trans("Month"));
-
-
-if (!empty($conf->global->MAIN_FEATURES_LEVEL))
-{
- print '
';
/*
- * Recap
- */
+ * Paid
+ */
- print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation
+ print load_fiche_titre($langs->trans("VATPaid"), '', '');
- $sql1 = "SELECT SUM(amount) as mm";
- $sql1 .= " FROM ".MAIN_DB_PREFIX."tva as f";
- $sql1 .= " WHERE f.entity = ".$conf->entity;
- $sql1 .= " AND f.datev >= '".$db->idate($date_start)."'";
- $sql1 .= " AND f.datev <= '".$db->idate($date_end)."'";
+ $sql = '';
- $result = $db->query($sql1);
- if ($result) {
- $obj = $db->fetch_object($result);
- print '
';
+ $sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
+ $sql .= " WHERE tva.entity = " . $conf->entity;
+ $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
+ $sql .= " GROUP BY dm";
- print "";
- print '| '.$langs->trans("VATDue").' | ';
- print ''.price(price2num($total, 'MT')).' | ';
- print "
\n";
+ $sql .= " UNION ";
- print "";
- print '| '.$langs->trans("VATPaid").' | ';
- print ''.price(price2num($obj->mm, 'MT'))." | \n";
- print "
\n";
+ $sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
+ $sql .= " WHERE tva.entity = " . $conf->entity;
+ $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
+ $sql .= " GROUP BY dm";
- $restopay = $total - $obj->mm;
- print "";
- print '| '.$langs->trans("RemainToPay").' | ';
- print ''.price(price2num($restopay, 'MT')).' | ';
- print "
\n";
+ $sql .= " ORDER BY dm ASC, mode ASC";
+//print $sql;
- print '
';
- }
+ pt($db, $sql, $langs->trans("Month"));
+
+
+ if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
+ print '
';
+
+ /*
+ * Recap
+ */
+
+ print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation
+
+ $sql1 = "SELECT SUM(amount) as mm";
+ $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f";
+ $sql1 .= " WHERE f.entity = " . $conf->entity;
+ $sql1 .= " AND f.datev >= '" . $db->idate($date_start) . "'";
+ $sql1 .= " AND f.datev <= '" . $db->idate($date_end) . "'";
+
+ $result = $db->query($sql1);
+ if ($result) {
+ $obj = $db->fetch_object($result);
+ print '
';
+
+ print "";
+ print '| ' . $langs->trans("VATDue") . ' | ';
+ print '' . price(price2num($total, 'MT')) . ' | ';
+ print "
\n";
+
+ print "";
+ print '| ' . $langs->trans("VATPaid") . ' | ';
+ print '' . price(price2num($obj->mm, 'MT')) . " | \n";
+ print "
\n";
+
+ $restopay = $total - $obj->mm;
+ print "";
+ print '| ' . $langs->trans("RemainToPay") . ' | ';
+ print '' . price(price2num($restopay, 'MT')) . ' | ';
+ print "
\n";
+
+ print '
';
+ }
+ }
+
+ print '
';
}
-print '
';
-
llxFooter();
$db->close();
diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php
index ba12b08b3b0..504ba78c2d8 100644
--- a/htdocs/compta/tva/quadri_detail.php
+++ b/htdocs/compta/tva/quadri_detail.php
@@ -45,56 +45,59 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.
$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
$now = dol_now();
-$current_date = dol_getdate($now);
-if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
-
-// Date range
-$year = GETPOST("year", "int");
-if (empty($year))
-{
- $year_current = $current_date['year'];
- $year_start = $year_current;
+$refresh = GETPOSTISSET('submit') ? true : false;
+$invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : '';
+$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1;
+$year_current = GETPOSTISSET('year') ? GETPOST('year', 'int') : intval(strftime('%Y', $now));
+$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 {
- $year_current = $year;
- $year_start = $year;
-}
-$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"));
-// Set default period if not defined
-if (empty($date_start) || empty($date_end)) // We define date_start and date_end
-{
- $q = GETPOST("q", "int");
- if (empty($q))
+ // Date range
+ //$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_end=dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
+ // Quarter
+ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
- 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 (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 {
- 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_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;
+ $q=GETPOST("q", "int");
+ 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
+ {
+ $date_start=dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false);
+ 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;
+ elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1;
+ elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $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 == 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); }
+ }
}
}
+$month_start = strftime('%m', $date_start);
+$year_start = strftime('%Y', $date_start);
+
+
$min = price2num(GETPOST("min", "alpha"));
if (empty($min)) $min = 0;
@@ -389,7 +392,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
{
// VAT Rate
print "
";
- print '| '.$langs->trans("Rate").': '.vatrate($rate).'% | | ';
+ print '';
+ print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
+ print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '';
+ print ' | ';
print '
'."\n";
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
@@ -405,171 +411,210 @@ if (!is_array($x_coll) || !is_array($x_paye))
$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'))
+ {
- print '
';
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+ }
+ }
+ }
- // Ref
- print '| '.$fields['link'].' | ';
+ // Total collected
+ $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
- // Invoice date
- print ''.dol_print_date($fields['datef'], 'day').' | ';
+ // VAT
+ $temp_vat=$fields['vat']*$ratiopaymentinvoice;
- // Payment date
- if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print ''.dol_print_date($fields['datep'], 'day').' | ';
- else print ' | ';
+ $subtot_coll_total_ht += $temp_ht;
+ $subtot_coll_vat += $temp_vat;
+ $x_coll_sum += $temp_vat;
+ }
+ }
- // Company name
- print ''.$fields['company_link'].' | ';
+ 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;
+ }
- // Description
- print '';
- if ($fields['pid'])
- {
- $product_static->id = $fields['pid'];
- $product_static->ref = $fields['pref'];
- $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
- print $product_static->getNomUrl(1);
- if (dol_string_nohtmltag($fields['descr'])) {
- print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
- }
- } else {
- if ($type) {
- $text = img_object($langs->trans('Service'), 'service');
- } else {
- $text = img_object($langs->trans('Product'), 'product');
- }
- if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
- if ($reg[1] == 'DEPOSIT') {
- $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
- } 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']), 24);
- // Show range
- print_date_range($fields['ddate_start'], $fields['ddate_end']);
- }
- print ' | ';
+ print '
';
- // Total HT
- if ($modetax != 1)
- {
- print '| ';
- print price($fields['totalht']);
- if (price2num($fields['ftotal_ttc']))
- {
- //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
- $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
- //print ' ('.round($ratiolineinvoice*100,2).'%)';
- }
- print ' | ';
- }
+ // Ref
+ print '' . $fields['link'] . ' | ';
- // Payment
- $ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
- print '';
- //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
- if ($fields['payment_amount'] && $fields['ftotal_ttc'])
- {
- $payment_static->id = $fields['payment_id'];
- print $payment_static->getNomUrl(2);
- }
- if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
- {
- print $langs->trans("NA");
- } else {
- if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
- $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
- }
- print price(price2num($fields['payment_amount'], 'MT'));
- if (isset($fields['payment_amount'])) {
- print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
- }
- }
- print ' | ';
- }
+ // Invoice date
+ print '' . dol_print_date($fields['datef'], 'day') . ' | ';
- // Total collected
- print '';
- $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
- print price(price2num($temp_ht, 'MT'), 1);
- print ' | ';
+ // Payment date
+ if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ' | ';
+ else print ' | ';
- // VAT
- print '';
- $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
- print price(price2num($temp_vat, 'MT'), 1);
- //print price($fields['vat']);
- print ' | ';
- print '
';
+ // Company name
+ print '
' . $fields['company_link'] . ' | ';
- $subtot_coll_total_ht += $temp_ht;
- $subtot_coll_vat += $temp_vat;
- $x_coll_sum += $temp_vat;
- }
- }
- // Total customers for this vat rate
- print '
';
- print ' | ';
- print ''.$langs->trans("Total").': | ';
- if ($modetax != 1) {
- print ' | ';
- print ' | ';
- }
- print ''.price(price2num($subtot_coll_total_ht, 'MT')).' | ';
- print ''.price(price2num($subtot_coll_vat, 'MT')).' | ';
- print '
';
- }
+ // Description
+ print '
';
+ if ($fields['pid']) {
+ $product_static->id = $fields['pid'];
+ $product_static->ref = $fields['pref'];
+ $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
+ print $product_static->getNomUrl(1);
+ if (dol_string_nohtmltag($fields['descr'])) {
+ print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
+ }
+ } else {
+ if ($type) {
+ $text = img_object($langs->trans('Service'), 'service');
+ } else {
+ $text = img_object($langs->trans('Product'), 'product');
+ }
+ if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
+ if ($reg[1] == 'DEPOSIT') {
+ $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
+ } 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']), 24);
- if (count($x_coll) == 0) // Show a total line if nothing shown
- {
- print ' | ';
- print ' | ';
- print ''.$langs->trans("Total").': | ';
- if ($modetax != 1) {
- print ' | ';
- print ' | ';
- }
- print ''.price(price2num(0, 'MT')).' | ';
- print ''.price(price2num(0, 'MT')).' | ';
- print '
';
- }
+ // Show range
+ print_date_range($fields['ddate_start'], $fields['ddate_end']);
+ }
+ print '';
- // Blank line
- print '
| |
';
+ // Total HT
+ if ($modetax != 1) {
+ print '
';
+ print price($fields['totalht']);
+ if (price2num($fields['ftotal_ttc'])) {
+ //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
+ $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
+ //print ' ('.round($ratiolineinvoice*100,2).'%)';
+ }
+ print ' | ';
+ }
- // Print table headers for this quadri - expenses now
- print '
';
- print '| '.$elementsup.' | ';
- print ''.$langs->trans("DateInvoice").' | ';
- if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").' | ';
- else print ' | ';
- print ''.$namesup.' | ';
- print ''.$productsup.' | ';
- if ($modetax != 1) {
- print ''.$amountsup.' | ';
- print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").') | ';
- }
- print ''.$langs->trans("AmountHTVATRealPaid").' | ';
- print ''.$vatsup.' | ';
- print '
'."\n";
+ // Payment
+ $ratiopaymentinvoice = 1;
+ if ($modetax != 1) {
+ print '
';
+ //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
+ if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
+ $payment_static->id = $fields['payment_id'];
+ print $payment_static->getNomUrl(2);
+ }
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
+ print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
+ }
+ print price(price2num($fields['payment_amount'], 'MT'));
+ if (isset($fields['payment_amount'])) {
+ print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
+ }
+ }
+ print ' | ';
+ }
- foreach (array_keys($x_paye) as $rate)
- {
- $subtot_paye_total_ht = 0;
- $subtot_paye_vat = 0;
+ // Total collected
+ print '
';
+ $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
+ print price(price2num($temp_ht, 'MT'), 1);
+ print ' | ';
- if (is_array($x_both[$rate]['paye']['detail']))
- {
- print "
";
- print '| '.$langs->trans("Rate").': '.vatrate($rate).'% | | ';
- print '
'."\n";
+ // VAT
+ print '
';
+ $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
+ print price(price2num($temp_vat, 'MT'), 1);
+ //print price($fields['vat']);
+ print ' | ';
+ print '';
+
+ //$subtot_coll_total_ht += $temp_ht;
+ //$subtot_coll_vat += $temp_vat;
+ //$x_coll_sum += $temp_vat;
+ }
+ }
+ }
+ // Total customers for this vat rate
+ print '
';
+ print ' | ';
+ print ''.$langs->trans("Total").': | ';
+ if ($modetax != 1) {
+ print ' | ';
+ print ' | ';
+ }
+ print ''.price(price2num($subtot_coll_total_ht, 'MT')).' | ';
+ print ''.price(price2num($subtot_coll_vat, 'MT')).' | ';
+ print '
';
+ }
+
+ if (count($x_coll) == 0) // Show a total line if nothing shown
+ {
+ print '
';
+ print ' | ';
+ print ''.$langs->trans("Total").': | ';
+ if ($modetax != 1) {
+ print ' | ';
+ print ' | ';
+ }
+ print ''.price(price2num(0, 'MT')).' | ';
+ print ''.price(price2num(0, 'MT')).' | ';
+ print '
';
+ }
+
+ // Blank line
+ print '
| |
';
+
+ // Print table headers for this quadri - expenses now
+ print '
';
+ print '| '.$elementsup.' | ';
+ print ''.$langs->trans("DateInvoice").' | ';
+ if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").' | ';
+ else print ' | ';
+ print ''.$namesup.' | ';
+ print ''.$productsup.' | ';
+ if ($modetax != 1) {
+ print ''.$amountsup.' | ';
+ print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").') | ';
+ }
+ print ''.$langs->trans("AmountHTVATRealPaid").' | ';
+ print ''.$vatsup.' | ';
+ print '
'."\n";
+
+ foreach (array_keys($x_paye) as $rate)
+ {
+ $subtot_paye_total_ht = 0;
+ $subtot_paye_vat = 0;
+
+ if (is_array($x_both[$rate]['paye']['detail']))
+ {
+ print "
";
+ print '| ';
+ print '' . $langs->trans('Rate') . ' : ' . vatrate($rate) . '%' . '';
+ print ' | | ';
+ print '
'."\n";
foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
// Define type
@@ -584,127 +629,161 @@ if (!is_array($x_coll) || !is_array($x_paye))
$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')) {
- print '
';
+ } else {
+ if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
+ $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
+ }
+ }
+ }
- // Ref
- print '| '.$fields['link'].' | ';
+ // VAT paid
+ $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
- // Invoice date
- print ''.dol_print_date($fields['datef'], 'day').' | ';
+ // VAT
+ $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
- // Payment date
- if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.dol_print_date($fields['datep'], 'day').' | ';
- else print ' | ';
+ $subtot_paye_total_ht += $temp_ht;
+ $subtot_paye_vat += $temp_vat;
+ $x_paye_sum += $temp_vat;
+ }
- // Company name
- print ''.$fields['company_link'].' | ';
+ 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;
+ }
- // Description
- print '';
- if ($fields['pid'])
- {
- $product_static->id = $fields['pid'];
- $product_static->ref = $fields['pref'];
- $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
- print $product_static->getNomUrl(1);
- if (dol_string_nohtmltag($fields['descr'])) {
- print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
- }
- } else {
- if ($type) {
- $text = img_object($langs->trans('Service'), 'service');
- } else {
- $text = img_object($langs->trans('Product'), 'product');
- }
- if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
- if ($reg[1] == 'DEPOSIT') {
- $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
- } 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']), 24);
- // Show range
- print_date_range($fields['ddate_start'], $fields['ddate_end']);
- }
- print ' | ';
+ print '
';
- // Total HT
- if ($modetax != 1)
- {
- print '| ';
- print price($fields['totalht']);
- if (price2num($fields['ftotal_ttc']))
- {
- //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
- $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
- //print ' ('.round($ratiolineinvoice*100,2).'%)';
- }
- print ' | ';
- }
+ // Ref
+ print '' . $fields['link'] . ' | ';
- // Payment
- $ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
- print '';
- if ($fields['payment_amount'] && $fields['ftotal_ttc'])
- {
- $paymentfourn_static->id = $fields['payment_id'];
- print $paymentfourn_static->getNomUrl(2);
- }
+ // Invoice date
+ print ' | ' . dol_print_date($fields['datef'], 'day') . ' | ';
- if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
- {
- print $langs->trans("NA");
- } else {
- if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
- $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
- }
- print price(price2num($fields['payment_amount'], 'MT'));
- if (isset($fields['payment_amount'])) {
- print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
- }
- }
- print '';
- }
+ // Payment date
+ if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ' | ';
+ else print ' | ';
- // VAT paid
- print '';
- $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
- print price(price2num($temp_ht, 'MT'), 1);
- print ' | ';
+ // Company name
+ print '' . $fields['company_link'] . ' | ';
- // VAT
- print '';
- $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
- print price(price2num($temp_vat, 'MT'), 1);
- //print price($fields['vat']);
- print ' | ';
- print '
';
+ // Description
+ print '
';
+ if ($fields['pid']) {
+ $product_static->id = $fields['pid'];
+ $product_static->ref = $fields['pref'];
+ $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
+ print $product_static->getNomUrl(1);
+ if (dol_string_nohtmltag($fields['descr'])) {
+ print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
+ }
+ } else {
+ if ($type) {
+ $text = img_object($langs->trans('Service'), 'service');
+ } else {
+ $text = img_object($langs->trans('Product'), 'product');
+ }
+ if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
+ if ($reg[1] == 'DEPOSIT') {
+ $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
+ } 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']), 24);
- $subtot_paye_total_ht += $temp_ht;
- $subtot_paye_vat += $temp_vat;
- $x_paye_sum += $temp_vat;
- }
- }
- // Total suppliers for this vat rate
- print ' | ';
- print ' | ';
- print ''.$langs->trans("Total").': | ';
- if ($modetax != 1) {
- print ' | ';
- print ' | ';
- }
- print ''.price(price2num($subtot_paye_total_ht, 'MT')).' | ';
- print ''.price(price2num($subtot_paye_vat, 'MT')).' | ';
- print '
';
- }
+ // Show range
+ print_date_range($fields['ddate_start'], $fields['ddate_end']);
+ }
+ print '';
+
+ // Total HT
+ if ($modetax != 1) {
+ print '
';
+ print price($fields['totalht']);
+ if (price2num($fields['ftotal_ttc'])) {
+ //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
+ $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
+ //print ' ('.round($ratiolineinvoice*100,2).'%)';
+ }
+ print ' | ';
+ }
+
+ // Payment
+ $ratiopaymentinvoice = 1;
+ if ($modetax != 1) {
+ print '
';
+ if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
+ $paymentfourn_static->id = $fields['payment_id'];
+ print $paymentfourn_static->getNomUrl(2);
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
+ print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
+ $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
+ }
+ print price(price2num($fields['payment_amount'], 'MT'));
+ if (isset($fields['payment_amount'])) {
+ print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
+ }
+ }
+ print ' | ';
+ }
+
+ // VAT paid
+ print '
';
+ $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
+ print price(price2num($temp_ht, 'MT'), 1);
+ print ' | ';
+
+ // VAT
+ print '
';
+ $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
+ print price(price2num($temp_vat, 'MT'), 1);
+ //print price($fields['vat']);
+ print ' | ';
+ print '';
+
+ //$subtot_paye_total_ht += $temp_ht;
+ //$subtot_paye_vat += $temp_vat;
+ //$x_paye_sum += $temp_vat;
+ }
+ }
+ }
+
+ // Total suppliers for this vat rate
+ print '
';
+ print ' | ';
+ print ''.$langs->trans("Total").': | ';
+ if ($modetax != 1) {
+ print ' | ';
+ print ' | ';
+ }
+ print ''.price(price2num($subtot_paye_total_ht, 'MT')).' | ';
+ print ''.price(price2num($subtot_paye_vat, 'MT')).' | ';
+ print '
';
+ }
if (count($x_paye) == 0) { // Show a total line if nothing shown
print '
';
diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php
index 36ce55f7c85..3df8e552e31 100644
--- a/htdocs/core/lib/tax.lib.php
+++ b/htdocs/core/lib/tax.lib.php
@@ -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 .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql .= " 0 as payment_id, 0 as payment_amount";
- $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
- $sql .= " ".MAIN_DB_PREFIX."societe as s,";
- $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
+ $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 .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$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)";
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)
{
$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 .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
$sql .= " pa.datep as datep";
- $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
- $sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
- $sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
- $sql .= " ".MAIN_DB_PREFIX."societe as s,";
- $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
+ $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 .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$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)";
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)
{
$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 .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
$sql .= " 0 as payment_id, 0 as payment_amount";
- $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
- $sql .= " ".MAIN_DB_PREFIX."societe as s,";
- $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
+ $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 .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$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)";
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)
{
$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 .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
$sql .= " pa.datep as datep";
- $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
- $sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
- $sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
- $sql .= " ".MAIN_DB_PREFIX."societe as s,";
- $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
+ $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 .= " WHERE f.entity IN (".getEntity($invoicetable).")";
$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)";
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)
{
$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
@@ -885,9 +873,9 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
$sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
$sql .= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
- $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
+ $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid";
$sql .= " WHERE e.entity = ".$conf->entity;
$sql .= " AND e.fk_statut in (6)";
if ($y && $m)
diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang
index 23e6cf0d724..62ad01b4f6b 100644
--- a/htdocs/langs/en_US/compta.lang
+++ b/htdocs/langs/en_US/compta.lang
@@ -191,6 +191,7 @@ VATReportByThirdParties=Sale tax report by third parties
VATReportByCustomers=Sale tax report by customer
VATReportByCustomersInInputOutputMode=Report by the customer VAT 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
LT2ReportByQuarters=Report tax 3 by rate
LT1ReportByQuartersES=Report by RE rate