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