26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
34 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
36 $localTaxType =
GETPOST(
'localTaxType',
'int');
41 $year_current = strftime(
"%Y",
dol_now());
42 $year_start = $year_current;
44 $year_current = $year;
49 if (empty($date_start) || empty($date_end)) {
56 $date_start =
dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
81 $modetax = $conf->global->TAX_MODE;
83 $modetax =
GETPOST(
"modetax",
'int');
85 if (empty($modetax)) {
90 $socid =
GETPOST(
'socid',
'int');
92 $socid = $user->socid;
105 function pt($db, $sql, $date)
107 global $conf, $bc, $langs;
109 $result = $db->query($sql);
111 $num = $db->num_rows($result);
114 print
'<table class="noborder centpercent">';
116 print
'<tr class="liste_titre">';
117 print
'<td class="nowrap">'.$date.
'</td>';
118 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
119 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").
'</td>';
131 $obj = $db->fetch_object($result);
135 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
136 print
'<tr class="oddeven">';
137 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
138 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
139 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
146 if ($obj->mode ==
'claimed') {
147 $amountclaimed = $obj->mm;
148 $totalclaimed = $totalclaimed + $amountclaimed;
150 if ($obj->mode ==
'paid') {
151 $amountpaid = $obj->mm;
152 $totalpaid = $totalpaid + $amountpaid;
155 if ($obj->mode ==
'paid') {
156 print
'<tr class="oddeven">';
157 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
158 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
159 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
166 $previousmode = $obj->mode;
167 $previousmonth = $obj->dm;
173 if ($mode ==
'claimed' && !empty($previousmode)) {
174 print
'<tr class="oddeven">';
175 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
176 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
177 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
184 print
'<tr class="liste_total">';
185 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
186 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
187 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
197 if (empty($localTaxType)) {
215 $company_static =
new Societe($db);
218 if ($localTaxType == 1) {
220 $LTSummary =
'LT1Summary';
222 $LTCustomer =
'LT1Customer';
223 $LTSupplier =
'LT1Supplier';
224 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC1;
227 $LTSummary =
'LT2Summary';
229 $LTCustomer =
'LT2Customer';
230 $LTSupplier =
'LT2Supplier';
231 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC2;
234 $fsearch =
'<!-- hidden fields for form -->';
235 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
236 $fsearch .=
'<input type="hidden" name="localTaxType" value="'.$localTaxType.
'">';
237 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
239 $description = $fsearch;
242 $name = $langs->transcountry($localTaxType == 1 ?
"LT1ReportByMonth" :
"LT2ReportByMonth", $mysoc->country_code);
243 $description .= $langs->trans($LT);
244 $calcmode = $langs->trans(
"LTReportBuildWithOptionDefinedInModule").
' ';
245 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.
'/admin/company.php').
')</span>';
249 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
260 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
266 print
'<div class="fichecenter"><div class="fichethirdleft">';
268 print
load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code),
'',
'');
270 print
'<table class="noborder centpercent">';
271 print
'<tr class="liste_titre">';
272 print
'<td width="30%">'.$langs->trans(
"Year").
" ".$y.
"</td>";
274 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td>';
275 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td>';
278 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td><td></td>';
281 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td><td></td>';
283 print
'<td class="right">'.$langs->trans(
"TotalToPay").
'</td>';
284 print
"<td> </td>\n";
291 $yend = $tmp[
'year'];
300 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
311 $x_coll =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'sell', $m);
312 $x_paye =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'buy', $m);
316 foreach (array_keys($x_coll) as $my_coll_rate) {
317 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
318 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
319 $x_both[$my_coll_rate][
'coll'][
'localtax1'] = $x_coll[$my_coll_rate][
'localtax1'];
320 $x_both[$my_coll_rate][
'coll'][
'localtax2'] = $x_coll[$my_coll_rate][
'localtax2'];
321 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
322 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
323 $x_both[$my_coll_rate][
'paye'][
'localtax1'] = 0;
324 $x_both[$my_coll_rate][
'paye'][
'localtax2'] = 0;
325 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
326 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
327 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
332 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
333 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
334 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
335 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
336 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
337 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
338 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
339 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
340 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
341 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
342 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
343 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
344 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
346 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
347 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
349 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
350 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
351 'localtax1' =>$x_coll[$my_coll_rate][
'localtax1_list'][$id],
352 'localtax2' =>$x_coll[$my_coll_rate][
'localtax2_list'][$id],
359 foreach (array_keys($x_paye) as $my_paye_rate) {
360 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
361 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
362 $x_both[$my_paye_rate][
'paye'][
'localtax1'] = $x_paye[$my_paye_rate][
'localtax1'];
363 $x_both[$my_paye_rate][
'paye'][
'localtax2'] = $x_paye[$my_paye_rate][
'localtax2'];
364 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
365 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
366 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
367 $x_both[$my_paye_rate][
'coll'][
'localtax1'] = 0;
368 $x_both[$my_paye_rate][
'coll'][
'localtax2'] = 0;
370 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
371 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
373 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
375 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
380 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
381 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
382 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
383 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
384 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
385 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
386 'payment_id' =>$x_paye[$my_paye_rate][
'payment_id'][$id],
387 'payment_amount' =>$x_paye[$my_paye_rate][
'payment_amount'][$id],
388 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
389 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
390 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
391 'ddate_start' =>$x_paye[$my_paye_rate][
'ddate_start'][$id],
392 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
394 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
395 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
396 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
397 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
405 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
406 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
407 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
408 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
409 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
410 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
411 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
412 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
413 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
414 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
415 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
416 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
417 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
419 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
420 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
422 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
423 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
424 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
425 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
434 $object = array(&$x_coll, &$x_paye, &$x_both);
435 $parameters[
"mode"] = $modetax;
436 $parameters[
"year"] = $y;
437 $parameters[
"month"] = $m;
438 $parameters[
"type"] =
'localtax'.$localTaxType;
441 $hookmanager->initHooks(array(
'externalbalance'));
442 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
444 if (!is_array($x_coll) && $coll_listbuy == -1) {
445 $langs->load(
"errors");
446 print
'<tr><td colspan="5">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
449 if (!is_array($x_paye) && $coll_listbuy == -2) {
450 print
'<tr><td colspan="5">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
455 print
'<tr class="oddeven">';
456 print
'<td class="nowrap"><a href="'.DOL_URL_ROOT.
'/compta/localtax/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>';
459 foreach (array_keys($x_coll) as $rate) {
460 $subtot_coll_total_ht = 0;
461 $subtot_coll_vat = 0;
463 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
465 $ratiopaymentinvoice = 1;
469 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
472 if (!empty($fields[
'ddate_start'])) {
475 if (!empty($fields[
'ddate_end'])) {
479 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
480 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
483 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
484 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
489 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
490 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
491 $subtot_coll_total_ht += $temp_ht;
492 $subtot_coll_vat += $temp_vat;
493 $x_coll_sum += $temp_vat;
496 print
'<td class="nowrap right">'.price(
price2num($x_coll_sum,
'MT')).
'</td>';
499 foreach (array_keys($x_paye) as $rate) {
500 $subtot_paye_total_ht = 0;
501 $subtot_paye_vat = 0;
503 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
505 $ratiopaymentinvoice = 1;
509 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
512 if (!empty($fields[
'ddate_start'])) {
515 if (!empty($fields[
'ddate_end'])) {
519 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
520 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
523 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
524 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
529 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
530 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
531 $subtot_paye_total_ht += $temp_ht;
532 $subtot_paye_vat += $temp_vat;
533 $x_paye_sum += $temp_vat;
536 print
'<td class="nowrap right">'.price(
price2num($x_paye_sum,
'MT')).
'</td>';
538 $subtotalcoll = $subtotalcoll + $x_coll_sum;
539 $subtotalpaid = $subtotalpaid + $x_paye_sum;
541 $diff = $x_coll_sum - $x_paye_sum;
542 $total = $total + $diff;
543 $subtotal =
price2num($subtotal + $diff,
'MT');
545 print
'<td class="nowrap right">'.price(
price2num($diff,
'MT')).
'</td>'.
"\n";
546 print
"<td> </td>\n";
552 print
'<tr class="liste_total">';
553 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).
'&year='.$y.
'">'.$langs->trans(
"SubTotal").
'</a>:</td>';
554 print
'<td class="nowrap right">'.price(
price2num($subtotalcoll,
'MT')).
'</td>';
555 print
'<td class="nowrap right">'.price(
price2num($subtotalpaid,
'MT')).
'</td>';
556 print
'<td class="nowrap right">'.price(
price2num($subtotal,
'MT')).
'</td>';
557 print
'<td> </td></tr>';
564 print
'<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans(
"TotalToPay").
':</td><td class="nowrap right">'.
price(
price2num($total,
'MT')).
'</td>';
565 print
"<td> </td>\n";
571 print
'</div><div class="fichetwothirdright">';
578 print
load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code),
'',
'');
582 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
583 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
584 $sql .=
" WHERE f.entity = ".$conf->entity;
585 $sql .=
" AND (f.datev >= '".$db->idate($date_start).
"' AND f.datev <= '".$db->idate($date_end).
"')";
586 $sql .=
" AND localtaxtype=".((int) $localTaxType);
587 $sql .=
" GROUP BY dm";
591 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
592 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
593 $sql .=
" WHERE f.entity = ".$conf->entity;
594 $sql .=
" AND (f.datep >= '".$db->idate($date_start).
"' AND f.datep <= '".$db->idate($date_end).
"')";
595 $sql .=
" AND localtaxtype=".((int) $localTaxType);
596 $sql .=
" GROUP BY dm";
598 $sql .=
" ORDER BY dm ASC, mode ASC";
601 pt($db, $sql, $langs->trans(
"Month"));
604 print
'</div></div>';