31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
46 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
48 $local =
GETPOST(
'localTaxType',
'int');
53 $year_start = $year_current;
55 $year_current = $year;
61 if (empty($date_start) || empty($date_end)) {
68 $date_start =
dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
69 if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) {
71 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
73 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
105 $calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
106 $modetax = $conf->global->$calc;
108 $modetax =
GETPOST(
"modetax",
'int');
110 if (empty($modetax)) {
115 $socid =
GETPOST(
'socid',
'int');
117 $socid = $user->socid;
133 $company_static =
new Societe($db);
134 $invoice_customer =
new Facture($db);
137 $product_static =
new Product($db);
138 $payment_static =
new Paiement($db);
142 $morequerystring =
'';
143 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
144 foreach ($listofparams as $param) {
146 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
150 llxHeader(
'', $langs->trans(
"LocalTaxReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
152 $fsearch =
'<!-- hidden fields for form -->';
153 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
154 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
155 $fsearch .=
'<input type="hidden" name="localTaxType" value="'.$local.
'">';
157 $name = $langs->transcountry($local == 1 ?
"LT1ReportByQuarters" :
"LT2ReportByQuarters", $mysoc->country_code);
160 $calcmode = $langs->trans(
'OptionVATDefault');
163 $calcmode = $langs->trans(
'OptionVATDebitOption');
166 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
168 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
170 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
171 $prevyear = $year_start;
173 if ($prevquarter > 1) {
179 $nextyear = $year_start;
181 if ($nextquarter < 4) {
187 $description .= $fsearch;
201 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
202 $description .= $langs->trans(
"ThisIsAnEstimatedValue");
206 $elementcust = $langs->trans(
"CustomersInvoices");
207 $productcust = $langs->trans(
"ProductOrService");
208 $amountcust = $langs->trans(
"AmountHT");
209 $vatcust = $langs->trans(
"VATReceived");
210 $namecust = $langs->trans(
"Name");
211 if ($mysoc->tva_assuj) {
212 $vatcust .=
' ('.$langs->trans(
"StatusToPay").
')';
216 $elementsup = $langs->trans(
"SuppliersInvoices");
217 $productsup = $productcust;
218 $amountsup = $amountcust;
219 $vatsup = $langs->trans(
"VATPaid");
220 $namesup = $namecust;
221 if ($mysoc->tva_assuj) {
222 $vatsup .=
' ('.$langs->trans(
"ToGetBack").
')';
226 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
229 $vatcust = $langs->transcountry(
"LT1", $mysoc->country_code);
230 $vatsup = $langs->transcountry(
"LT1", $mysoc->country_code);
231 $vatexpensereport = $langs->transcountry(
"LT1", $mysoc->country_code);
233 $vatcust = $langs->transcountry(
"LT2", $mysoc->country_code);
234 $vatsup = $langs->transcountry(
"LT2", $mysoc->country_code);
235 $vatexpensereport = $langs->transcountry(
"LT2", $mysoc->country_code);
239 print
'<div class="div-table-responsive">';
240 echo
'<table class="noborder centpercent">';
248 $x_coll =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'sell');
249 $x_paye =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'buy');
251 if (!is_array($x_coll) || !is_array($x_paye)) {
252 $langs->load(
"errors");
254 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
255 } elseif ($x_coll == -2) {
256 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
258 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
264 foreach (array_keys($x_coll) as $my_coll_rate) {
265 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
266 $x_both[$my_coll_rate][
'coll'][
'localtax'.$local] = $x_coll[$my_coll_rate][
'localtax'.$local];
267 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
268 $x_both[$my_coll_rate][
'paye'][
'localtax'.$local] = 0;
269 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
270 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
271 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
272 $invoice_customer->id = $x_coll[$my_coll_rate][
'facid'][$id];
273 $invoice_customer->ref = $x_coll[$my_coll_rate][
'facnum'][$id];
274 $invoice_customer->type = $x_coll[$my_coll_rate][
'type'][$id];
275 $company_static->fetch($x_coll[$my_coll_rate][
'company_id'][$id]);
276 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
277 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
278 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
279 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
280 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
281 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
282 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
283 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
284 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
285 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
286 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
287 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
288 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
289 'company_link'=>$company_static->getNomUrl(1,
'', 20),
290 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
291 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
292 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
293 'localtax1'=> $x_coll[$my_coll_rate][
'localtax1_list'][$id],
294 'localtax2'=> $x_coll[$my_coll_rate][
'localtax2_list'][$id],
295 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
296 'link' =>$invoice_customer->getNomUrl(1,
'', 12)
301 foreach (array_keys($x_paye) as $my_paye_rate) {
302 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
303 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
304 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
305 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
306 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
308 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
309 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
311 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
312 $invoice_supplier->id = $x_paye[$my_paye_rate][
'facid'][$id];
313 $invoice_supplier->ref = $x_paye[$my_paye_rate][
'facnum'][$id];
314 $invoice_supplier->type = $x_paye[$my_paye_rate][
'type'][$id];
315 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
316 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
317 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
318 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
319 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
320 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
321 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
322 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
323 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
324 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
325 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
326 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
327 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
328 'company_link'=>$company_static->getNomUrl(1,
'', 20),
329 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
330 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
331 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
332 'localtax1'=> $x_paye[$my_paye_rate][
'localtax1_list'][$id],
333 'localtax2'=> $x_paye[$my_paye_rate][
'localtax2_list'][$id],
334 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
335 'link' =>$invoice_supplier->getNomUrl(1,
'', 12)
348 $span = $columns - 1;
357 print
'<tr class="liste_titre">';
358 print
'<td class="left">'.$elementcust.
'</td>';
359 print
'<td class="left">'.$productcust.
'</td>';
361 print
'<td class="right">'.$amountcust.
'</td>';
364 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
366 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
367 print
'<td class="right">'.$vatcust.
'</td>';
373 foreach (array_keys($x_coll) as $rate) {
374 $subtot_coll_total_ht = 0;
375 $subtot_coll_vat = 0;
377 if (is_array($x_both[$rate][
'coll'][
'detail'])) {
381 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
384 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
385 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
387 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
390 if (!empty($fields[
'ddate_start'])) {
393 if (!empty($fields[
'ddate_end'])) {
398 print
'<tr class="oddeven">';
401 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
404 print
'<td class="left">';
405 if ($fields[
'pid']) {
406 $product_static->id = $fields[
'pid'];
407 $product_static->ref = $fields[
'pref'];
408 $product_static->type = $fields[
'ptype'];
409 print $product_static->getNomUrl(1);
415 $text =
img_object($langs->trans(
'Service'),
'service');
417 $text =
img_object($langs->trans(
'Product'),
'product');
419 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
420 if ($reg[1] ==
'DEPOSIT') {
421 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
422 } elseif ($reg[1] ==
'CREDIT_NOTE') {
423 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
425 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
437 print
'<td class="nowrap right">';
438 print
price($fields[
'totalht']);
440 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
446 $ratiopaymentinvoice = 1;
448 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
449 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
451 print
'<td class="nowrap right">';
452 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
453 $payment_static->id = $fields[
'payment_id'];
454 print $payment_static->getNomUrl(2);
457 print $langs->trans(
"NotUsedForGoods");
459 print
price($fields[
'payment_amount']);
460 if (isset($fields[
'payment_amount'])) {
461 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
468 print
'<td class="nowrap right">';
469 $temp_ht = $fields[
'totalht'];
471 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
477 print
'<td class="nowrap right">';
478 $temp_vat = $local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2'];
484 $subtot_coll_total_ht += $temp_ht;
485 $subtot_coll_vat += $temp_vat;
486 $x_coll_sum += $temp_vat;
492 print
'<tr class="liste_total">';
494 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
496 print
'<td class="nowrap right"> </td>';
497 print
'<td class="right"> </td>';
499 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht,
'MT')).
'</span></td>';
500 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat,
'MT')).
'</span></td>';
504 if (count($x_coll) == 0) {
505 print
'<tr class="liste_total">';
506 print
'<td> </td>';
507 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
509 print
'<td class="nowrap right"> </td>';
510 print
'<td class="right"> </td>';
512 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
513 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
518 print
'<tr><td colspan="'.($span + 1).
'"> </td></tr>';
524 print
'<tr class="liste_titre">';
525 print
'<td class="left">'.$elementsup.
'</td>';
526 print
'<td class="left">'.$productsup.
'</td>';
528 print
'<td class="right">'.$amountsup.
'</td>';
529 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
531 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
532 print
'<td class="right">'.$vatsup.
'</td>';
535 foreach (array_keys($x_paye) as $rate) {
536 $subtot_paye_total_ht = 0;
537 $subtot_paye_vat = 0;
539 if (is_array($x_both[$rate][
'paye'][
'detail'])) {
542 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
545 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
546 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
548 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
551 if (!empty($fields[
'ddate_start'])) {
554 if (!empty($fields[
'ddate_end'])) {
559 print
'<tr class="oddeven">';
562 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
565 print
'<td class="left">';
566 if ($fields[
'pid']) {
567 $product_static->id = $fields[
'pid'];
568 $product_static->ref = $fields[
'pref'];
569 $product_static->type = $fields[
'ptype'];
570 print $product_static->getNomUrl(1);
576 $text =
img_object($langs->trans(
'Service'),
'service');
578 $text =
img_object($langs->trans(
'Product'),
'product');
589 print
'<td class="nowrap right">';
590 print
price($fields[
'totalht']);
593 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
600 $ratiopaymentinvoice = 1;
602 print
'<td class="nowrap right">';
603 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
604 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
606 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
607 $paymentfourn_static->id = $fields[
'payment_id'];
608 print $paymentfourn_static->getNomUrl(2);
611 print $langs->trans(
"NA");
614 if (isset($fields[
'payment_amount'])) {
615 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
622 print
'<td class="nowrap right">';
623 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
628 print
'<td class="nowrap right">';
629 $temp_vat = ($local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2']) * $ratiopaymentinvoice;
635 $subtot_paye_total_ht += $temp_ht;
636 $subtot_paye_vat += $temp_vat;
637 $x_paye_sum += $temp_vat;
643 print
'<tr class="liste_total">';
644 print
'<td> </td>';
645 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
647 print
'<td class="nowrap right"> </td>';
648 print
'<td class="right"> </td>';
650 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht,
'MT')).
'</span></td>';
651 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat,
'MT')).
'</span></td>';
655 if (count($x_paye) == 0) {
656 print
'<tr class="liste_total">';
657 print
'<td> </td>';
658 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
660 print
'<td class="nowrap right"> </td>';
661 print
'<td class="right"> </td>';
663 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
664 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
669 $diff = $x_coll_sum - $x_paye_sum;
670 print
'<tr class="liste_total">';
671 print
'<td class="liste_total" colspan="'.$span.
'">'.$langs->trans(
"TotalToPay").($q ?
', '.$langs->trans(
"Quadri").
' '.$q :
'').
'</td>';
672 print
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff,
'MT')).
"</b></td>\n";