108function pt($db, $sql, $date)
110 global $conf, $bc, $langs;
112 $result = $db->query($sql);
114 $num = $db->num_rows($result);
117 print
'<table class="noborder centpercent">';
119 print
'<tr class="liste_titre">';
120 print
'<td class="nowrap">'.$date.
'</td>';
121 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
122 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").
'</td>';
134 $obj = $db->fetch_object($result);
138 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
139 print
'<tr class="oddeven">';
140 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
141 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
142 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
149 if ($obj->mode ==
'claimed') {
150 $amountclaimed = $obj->mm;
151 $totalclaimed += $amountclaimed;
153 if ($obj->mode ==
'paid') {
154 $amountpaid = $obj->mm;
155 $totalpaid += $amountpaid;
158 if ($obj->mode ==
'paid') {
159 print
'<tr class="oddeven">';
160 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
161 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
162 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
169 $previousmode = $obj->mode;
170 $previousmonth = $obj->dm;
176 if ($mode ==
'claimed' && !empty($previousmode)) {
177 print
'<tr class="oddeven">';
178 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
179 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
180 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
187 print
'<tr class="liste_total">';
188 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
189 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
190 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
200if (empty($localTaxType)) {
217$form =
new Form($db);
218$company_static =
new Societe($db);
221if ($localTaxType == 1) {
223 $LTSummary =
'LT1Summary';
225 $LTCustomer =
'LT1Customer';
226 $LTSupplier =
'LT1Supplier';
230 $LTSummary =
'LT2Summary';
232 $LTCustomer =
'LT2Customer';
233 $LTSupplier =
'LT2Supplier';
237$fsearch =
'<!-- hidden fields for form -->';
238$fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
239$fsearch .=
'<input type="hidden" name="localTaxType" value="'.$localTaxType.
'">';
240$fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
242$description = $fsearch;
245$name = $langs->transcountry($localTaxType == 1 ?
"LT1ReportByMonth" :
"LT2ReportByMonth", $mysoc->country_code);
246$description .= $langs->trans($LT);
247$calcmode = $langs->trans(
"LTReportBuildWithOptionDefinedInModule").
' ';
248$calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.
'/admin/company.php').
')</span>';
250$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
264report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
270print
'<div class="fichecenter"><div class="fichethirdleft">';
272print
load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code),
'',
'');
274print
'<table class="noborder centpercent">';
275print
'<tr class="liste_titre">';
276print
'<td>'.$langs->trans(
"Year").
"</td>";
278 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td>';
279 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td>';
282 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td><td></td>';
285 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td><td></td>';
287print
'<td class="right">'.$langs->trans(
"TotalToPay").
'</td>';
288print
"<td> </td>\n";
304while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
315 $x_coll =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'sell', $m);
316 $x_paye =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'buy', $m);
320 foreach (array_keys($x_coll) as $my_coll_rate) {
321 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
322 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
323 $x_both[$my_coll_rate][
'coll'][
'localtax1'] = $x_coll[$my_coll_rate][
'localtax1'];
324 $x_both[$my_coll_rate][
'coll'][
'localtax2'] = $x_coll[$my_coll_rate][
'localtax2'];
325 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
326 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
327 $x_both[$my_coll_rate][
'paye'][
'localtax1'] = 0;
328 $x_both[$my_coll_rate][
'paye'][
'localtax2'] = 0;
329 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
330 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
331 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
336 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
337 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
338 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
339 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
340 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
341 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
342 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
343 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
344 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
345 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
346 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
347 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
348 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
350 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
351 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
353 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
354 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
355 'localtax1' => $x_coll[$my_coll_rate][
'localtax1_list'][$id],
356 'localtax2' => $x_coll[$my_coll_rate][
'localtax2_list'][$id],
363 foreach (array_keys($x_paye) as $my_paye_rate) {
364 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
365 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
366 $x_both[$my_paye_rate][
'paye'][
'localtax1'] = $x_paye[$my_paye_rate][
'localtax1'];
367 $x_both[$my_paye_rate][
'paye'][
'localtax2'] = $x_paye[$my_paye_rate][
'localtax2'];
368 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
369 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
370 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
371 $x_both[$my_paye_rate][
'coll'][
'localtax1'] = 0;
372 $x_both[$my_paye_rate][
'coll'][
'localtax2'] = 0;
374 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
375 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
377 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
379 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
384 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
385 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
386 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
387 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
388 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
389 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
390 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
391 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
392 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
393 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
394 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
395 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
396 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
398 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
399 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
400 'localtax1' => $x_paye[$my_paye_rate][
'localtax1_list'][$id],
401 'localtax2' => $x_paye[$my_paye_rate][
'localtax2_list'][$id],
409 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
410 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
411 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
412 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
413 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
414 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
415 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
416 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
417 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
418 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
419 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
420 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
421 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
423 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
424 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
426 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
427 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
428 'localtax1' => $x_paye[$my_paye_rate][
'localtax1_list'][$id],
429 'localtax2' => $x_paye[$my_paye_rate][
'localtax2_list'][$id],
438 $object = array(&$x_coll, &$x_paye, &$x_both);
439 $parameters[
"mode"] = $modetax;
440 $parameters[
"year"] = $y;
441 $parameters[
"month"] = $m;
442 $parameters[
"type"] =
'localtax'.$localTaxType;
445 $hookmanager->initHooks(array(
'externalbalance'));
446 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
449 print
'<tr class="oddeven">';
450 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>';
453 foreach (array_keys($x_coll) as $rate) {
454 $subtot_coll_total_ht = 0;
455 $subtot_coll_vat = 0;
457 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
459 $ratiopaymentinvoice = 1;
463 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
466 if (!empty($fields[
'ddate_start'])) {
469 if (!empty($fields[
'ddate_end'])) {
477 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
478 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
483 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
484 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
485 $subtot_coll_total_ht += $temp_ht;
486 $subtot_coll_vat += $temp_vat;
487 $x_coll_sum += $temp_vat;
490 print
'<td class="nowrap right">'.price(
price2num($x_coll_sum,
'MT')).
'</td>';
493 foreach (array_keys($x_paye) as $rate) {
494 $subtot_paye_total_ht = 0;
495 $subtot_paye_vat = 0;
497 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
499 $ratiopaymentinvoice = 1;
503 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
506 if (!empty($fields[
'ddate_start'])) {
509 if (!empty($fields[
'ddate_end'])) {
517 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
518 $ratiopaymentinvoice = ($fields[
'payment_amount'] / (float) $fields[
'ftotal_ttc']);
523 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
524 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
525 $subtot_paye_total_ht += $temp_ht;
526 $subtot_paye_vat += $temp_vat;
527 $x_paye_sum += $temp_vat;
530 print
'<td class="nowrap right">'.price(
price2num($x_paye_sum,
'MT')).
'</td>';
532 $subtotalcoll += $x_coll_sum;
533 $subtotalpaid += $x_paye_sum;
535 $diff = $x_coll_sum - $x_paye_sum;
537 $subtotal =
price2num($subtotal + $diff,
'MT');
539 print
'<td class="nowrap right">'.price(
price2num($diff,
'MT')).
'</td>'.
"\n";
540 print
"<td> </td>\n";
546 print
'<tr class="liste_total">';
547 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).
'&year='.$y.
'">'.$langs->trans(
"SubTotal").
'</a>:</td>';
548 print
'<td class="nowrap right">'.price(
price2num($subtotalcoll,
'MT')).
'</td>';
549 print
'<td class="nowrap right">'.price(
price2num($subtotalpaid,
'MT')).
'</td>';
550 print
'<td class="nowrap right">'.price(
price2num($subtotal,
'MT')).
'</td>';
551 print
'<td> </td></tr>';