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