dolibarr  19.0.0-dev
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 = getDolGlobalString('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 = getDolGlobalString('MAIN_INFO_LOCALTAX_CALC1');
227 } else {
228  $LT = 'LT2';
229  $LTSummary = 'LT2Summary';
230  $LTPaid = 'LT2Paid';
231  $LTCustomer = 'LT2Customer';
232  $LTSupplier = 'LT2Supplier';
233  $CalcLT = getDolGlobalString('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 $periodlink = '';
263 $exportlink = '';
264 
265 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
266 //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
267 
268 
269 print '<br>';
270 
271 print '<div class="fichecenter"><div class="fichethirdleft">';
272 
273 print load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code), '', '');
274 
275 print '<table class="noborder centpercent">';
276 print '<tr class="liste_titre">';
277 print '<td>'.$langs->trans("Year")."</td>";
278 if ($CalcLT == 0) {
279  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td>';
280  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td>';
281 }
282 if ($CalcLT == 1) {
283  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td><td></td>';
284 }
285 if ($CalcLT == 2) {
286  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td><td></td>';
287 }
288 print '<td class="right">'.$langs->trans("TotalToPay").'</td>';
289 print "<td>&nbsp;</td>\n";
290 print "</tr>\n";
291 
292 $tmp = dol_getdate($date_start);
293 $y = $tmp['year'];
294 $m = $tmp['mon'];
295 $tmp = dol_getdate($date_end);
296 $yend = $tmp['year'];
297 $mend = $tmp['mon'];
298 
299 $total = 0;
300 $subtotalcoll = 0;
301 $subtotalpaid = 0;
302 $subtotal = 0;
303 $i = 0;
304 $mcursor = 0;
305 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
306  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
307  if ($m == 13) {
308  $y++;
309  }
310  if ($m > 12) {
311  $m -= 12;
312  }
313  $mcursor++;
314 
315  // Get array with details of each line
316  $x_coll = tax_by_rate(($localTaxType == 1 ? 'localtax1' : 'localtax2'), $db, $y, 0, 0, 0, $modetax, 'sell', $m);
317  $x_paye = tax_by_rate(($localTaxType == 1 ? 'localtax1' : 'localtax2'), $db, $y, 0, 0, 0, $modetax, 'buy', $m);
318 
319  $x_both = array();
320  //now, from these two arrays, get another array with one rate per line
321  foreach (array_keys($x_coll) as $my_coll_rate) {
322  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
323  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
324  $x_both[$my_coll_rate]['coll']['localtax1'] = $x_coll[$my_coll_rate]['localtax1'];
325  $x_both[$my_coll_rate]['coll']['localtax2'] = $x_coll[$my_coll_rate]['localtax2'];
326  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
327  $x_both[$my_coll_rate]['paye']['vat'] = 0;
328  $x_both[$my_coll_rate]['paye']['localtax1'] = 0;
329  $x_both[$my_coll_rate]['paye']['localtax2'] = 0;
330  $x_both[$my_coll_rate]['coll']['links'] = '';
331  $x_both[$my_coll_rate]['coll']['detail'] = array();
332  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
333  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
334  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
335  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
336  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
337  $x_both[$my_coll_rate]['coll']['detail'][] = array(
338  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
339  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
340  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
341  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
342  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
343  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
344  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
345  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
346  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
347  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
348  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
349  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
350  //'company_link'=>$company_static->getNomUrl(1,'',20),
351  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
352  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
353 
354  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
355  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
356  'localtax1' =>$x_coll[$my_coll_rate]['localtax1_list'][$id],
357  'localtax2' =>$x_coll[$my_coll_rate]['localtax2_list'][$id],
358  //'link' =>$invoice_customer->getNomUrl(1,'',12)
359  );
360  }
361  }
362 
363  // tva paid
364  foreach (array_keys($x_paye) as $my_paye_rate) {
365  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
366  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
367  $x_both[$my_paye_rate]['paye']['localtax1'] = $x_paye[$my_paye_rate]['localtax1'];
368  $x_both[$my_paye_rate]['paye']['localtax2'] = $x_paye[$my_paye_rate]['localtax2'];
369  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
370  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
371  $x_both[$my_paye_rate]['coll']['vat'] = 0;
372  $x_both[$my_paye_rate]['coll']['localtax1'] = 0;
373  $x_both[$my_paye_rate]['coll']['localtax2'] = 0;
374  }
375  $x_both[$my_paye_rate]['paye']['links'] = '';
376  $x_both[$my_paye_rate]['paye']['detail'] = array();
377 
378  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
379  // ExpenseReport
380  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
381  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
382  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
383  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
384 
385  $x_both[$my_paye_rate]['paye']['detail'][] = array(
386  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
387  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
388  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
389  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
390  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
391  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
392  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
393  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
394  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
395  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
396  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
397  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
398 
399  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
400  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
401  'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
402  'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
403  //'link' =>$expensereport->getNomUrl(1)
404  );
405  } else {
406  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
407  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
408  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
409  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
410  $x_both[$my_paye_rate]['paye']['detail'][] = array(
411  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
412  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
413  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
414  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
415  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
416  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
417  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
418  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
419  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
420  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
421  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
422  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
423  //'company_link'=>$company_static->getNomUrl(1,'',20),
424  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
425  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
426 
427  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
428  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
429  'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
430  'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
431  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
432  );
433  }
434  }
435  }
436  //now we have an array (x_both) indexed by rates for coll and paye
437 
438  $action = "tva";
439  $object = array(&$x_coll, &$x_paye, &$x_both);
440  $parameters["mode"] = $modetax;
441  $parameters["year"] = $y;
442  $parameters["month"] = $m;
443  $parameters["type"] = 'localtax'.$localTaxType;
444 
445  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
446  $hookmanager->initHooks(array('externalbalance'));
447  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
448 
449 
450  print '<tr class="oddeven">';
451  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>';
452 
453  $x_coll_sum = 0;
454  foreach (array_keys($x_coll) as $rate) {
455  $subtot_coll_total_ht = 0;
456  $subtot_coll_vat = 0;
457 
458  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
459  // Payment
460  $ratiopaymentinvoice = 1;
461  if ($modetax != 1) {
462  // Define type
463  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
464  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
465  // Try to enhance type detection using date_start and date_end for free lines where type
466  // was not saved.
467  if (!empty($fields['ddate_start'])) {
468  $type = 1;
469  }
470  if (!empty($fields['ddate_end'])) {
471  $type = 1;
472  }
473 
474  if (($type == 0 && getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'invoice')
475  || ($type == 1 && getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'invoice')) {
476  //print $langs->trans("NA");
477  } else {
478  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
479  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
480  }
481  }
482  }
483  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
484  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
485  $temp_vat = $fields['localtax'.$localTaxType] * $ratiopaymentinvoice;
486  $subtot_coll_total_ht += $temp_ht;
487  $subtot_coll_vat += $temp_vat;
488  $x_coll_sum += $temp_vat;
489  }
490  }
491  print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>';
492 
493  $x_paye_sum = 0;
494  foreach (array_keys($x_paye) as $rate) {
495  $subtot_paye_total_ht = 0;
496  $subtot_paye_vat = 0;
497 
498  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
499  // Payment
500  $ratiopaymentinvoice = 1;
501  if ($modetax != 1) {
502  // Define type
503  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
504  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
505  // Try to enhance type detection using date_start and date_end for free lines where type
506  // was not saved.
507  if (!empty($fields['ddate_start'])) {
508  $type = 1;
509  }
510  if (!empty($fields['ddate_end'])) {
511  $type = 1;
512  }
513 
514  if (($type == 0 && getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'invoice')
515  || ($type == 1 && getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'invoice')) {
516  //print $langs->trans("NA");
517  } else {
518  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
519  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
520  }
521  }
522  }
523  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
524  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
525  $temp_vat = $fields['localtax'.$localTaxType] * $ratiopaymentinvoice;
526  $subtot_paye_total_ht += $temp_ht;
527  $subtot_paye_vat += $temp_vat;
528  $x_paye_sum += $temp_vat;
529  }
530  }
531  print '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>';
532 
533  $subtotalcoll = $subtotalcoll + $x_coll_sum;
534  $subtotalpaid = $subtotalpaid + $x_paye_sum;
535 
536  $diff = $x_coll_sum - $x_paye_sum;
537  $total = $total + $diff;
538  $subtotal = price2num($subtotal + $diff, 'MT');
539 
540  print '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n";
541  print "<td>&nbsp;</td>\n";
542  print "</tr>\n";
543 
544  $i++;
545  $m++;
546  if ($i > 2) {
547  print '<tr class="liste_total">';
548  print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
549  print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>';
550  print '<td class="nowrap right">'.price(price2num($subtotalpaid, 'MT')).'</td>';
551  print '<td class="nowrap right">'.price(price2num($subtotal, 'MT')).'</td>';
552  print '<td>&nbsp;</td></tr>';
553  $i = 0;
554  $subtotalcoll = 0;
555  $subtotalpaid = 0;
556  $subtotal = 0;
557  }
558 }
559 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap right">'.price(price2num($total, 'MT')).'</td>';
560 print "<td>&nbsp;</td>\n";
561 print '</tr>';
562 
563 print '</table>';
564 
565 
566 print '</div><div class="fichetwothirdright">';
567 
568 
569 /*
570  * Paid
571  */
572 
573 print load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code), '', '');
574 
575 $sql = '';
576 
577 $sql .= "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
578 $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f";
579 $sql .= " WHERE f.entity = ".$conf->entity;
580 $sql .= " AND (f.datev >= '".$db->idate($date_start)."' AND f.datev <= '".$db->idate($date_end)."')";
581 $sql .= " AND localtaxtype=".((int) $localTaxType);
582 $sql .= " GROUP BY dm";
583 
584 $sql .= " UNION ";
585 
586 $sql .= "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
587 $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f";
588 $sql .= " WHERE f.entity = ".$conf->entity;
589 $sql .= " AND (f.datep >= '".$db->idate($date_start)."' AND f.datep <= '".$db->idate($date_end)."')";
590 $sql .= " AND localtaxtype=".((int) $localTaxType);
591 $sql .= " GROUP BY dm";
592 
593 $sql .= " ORDER BY dm ASC, mode ASC";
594 //print $sql;
595 
596 pt($db, $sql, $langs->trans("Month"));
597 
598 
599 print '</div></div>';
600 
601 // End of page
602 llxFooter();
603 $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(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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:576
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:595
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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:701