97function pt($db, $sql, $date)
99 global
$conf, $bc, $langs, $form;
101 $result = $db->query($sql);
103 $num = $db->num_rows($result);
106 print
'<table class="noborder centpercent">';
108 print
'<tr class="liste_titre">';
109 print
'<td class="nowrap">'.$date.
'</td>';
110 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
111 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
123 $obj = $db->fetch_object($result);
127 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
128 print
'<tr class="oddeven">';
129 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
130 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
131 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
138 if ($obj->mode ==
'claimed') {
139 $amountclaimed = $obj->mm;
140 $totalclaimed += $amountclaimed;
142 if ($obj->mode ==
'paid') {
143 $amountpaid = $obj->mm;
144 $totalpaid += $amountpaid;
147 if ($obj->mode ==
'paid') {
148 print
'<tr class="oddeven">';
149 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
150 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
151 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
158 $previousmode = $obj->mode;
159 $previousmonth = $obj->dm;
165 if ($mode ==
'claimed' && !empty($previousmode)) {
166 print
'<tr class="oddeven">';
167 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
168 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
169 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
176 print
'<tr class="liste_total">';
177 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
178 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
179 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
195$form =
new Form($db);
196$company_static =
new Societe($db);
199$fsearch =
'<!-- hidden fields for form -->';
200$fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
201$fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
203$description = $fsearch;
206$name = $langs->trans(
"VATReportByMonth");
209 $calcmode = $langs->trans(
'OptionVATDefault');
212 $calcmode = $langs->trans(
'OptionVATDebitOption');
215 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
217$calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
219$description .= $langs->trans(
"VATSummary").
'<br>';
221 $description .= $langs->trans(
"RulesVATDueProducts");
224 $description .= $langs->trans(
"RulesVATInProducts");
227 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
230 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
233 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
236 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
238if (isModEnabled(
'accounting')) {
239 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
242$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
256report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
262if ($refresh ===
true) {
263 print
'<div class="fichecenter"><div class="fichethirdleft">';
267 print
'<table class="noborder centpercent">';
268 print
'<tr class="liste_titre">';
269 print
'<td width="30%">' . $langs->trans(
"Year") .
'</td>';
270 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
271 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
272 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
273 print
'<td> </td>' .
"\n";
274 print
'</tr>' .
"\n";
280 $yend = $tmp[
'year'];
290 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
300 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
301 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
305 foreach (array_keys($x_coll) as $my_coll_rate) {
306 $x_both[$my_coll_rate] = array(
312 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
313 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
314 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
315 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
316 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
317 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
318 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
323 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
324 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
325 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
326 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
327 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
328 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
329 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
330 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
331 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
332 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
333 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
334 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
335 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
337 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
338 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
339 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
340 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
347 foreach (array_keys($x_paye) as $my_paye_rate) {
348 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
349 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
350 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
351 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
352 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
354 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
355 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
357 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
359 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
364 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
365 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
366 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
367 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
368 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
369 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
370 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
371 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
372 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
373 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
374 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$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],
386 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
387 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
388 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
389 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
390 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
391 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
392 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
393 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
394 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
395 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
396 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
397 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
398 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
400 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
401 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
402 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
403 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
412 $object = array(&$x_coll, &$x_paye, &$x_both);
413 $parameters[
"mode"] = $modetax;
414 $parameters[
"year"] = $y;
415 $parameters[
"month"] = $m;
416 $parameters[
"type"] =
'vat';
419 $hookmanager->initHooks(array(
'externalbalance'));
420 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
423 print
'<tr class="oddeven">';
424 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>';
427 foreach (array_keys($x_coll) as $rate) {
428 $subtot_coll_total_ht = 0;
429 $subtot_coll_vat = 0;
431 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
433 $ratiopaymentinvoice = 1;
437 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
440 if (!empty($fields[
'ddate_start'])) {
443 if (!empty($fields[
'ddate_end'])) {
451 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
452 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
457 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
458 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
459 $subtot_coll_total_ht += $temp_ht;
460 $subtot_coll_vat += $temp_vat;
461 $x_coll_sum += $temp_vat;
464 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
467 foreach (array_keys($x_paye) as $rate) {
468 $subtot_paye_total_ht = 0;
469 $subtot_paye_vat = 0;
471 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
473 $ratiopaymentinvoice = 1;
477 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
480 if (!empty($fields[
'ddate_start'])) {
483 if (!empty($fields[
'ddate_end'])) {
491 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
492 $ratiopaymentinvoice = ($fields[
'payment_amount'] / (float) $fields[
'ftotal_ttc']);
497 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
498 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
499 $subtot_paye_total_ht += $temp_ht;
500 $subtot_paye_vat += $temp_vat;
501 $x_paye_sum += $temp_vat;
504 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
506 $subtotalcoll += $x_coll_sum;
507 $subtotalpaid += $x_paye_sum;
509 $diff = $x_coll_sum - $x_paye_sum;
511 $subtotal =
price2num($subtotal + $diff,
'MT');
513 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
514 print
"<td> </td>\n";
521 print
'<tr class="liste_total">';
522 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
523 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
524 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
525 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
526 print
'<td> </td></tr>';
533 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
534 print
"<td> </td>\n";
540 print
'</div><div class="fichetwothirdright">';
550 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
551 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
552 $sql .=
" WHERE tva.entity = " .
$conf->entity;
553 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
554 $sql .=
" GROUP BY dm";
558 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
559 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
560 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
561 $sql .=
" WHERE tva.entity = " .
$conf->entity;
562 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
563 $sql .=
" GROUP BY dm";
565 $sql .=
" ORDER BY dm ASC, mode ASC";
568 pt($db, $sql, $langs->trans(
"Month"));