NEW: VAT report - Optimisation & collapse by rate
This commit is contained in:
parent
9e16cd5b77
commit
8079105aaf
@ -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 '<br>';
|
||||
|
||||
print '<div class="fichecenter"><div class="fichethirdleft">';
|
||||
if ($refresh === true) {
|
||||
print '<div class="fichecenter"><div class="fichethirdleft">';
|
||||
|
||||
print load_fiche_titre($langs->trans("VATSummary"), '', '');
|
||||
print load_fiche_titre($langs->trans("VATSummary"), '', '');
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="30%">'.$langs->trans("Year")." ".$y.'</td>';
|
||||
print '<td class="right">'.$langs->trans("VATToPay").'</td>';
|
||||
print '<td class="right">'.$langs->trans("VATToCollect").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Balance").'</td>';
|
||||
print '<td> </td>'."\n";
|
||||
print '</tr>'."\n";
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="30%">' . $langs->trans("Year") . " " . $y . '</td>';
|
||||
print '<td class="right">' . $langs->trans("VATToPay") . '</td>';
|
||||
print '<td class="right">' . $langs->trans("VATToCollect") . '</td>';
|
||||
print '<td class="right">' . $langs->trans("Balance") . '</td>';
|
||||
print '<td> </td>' . "\n";
|
||||
print '</tr>' . "\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 '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
break;
|
||||
}
|
||||
if (!is_array($x_paye) && $coll_listbuy == -2) {
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="nowrap"><a href="' . DOL_URL_ROOT . '/compta/tva/quadri_detail.php?leftmenu=tax_vat&month=' . $m . '&year=' . $y . '">' . dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y") . '</a></td>';
|
||||
|
||||
$x_coll_sum = 0;
|
||||
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 '<td class="nowrap right">' . price(price2num($x_coll_sum, 'MT')) . '</td>';
|
||||
|
||||
$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 '<td class="nowrap right">' . price(price2num($x_paye_sum, 'MT')) . '</td>';
|
||||
|
||||
$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 '<td class="nowrap right">' . price(price2num($diff, 'MT')) . '</td>' . "\n";
|
||||
print "<td> </td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
$i++;
|
||||
$m++;
|
||||
if ($i > 2) {
|
||||
print '<tr class="liste_total">';
|
||||
print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) . '&year=' . $y . '">' . $langs->trans("SubTotal") . '</a>:</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($subtotalcoll, 'MT')) . '</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($subtotalpaye, 'MT')) . '</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($subtotal, 'MT')) . '</td>';
|
||||
print '<td> </td></tr>';
|
||||
$i = 0;
|
||||
$subtotalcoll = 0;
|
||||
$subtotalpaye = 0;
|
||||
$subtotal = 0;
|
||||
}
|
||||
}
|
||||
//now we have an array (x_both) indexed by rates for coll and paye
|
||||
print '<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans("TotalToPay") . ':</td><td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>';
|
||||
print "<td> </td>\n";
|
||||
print '</tr>';
|
||||
|
||||
$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 '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
|
||||
break;
|
||||
}
|
||||
if (!is_array($x_paye) && $coll_listbuy == -2)
|
||||
{
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
break;
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/tva/quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").'</a></td>';
|
||||
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
|
||||
|
||||
$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 '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>';
|
||||
|
||||
$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 '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>';
|
||||
|
||||
$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 '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n";
|
||||
print "<td> </td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
$i++; $m++;
|
||||
if ($i > 2)
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtotalpaye, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtotal, 'MT')).'</td>';
|
||||
print '<td> </td></tr>';
|
||||
$i = 0;
|
||||
$subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
|
||||
}
|
||||
}
|
||||
print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap right">'.price(price2num($total, 'MT')).'</td>';
|
||||
print "<td> </td>\n";
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 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 '<br>';
|
||||
|
||||
/*
|
||||
* 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 '<table class="noborder centpercent">';
|
||||
$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 "<tr>";
|
||||
print '<td class="right">'.$langs->trans("VATDue").'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($total, 'MT')).'</td>';
|
||||
print "</tr>\n";
|
||||
$sql .= " UNION ";
|
||||
|
||||
print "<tr>";
|
||||
print '<td class="right">'.$langs->trans("VATPaid").'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($obj->mm, 'MT'))."</td>\n";
|
||||
print "</tr>\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 "<tr>";
|
||||
print '<td class="right">'.$langs->trans("RemainToPay").'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($restopay, 'MT')).'</td>';
|
||||
print "</tr>\n";
|
||||
$sql .= " ORDER BY dm ASC, mode ASC";
|
||||
//print $sql;
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
pt($db, $sql, $langs->trans("Month"));
|
||||
|
||||
|
||||
if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
|
||||
print '<br>';
|
||||
|
||||
/*
|
||||
* 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 '<table class="noborder centpercent">';
|
||||
|
||||
print "<tr>";
|
||||
print '<td class="right">' . $langs->trans("VATDue") . '</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr>";
|
||||
print '<td class="right">' . $langs->trans("VATPaid") . '</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($obj->mm, 'MT')) . "</td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
$restopay = $total - $obj->mm;
|
||||
print "<tr>";
|
||||
print '<td class="right">' . $langs->trans("RemainToPay") . '</td>';
|
||||
print '<td class="nowrap right">' . price(price2num($restopay, 'MT')) . '</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
print '</div></div>';
|
||||
}
|
||||
|
||||
print '</div></div>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
|
||||
@ -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 "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>';
|
||||
print '<td class="tax_rate" colspan="' . ($span+1) . '">';
|
||||
print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
|
||||
print ' - <a href="' . dol_buildpath('/compta/tva/quadri_detail.php', 1) . '?invoice_type=customer&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";
|
||||
|
||||
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 '<tr class="oddeven">';
|
||||
} else {
|
||||
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
|
||||
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap left">'.$fields['link'].'</td>';
|
||||
// Total collected
|
||||
$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
|
||||
// Invoice date
|
||||
print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>';
|
||||
// VAT
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
|
||||
// Payment date
|
||||
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>';
|
||||
else print '<td></td>';
|
||||
$subtot_coll_total_ht += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
|
||||
// Company name
|
||||
print '<td class="left">'.$fields['company_link'].'</td>';
|
||||
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 '<td class="left">';
|
||||
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 '</td>';
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap right">';
|
||||
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 '</td>';
|
||||
}
|
||||
// Ref
|
||||
print '<td class="nowrap left">' . $fields['link'] . '</td>';
|
||||
|
||||
// Payment
|
||||
$ratiopaymentinvoice = 1;
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap right">';
|
||||
//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 '</td>';
|
||||
}
|
||||
// Invoice date
|
||||
print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
||||
|
||||
// Total collected
|
||||
print '<td class="nowrap right">';
|
||||
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht, 'MT'), 1);
|
||||
print '</td>';
|
||||
// Payment date
|
||||
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>';
|
||||
else print '<td></td>';
|
||||
|
||||
// VAT
|
||||
print '<td class="nowrap right">';
|
||||
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat, 'MT'), 1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
// Company name
|
||||
print '<td class="left">' . $fields['company_link'] . '</td>';
|
||||
|
||||
$subtot_coll_total_ht += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
// Total customers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num($subtot_coll_total_ht, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtot_coll_vat, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
// Description
|
||||
print '<td class="left">';
|
||||
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 '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'], $fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Blank line
|
||||
print '<tr><td colspan="'.($span + 2).'"> </td></tr>';
|
||||
// Total HT
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right">';
|
||||
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 '</td>';
|
||||
}
|
||||
|
||||
// Print table headers for this quadri - expenses now
|
||||
print '<tr class="liste_titre liste_titre_topborder">';
|
||||
print '<td class="left">'.$elementsup.'</td>';
|
||||
print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
|
||||
else print '<td></td>';
|
||||
print '<td class="left">'.$namesup.'</td>';
|
||||
print '<td class="left">'.$productsup.'</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="right">'.$amountsup.'</td>';
|
||||
print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
}
|
||||
print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
|
||||
print '<td class="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\n";
|
||||
// Payment
|
||||
$ratiopaymentinvoice = 1;
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right">';
|
||||
//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 '</td>';
|
||||
}
|
||||
|
||||
foreach (array_keys($x_paye) as $rate)
|
||||
{
|
||||
$subtot_paye_total_ht = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
// Total collected
|
||||
print '<td class="nowrap right">';
|
||||
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht, 'MT'), 1);
|
||||
print '</td>';
|
||||
|
||||
if (is_array($x_both[$rate]['paye']['detail']))
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
// VAT
|
||||
print '<td class="nowrap right">';
|
||||
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat, 'MT'), 1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
//$subtot_coll_total_ht += $temp_ht;
|
||||
//$subtot_coll_vat += $temp_vat;
|
||||
//$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Total customers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num($subtot_coll_total_ht, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtot_coll_vat, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_coll) == 0) // Show a total line if nothing shown
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Blank line
|
||||
print '<tr><td colspan="'.($span+2).'"> </td></tr>';
|
||||
|
||||
// Print table headers for this quadri - expenses now
|
||||
print '<tr class="liste_titre liste_titre_topborder">';
|
||||
print '<td class="left">'.$elementsup.'</td>';
|
||||
print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
|
||||
else print '<td></td>';
|
||||
print '<td class="left">'.$namesup.'</td>';
|
||||
print '<td class="left">'.$productsup.'</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="right">'.$amountsup.'</td>';
|
||||
print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
}
|
||||
print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
|
||||
print '<td class="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\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 "<tr>";
|
||||
print '<td class="tax_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 . '" title="' . $langs->trans('VATReportShowByRateDetails') . '">' . $langs->trans('Rate') . ' : ' . vatrate($rate) . '%' . '</a>';
|
||||
print '</td><td colspan="' . ($span+1) . '"></td>';
|
||||
print '</tr>'."\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 '<tr class="oddeven">';
|
||||
} else {
|
||||
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
|
||||
$ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap left">'.$fields['link'].'</td>';
|
||||
// VAT paid
|
||||
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
|
||||
|
||||
// Invoice date
|
||||
print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>';
|
||||
// VAT
|
||||
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
|
||||
|
||||
// Payment date
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>';
|
||||
else print '<td></td>';
|
||||
$subtot_paye_total_ht += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
|
||||
// Company name
|
||||
print '<td class="left">'.$fields['company_link'].'</td>';
|
||||
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 '<td class="left">';
|
||||
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 '</td>';
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap right">';
|
||||
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 '</td>';
|
||||
}
|
||||
// Ref
|
||||
print '<td class="nowrap left">' . $fields['link'] . '</td>';
|
||||
|
||||
// Payment
|
||||
$ratiopaymentinvoice = 1;
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$paymentfourn_static->id = $fields['payment_id'];
|
||||
print $paymentfourn_static->getNomUrl(2);
|
||||
}
|
||||
// Invoice date
|
||||
print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
||||
|
||||
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 '</td>';
|
||||
}
|
||||
// Payment date
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
|
||||
else print '<td></td>';
|
||||
|
||||
// VAT paid
|
||||
print '<td class="nowrap right">';
|
||||
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht, 'MT'), 1);
|
||||
print '</td>';
|
||||
// Company name
|
||||
print '<td class="left">' . $fields['company_link'] . '</td>';
|
||||
|
||||
// VAT
|
||||
print '<td class="nowrap right">';
|
||||
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat, 'MT'), 1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
// Description
|
||||
print '<td class="left">';
|
||||
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 '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num($subtot_paye_total_ht, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtot_paye_vat, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'], $fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right">';
|
||||
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 '</td>';
|
||||
}
|
||||
|
||||
// Payment
|
||||
$ratiopaymentinvoice = 1;
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right">';
|
||||
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 '</td>';
|
||||
}
|
||||
|
||||
// VAT paid
|
||||
print '<td class="nowrap right">';
|
||||
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht, 'MT'), 1);
|
||||
print '</td>';
|
||||
|
||||
// VAT
|
||||
print '<td class="nowrap right">';
|
||||
$temp_vat = $fields['vat'] * $ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat, 'MT'), 1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
//$subtot_paye_total_ht += $temp_ht;
|
||||
//$subtot_paye_vat += $temp_vat;
|
||||
//$x_paye_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Total suppliers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td class="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap right"> </td>';
|
||||
print '<td class="right"> </td>';
|
||||
}
|
||||
print '<td class="right">'.price(price2num($subtot_paye_total_ht, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($subtot_paye_vat, 'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_paye) == 0) { // Show a total line if nothing shown
|
||||
print '<tr class="liste_total">';
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user