dolibarr  16.0.5
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 
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';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
35 
36 $localTaxType = GETPOST('localTaxType', 'int');
37 
38 // Date range
39 $year = GETPOST("year", "int");
40 if (empty($year)) {
41  $year_current = strftime("%Y", dol_now());
42  $year_start = $year_current;
43 } else {
44  $year_current = $year;
45  $year_start = $year;
46 }
47 $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
48 $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
49 if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
50  $q = GETPOST("q", "int");
51  if (empty($q)) {
52  if (GETPOST("month", "int")) {
53  $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false);
54  $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
55  } else {
56  $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false);
57  $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
58  }
59  } else {
60  if ($q == 1) {
61  $date_start = dol_get_first_day($year_start, 1, false);
62  $date_end = dol_get_last_day($year_start, 3, false);
63  }
64  if ($q == 2) {
65  $date_start = dol_get_first_day($year_start, 4, false);
66  $date_end = dol_get_last_day($year_start, 6, false);
67  }
68  if ($q == 3) {
69  $date_start = dol_get_first_day($year_start, 7, false);
70  $date_end = dol_get_last_day($year_start, 9, false);
71  }
72  if ($q == 4) {
73  $date_start = dol_get_first_day($year_start, 10, false);
74  $date_end = dol_get_last_day($year_start, 12, false);
75  }
76  }
77 }
78 
79 // Define modetax (0 or 1)
80 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
81 $modetax = $conf->global->TAX_MODE;
82 if (GETPOSTISSET("modetax")) {
83  $modetax = GETPOST("modetax", 'int');
84 }
85 if (empty($modetax)) {
86  $modetax = 0;
87 }
88 
89 // Security check
90 $socid = GETPOST('socid', 'int');
91 if ($user->socid) {
92  $socid = $user->socid;
93 }
94 $result = restrictedArea($user, 'tax', '', '', 'charges');
95 
96 
105 function pt($db, $sql, $date)
106 {
107  global $conf, $bc, $langs;
108 
109  $result = $db->query($sql);
110  if ($result) {
111  $num = $db->num_rows($result);
112  $i = 0;
113  $total = 0;
114  print '<table class="noborder centpercent">';
115 
116  print '<tr class="liste_titre">';
117  print '<td class="nowrap">'.$date.'</td>';
118  print '<td class="right">'.$langs->trans("ClaimedForThisPeriod").'</td>';
119  print '<td class="right">'.$langs->trans("PaidDuringThisPeriod").'</td>';
120  print "</tr>\n";
121 
122  $totalclaimed = 0;
123  $totalpaid = 0;
124  $amountclaimed = 0;
125  $amountpaid = 0;
126  $previousmonth = '';
127  $previousmode = '';
128  $mode = '';
129 
130  while ($i < $num) {
131  $obj = $db->fetch_object($result);
132  $mode = $obj->mode;
133 
134  //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode;
135  if ($obj->mode == 'claimed' && !empty($previousmode)) {
136  print '<tr class="oddeven">';
137  print '<td class="nowrap">'.$previousmonth."</td>\n";
138  print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
139  print '<td class="nowrap right">'.price($amountpaid)."</td>\n";
140  print "</tr>\n";
141 
142  $amountclaimed = 0;
143  $amountpaid = 0;
144  }
145 
146  if ($obj->mode == 'claimed') {
147  $amountclaimed = $obj->mm;
148  $totalclaimed = $totalclaimed + $amountclaimed;
149  }
150  if ($obj->mode == 'paid') {
151  $amountpaid = $obj->mm;
152  $totalpaid = $totalpaid + $amountpaid;
153  }
154 
155  if ($obj->mode == 'paid') {
156  print '<tr class="oddeven">';
157  print '<td class="nowrap">'.$obj->dm."</td>\n";
158  print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
159  print '<td class="nowrap right">'.price($amountpaid)."</td>\n";
160  print "</tr>\n";
161  $amountclaimed = 0;
162  $amountpaid = 0;
163  $previousmode = '';
164  $previousmonth = '';
165  } else {
166  $previousmode = $obj->mode;
167  $previousmonth = $obj->dm;
168  }
169 
170  $i++;
171  }
172 
173  if ($mode == 'claimed' && !empty($previousmode)) {
174  print '<tr class="oddeven">';
175  print '<td class="nowrap">'.$previousmonth."</td>\n";
176  print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
177  print '<td class="nowrap right">'.price($amountpaid)."</td>\n";
178  print "</tr>\n";
179 
180  $amountclaimed = 0;
181  $amountpaid = 0;
182  }
183 
184  print '<tr class="liste_total">';
185  print '<td class="right">'.$langs->trans("Total").'</td>';
186  print '<td class="nowrap right">'.price($totalclaimed).'</td>';
187  print '<td class="nowrap right">'.price($totalpaid).'</td>';
188  print "</tr>";
189 
190  print "</table>";
191  $db->free($result);
192  } else {
193  dol_print_error($db);
194  }
195 }
196 
197 if (empty($localTaxType)) {
198  accessforbidden('Parameter localTaxType is missing');
199  exit;
200 }
201 
202 
203 /*
204  * Actions
205  */
206 
207 // None
208 
209 
210 /*
211  * View
212  */
213 
214 $form = new Form($db);
215 $company_static = new Societe($db);
216 $tva = new Tva($db);
217 
218 if ($localTaxType == 1) {
219  $LT = 'LT1';
220  $LTSummary = 'LT1Summary';
221  $LTPaid = 'LT1Paid';
222  $LTCustomer = 'LT1Customer';
223  $LTSupplier = 'LT1Supplier';
224  $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC1;
225 } else {
226  $LT = 'LT2';
227  $LTSummary = 'LT2Summary';
228  $LTPaid = 'LT2Paid';
229  $LTCustomer = 'LT2Customer';
230  $LTSupplier = 'LT2Supplier';
231  $CalcLT = $conf->global->MAIN_INFO_LOCALTAX_CALC2;
232 }
233 
234 $fsearch = '<!-- hidden fields for form -->';
235 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
236 $fsearch .= '<input type="hidden" name="localTaxType" value="'.$localTaxType.'">';
237 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
238 
239 $description = $fsearch;
240 
241 // Show report header
242 $name = $langs->transcountry($localTaxType == 1 ? "LT1ReportByMonth" : "LT2ReportByMonth", $mysoc->country_code);
243 $description .= $langs->trans($LT);
244 $calcmode = $langs->trans("LTReportBuildWithOptionDefinedInModule").' ';
245 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
246 
247 //if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue");
248 
249 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
250 
251 $builddate = dol_now();
252 
253 
254 llxHeader('', $name);
255 
256 //$textprevyear="<a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current-1) . "\">".img_previous()."</a>";
257 //$textnextyear=" <a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current+1) . "\">".img_next()."</a>";
258 //print load_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear", 'bill');
259 
260 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
261 //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
262 
263 
264 print '<br>';
265 
266 print '<div class="fichecenter"><div class="fichethirdleft">';
267 
268 print load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code), '', '');
269 
270 print '<table class="noborder centpercent">';
271 print '<tr class="liste_titre">';
272 print '<td width="30%">'.$langs->trans("Year")." ".$y."</td>";
273 if ($CalcLT == 0) {
274  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td>';
275  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td>';
276 }
277 if ($CalcLT == 1) {
278  print '<td class="right">'.$langs->transcountry($LTSupplier, $mysoc->country_code).'</td><td></td>';
279 }
280 if ($CalcLT == 2) {
281  print '<td class="right">'.$langs->transcountry($LTCustomer, $mysoc->country_code).'</td><td></td>';
282 }
283 print '<td class="right">'.$langs->trans("TotalToPay").'</td>';
284 print "<td>&nbsp;</td>\n";
285 print "</tr>\n";
286 
287 $tmp = dol_getdate($date_start);
288 $y = $tmp['year'];
289 $m = $tmp['mon'];
290 $tmp = dol_getdate($date_end);
291 $yend = $tmp['year'];
292 $mend = $tmp['mon'];
293 
294 $total = 0;
295 $subtotalcoll = 0;
296 $subtotalpaid = 0;
297 $subtotal = 0;
298 $i = 0;
299 $mcursor = 0;
300 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
301  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
302  if ($m == 13) {
303  $y++;
304  }
305  if ($m > 12) {
306  $m -= 12;
307  }
308  $mcursor++;
309 
310  // Get array with details of each line
311  $x_coll = tax_by_rate(($localTaxType == 1 ? 'localtax1' : 'localtax2'), $db, $y, 0, 0, 0, $modetax, 'sell', $m);
312  $x_paye = tax_by_rate(($localTaxType == 1 ? 'localtax1' : 'localtax2'), $db, $y, 0, 0, 0, $modetax, 'buy', $m);
313 
314  $x_both = array();
315  //now, from these two arrays, get another array with one rate per line
316  foreach (array_keys($x_coll) as $my_coll_rate) {
317  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
318  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
319  $x_both[$my_coll_rate]['coll']['localtax1'] = $x_coll[$my_coll_rate]['localtax1'];
320  $x_both[$my_coll_rate]['coll']['localtax2'] = $x_coll[$my_coll_rate]['localtax2'];
321  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
322  $x_both[$my_coll_rate]['paye']['vat'] = 0;
323  $x_both[$my_coll_rate]['paye']['localtax1'] = 0;
324  $x_both[$my_coll_rate]['paye']['localtax2'] = 0;
325  $x_both[$my_coll_rate]['coll']['links'] = '';
326  $x_both[$my_coll_rate]['coll']['detail'] = array();
327  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
328  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
329  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
330  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
331  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
332  $x_both[$my_coll_rate]['coll']['detail'][] = array(
333  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
334  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
335  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
336  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
337  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
338  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
339  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
340  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
341  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
342  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
343  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
344  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
345  //'company_link'=>$company_static->getNomUrl(1,'',20),
346  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
347  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
348 
349  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
350  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
351  'localtax1' =>$x_coll[$my_coll_rate]['localtax1_list'][$id],
352  'localtax2' =>$x_coll[$my_coll_rate]['localtax2_list'][$id],
353  //'link' =>$invoice_customer->getNomUrl(1,'',12)
354  );
355  }
356  }
357 
358  // tva paid
359  foreach (array_keys($x_paye) as $my_paye_rate) {
360  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
361  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
362  $x_both[$my_paye_rate]['paye']['localtax1'] = $x_paye[$my_paye_rate]['localtax1'];
363  $x_both[$my_paye_rate]['paye']['localtax2'] = $x_paye[$my_paye_rate]['localtax2'];
364  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
365  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
366  $x_both[$my_paye_rate]['coll']['vat'] = 0;
367  $x_both[$my_paye_rate]['coll']['localtax1'] = 0;
368  $x_both[$my_paye_rate]['coll']['localtax2'] = 0;
369  }
370  $x_both[$my_paye_rate]['paye']['links'] = '';
371  $x_both[$my_paye_rate]['paye']['detail'] = array();
372 
373  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
374  // ExpenseReport
375  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
376  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
377  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
378  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
379 
380  $x_both[$my_paye_rate]['paye']['detail'][] = array(
381  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
382  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
383  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
384  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
385  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
386  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
387  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
388  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
389  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
390  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
391  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
392  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
393 
394  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
395  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
396  'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
397  'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
398  //'link' =>$expensereport->getNomUrl(1)
399  );
400  } else {
401  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
402  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
403  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
404  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
405  $x_both[$my_paye_rate]['paye']['detail'][] = array(
406  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
407  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
408  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
409  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
410  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
411  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
412  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
413  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
414  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
415  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
416  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
417  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
418  //'company_link'=>$company_static->getNomUrl(1,'',20),
419  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
420  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
421 
422  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
423  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
424  'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
425  'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
426  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
427  );
428  }
429  }
430  }
431  //now we have an array (x_both) indexed by rates for coll and paye
432 
433  $action = "tva";
434  $object = array(&$x_coll, &$x_paye, &$x_both);
435  $parameters["mode"] = $modetax;
436  $parameters["year"] = $y;
437  $parameters["month"] = $m;
438  $parameters["type"] = 'localtax'.$localTaxType;
439 
440  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
441  $hookmanager->initHooks(array('externalbalance'));
442  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
443 
444  if (!is_array($x_coll) && $coll_listbuy == -1) {
445  $langs->load("errors");
446  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
447  break;
448  }
449  if (!is_array($x_paye) && $coll_listbuy == -2) {
450  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
451  break;
452  }
453 
454 
455  print '<tr class="oddeven">';
456  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>';
457 
458  $x_coll_sum = 0;
459  foreach (array_keys($x_coll) as $rate) {
460  $subtot_coll_total_ht = 0;
461  $subtot_coll_vat = 0;
462 
463  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
464  // Payment
465  $ratiopaymentinvoice = 1;
466  if ($modetax != 1) {
467  // Define type
468  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
469  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
470  // Try to enhance type detection using date_start and date_end for free lines where type
471  // was not saved.
472  if (!empty($fields['ddate_start'])) {
473  $type = 1;
474  }
475  if (!empty($fields['ddate_end'])) {
476  $type = 1;
477  }
478 
479  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
480  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
481  //print $langs->trans("NA");
482  } else {
483  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
484  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
485  }
486  }
487  }
488  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
489  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
490  $temp_vat = $fields['localtax'.$localTaxType] * $ratiopaymentinvoice;
491  $subtot_coll_total_ht += $temp_ht;
492  $subtot_coll_vat += $temp_vat;
493  $x_coll_sum += $temp_vat;
494  }
495  }
496  print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>';
497 
498  $x_paye_sum = 0;
499  foreach (array_keys($x_paye) as $rate) {
500  $subtot_paye_total_ht = 0;
501  $subtot_paye_vat = 0;
502 
503  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
504  // Payment
505  $ratiopaymentinvoice = 1;
506  if ($modetax != 1) {
507  // Define type
508  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
509  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
510  // Try to enhance type detection using date_start and date_end for free lines where type
511  // was not saved.
512  if (!empty($fields['ddate_start'])) {
513  $type = 1;
514  }
515  if (!empty($fields['ddate_end'])) {
516  $type = 1;
517  }
518 
519  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
520  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
521  //print $langs->trans("NA");
522  } else {
523  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
524  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
525  }
526  }
527  }
528  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
529  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
530  $temp_vat = $fields['localtax'.$localTaxType] * $ratiopaymentinvoice;
531  $subtot_paye_total_ht += $temp_ht;
532  $subtot_paye_vat += $temp_vat;
533  $x_paye_sum += $temp_vat;
534  }
535  }
536  print '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>';
537 
538  $subtotalcoll = $subtotalcoll + $x_coll_sum;
539  $subtotalpaid = $subtotalpaid + $x_paye_sum;
540 
541  $diff = $x_coll_sum - $x_paye_sum;
542  $total = $total + $diff;
543  $subtotal = price2num($subtotal + $diff, 'MT');
544 
545  print '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n";
546  print "<td>&nbsp;</td>\n";
547  print "</tr>\n";
548 
549  $i++;
550  $m++;
551  if ($i > 2) {
552  print '<tr class="liste_total">';
553  print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
554  print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>';
555  print '<td class="nowrap right">'.price(price2num($subtotalpaid, 'MT')).'</td>';
556  print '<td class="nowrap right">'.price(price2num($subtotal, 'MT')).'</td>';
557  print '<td>&nbsp;</td></tr>';
558  $i = 0;
559  $subtotalcoll = 0;
560  $subtotalpaid = 0;
561  $subtotal = 0;
562  }
563 }
564 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap right">'.price(price2num($total, 'MT')).'</td>';
565 print "<td>&nbsp;</td>\n";
566 print '</tr>';
567 
568 print '</table>';
569 
570 
571 print '</div><div class="fichetwothirdright">';
572 
573 
574 /*
575  * Paid
576  */
577 
578 print load_fiche_titre($langs->transcountry($LTPaid, $mysoc->country_code), '', '');
579 
580 $sql = '';
581 
582 $sql .= "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
583 $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f";
584 $sql .= " WHERE f.entity = ".$conf->entity;
585 $sql .= " AND (f.datev >= '".$db->idate($date_start)."' AND f.datev <= '".$db->idate($date_end)."')";
586 $sql .= " AND localtaxtype=".((int) $localTaxType);
587 $sql .= " GROUP BY dm";
588 
589 $sql .= " UNION ";
590 
591 $sql .= "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
592 $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f";
593 $sql .= " WHERE f.entity = ".$conf->entity;
594 $sql .= " AND (f.datep >= '".$db->idate($date_start)."' AND f.datep <= '".$db->idate($date_end)."')";
595 $sql .= " AND localtaxtype=".((int) $localTaxType);
596 $sql .= " GROUP BY dm";
597 
598 $sql .= " ORDER BY dm ASC, mode ASC";
599 //print $sql;
600 
601 pt($db, $sql, $langs->trans("Month"));
602 
603 
604 print '</div></div>';
605 
606 // End of page
607 llxFooter();
608 $db->close();
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
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.
Definition: security.lib.php:234
tax_by_rate
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
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
llxHeader
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
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
pt
pt($db, $sql, $date)
print function
Definition: index.php:105
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
Tva
Put here description of your class.
Definition: tva.class.php:35