30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
45 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
47 $local =
GETPOST(
'localTaxType',
'int');
51 $year_current = strftime(
"%Y",
dol_now());
52 $year_start = $year_current;
54 $year_current = $year;
60 if (empty($date_start) || empty($date_end)) {
67 $date_start =
dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
68 if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) {
70 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
72 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
104 $calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
105 $modetax = $conf->global->$calc;
107 $modetax =
GETPOST(
"modetax",
'int');
109 if (empty($modetax)) {
114 $socid =
GETPOST(
'socid',
'int');
116 $socid = $user->socid;
132 $company_static =
new Societe($db);
133 $invoice_customer =
new Facture($db);
136 $product_static =
new Product($db);
137 $payment_static =
new Paiement($db);
141 $morequerystring =
'';
142 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
143 foreach ($listofparams as $param) {
145 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
149 llxHeader(
'', $langs->trans(
"LocalTaxReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
151 $fsearch =
'<!-- hidden fields for form -->';
152 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
153 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
154 $fsearch .=
'<input type="hidden" name="localTaxType" value="'.$local.
'">';
156 $name = $langs->transcountry($local == 1 ?
"LT1ReportByQuarters" :
"LT2ReportByQuarters", $mysoc->country_code);
159 $calcmode = $langs->trans(
'OptionVATDefault');
162 $calcmode = $langs->trans(
'OptionVATDebitOption');
165 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
167 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
169 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
170 $prevyear = $year_start;
172 if ($prevquarter > 1) {
178 $nextyear = $year_start;
180 if ($nextquarter < 4) {
186 $description .= $fsearch;
200 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
201 $description .= $langs->trans(
"ThisIsAnEstimatedValue");
205 $elementcust = $langs->trans(
"CustomersInvoices");
206 $productcust = $langs->trans(
"ProductOrService");
207 $amountcust = $langs->trans(
"AmountHT");
208 $vatcust = $langs->trans(
"VATReceived");
209 $namecust = $langs->trans(
"Name");
210 if ($mysoc->tva_assuj) {
211 $vatcust .=
' ('.$langs->trans(
"StatusToPay").
')';
215 $elementsup = $langs->trans(
"SuppliersInvoices");
216 $productsup = $productcust;
217 $amountsup = $amountcust;
218 $vatsup = $langs->trans(
"VATPaid");
219 $namesup = $namecust;
220 if ($mysoc->tva_assuj) {
221 $vatsup .=
' ('.$langs->trans(
"ToGetBack").
')';
225 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
228 $vatcust = $langs->transcountry(
"LT1", $mysoc->country_code);
229 $vatsup = $langs->transcountry(
"LT1", $mysoc->country_code);
230 $vatexpensereport = $langs->transcountry(
"LT1", $mysoc->country_code);
232 $vatcust = $langs->transcountry(
"LT2", $mysoc->country_code);
233 $vatsup = $langs->transcountry(
"LT2", $mysoc->country_code);
234 $vatexpensereport = $langs->transcountry(
"LT2", $mysoc->country_code);
238 print
'<div class="div-table-responsive">';
239 echo
'<table class="noborder centpercent">';
247 $x_coll =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'sell');
248 $x_paye =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'buy');
250 if (!is_array($x_coll) || !is_array($x_paye)) {
251 $langs->load(
"errors");
253 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
254 } elseif ($x_coll == -2) {
255 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
257 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
263 foreach (array_keys($x_coll) as $my_coll_rate) {
264 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
265 $x_both[$my_coll_rate][
'coll'][
'localtax'.$local] = $x_coll[$my_coll_rate][
'localtax'.$local];
266 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
267 $x_both[$my_coll_rate][
'paye'][
'localtax'.$local] = 0;
268 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
269 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
270 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
271 $invoice_customer->id = $x_coll[$my_coll_rate][
'facid'][$id];
272 $invoice_customer->ref = $x_coll[$my_coll_rate][
'facnum'][$id];
273 $invoice_customer->type = $x_coll[$my_coll_rate][
'type'][$id];
274 $company_static->fetch($x_coll[$my_coll_rate][
'company_id'][$id]);
275 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
276 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
277 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
278 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
279 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
280 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
281 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
282 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
283 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
284 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
285 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
286 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
287 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
288 'company_link'=>$company_static->getNomUrl(1,
'', 20),
289 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
290 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
291 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
292 'localtax1'=> $x_coll[$my_coll_rate][
'localtax1_list'][$id],
293 'localtax2'=> $x_coll[$my_coll_rate][
'localtax2_list'][$id],
294 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
295 'link' =>$invoice_customer->getNomUrl(1,
'', 12)
300 foreach (array_keys($x_paye) as $my_paye_rate) {
301 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
302 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
303 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
304 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
305 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
307 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
308 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
310 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
311 $invoice_supplier->id = $x_paye[$my_paye_rate][
'facid'][$id];
312 $invoice_supplier->ref = $x_paye[$my_paye_rate][
'facnum'][$id];
313 $invoice_supplier->type = $x_paye[$my_paye_rate][
'type'][$id];
314 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
315 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
316 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
317 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
318 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
319 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
320 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
321 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
322 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
323 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
324 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
325 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
326 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
327 'company_link'=>$company_static->getNomUrl(1,
'', 20),
328 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
329 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
330 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
331 'localtax1'=> $x_paye[$my_paye_rate][
'localtax1_list'][$id],
332 'localtax2'=> $x_paye[$my_paye_rate][
'localtax2_list'][$id],
333 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
334 'link' =>$invoice_supplier->getNomUrl(1,
'', 12)
347 $span = $columns - 1;
356 print
'<tr class="liste_titre">';
357 print
'<td class="left">'.$elementcust.
'</td>';
358 print
'<td class="left">'.$productcust.
'</td>';
360 print
'<td class="right">'.$amountcust.
'</td>';
363 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
365 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
366 print
'<td class="right">'.$vatcust.
'</td>';
372 foreach (array_keys($x_coll) as $rate) {
373 $subtot_coll_total_ht = 0;
374 $subtot_coll_vat = 0;
376 if (is_array($x_both[$rate][
'coll'][
'detail'])) {
380 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
383 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
384 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
386 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
389 if (!empty($fields[
'ddate_start'])) {
392 if (!empty($fields[
'ddate_end'])) {
397 print
'<tr class="oddeven">';
400 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
403 print
'<td class="left">';
404 if ($fields[
'pid']) {
405 $product_static->id = $fields[
'pid'];
406 $product_static->ref = $fields[
'pref'];
407 $product_static->type = $fields[
'ptype'];
408 print $product_static->getNomUrl(1);
414 $text =
img_object($langs->trans(
'Service'),
'service');
416 $text =
img_object($langs->trans(
'Product'),
'product');
418 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
419 if ($reg[1] ==
'DEPOSIT') {
420 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
421 } elseif ($reg[1] ==
'CREDIT_NOTE') {
422 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
424 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
436 print
'<td class="nowrap right">';
437 print
price($fields[
'totalht']);
439 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
445 $ratiopaymentinvoice = 1;
447 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
448 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
450 print
'<td class="nowrap right">';
451 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
452 $payment_static->id = $fields[
'payment_id'];
453 print $payment_static->getNomUrl(2);
456 print $langs->trans(
"NotUsedForGoods");
458 print
price($fields[
'payment_amount']);
459 if (isset($fields[
'payment_amount'])) {
460 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
467 print
'<td class="nowrap right">';
468 $temp_ht = $fields[
'totalht'];
470 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
476 print
'<td class="nowrap right">';
477 $temp_vat = $local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2'];
483 $subtot_coll_total_ht += $temp_ht;
484 $subtot_coll_vat += $temp_vat;
485 $x_coll_sum += $temp_vat;
491 print
'<tr class="liste_total">';
493 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
495 print
'<td class="nowrap right"> </td>';
496 print
'<td class="right"> </td>';
498 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht,
'MT')).
'</span></td>';
499 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat,
'MT')).
'</span></td>';
503 if (count($x_coll) == 0) {
504 print
'<tr class="liste_total">';
505 print
'<td> </td>';
506 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
508 print
'<td class="nowrap right"> </td>';
509 print
'<td class="right"> </td>';
511 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
512 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
517 print
'<tr><td colspan="'.($span + 1).
'"> </td></tr>';
523 print
'<tr class="liste_titre">';
524 print
'<td class="left">'.$elementsup.
'</td>';
525 print
'<td class="left">'.$productsup.
'</td>';
527 print
'<td class="right">'.$amountsup.
'</td>';
528 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
530 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
531 print
'<td class="right">'.$vatsup.
'</td>';
534 foreach (array_keys($x_paye) as $rate) {
535 $subtot_paye_total_ht = 0;
536 $subtot_paye_vat = 0;
538 if (is_array($x_both[$rate][
'paye'][
'detail'])) {
541 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
544 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
545 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
547 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
550 if (!empty($fields[
'ddate_start'])) {
553 if (!empty($fields[
'ddate_end'])) {
558 print
'<tr class="oddeven">';
561 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
564 print
'<td class="left">';
565 if ($fields[
'pid']) {
566 $product_static->id = $fields[
'pid'];
567 $product_static->ref = $fields[
'pref'];
568 $product_static->type = $fields[
'ptype'];
569 print $product_static->getNomUrl(1);
575 $text =
img_object($langs->trans(
'Service'),
'service');
577 $text =
img_object($langs->trans(
'Product'),
'product');
588 print
'<td class="nowrap right">';
589 print
price($fields[
'totalht']);
592 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
599 $ratiopaymentinvoice = 1;
601 print
'<td class="nowrap right">';
602 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
603 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
605 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
606 $paymentfourn_static->id = $fields[
'payment_id'];
607 print $paymentfourn_static->getNomUrl(2);
610 print $langs->trans(
"NA");
613 if (isset($fields[
'payment_amount'])) {
614 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
621 print
'<td class="nowrap right">';
622 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
627 print
'<td class="nowrap right">';
628 $temp_vat = ($local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2']) * $ratiopaymentinvoice;
634 $subtot_paye_total_ht += $temp_ht;
635 $subtot_paye_vat += $temp_vat;
636 $x_paye_sum += $temp_vat;
642 print
'<tr class="liste_total">';
643 print
'<td> </td>';
644 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
646 print
'<td class="nowrap right"> </td>';
647 print
'<td class="right"> </td>';
649 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht,
'MT')).
'</span></td>';
650 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat,
'MT')).
'</span></td>';
654 if (count($x_paye) == 0) {
655 print
'<tr class="liste_total">';
656 print
'<td> </td>';
657 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
659 print
'<td class="nowrap right"> </td>';
660 print
'<td class="right"> </td>';
662 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
663 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
668 $diff = $x_coll_sum - $x_paye_sum;
669 print
'<tr class="liste_total">';
670 print
'<td class="liste_total" colspan="'.$span.
'">'.$langs->trans(
"TotalToPay").($q ?
', '.$langs->trans(
"Quadri").
' '.$q :
'').
'</td>';
671 print
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff,
'MT')).
"</b></td>\n";