Merge pull request #16307 from aspangaro/14a15
NEW: VAT report - Optimisation & collapse by rate
This commit is contained in:
commit
85eaec48e1
@ -6,6 +6,7 @@
|
|||||||
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
||||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
|
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
|
||||||
* Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
|
* Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
|
||||||
|
* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -43,10 +44,55 @@ if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) {
|
|||||||
$conf->global->SOCIETE_FISCAL_MONTH_START = 1;
|
$conf->global->SOCIETE_FISCAL_MONTH_START = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$refresh = GETPOSTISSET('submit') ? true : false;
|
||||||
|
|
||||||
|
if ($refresh === false) {
|
||||||
|
$year_current = dol_print_date('%Y', $now);
|
||||||
|
$month_current = dol_print_date('%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 = $current_date['year'];
|
$year_current = dol_print_date(dol_now(), "%Y");
|
||||||
|
if ($conf->global->SOCIETE_FISCAL_MONTH_START > dol_print_date(dol_now(), "%m")) $year_current--;
|
||||||
$year_start = $year_current;
|
$year_start = $year_current;
|
||||||
} else {
|
} else {
|
||||||
$year_current = $year;
|
$year_current = $year;
|
||||||
@ -54,7 +100,6 @@ 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)) {
|
||||||
@ -62,25 +107,8 @@ if (empty($date_start) || empty($date_end)) { // We define date_start and date_e
|
|||||||
$date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false);
|
$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_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
|
||||||
} else {
|
} 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_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
|
|
||||||
$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 {
|
} else {
|
||||||
if ($q == 1) {
|
if ($q == 1) {
|
||||||
@ -101,6 +129,7 @@ if (empty($date_start) || empty($date_end)) { // We define date_start and date_e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Define modetax (0 or 1)
|
// Define modetax (0 or 1)
|
||||||
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
|
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
|
||||||
@ -286,6 +315,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"), '', '');
|
||||||
@ -569,11 +599,9 @@ print '</table>';
|
|||||||
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
|
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* VAT Paid
|
* Paid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans("VATPaid"), '', '');
|
print load_fiche_titre($langs->trans("VATPaid"), '', '');
|
||||||
|
|
||||||
$sql = '';
|
$sql = '';
|
||||||
@ -599,6 +627,7 @@ $sql .= " ORDER BY dm ASC, mode ASC";
|
|||||||
pt($db, $sql, $langs->trans("Month"));
|
pt($db, $sql, $langs->trans("Month"));
|
||||||
|
|
||||||
print '</div></div>';
|
print '</div></div>';
|
||||||
|
}
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
||||||
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
|
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
|
||||||
* Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
|
* Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
|
||||||
|
* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -45,23 +46,31 @@ 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)) {
|
$invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : '';
|
||||||
$conf->global->SOCIETE_FISCAL_MONTH_START = 1;
|
$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1;
|
||||||
}
|
$year_current = GETPOSTISSET('year') ? GETPOST('year', 'int') : intval(strftime('%Y', $now));
|
||||||
|
|
||||||
// Date range
|
|
||||||
$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)) {
|
||||||
@ -69,45 +78,35 @@ if (empty($date_start) || empty($date_end)) { // We define date_start and date_e
|
|||||||
$date_start=dol_get_first_day($year_start, GETPOST("month", "int"), false);
|
$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_end=dol_get_last_day($year_start, GETPOST("month", "int"), false);
|
||||||
} else {
|
} 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_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false);
|
||||||
$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');
|
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;
|
$date_end=dol_time_plus_duree($date_start, 3, 'm') - 1;
|
||||||
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat
|
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
|
||||||
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;
|
$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
|
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
|
||||||
$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;
|
$date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($q == 1) {
|
if ($q == 1) {
|
||||||
$date_start = dol_get_first_day($year_start, 1, false);
|
$date_start=dol_get_first_day($year_start, 1, false); $date_end=dol_get_last_day($year_start, 3, false);
|
||||||
$date_end = dol_get_last_day($year_start, 3, false);
|
|
||||||
}
|
}
|
||||||
if ($q == 2) {
|
if ($q == 2) {
|
||||||
$date_start = dol_get_first_day($year_start, 4, false);
|
$date_start=dol_get_first_day($year_start, 4, false); $date_end=dol_get_last_day($year_start, 6, false);
|
||||||
$date_end = dol_get_last_day($year_start, 6, false);
|
|
||||||
}
|
}
|
||||||
if ($q == 3) {
|
if ($q == 3) {
|
||||||
$date_start = dol_get_first_day($year_start, 7, false);
|
$date_start=dol_get_first_day($year_start, 7, false); $date_end=dol_get_last_day($year_start, 9, false);
|
||||||
$date_end = dol_get_last_day($year_start, 9, false);
|
|
||||||
}
|
}
|
||||||
if ($q == 4) {
|
if ($q == 4) {
|
||||||
$date_start = dol_get_first_day($year_start, 10, false);
|
$date_start=dol_get_first_day($year_start, 10, false); $date_end=dol_get_last_day($year_start, 12, false);
|
||||||
$date_end = dol_get_last_day($year_start, 12, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$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)) {
|
if (empty($min)) {
|
||||||
@ -428,9 +427,51 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
|
|||||||
if (is_array($x_both[$rate]['coll']['detail'])) {
|
if (is_array($x_both[$rate]['coll']['detail'])) {
|
||||||
// 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_URL_ROOT . '/compta/tva/quadri_detail.php?invoice_type=customer&vat_rate_show=' . urlencode($rate) . '&year=' . urlencode($year_start) . '&month=' . urlencode($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) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
|
||||||
// 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.
|
||||||
@ -454,11 +495,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
|
|||||||
print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
||||||
|
|
||||||
// Payment date
|
// Payment date
|
||||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
|
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
|
||||||
print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>';
|
else print '<td></td>';
|
||||||
} else {
|
|
||||||
print '<td></td>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Company name
|
// Company name
|
||||||
print '<td class="left">' . $fields['company_link'] . '</td>';
|
print '<td class="left">' . $fields['company_link'] . '</td>';
|
||||||
@ -545,9 +583,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
|
||||||
@ -583,11 +622,8 @@ if (!is_array($x_coll) || !is_array($x_paye)) {
|
|||||||
print '<tr class="liste_titre liste_titre_topborder">';
|
print '<tr class="liste_titre liste_titre_topborder">';
|
||||||
print '<td class="left">'.$elementsup.'</td>';
|
print '<td class="left">'.$elementsup.'</td>';
|
||||||
print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
|
print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
|
||||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') {
|
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
|
||||||
print '<td class="left">'.$langs->trans("DatePayment").'</td>';
|
else print '<td></td>';
|
||||||
} else {
|
|
||||||
print '<td></td>';
|
|
||||||
}
|
|
||||||
print '<td class="left">'.$namesup.'</td>';
|
print '<td class="left">'.$namesup.'</td>';
|
||||||
print '<td class="left">'.$productsup.'</td>';
|
print '<td class="left">'.$productsup.'</td>';
|
||||||
if ($modetax != 1) {
|
if ($modetax != 1) {
|
||||||
@ -604,9 +640,49 @@ 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" colspan="' . ($span+1) . '">';
|
||||||
|
print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
|
||||||
|
print ' - <a href="' . dol_buildpath('/compta/tva/quadri_detail.php', 1) . '?invoice_type=supplier&vat_rate_show=' . $rate . '&year=' . $year_start . '&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]['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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
|
||||||
// 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.
|
||||||
@ -721,11 +797,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>';
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
|
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
|
||||||
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
||||||
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
|
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
|
||||||
|
* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -642,9 +643,9 @@ 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 .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
$sql .= " INNER 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)
|
||||||
@ -653,8 +654,6 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
|||||||
} else {
|
} else {
|
||||||
$sql .= " AND f.type IN (0,1,2,3,5)";
|
$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))."'";
|
||||||
$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
||||||
@ -683,11 +682,11 @@ 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 .= " INNER JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";;
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
|
$sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
|
||||||
$sql .= " ".MAIN_DB_PREFIX."societe as s,";
|
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
$sql .= " INNER 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)
|
||||||
@ -696,10 +695,6 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
|||||||
} else {
|
} else {
|
||||||
$sql .= " AND f.type IN (0,1,2,3,5)";
|
$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))."'";
|
||||||
$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
||||||
@ -805,9 +800,9 @@ 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 .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
$sql .= " INNER 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)
|
||||||
@ -816,8 +811,6 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
|||||||
} else {
|
} else {
|
||||||
$sql .= " AND f.type IN (0,1,2,3,5)";
|
$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))."'";
|
||||||
$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
||||||
@ -846,11 +839,11 @@ 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 .= " INNER JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
|
$sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment;
|
||||||
$sql .= " ".MAIN_DB_PREFIX."societe as s,";
|
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
|
||||||
$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
$sql .= " INNER 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)
|
||||||
@ -859,10 +852,6 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
|||||||
} else {
|
} else {
|
||||||
$sql .= " AND f.type IN (0,1,2,3,5)";
|
$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))."'";
|
||||||
$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
|
||||||
|
|||||||
@ -195,6 +195,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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user