79function pt($db, $sql, $date)
81 global $conf, $bc, $langs, $form;
83 $result = $db->query($sql);
85 $num = $db->num_rows($result);
88 print
'<table class="noborder centpercent">';
90 print
'<tr class="liste_titre">';
91 print
'<td class="nowrap">'.$date.
'</td>';
92 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
93 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
105 $obj = $db->fetch_object($result);
109 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
110 print
'<tr class="oddeven">';
111 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
112 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
113 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
120 if ($obj->mode ==
'claimed') {
121 $amountclaimed = $obj->mm;
122 $totalclaimed += $amountclaimed;
124 if ($obj->mode ==
'paid') {
125 $amountpaid = $obj->mm;
126 $totalpaid += $amountpaid;
129 if ($obj->mode ==
'paid') {
130 print
'<tr class="oddeven">';
131 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
132 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
133 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
140 $previousmode = $obj->mode;
141 $previousmonth = $obj->dm;
147 if ($mode ==
'claimed' && !empty($previousmode)) {
148 print
'<tr class="oddeven">';
149 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
150 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
151 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
158 print
'<tr class="liste_total">';
159 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
160 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
161 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
177$form =
new Form($db);
178$company_static =
new Societe($db);
181$fsearch =
'<!-- hidden fields for form -->';
182$fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
183$fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
185$description = $fsearch;
188$name = $langs->trans(
"VATReportByMonth");
191 $calcmode = $langs->trans(
'OptionVATDefault');
194 $calcmode = $langs->trans(
'OptionVATDebitOption');
197 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
199$calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
201$description .= $langs->trans(
"VATSummary").
'<br>';
203 $description .= $langs->trans(
"RulesVATDueProducts");
206 $description .= $langs->trans(
"RulesVATInProducts");
209 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
212 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
215 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
218 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
220if (isModEnabled(
'accounting')) {
221 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
224$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
238report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
244if ($refresh ===
true) {
245 print
'<div class="fichecenter"><div class="fichethirdleft">';
249 print
'<table class="noborder centpercent">';
250 print
'<tr class="liste_titre">';
251 print
'<td width="30%">' . $langs->trans(
"Year") .
'</td>';
252 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
253 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
254 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
255 print
'<td> </td>' .
"\n";
256 print
'</tr>' .
"\n";
262 $yend = $tmp[
'year'];
272 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
282 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
283 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
287 foreach (array_keys($x_coll) as $my_coll_rate) {
288 $x_both[$my_coll_rate] = array(
294 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
295 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
296 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
297 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
298 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
299 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
300 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
305 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
306 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
307 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
308 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
309 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
310 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
311 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
312 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
313 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
314 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
315 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
316 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
317 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
319 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
320 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
321 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
322 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
329 foreach (array_keys($x_paye) as $my_paye_rate) {
330 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
331 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
332 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
333 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
334 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
336 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
337 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
339 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
341 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
346 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
347 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
348 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
349 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
350 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
351 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
352 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
353 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
354 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
355 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
356 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
357 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
358 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
359 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
360 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
368 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
369 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
370 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
371 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
372 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
373 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
374 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
375 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
376 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
377 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
378 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
379 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
380 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
382 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
383 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
384 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
385 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
394 $object = array(&$x_coll, &$x_paye, &$x_both);
395 $parameters[
"mode"] = $modetax;
396 $parameters[
"year"] = $y;
397 $parameters[
"month"] = $m;
398 $parameters[
"type"] =
'vat';
401 $hookmanager->initHooks(array(
'externalbalance'));
402 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
405 print
'<tr class="oddeven">';
406 print
'<td class="nowrap"><a href="' . DOL_URL_ROOT .
'/compta/tva/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>';
409 foreach (array_keys($x_coll) as $rate) {
410 $subtot_coll_total_ht = 0;
411 $subtot_coll_vat = 0;
413 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
415 $ratiopaymentinvoice = 1;
419 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
422 if (!empty($fields[
'ddate_start'])) {
425 if (!empty($fields[
'ddate_end'])) {
433 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
434 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
439 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
440 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
441 $subtot_coll_total_ht += $temp_ht;
442 $subtot_coll_vat += $temp_vat;
443 $x_coll_sum += $temp_vat;
446 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
449 foreach (array_keys($x_paye) as $rate) {
450 $subtot_paye_total_ht = 0;
451 $subtot_paye_vat = 0;
453 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
455 $ratiopaymentinvoice = 1;
459 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
462 if (!empty($fields[
'ddate_start'])) {
465 if (!empty($fields[
'ddate_end'])) {
473 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
474 $ratiopaymentinvoice = ($fields[
'payment_amount'] / (float) $fields[
'ftotal_ttc']);
479 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
480 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
481 $subtot_paye_total_ht += $temp_ht;
482 $subtot_paye_vat += $temp_vat;
483 $x_paye_sum += $temp_vat;
486 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
488 $subtotalcoll += $x_coll_sum;
489 $subtotalpaid += $x_paye_sum;
491 $diff = $x_coll_sum - $x_paye_sum;
493 $subtotal =
price2num($subtotal + $diff,
'MT');
495 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
496 print
"<td> </td>\n";
503 print
'<tr class="liste_total">';
504 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
505 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
506 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
507 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
508 print
'<td> </td></tr>';
515 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
516 print
"<td> </td>\n";
522 print
'</div><div class="fichetwothirdright">';
532 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
533 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
534 $sql .=
" WHERE tva.entity = " . $conf->entity;
535 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
536 $sql .=
" GROUP BY dm";
540 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
541 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
542 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
543 $sql .=
" WHERE tva.entity = " . $conf->entity;
544 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
545 $sql .=
" GROUP BY dm";
547 $sql .=
" ORDER BY dm ASC, mode ASC";
550 pt($db, $sql, $langs->trans(
"Month"));