dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
4  * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 
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';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
37 
38 $localTaxType = GETPOST('localTaxType', 'int');
39 
40 // Date range
41 $year = GETPOST("year", "int");
42 if (empty($year)) {
43  $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
44  $year_start = $year_current;
45 } else {
46  $year_current = $year;
47  $year_start = $year;
48 }
49 $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
50 $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
51 if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
52  $q = GETPOST("q", "int");
53  if (empty($q)) {
54  if (GETPOST("month", "int")) {
55  $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false);
56  $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
57  } else {
58  $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false);
59  $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
60  }
61  } else {
62  if ($q == 1) {
63  $date_start = dol_get_first_day($year_start, 1, false);
64  $date_end = dol_get_last_day($year_start, 3, false);
65  }
66  if ($q == 2) {
67  $date_start = dol_get_first_day($year_start, 4, false);
68  $date_end = dol_get_last_day($year_start, 6, false);
69  }
70  if ($q == 3) {
71  $date_start = dol_get_first_day($year_start, 7, false);
72  $date_end = dol_get_last_day($year_start, 9, false);
73  }
74  if ($q == 4) {
75  $date_start = dol_get_first_day($year_start, 10, false);
76  $date_end = dol_get_last_day($year_start, 12, false);
77  }
78  }
79 }
80 
81 // Define modetax (0 or 1)
82 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
83 $modetax = $conf->global->TAX_MODE;
84 if (GETPOSTISSET("modetax")) {
85  $modetax = GETPOST("modetax", 'int');
86 }
87 if (empty($modetax)) {
88  $modetax = 0;
89 }
90 
91 // Security check
92 $socid = GETPOST('socid', 'int');
93 if ($user->socid) {
94  $socid = $user->socid;
95 }
96 $result = restrictedArea($user, 'tax', '', '', 'charges');
97 
98 
107 function pt($db, $sql, $date)
108 {
109  global $conf, $bc, $langs;
110 
111  $result = $db->query($sql);
112  if ($result) {
113  $num = $db->num_rows($result);
114  $i = 0;
115  $total = 0;
116  print '<table class="noborder centpercent">';
117 
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>';
122  print "</tr>\n";
123 
124  $totalclaimed = 0;
125  $totalpaid = 0;
126  $amountclaimed = 0;
127  $amountpaid = 0;
128  $previousmonth = '';
129  $previousmode = '';
130  $mode = '';
131 
132  while ($i < $num) {
133  $obj = $db->fetch_object($result);
134  $mode = $obj->mode;
135 
136  //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode;
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";
142  print "</tr>\n";
143 
144  $amountclaimed = 0;
145  $amountpaid = 0;
146  }
147 
148  if ($obj->mode == 'claimed') {
149  $amountclaimed = $obj->mm;
150  $totalclaimed = $totalclaimed + $amountclaimed;
151  }
152  if ($obj->mode == 'paid') {
153  $amountpaid = $obj->mm;
154  $totalpaid = $totalpaid + $amountpaid;
155  }
156 
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";
162  print "</tr>\n";
163  $amountclaimed = 0;
164  $amountpaid = 0;
165  $previousmode = '';
166  $previousmonth = '';
167  } else {
168  $previousmode = $obj->mode;
169  $previousmonth = $obj->dm;
170  }
171 
172  $i++;
173  }
174 
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";
180  print "</tr>\n";
181 
182  $amountclaimed = 0;
183  $amountpaid = 0;
184  }
185 
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>';
190  print "</tr>";
191 
192  print "</table>";
193  $db->free($result);
194  } else {
195  dol_print_error($db);
196  }
197 }
198 
199 if (empty($localTaxType)) {
200  accessforbidden('Parameter localTaxType is missing');
201  exit;
202 }
203 
204 
205 /*
206  * Actions
207  */
208 
209 // None
210 
211 
212 /*
213  * View
214  */
215 
216 $form = new Form($db);
217 $company_static = new Societe($db);
218 $tva = new Tva($db);
219 
220 if ($localTaxType == 1) {
221  $LT = 'LT1';
222  $LTSummary = 'LT1Summary';
223  $LTPaid = 'LT1Paid';
224  $LTCustomer = 'LT1Customer';
225  $LTSupplier = 'LT1Supplier';
226  $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC1;
227 } else {
228  $LT = 'LT2';
229  $LTSummary = 'LT2Summary';
230  $LTPaid = 'LT2Paid';
231  $LTCustomer = 'LT2Customer';
232  $LTSupplier = 'LT2Supplier';
233  $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC2;
234 }
235 
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.'">';
240 
241 $description = $fsearch;
242 
243 // Show report header
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>';
248 
249 //if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue");
250 
251 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
252 
253 $builddate = dol_now();
254 
255 
256 llxHeader('', $name);
257 
258 //$textprevyear="<a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current-1) . "\">".img_previous()."</a>";
259 //$textnextyear=" <a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current+1) . "\">".img_next()."</a>";
260 //print load_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear", 'bill');
261 
262 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
263 //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
264 
265 
266 print '<br>';
267 
268 print '<div class="fichecenter"><div class="fichethirdleft">';
269 
270 print load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code), '', '');
271 
272 print '<table class="noborder centpercent">';
273 print '<tr class="liste_titre">';
274 print '<td width="30%">'.$langs->trans("Year")." ".$y."</td>";
275 if ($CalcLT == 0) {
276  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td>';
277  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td>';
278 }
279 if ($CalcLT == 1) {
280  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td><td></td>';
281 }
282 if ($CalcLT == 2) {
283  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td><td></td>';
284 }
285 print '<td class="right">'.$langs->trans("TotalToPay").'</td>';
286 print "<td>&nbsp;</td>\n";
287 print "</tr>\n";
288 
289 $tmp = dol_getdate($date_start);
290 $y = $tmp['year'];
291 $m = $tmp['mon'];
292 $tmp = dol_getdate($date_end);
293 $yend = $tmp['year'];
294 $mend = $tmp['mon'];
295 
296 $total = 0;
297 $subtotalcoll = 0;
298 $subtotalpaid = 0;
299 $subtotal = 0;
300 $i = 0;
301 $mcursor = 0;
302 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
303  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
304  if ($m == 13) {
305  $y++;
306  }
307  if ($m > 12) {
308  $m -= 12;
309  }
310  $mcursor++;
311 
312  // Get array with details of each line
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);
315 
316  $x_both = array();
317  //now, from these two arrays, get another array with one rate per line
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) {
330  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
331  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
332  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
333  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
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],
347  //'company_link'=>$company_static->getNomUrl(1,'',20),
348  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
349  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
350 
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],
355  //'link' =>$invoice_customer->getNomUrl(1,'',12)
356  );
357  }
358  }
359 
360  // tva paid
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;
371  }
372  $x_both[$my_paye_rate]['paye']['links'] = '';
373  $x_both[$my_paye_rate]['paye']['detail'] = array();
374 
375  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
376  // ExpenseReport
377  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
378  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
379  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
380  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
381 
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],
395 
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],
400  //'link' =>$expensereport->getNomUrl(1)
401  );
402  } else {
403  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
404  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
405  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
406  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$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],
420  //'company_link'=>$company_static->getNomUrl(1,'',20),
421  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
422  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
423 
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],
428  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
429  );
430  }
431  }
432  }
433  //now we have an array (x_both) indexed by rates for coll and paye
434 
435  $action = "tva";
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;
441 
442  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
443  $hookmanager->initHooks(array('externalbalance'));
444  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
445 
446 
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>';
449 
450  $x_coll_sum = 0;
451  foreach (array_keys($x_coll) as $rate) {
452  $subtot_coll_total_ht = 0;
453  $subtot_coll_vat = 0;
454 
455  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
456  // Payment
457  $ratiopaymentinvoice = 1;
458  if ($modetax != 1) {
459  // Define type
460  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
461  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
462  // Try to enhance type detection using date_start and date_end for free lines where type
463  // was not saved.
464  if (!empty($fields['ddate_start'])) {
465  $type = 1;
466  }
467  if (!empty($fields['ddate_end'])) {
468  $type = 1;
469  }
470 
471  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
472  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
473  //print $langs->trans("NA");
474  } else {
475  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
476  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
477  }
478  }
479  }
480  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
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;
486  }
487  }
488  print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>';
489 
490  $x_paye_sum = 0;
491  foreach (array_keys($x_paye) as $rate) {
492  $subtot_paye_total_ht = 0;
493  $subtot_paye_vat = 0;
494 
495  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
496  // Payment
497  $ratiopaymentinvoice = 1;
498  if ($modetax != 1) {
499  // Define type
500  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
501  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
502  // Try to enhance type detection using date_start and date_end for free lines where type
503  // was not saved.
504  if (!empty($fields['ddate_start'])) {
505  $type = 1;
506  }
507  if (!empty($fields['ddate_end'])) {
508  $type = 1;
509  }
510 
511  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
512  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
513  //print $langs->trans("NA");
514  } else {
515  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
516  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
517  }
518  }
519  }
520  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
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;
526  }
527  }
528  print '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>';
529 
530  $subtotalcoll = $subtotalcoll + $x_coll_sum;
531  $subtotalpaid = $subtotalpaid + $x_paye_sum;
532 
533  $diff = $x_coll_sum - $x_paye_sum;
534  $total = $total + $diff;
535  $subtotal = price2num($subtotal + $diff, 'MT');
536 
537  print '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n";
538  print "<td>&nbsp;</td>\n";
539  print "</tr>\n";
540 
541  $i++;
542  $m++;
543  if ($i > 2) {
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>&nbsp;</td></tr>';
550  $i = 0;
551  $subtotalcoll = 0;
552  $subtotalpaid = 0;
553  $subtotal = 0;
554  }
555 }
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>&nbsp;</td>\n";
558 print '</tr>';
559 
560 print '</table>';
561 
562 
563 print '</div><div class="fichetwothirdright">';
564 
565 
566 /*
567  * Paid
568  */
569 
570 print load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code), '', '');
571 
572 $sql = '';
573 
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";
580 
581 $sql .= " UNION ";
582 
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";
589 
590 $sql .= " ORDER BY dm ASC, mode ASC";
591 //print $sql;
592 
593 pt($db, $sql, $langs->trans("Month"));
594 
595 
596 print '</div></div>';
597 
598 // End of page
599 llxFooter();
600 $db->close();
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Put here description of your class.
Definition: tva.class.php:36
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
pt($db, $sql, $date)
print function
Definition: index.php:107
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:575
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
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.
llxFooter()
Footer empty.
Definition: index.php:71
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.
Definition: index.php:63
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
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...
Definition: tax.lib.php:699