30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
38 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
42 $year_start = $year_current;
44 $month_start = $month_current;
48 include DOL_DOCUMENT_ROOT.
'/compta/tva/initdatesforvat.inc.php';
52 $modetax = $conf->global->TAX_MODE;
54 $modetax =
GETPOST(
"modetax",
'int');
56 if (empty($modetax)) {
61 $socid =
GETPOST(
'socid',
'int');
63 $socid = $user->socid;
76 function pt($db, $sql, $date)
78 global $conf, $bc, $langs,
$form;
80 $result = $db->query($sql);
82 $num = $db->num_rows($result);
85 print
'<table class="noborder centpercent">';
87 print
'<tr class="liste_titre">';
88 print
'<td class="nowrap">'.$date.
'</td>';
89 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
90 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
102 $obj = $db->fetch_object($result);
106 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
107 print
'<tr class="oddeven">';
108 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
109 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
110 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
117 if ($obj->mode ==
'claimed') {
118 $amountclaimed = $obj->mm;
119 $totalclaimed = $totalclaimed + $amountclaimed;
121 if ($obj->mode ==
'paid') {
122 $amountpaid = $obj->mm;
123 $totalpaid = $totalpaid + $amountpaid;
126 if ($obj->mode ==
'paid') {
127 print
'<tr class="oddeven">';
128 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
129 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
130 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
137 $previousmode = $obj->mode;
138 $previousmonth = $obj->dm;
144 if ($mode ==
'claimed' && !empty($previousmode)) {
145 print
'<tr class="oddeven">';
146 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
147 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
148 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
155 print
'<tr class="liste_total">';
156 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
157 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
158 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
175 $company_static =
new Societe($db);
178 $fsearch =
'<!-- hidden fields for form -->';
179 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
180 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
182 $description = $fsearch;
185 $name = $langs->trans(
"VATReportByMonth");
188 $calcmode = $langs->trans(
'OptionVATDefault');
191 $calcmode = $langs->trans(
'OptionVATDebitOption');
194 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
196 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
198 $description .= $langs->trans(
"VATSummary").
'<br>';
199 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
200 $description .= $langs->trans(
"RulesVATDueProducts");
202 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
203 $description .= $langs->trans(
"RulesVATInProducts");
205 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
206 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
208 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
209 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
211 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
212 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
214 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
215 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
218 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
229 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
235 if ($refresh ===
true) {
236 print
'<div class="fichecenter"><div class="fichethirdleft">';
240 print
'<table class="noborder centpercent">';
241 print
'<tr class="liste_titre">';
242 print
'<td width="30%">' . $langs->trans(
"Year") .
" " . $y .
'</td>';
243 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
244 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
245 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
246 print
'<td> </td>' .
"\n";
247 print
'</tr>' .
"\n";
253 $yend = $tmp[
'year'];
263 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
273 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
274 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
278 foreach (array_keys($x_coll) as $my_coll_rate) {
279 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
280 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
281 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
282 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
283 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
284 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
285 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
290 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
291 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
292 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
293 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
294 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
295 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
296 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
297 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
298 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
299 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
300 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
301 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
302 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
304 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
305 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
306 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
307 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
314 foreach (array_keys($x_paye) as $my_paye_rate) {
315 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
316 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
317 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
318 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
319 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
321 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
322 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
324 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
326 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
331 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
332 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
333 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
334 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
335 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
336 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
337 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
338 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
339 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
340 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
341 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
342 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
343 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
344 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
345 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
353 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
354 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
355 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
356 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
357 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
358 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
359 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
360 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
361 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
362 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
363 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
364 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
365 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
367 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
368 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
369 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
370 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
379 $object = array(&$x_coll, &$x_paye, &$x_both);
380 $parameters[
"mode"] = $modetax;
381 $parameters[
"year"] = $y;
382 $parameters[
"month"] = $m;
383 $parameters[
"type"] =
'vat';
386 $hookmanager->initHooks(array(
'externalbalance'));
387 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
389 if (!is_array($x_coll) && $coll_listbuy == -1) {
390 $langs->load(
"errors");
391 print
'<tr><td colspan="5">' . $langs->trans(
"ErrorNoAccountancyModuleLoaded") .
'</td></tr>';
394 if (!is_array($x_paye) && $coll_listbuy == -2) {
395 print
'<tr><td colspan="5">' . $langs->trans(
"FeatureNotYetAvailable") .
'</td></tr>';
400 print
'<tr class="oddeven">';
401 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>';
404 foreach (array_keys($x_coll) as $rate) {
405 $subtot_coll_total_ht = 0;
406 $subtot_coll_vat = 0;
408 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
410 $ratiopaymentinvoice = 1;
414 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
417 if (!empty($fields[
'ddate_start'])) {
420 if (!empty($fields[
'ddate_end'])) {
424 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
425 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
428 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
429 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
434 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
435 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
436 $subtot_coll_total_ht += $temp_ht;
437 $subtot_coll_vat += $temp_vat;
438 $x_coll_sum += $temp_vat;
441 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
444 foreach (array_keys($x_paye) as $rate) {
445 $subtot_paye_total_ht = 0;
446 $subtot_paye_vat = 0;
448 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
450 $ratiopaymentinvoice = 1;
454 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
457 if (!empty($fields[
'ddate_start'])) {
460 if (!empty($fields[
'ddate_end'])) {
464 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
465 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
468 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
469 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
474 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
475 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
476 $subtot_paye_total_ht += $temp_ht;
477 $subtot_paye_vat += $temp_vat;
478 $x_paye_sum += $temp_vat;
481 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
483 $subtotalcoll = $subtotalcoll + $x_coll_sum;
484 $subtotalpaid = $subtotalpaid + $x_paye_sum;
486 $diff = $x_coll_sum - $x_paye_sum;
487 $total = $total + $diff;
488 $subtotal =
price2num($subtotal + $diff,
'MT');
490 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
491 print
"<td> </td>\n";
498 print
'<tr class="liste_total">';
499 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
500 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
501 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
502 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
503 print
'<td> </td></tr>';
510 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
511 print
"<td> </td>\n";
517 print
'</div><div class="fichetwothirdright">';
527 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
528 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
529 $sql .=
" WHERE tva.entity = " . $conf->entity;
530 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
531 $sql .=
" GROUP BY dm";
535 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
536 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
537 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
538 $sql .=
" WHERE tva.entity = " . $conf->entity;
539 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
540 $sql .=
" GROUP BY dm";
542 $sql .=
" ORDER BY dm ASC, mode ASC";
545 pt($db, $sql, $langs->trans(
"Month"));
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
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 from a POST of a form...
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, $mode=0)
Check permissions of a user to show a page and an object.
pt($db, $sql, $date)
print function
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...