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"));
38 $localTaxType =
GETPOST(
'localTaxType',
'int');
44 $year_start = $year_current;
46 $year_current = $year;
51 if (empty($date_start) || empty($date_end)) {
58 $date_start =
dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,
false);
83 $modetax = $conf->global->TAX_MODE;
85 $modetax =
GETPOST(
"modetax",
'int');
87 if (empty($modetax)) {
92 $socid =
GETPOST(
'socid',
'int');
94 $socid = $user->socid;
107 function pt($db, $sql, $date)
109 global $conf, $bc, $langs;
111 $result = $db->query($sql);
113 $num = $db->num_rows($result);
116 print
'<table class="noborder centpercent">';
118 print
'<tr class="liste_titre">';
119 print
'<td class="nowrap">'.$date.
'</td>';
120 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
121 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").
'</td>';
133 $obj = $db->fetch_object($result);
137 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
138 print
'<tr class="oddeven">';
139 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
140 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
141 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
148 if ($obj->mode ==
'claimed') {
149 $amountclaimed = $obj->mm;
150 $totalclaimed = $totalclaimed + $amountclaimed;
152 if ($obj->mode ==
'paid') {
153 $amountpaid = $obj->mm;
154 $totalpaid = $totalpaid + $amountpaid;
157 if ($obj->mode ==
'paid') {
158 print
'<tr class="oddeven">';
159 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
160 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
161 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
168 $previousmode = $obj->mode;
169 $previousmonth = $obj->dm;
175 if ($mode ==
'claimed' && !empty($previousmode)) {
176 print
'<tr class="oddeven">';
177 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
178 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
179 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
186 print
'<tr class="liste_total">';
187 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
188 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
189 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
199 if (empty($localTaxType)) {
217 $company_static =
new Societe($db);
220 if ($localTaxType == 1) {
222 $LTSummary =
'LT1Summary';
224 $LTCustomer =
'LT1Customer';
225 $LTSupplier =
'LT1Supplier';
226 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC1;
229 $LTSummary =
'LT2Summary';
231 $LTCustomer =
'LT2Customer';
232 $LTSupplier =
'LT2Supplier';
233 $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC2;
236 $fsearch =
'<!-- hidden fields for form -->';
237 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
238 $fsearch .=
'<input type="hidden" name="localTaxType" value="'.$localTaxType.
'">';
239 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
241 $description = $fsearch;
244 $name = $langs->transcountry($localTaxType == 1 ?
"LT1ReportByMonth" :
"LT2ReportByMonth", $mysoc->country_code);
245 $description .= $langs->trans($LT);
246 $calcmode = $langs->trans(
"LTReportBuildWithOptionDefinedInModule").
' ';
247 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.
'/admin/company.php').
')</span>';
251 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
262 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
268 print
'<div class="fichecenter"><div class="fichethirdleft">';
270 print
load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code),
'',
'');
272 print
'<table class="noborder centpercent">';
273 print
'<tr class="liste_titre">';
274 print
'<td width="30%">'.$langs->trans(
"Year").
" ".$y.
"</td>";
276 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td>';
277 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td>';
280 print
'<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).
'</td><td></td>';
283 print
'<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).
'</td><td></td>';
285 print
'<td class="right">'.$langs->trans(
"TotalToPay").
'</td>';
286 print
"<td> </td>\n";
293 $yend = $tmp[
'year'];
302 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
313 $x_coll =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'sell', $m);
314 $x_paye =
tax_by_rate(($localTaxType == 1 ?
'localtax1' :
'localtax2'), $db, $y, 0, 0, 0, $modetax,
'buy', $m);
318 foreach (array_keys($x_coll) as $my_coll_rate) {
319 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
320 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
321 $x_both[$my_coll_rate][
'coll'][
'localtax1'] = $x_coll[$my_coll_rate][
'localtax1'];
322 $x_both[$my_coll_rate][
'coll'][
'localtax2'] = $x_coll[$my_coll_rate][
'localtax2'];
323 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
324 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
325 $x_both[$my_coll_rate][
'paye'][
'localtax1'] = 0;
326 $x_both[$my_coll_rate][
'paye'][
'localtax2'] = 0;
327 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
328 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
329 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
334 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
335 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
336 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
337 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
338 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
339 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
340 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
341 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
342 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
343 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
344 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
345 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
346 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
348 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
349 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
351 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
352 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
353 'localtax1' =>$x_coll[$my_coll_rate][
'localtax1_list'][$id],
354 'localtax2' =>$x_coll[$my_coll_rate][
'localtax2_list'][$id],
361 foreach (array_keys($x_paye) as $my_paye_rate) {
362 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
363 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
364 $x_both[$my_paye_rate][
'paye'][
'localtax1'] = $x_paye[$my_paye_rate][
'localtax1'];
365 $x_both[$my_paye_rate][
'paye'][
'localtax2'] = $x_paye[$my_paye_rate][
'localtax2'];
366 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
367 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
368 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
369 $x_both[$my_paye_rate][
'coll'][
'localtax1'] = 0;
370 $x_both[$my_paye_rate][
'coll'][
'localtax2'] = 0;
372 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
373 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
375 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
377 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
382 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
383 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
384 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
385 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
386 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
387 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
388 'payment_id' =>$x_paye[$my_paye_rate][
'payment_id'][$id],
389 'payment_amount' =>$x_paye[$my_paye_rate][
'payment_amount'][$id],
390 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
391 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
392 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
393 'ddate_start' =>$x_paye[$my_paye_rate][
'ddate_start'][$id],
394 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
396 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
397 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
398 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
399 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
407 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
408 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
409 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
410 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
411 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
412 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
413 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
414 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
415 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
416 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
417 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
418 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
419 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
421 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
422 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
424 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
425 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
426 'localtax1' =>$x_paye[$my_paye_rate][
'localtax1_list'][$id],
427 'localtax2' =>$x_paye[$my_paye_rate][
'localtax2_list'][$id],
436 $object = array(&$x_coll, &$x_paye, &$x_both);
437 $parameters[
"mode"] = $modetax;
438 $parameters[
"year"] = $y;
439 $parameters[
"month"] = $m;
440 $parameters[
"type"] =
'localtax'.$localTaxType;
443 $hookmanager->initHooks(array(
'externalbalance'));
444 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
447 print
'<tr class="oddeven">';
448 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>';
451 foreach (array_keys($x_coll) as $rate) {
452 $subtot_coll_total_ht = 0;
453 $subtot_coll_vat = 0;
455 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
457 $ratiopaymentinvoice = 1;
461 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
464 if (!empty($fields[
'ddate_start'])) {
467 if (!empty($fields[
'ddate_end'])) {
471 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
472 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
475 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
476 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
481 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
482 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
483 $subtot_coll_total_ht += $temp_ht;
484 $subtot_coll_vat += $temp_vat;
485 $x_coll_sum += $temp_vat;
488 print
'<td class="nowrap right">'.price(
price2num($x_coll_sum,
'MT')).
'</td>';
491 foreach (array_keys($x_paye) as $rate) {
492 $subtot_paye_total_ht = 0;
493 $subtot_paye_vat = 0;
495 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
497 $ratiopaymentinvoice = 1;
501 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
504 if (!empty($fields[
'ddate_start'])) {
507 if (!empty($fields[
'ddate_end'])) {
511 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
512 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
515 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
516 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
521 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
522 $temp_vat = $fields[
'localtax'.$localTaxType] * $ratiopaymentinvoice;
523 $subtot_paye_total_ht += $temp_ht;
524 $subtot_paye_vat += $temp_vat;
525 $x_paye_sum += $temp_vat;
528 print
'<td class="nowrap right">'.price(
price2num($x_paye_sum,
'MT')).
'</td>';
530 $subtotalcoll = $subtotalcoll + $x_coll_sum;
531 $subtotalpaid = $subtotalpaid + $x_paye_sum;
533 $diff = $x_coll_sum - $x_paye_sum;
534 $total = $total + $diff;
535 $subtotal =
price2num($subtotal + $diff,
'MT');
537 print
'<td class="nowrap right">'.price(
price2num($diff,
'MT')).
'</td>'.
"\n";
538 print
"<td> </td>\n";
544 print
'<tr class="liste_total">';
545 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).
'&year='.$y.
'">'.$langs->trans(
"SubTotal").
'</a>:</td>';
546 print
'<td class="nowrap right">'.price(
price2num($subtotalcoll,
'MT')).
'</td>';
547 print
'<td class="nowrap right">'.price(
price2num($subtotalpaid,
'MT')).
'</td>';
548 print
'<td class="nowrap right">'.price(
price2num($subtotal,
'MT')).
'</td>';
549 print
'<td> </td></tr>';
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">';
570 print
load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code),
'',
'');
574 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
575 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
576 $sql .=
" WHERE f.entity = ".$conf->entity;
577 $sql .=
" AND (f.datev >= '".$db->idate($date_start).
"' AND f.datev <= '".$db->idate($date_end).
"')";
578 $sql .=
" AND localtaxtype=".((int) $localTaxType);
579 $sql .=
" GROUP BY dm";
583 $sql .=
"SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
584 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
585 $sql .=
" WHERE f.entity = ".$conf->entity;
586 $sql .=
" AND (f.datep >= '".$db->idate($date_start).
"' AND f.datep <= '".$db->idate($date_end).
"')";
587 $sql .=
" AND localtaxtype=".((int) $localTaxType);
588 $sql .=
" GROUP BY dm";
590 $sql .=
" ORDER BY dm ASC, mode ASC";
593 pt($db, $sql, $langs->trans(
"Month"));
596 print
'</div></div>';
Class to manage third parties objects (customers, suppliers, prospects...)
Put here description of your class.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
pt($db, $sql, $date)
print function
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
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...