26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
34 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
36 $localTaxType =
GETPOST(
'localTaxType',
'int');
42 $year_current = strftime(
"%Y",
dol_now());
43 $year_start = $year_current;
45 $year_current = $year;
50 if (empty($date_start) || empty($date_end))
56 $date_start =
dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
69 $modetax = $conf->global->TAX_MODE;
71 if (empty($modetax)) $modetax = 0;
74 $socid =
GETPOST(
'socid',
'int');
75 if ($user->socid) $socid = $user->socid;
87 function pt($db, $sql, $date)
89 global $conf, $bc, $langs;
91 $result = $db->query($sql);
93 $num = $db->num_rows($result);
96 print '<table class="noborder centpercent">';
98 print '<tr class="liste_titre">';
99 print '<td class="nowrap">'.$date.
'</td>';
100 print '<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
101 print '<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").
'</td>';
113 $obj = $db->fetch_object($result);
117 if ($obj->mode ==
'claimed' && !empty($previousmode))
119 print '<tr class="oddeven">';
120 print '<td class="nowrap">'.$previousmonth.
"</td>\n";
121 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
122 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
129 if ($obj->mode ==
'claimed')
131 $amountclaimed = $obj->mm;
132 $totalclaimed = $totalclaimed + $amountclaimed;
134 if ($obj->mode ==
'paid')
136 $amountpaid = $obj->mm;
137 $totalpaid = $totalpaid + $amountpaid;
140 if ($obj->mode ==
'paid')
142 print '<tr class="oddeven">';
143 print '<td class="nowrap">'.$obj->dm.
"</td>\n";
144 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
145 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
152 $previousmode = $obj->mode;
153 $previousmonth = $obj->dm;
159 if ($mode ==
'claimed' && !empty($previousmode))
161 print '<tr class="oddeven">';
162 print '<td class="nowrap">'.$previousmonth.
"</td>\n";
163 print '<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
164 print '<td class="nowrap right">'.price($amountpaid).
"</td>\n";
171 print '<tr class="liste_total">';
172 print '<td class="right">'.$langs->trans(
"Total").
'</td>';
173 print '<td class="nowrap right">'.price($totalclaimed).
'</td>';
174 print '<td class="nowrap right">'.price($totalpaid).
'</td>';
184 if (empty($localTaxType))
202 $form =
new Form($db);
203 $company_static =
new Societe($db);
206 if ($localTaxType == 1) {
208 $LTSummary =
'LT1Summary';
210 $LTCustomer =
'LT1Customer';
211 $LTSupplier =
'LT1Supplier';
212 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC1;
215 $LTSummary =
'LT2Summary';
217 $LTCustomer =
'LT2Customer';
218 $LTSupplier =
'LT2Supplier';
219 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC2;
222 $fsearch =
'<!-- hidden fields for form -->';
223 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
224 $fsearch .=
'<input type="hidden" name="localTaxType" value="'.$localTaxType.
'">';
225 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
227 $description = $fsearch;
230 $name = $langs->transcountry($localTaxType == 1 ?
"LT1ReportByMonth" :
"LT2ReportByMonth", $mysoc->country_code);
231 $description .= $langs->trans($LT);
232 $calcmode = $langs->trans(
"LTReportBuildWithOptionDefinedInModule").
' ';
233 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.
'/admin/company.php').
')</span>';
237 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
248 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
254 print '<div class="fichecenter"><div class="fichethirdleft">';
258 print '<table class="noborder centpercent">';
259 print
'<tr class="liste_titre">';
260 print
'<td width="30%">'.$langs->trans(
"Year").
" ".$y.
"</td>";
262 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td>';
263 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td>';
266 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td><td></td>';
269 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td><td></td>';
271 print
'<td class="right">'.$langs->trans(
"TotalToPay").
'</td>';
272 print
"<td> </td>\n";
279 $yend = $tmp[
'year'];
282 $total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
283 $i = 0; $mcursor = 0;
284 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000)
288 if ($m > 12) $m -= 12;
292 $x_coll =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'sell', $m);
293 $x_paye =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'buy', $m);
297 foreach (array_keys($x_coll) as $my_coll_rate)
299 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
300 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
301 $x_both[$my_coll_rate][
'coll'][
'localtax1'] = $x_coll[$my_coll_rate][
'localtax1'];
302 $x_both[$my_coll_rate][
'coll'][
'localtax2'] = $x_coll[$my_coll_rate][
'localtax2'];
303 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
304 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
305 $x_both[$my_coll_rate][
'paye'][
'localtax1'] = 0;
306 $x_both[$my_coll_rate][
'paye'][
'localtax2'] = 0;
307 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
308 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
309 foreach ($x_coll[$my_coll_rate][
'facid'] as $id=>$dummy) {
314 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
315 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
316 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
317 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
318 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
319 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
320 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
321 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
322 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
323 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
324 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
325 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
326 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
328 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
329 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
331 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
332 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
333 'localtax1' =>$x_coll[$my_coll_rate][
'localtax1_list'][$id],
334 'localtax2' =>$x_coll[$my_coll_rate][
'localtax2_list'][$id],
341 foreach (array_keys($x_paye) as $my_paye_rate) {
342 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
343 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
344 $x_both[$my_paye_rate][
'paye'][
'localtax1'] = $x_paye[$my_paye_rate][
'localtax1'];
345 $x_both[$my_paye_rate][
'paye'][
'localtax2'] = $x_paye[$my_paye_rate][
'localtax2'];
346 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
347 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
348 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
349 $x_both[$my_paye_rate][
'coll'][
'localtax1'] = 0;
350 $x_both[$my_paye_rate][
'coll'][
'localtax2'] = 0;
352 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
353 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
355 foreach ($x_paye[$my_paye_rate][
'facid'] as $id=>$dummy)
358 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],
378 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
379 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
380 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
381 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
389 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
390 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
391 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
392 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
393 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
394 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
395 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
396 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
397 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
398 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
399 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
400 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
401 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
403 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
404 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
406 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
407 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
408 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
409 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
418 $object = array(&$x_coll, &$x_paye, &$x_both);
419 $parameters[
"mode"] = $modetax;
420 $parameters[
"year"] = $y;
421 $parameters[
"month"] = $m;
422 $parameters[
"type"] =
'localtax'.$localTaxType;
425 $hookmanager->initHooks(array(
'externalbalance'));
426 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
428 if (!is_array($x_coll) && $coll_listbuy == -1)
430 $langs->load(
"errors");
431 print
'<tr><td colspan="5">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
434 if (!is_array($x_paye) && $coll_listbuy == -2)
436 print
'<tr><td colspan="5">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
441 print
'<tr class="oddeven">';
442 print
'<td class="nowrap"><a href="'.DOL_URL_ROOT.
'/compta/localtax/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>';
445 foreach (array_keys($x_coll) as $rate)
447 $subtot_coll_total_ht = 0;
448 $subtot_coll_vat = 0;
450 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields)
453 $ratiopaymentinvoice = 1;
458 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
461 if (!empty($fields[
'ddate_start'])) {
464 if (!empty($fields[
'ddate_end'])) {
468 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
469 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice'))
473 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
474 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
479 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
480 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
481 $subtot_coll_total_ht += $temp_ht;
482 $subtot_coll_vat += $temp_vat;
483 $x_coll_sum += $temp_vat;
486 print
'<td class="nowrap right">'.price(
price2num($x_coll_sum,
'MT')).
'</td>';
489 foreach (array_keys($x_paye) as $rate)
491 $subtot_paye_total_ht = 0;
492 $subtot_paye_vat = 0;
494 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields)
497 $ratiopaymentinvoice = 1;
502 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
505 if (!empty($fields[
'ddate_start'])) {
508 if (!empty($fields[
'ddate_end'])) {
512 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
513 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice'))
517 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
518 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
523 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
524 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
525 $subtot_paye_total_ht += $temp_ht;
526 $subtot_paye_vat += $temp_vat;
527 $x_paye_sum += $temp_vat;
530 print
'<td class="nowrap right">'.price(
price2num($x_paye_sum,
'MT')).
'</td>';
532 $subtotalcoll = $subtotalcoll + $x_coll_sum;
533 $subtotalpaye = $subtotalpaye + $x_paye_sum;
535 $diff = $x_coll_sum - $x_paye_sum;
536 $total = $total + $diff;
537 $subtotal =
price2num($subtotal + $diff,
'MT');
539 print
'<td class="nowrap right">'.price(
price2num($diff,
'MT')).
'</td>'.
"\n";
540 print
"<td> </td>\n";
546 print
'<tr class="liste_total">';
547 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).
'&year='.$y.
'">'.$langs->trans(
"SubTotal").
'</a>:</td>';
548 print
'<td class="nowrap right">'.price(
price2num($subtotalcoll,
'MT')).
'</td>';
549 print
'<td class="nowrap right">'.price(
price2num($subtotalpaye,
'MT')).
'</td>';
550 print
'<td class="nowrap right">'.price(
price2num($subtotal,
'MT')).
'</td>';
551 print
'<td> </td></tr>';
553 $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
556 print
'<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans(
"TotalToPay").
':</td><td class="nowrap right">'.
price(
price2num($total,
'MT')).
'</td>';
557 print
"<td> </td>\n";
563 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
571 print
load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code),
'',
'');
575 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
577 $sql .=
" WHERE f.entity = ".$conf->entity;
578 $sql .=
" AND (f.datev >= '".$db->idate($date_start).
"' AND f.datev <= '".$db->idate($date_end).
"')";
579 $sql .=
" AND localtaxtype=".$localTaxType;
580 $sql .=
" GROUP BY dm";
584 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
585 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
586 $sql .=
" WHERE f.entity = ".$conf->entity;
587 $sql .=
" AND (f.datep >= '".$db->idate($date_start).
"' AND f.datep <= '".$db->idate($date_end).
"')";
588 $sql .=
" AND localtaxtype=".$localTaxType;
589 $sql .=
" GROUP BY dm";
591 $sql .=
" ORDER BY dm ASC, mode ASC";
594 pt($db, $sql, $langs->trans(
"Month"));
597 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.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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.