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) {
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;
174 if ($prevquarter > 1) {
180 $nextyear = $year_start;
182 if ($nextquarter < 4) {
188 $description = $fsearch;
202 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
203 $description .= $langs->trans(
"ThisIsAnEstimatedValue");
207 $elementcust = $langs->trans(
"CustomersInvoices");
208 $productcust = $langs->trans(
"ProductOrService");
209 $amountcust = $langs->trans(
"AmountHT");
210 $vatcust = $langs->trans(
"VATReceived");
211 $namecust = $langs->trans(
"Name");
212 if ($mysoc->tva_assuj) {
213 $vatcust .=
' ('.$langs->trans(
"StatusToPay").
')';
217 $elementsup = $langs->trans(
"SuppliersInvoices");
218 $productsup = $productcust;
219 $amountsup = $amountcust;
220 $vatsup = $langs->trans(
"VATPaid");
221 $namesup = $namecust;
222 if ($mysoc->tva_assuj) {
223 $vatsup .=
' ('.$langs->trans(
"ToGetBack").
')';
229 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
232 $vatcust = $langs->transcountry(
"LT1", $mysoc->country_code);
233 $vatsup = $langs->transcountry(
"LT1", $mysoc->country_code);
234 $vatexpensereport = $langs->transcountry(
"LT1", $mysoc->country_code);
236 $vatcust = $langs->transcountry(
"LT2", $mysoc->country_code);
237 $vatsup = $langs->transcountry(
"LT2", $mysoc->country_code);
238 $vatexpensereport = $langs->transcountry(
"LT2", $mysoc->country_code);
242 print
'<div class="div-table-responsive">';
243 echo
'<table class="noborder centpercent">';
251 $x_coll =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'sell');
252 $x_paye =
tax_by_rate(
'localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax,
'buy');
254 if (!is_array($x_coll) || !is_array($x_paye)) {
255 $langs->load(
"errors");
257 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
258 } elseif ($x_coll == -2) {
259 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
261 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
267 foreach (array_keys($x_coll) as $my_coll_rate) {
268 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
269 $x_both[$my_coll_rate][
'coll'][
'localtax'.$local] = $x_coll[$my_coll_rate][
'localtax'.$local];
270 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
271 $x_both[$my_coll_rate][
'paye'][
'localtax'.$local] = 0;
272 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
273 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
274 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
275 $invoice_customer->id = $x_coll[$my_coll_rate][
'facid'][$id];
276 $invoice_customer->ref = $x_coll[$my_coll_rate][
'facnum'][$id];
277 $invoice_customer->type = $x_coll[$my_coll_rate][
'type'][$id];
278 $company_static->fetch($x_coll[$my_coll_rate][
'company_id'][$id]);
279 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
280 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
281 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
282 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
283 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
284 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
285 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
286 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
287 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
288 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
289 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
290 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
291 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
292 'company_link'=>$company_static->getNomUrl(1,
'', 20),
293 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
294 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
295 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
296 'localtax1'=> $x_coll[$my_coll_rate][
'localtax1_list'][$id],
297 'localtax2'=> $x_coll[$my_coll_rate][
'localtax2_list'][$id],
298 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
299 'link' =>$invoice_customer->getNomUrl(1,
'', 12)
304 foreach (array_keys($x_paye) as $my_paye_rate) {
305 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
306 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
307 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
308 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
309 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
311 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
312 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
314 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
315 $invoice_supplier->id = $x_paye[$my_paye_rate][
'facid'][$id];
316 $invoice_supplier->ref = $x_paye[$my_paye_rate][
'facnum'][$id];
317 $invoice_supplier->type = $x_paye[$my_paye_rate][
'type'][$id];
318 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
319 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
320 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
321 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
322 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
323 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
324 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
325 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
326 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
327 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
328 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
329 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
330 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
331 'company_link'=>$company_static->getNomUrl(1,
'', 20),
332 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
333 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
334 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
335 'localtax1'=> $x_paye[$my_paye_rate][
'localtax1_list'][$id],
336 'localtax2'=> $x_paye[$my_paye_rate][
'localtax2_list'][$id],
337 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
338 'link' =>$invoice_supplier->getNomUrl(1,
'', 12)
351 $span = $columns - 1;
360 print
'<tr class="liste_titre">';
361 print
'<td class="left">'.$elementcust.
'</td>';
362 print
'<td class="left">'.$productcust.
'</td>';
364 print
'<td class="right">'.$amountcust.
'</td>';
367 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
369 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
370 print
'<td class="right">'.$vatcust.
'</td>';
376 foreach (array_keys($x_coll) as $rate) {
377 $subtot_coll_total_ht = 0;
378 $subtot_coll_vat = 0;
380 if (is_array($x_both[$rate][
'coll'][
'detail'])) {
384 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
387 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
388 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
390 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
393 if (!empty($fields[
'ddate_start'])) {
396 if (!empty($fields[
'ddate_end'])) {
401 print
'<tr class="oddeven">';
404 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
407 print
'<td class="left">';
408 if ($fields[
'pid']) {
409 $product_static->id = $fields[
'pid'];
410 $product_static->ref = $fields[
'pref'];
411 $product_static->type = $fields[
'ptype'];
412 print $product_static->getNomUrl(1);
418 $text =
img_object($langs->trans(
'Service'),
'service');
420 $text =
img_object($langs->trans(
'Product'),
'product');
422 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
423 if ($reg[1] ==
'DEPOSIT') {
424 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
425 } elseif ($reg[1] ==
'CREDIT_NOTE') {
426 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
428 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
440 print
'<td class="nowrap right">';
441 print
price($fields[
'totalht']);
443 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
449 $ratiopaymentinvoice = 1;
451 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
452 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
454 print
'<td class="nowrap right">';
455 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
456 $payment_static->id = $fields[
'payment_id'];
457 print $payment_static->getNomUrl(2);
460 print $langs->trans(
"NotUsedForGoods");
462 print
price($fields[
'payment_amount']);
463 if (isset($fields[
'payment_amount'])) {
464 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
471 print
'<td class="nowrap right">';
472 $temp_ht = $fields[
'totalht'];
474 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
480 print
'<td class="nowrap right">';
481 $temp_vat = $local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2'];
487 $subtot_coll_total_ht += $temp_ht;
488 $subtot_coll_vat += $temp_vat;
489 $x_coll_sum += $temp_vat;
495 print
'<tr class="liste_total">';
497 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
499 print
'<td class="nowrap right"> </td>';
500 print
'<td class="right"> </td>';
502 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht,
'MT')).
'</span></td>';
503 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat,
'MT')).
'</span></td>';
507 if (count($x_coll) == 0) {
508 print
'<tr class="liste_total">';
509 print
'<td> </td>';
510 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
512 print
'<td class="nowrap right"> </td>';
513 print
'<td class="right"> </td>';
515 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
516 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
521 print
'<tr><td colspan="'.($span + 1).
'"> </td></tr>';
527 print
'<tr class="liste_titre">';
528 print
'<td class="left">'.$elementsup.
'</td>';
529 print
'<td class="left">'.$productsup.
'</td>';
531 print
'<td class="right">'.$amountsup.
'</td>';
532 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
534 print
'<td class="right">'.$langs->trans(
"BI").
'</td>';
535 print
'<td class="right">'.$vatsup.
'</td>';
538 foreach (array_keys($x_paye) as $rate) {
539 $subtot_paye_total_ht = 0;
540 $subtot_paye_vat = 0;
542 if (is_array($x_both[$rate][
'paye'][
'detail'])) {
545 print
'<td class="tax_rate">'.$langs->trans(
"Rate").
': '.
vatrate($rate).
'%</td><td colspan="'.$span.
'"></td>';
548 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
549 if (($local == 1 && $fields[
'localtax1'] != 0) || ($local == 2 && $fields[
'localtax2'] != 0)) {
551 $type = ($fields[
'dtype'] ? $fields[
'dtype'] : $fields[
'ptype']);
554 if (!empty($fields[
'ddate_start'])) {
557 if (!empty($fields[
'ddate_end'])) {
562 print
'<tr class="oddeven">';
565 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
568 print
'<td class="left">';
569 if ($fields[
'pid']) {
570 $product_static->id = $fields[
'pid'];
571 $product_static->ref = $fields[
'pref'];
572 $product_static->type = $fields[
'ptype'];
573 print $product_static->getNomUrl(1);
579 $text =
img_object($langs->trans(
'Service'),
'service');
581 $text =
img_object($langs->trans(
'Product'),
'product');
592 print
'<td class="nowrap right">';
593 print
price($fields[
'totalht']);
596 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
603 $ratiopaymentinvoice = 1;
605 print
'<td class="nowrap right">';
606 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
607 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
609 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
610 $paymentfourn_static->id = $fields[
'payment_id'];
611 print $paymentfourn_static->getNomUrl(2);
614 print $langs->trans(
"NA");
617 if (isset($fields[
'payment_amount'])) {
618 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
625 print
'<td class="nowrap right">';
626 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
631 print
'<td class="nowrap right">';
632 $temp_vat = ($local == 1 ? $fields[
'localtax1'] : $fields[
'localtax2']) * $ratiopaymentinvoice;
638 $subtot_paye_total_ht += $temp_ht;
639 $subtot_paye_vat += $temp_vat;
640 $x_paye_sum += $temp_vat;
646 print
'<tr class="liste_total">';
647 print
'<td> </td>';
648 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
650 print
'<td class="nowrap right"> </td>';
651 print
'<td class="right"> </td>';
653 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht,
'MT')).
'</span></td>';
654 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat,
'MT')).
'</span></td>';
658 if (count($x_paye) == 0) {
659 print
'<tr class="liste_total">';
660 print
'<td> </td>';
661 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
663 print
'<td class="nowrap right"> </td>';
664 print
'<td class="right"> </td>';
666 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
667 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
672 $diff = $x_coll_sum - $x_paye_sum;
673 print
'<tr class="liste_total">';
674 print
'<td class="liste_total" colspan="'.$span.
'">'.$langs->trans(
"TotalToPay").($q ?
', '.$langs->trans(
"Quadri").
' '.$q :
'').
'</td>';
675 print
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff,
'MT')).
"</b></td>\n";