28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
36 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
40 if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
46 $year_current = $current_date[
'year'];
47 $year_start = $year_current;
49 $year_current = $year;
55 if (empty($date_start) || empty($date_end))
61 if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) {
62 $date_start =
dol_time_plus_duree(
dol_get_first_day($year_start, $current_date[
'mon'],
false), -3 - (($current_date[
'mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3),
'm');
64 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
65 if ($current_date[
'mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) {
66 if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date[
'mon']) > 6) {
70 if (($current_date[
'mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) {
74 $date_start =
dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
76 } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
91 $modetax = $conf->global->TAX_MODE;
93 if (empty($modetax)) $modetax = 0;
96 $socid =
GETPOST(
'socid',
'int');
97 if ($user->socid) $socid = $user->socid;
109 function pt($db, $sql, $date)
111 global $conf, $bc, $langs;
113 $result = $db->query($sql);
115 $num = $db->num_rows($result);
118 print '<table class="noborder centpercent">';
120 print '<tr class="liste_titre">';
121 print '<td class="nowrap">'.$date.
'</td>';
122 print '<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
123 print '<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").
'</td>';
135 $obj = $db->fetch_object($result);
139 if ($obj->mode ==
'claimed' && !empty($previousmode))
141 print '<tr class="oddeven">';
142 print '<td class="nowrap">'.$previousmonth.
"</td>\n";
143 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
144 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
151 if ($obj->mode ==
'claimed')
153 $amountclaimed = $obj->mm;
154 $totalclaimed = $totalclaimed + $amountclaimed;
156 if ($obj->mode ==
'paid')
158 $amountpaid = $obj->mm;
159 $totalpaid = $totalpaid + $amountpaid;
162 if ($obj->mode ==
'paid')
164 print '<tr class="oddeven">';
165 print '<td class="nowrap">'.$obj->dm.
"</td>\n";
166 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
167 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
174 $previousmode = $obj->mode;
175 $previousmonth = $obj->dm;
181 if ($mode ==
'claimed' && !empty($previousmode))
183 print '<tr class="oddeven">';
184 print '<td class="nowrap">'.$previousmonth.
"</td>\n";
185 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
186 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
193 print '<tr class="liste_total">';
194 print '<td class="right">'.$langs->trans(
"Total").
'</td>';
195 print '<td class="nowrap right">'.price($totalclaimed).
'</td>';
196 print '<td class="nowrap right">'.price($totalpaid).
'</td>';
212 $form =
new Form($db);
213 $company_static =
new Societe($db);
216 $fsearch =
'<!-- hidden fields for form -->';
217 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
218 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
220 $description = $fsearch;
223 $name = $langs->trans(
"VATReportByMonth");
225 if ($modetax == 0) $calcmode = $langs->trans(
'OptionVATDefault');
226 if ($modetax == 1) $calcmode = $langs->trans(
'OptionVATDebitOption');
227 if ($modetax == 2) $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
228 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
230 $description .= $langs->trans(
"VATSummary").
'<br>';
231 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') $description .= $langs->trans(
"RulesVATDueProducts");
232 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') $description .= $langs->trans(
"RulesVATInProducts");
233 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
234 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
235 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
236 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
238 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
240 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
251 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
257 print '<div class="fichecenter"><div class="fichethirdleft">';
261 print '<table class="noborder centpercent">';
262 print
'<tr class="liste_titre">';
263 print
'<td width="30%">'.$langs->trans(
"Year").
" ".$y.
'</td>';
264 print
'<td class="right">'.$langs->trans(
"VATToPay").
'</td>';
265 print
'<td class="right">'.$langs->trans(
"VATToCollect").
'</td>';
266 print
'<td class="right">'.$langs->trans(
"Balance").
'</td>';
267 print
'<td> </td>'.
"\n";
274 $yend = $tmp[
'year'];
277 $total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
278 $i = 0; $mcursor = 0;
280 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000)
284 if ($m > 12) $m -= 12;
287 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
288 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
292 foreach (array_keys($x_coll) as $my_coll_rate)
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)
342 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment')
348 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
349 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
350 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
351 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
352 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
353 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
354 'payment_id' =>$x_paye[$my_paye_rate][
'payment_id'][$id],
355 'payment_amount' =>$x_paye[$my_paye_rate][
'payment_amount'][$id],
356 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
357 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
358 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
359 'ddate_start' =>$x_paye[$my_paye_rate][
'ddate_start'][$id],
360 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
361 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
362 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
370 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
371 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
372 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
373 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
374 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
375 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
376 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
377 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
378 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
379 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
380 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
381 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
382 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
384 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
385 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
386 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
387 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
396 $object = array(&$x_coll, &$x_paye, &$x_both);
397 $parameters[
"mode"] = $modetax;
398 $parameters[
"year"] = $y;
399 $parameters[
"month"] = $m;
400 $parameters[
"type"] =
'vat';
403 $hookmanager->initHooks(array(
'externalbalance'));
404 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
406 if (!is_array($x_coll) && $coll_listbuy == -1)
408 $langs->load(
"errors");
409 print
'<tr><td colspan="5">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
412 if (!is_array($x_paye) && $coll_listbuy == -2)
414 print
'<tr><td colspan="5">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
419 print
'<tr class="oddeven">';
420 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>';
423 foreach (array_keys($x_coll) as $rate)
425 $subtot_coll_total_ht = 0;
426 $subtot_coll_vat = 0;
428 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields)
431 $ratiopaymentinvoice = 1;
436 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
439 if (!empty($fields[
'ddate_start'])) {
442 if (!empty($fields[
'ddate_end'])) {
446 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
447 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice'))
451 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
452 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
457 $temp_ht = $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">'.price(
price2num($x_coll_sum,
'MT')).
'</td>';
467 foreach (array_keys($x_paye) as $rate)
469 $subtot_paye_total_ht = 0;
470 $subtot_paye_vat = 0;
472 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields)
475 $ratiopaymentinvoice = 1;
480 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
483 if (!empty($fields[
'ddate_start'])) {
486 if (!empty($fields[
'ddate_end'])) {
490 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
491 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice'))
495 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
496 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
501 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
502 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
503 $subtot_paye_total_ht += $temp_ht;
504 $subtot_paye_vat += $temp_vat;
505 $x_paye_sum += $temp_vat;
508 print
'<td class="nowrap right">'.price(
price2num($x_paye_sum,
'MT')).
'</td>';
510 $subtotalcoll = $subtotalcoll + $x_coll_sum;
511 $subtotalpaye = $subtotalpaye + $x_paye_sum;
513 $diff = $x_coll_sum - $x_paye_sum;
514 $total = $total + $diff;
515 $subtotal =
price2num($subtotal + $diff,
'MT');
517 print
'<td class="nowrap right">'.price(
price2num($diff,
'MT')).
'</td>'.
"\n";
518 print
"<td> </td>\n";
524 print
'<tr class="liste_total">';
525 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).
'&year='.$y.
'">'.$langs->trans(
"SubTotal").
'</a>:</td>';
526 print
'<td class="nowrap right">'.price(
price2num($subtotalcoll,
'MT')).
'</td>';
527 print
'<td class="nowrap right">'.price(
price2num($subtotalpaye,
'MT')).
'</td>';
528 print
'<td class="nowrap right">'.price(
price2num($subtotal,
'MT')).
'</td>';
529 print
'<td> </td></tr>';
531 $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
534 print
'<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans(
"TotalToPay").
':</td><td class="nowrap right">'.
price(
price2num($total,
'MT')).
'</td>';
535 print
"<td> </td>\n";
541 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
553 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
554 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
555 $sql .=
" WHERE f.entity = ".$conf->entity;
556 $sql .=
" AND (f.datev >= '".$db->idate($date_start).
"' AND f.datev <= '".$db->idate($date_end).
"')";
557 $sql .=
" GROUP BY dm";
561 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
562 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
563 $sql .=
" WHERE f.entity = ".$conf->entity;
564 $sql .=
" AND (f.datep >= '".$db->idate($date_start).
"' AND f.datep <= '".$db->idate($date_end).
"')";
565 $sql .=
" GROUP BY dm";
567 $sql .=
" ORDER BY dm ASC, mode ASC";
570 pt($db, $sql, $langs->trans(
"Month"));
573 if (!empty($conf->global->MAIN_FEATURES_LEVEL))
583 $sql1 =
"SELECT SUM(amount) as mm";
584 $sql1 .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
585 $sql1 .=
" WHERE f.entity = ".$conf->entity;
586 $sql1 .=
" AND f.datev >= '".$db->idate($date_start).
"'";
587 $sql1 .=
" AND f.datev <= '".$db->idate($date_end).
"'";
589 $result = $db->query($sql1);
591 $obj = $db->fetch_object($result);
592 print
'<table class="noborder centpercent">';
595 print
'<td class="right">'.$langs->trans(
"VATDue").
'</td>';
596 print
'<td class="nowrap right">'.price(
price2num($total,
'MT')).
'</td>';
600 print
'<td class="right">'.$langs->trans(
"VATPaid").
'</td>';
601 print
'<td class="nowrap right">'.price(
price2num($obj->mm,
'MT')).
"</td>\n";
604 $restopay = $total - $obj->mm;
606 print
'<td class="right">'.$langs->trans(
"RemainToPay").
'</td>';
607 print
'<td class="nowrap right">'.price(
price2num($restopay,
'MT')).
'</td>';
614 print
'</div></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Put here description of your class.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets Tax to collect for the given year (and given quarter or month) The function gets the Tax in spli...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
pt($db, $sql, $date)
print function
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.