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