78function pt($db, $sql, $date)
80 global $conf, $bc, $langs, $form;
82 $result = $db->query($sql);
84 $num = $db->num_rows($result);
87 print
'<table class="noborder centpercent">';
89 print
'<tr class="liste_titre">';
90 print
'<td class="nowrap">'.$date.
'</td>';
91 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
92 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
104 $obj = $db->fetch_object($result);
108 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
109 print
'<tr class="oddeven">';
110 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
111 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
112 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
119 if ($obj->mode ==
'claimed') {
120 $amountclaimed = $obj->mm;
121 $totalclaimed = $totalclaimed + $amountclaimed;
123 if ($obj->mode ==
'paid') {
124 $amountpaid = $obj->mm;
125 $totalpaid = $totalpaid + $amountpaid;
128 if ($obj->mode ==
'paid') {
129 print
'<tr class="oddeven">';
130 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
131 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
132 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
139 $previousmode = $obj->mode;
140 $previousmonth = $obj->dm;
146 if ($mode ==
'claimed' && !empty($previousmode)) {
147 print
'<tr class="oddeven">';
148 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
149 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
150 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
157 print
'<tr class="liste_total">';
158 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
159 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
160 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
176$form =
new Form($db);
177$company_static =
new Societe($db);
180$fsearch =
'<!-- hidden fields for form -->';
181$fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
182$fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
184$description = $fsearch;
187$name = $langs->trans(
"VATReportByMonth");
190 $calcmode = $langs->trans(
'OptionVATDefault');
193 $calcmode = $langs->trans(
'OptionVATDebitOption');
196 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
198$calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
200$description .= $langs->trans(
"VATSummary").
'<br>';
202 $description .= $langs->trans(
"RulesVATDueProducts");
205 $description .= $langs->trans(
"RulesVATInProducts");
208 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
211 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
214 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
217 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
219if (isModEnabled(
'accounting')) {
220 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
223$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
237report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
243if ($refresh ===
true) {
244 print
'<div class="fichecenter"><div class="fichethirdleft">';
248 print
'<table class="noborder centpercent">';
249 print
'<tr class="liste_titre">';
250 print
'<td width="30%">' . $langs->trans(
"Year") .
'</td>';
251 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
252 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
253 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
254 print
'<td> </td>' .
"\n";
255 print
'</tr>' .
"\n";
261 $yend = $tmp[
'year'];
271 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
281 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
282 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
286 foreach (array_keys($x_coll) as $my_coll_rate) {
287 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
288 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
289 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
290 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
291 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
292 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
293 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
298 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
299 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
300 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
301 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
302 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
303 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
304 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
305 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
306 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
307 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
308 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
309 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
310 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
312 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
313 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
314 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
315 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
322 foreach (array_keys($x_paye) as $my_paye_rate) {
323 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
324 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
325 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
326 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
327 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
329 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
330 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
332 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
334 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
339 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
340 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
341 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
342 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
343 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
344 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
345 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
346 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
347 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
348 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
349 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
350 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
351 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
352 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
353 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
361 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
362 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
363 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
364 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
365 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
366 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
367 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
368 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
369 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
370 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
371 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
372 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
373 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
375 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
376 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
377 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
378 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
387 $object = array(&$x_coll, &$x_paye, &$x_both);
388 $parameters[
"mode"] = $modetax;
389 $parameters[
"year"] = $y;
390 $parameters[
"month"] = $m;
391 $parameters[
"type"] =
'vat';
394 $hookmanager->initHooks(array(
'externalbalance'));
395 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
398 print
'<tr class="oddeven">';
399 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>';
402 foreach (array_keys($x_coll) as $rate) {
403 $subtot_coll_total_ht = 0;
404 $subtot_coll_vat = 0;
406 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
408 $ratiopaymentinvoice = 1;
412 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
415 if (!empty($fields[
'ddate_start'])) {
418 if (!empty($fields[
'ddate_end'])) {
426 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
427 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
432 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
433 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
434 $subtot_coll_total_ht += $temp_ht;
435 $subtot_coll_vat += $temp_vat;
436 $x_coll_sum += $temp_vat;
439 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
442 foreach (array_keys($x_paye) as $rate) {
443 $subtot_paye_total_ht = 0;
444 $subtot_paye_vat = 0;
446 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
448 $ratiopaymentinvoice = 1;
452 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
455 if (!empty($fields[
'ddate_start'])) {
458 if (!empty($fields[
'ddate_end'])) {
466 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
467 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
472 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
473 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
474 $subtot_paye_total_ht += $temp_ht;
475 $subtot_paye_vat += $temp_vat;
476 $x_paye_sum += $temp_vat;
479 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
481 $subtotalcoll = $subtotalcoll + $x_coll_sum;
482 $subtotalpaid = $subtotalpaid + $x_paye_sum;
484 $diff = $x_coll_sum - $x_paye_sum;
485 $total = $total + $diff;
486 $subtotal =
price2num($subtotal + $diff,
'MT');
488 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
489 print
"<td> </td>\n";
496 print
'<tr class="liste_total">';
497 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
498 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
499 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
500 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
501 print
'<td> </td></tr>';
508 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
509 print
"<td> </td>\n";
515 print
'</div><div class="fichetwothirdright">';
525 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
526 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
527 $sql .=
" WHERE tva.entity = " . $conf->entity;
528 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
529 $sql .=
" GROUP BY dm";
533 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
534 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
535 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
536 $sql .=
" WHERE tva.entity = " . $conf->entity;
537 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
538 $sql .=
" GROUP BY dm";
540 $sql .=
" ORDER BY dm ASC, mode ASC";
543 pt($db, $sql, $langs->trans(
"Month"));