dolibarr 21.0.0-alpha
quadri_detail.php
1<?php
2/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2006-2007 Yannick Warnier <ywarnier@beeznest.org>
6 * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29global $mysoc;
30
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
43require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
44require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
48
49$local = GETPOSTINT('localTaxType');
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, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
60$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
61// Quarter
62if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
63 $q = GETPOSTINT("q");
64 if (empty($q)) {
65 if (GETPOSTINT("month")) {
66 $date_start = dol_get_first_day($year_start, GETPOSTINT("month"), false);
67 $date_end = dol_get_last_day($year_start, GETPOSTINT("month"), false);
68 } else {
69 $date_start = dol_get_first_day($year_start, !getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
70 if (!getDolGlobalString('MAIN_INFO_VAT_RETURN') || getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 2) {
71 $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
72 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 3) {
73 $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
74 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 1) {
75 $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
76 }
77 }
78 } else {
79 if ($q == 1) {
80 $date_start = dol_get_first_day($year_start, 1, false);
81 $date_end = dol_get_last_day($year_start, 3, false);
82 }
83 if ($q == 2) {
84 $date_start = dol_get_first_day($year_start, 4, false);
85 $date_end = dol_get_last_day($year_start, 6, false);
86 }
87 if ($q == 3) {
88 $date_start = dol_get_first_day($year_start, 7, false);
89 $date_end = dol_get_last_day($year_start, 9, false);
90 }
91 if ($q == 4) {
92 $date_start = dol_get_first_day($year_start, 10, false);
93 $date_end = dol_get_last_day($year_start, 12, false);
94 }
95 }
96}
97
98$min = price2num(GETPOST("min", "alpha"));
99if (empty($min)) {
100 $min = 0;
101}
102
103// Define modetax (0 or 1)
104// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
105//$modetax = $conf->global->TAX_MODE;
106$calc = getDolGlobalString('MAIN_INFO_LOCALTAX_CALC').$local;
107$modetax = getDolGlobalInt('TAX_MODE');
108if (GETPOSTISSET("modetax")) {
109 $modetax = GETPOSTINT("modetax");
110}
111if (empty($modetax)) {
112 $modetax = 0;
113}
114
115// Security check
116$socid = GETPOSTINT('socid');
117if ($user->socid) {
118 $socid = $user->socid;
119}
120$result = restrictedArea($user, 'tax', '', '', 'charges');
121
122if (empty($local)) {
123 accessforbidden('Parameter localTaxType is missing');
124 exit;
125}
126
127
128
129/*
130 * View
131 */
132
133$form = new Form($db);
134$company_static = new Societe($db);
135$invoice_customer = new Facture($db);
136$invoice_supplier = new FactureFournisseur($db);
137$expensereport = new ExpenseReport($db);
138$product_static = new Product($db);
139$payment_static = new Paiement($db);
140$paymentfourn_static = new PaiementFourn($db);
141$paymentexpensereport_static = new PaymentExpenseReport($db);
142
143$morequerystring = '';
144$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
145foreach ($listofparams as $param) {
146 if (GETPOST($param) != '') {
147 $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
148 }
149}
150
151llxHeader('', $langs->trans("LocalTaxReport"), '', '', 0, 0, '', '', $morequerystring);
152
153$fsearch = '<!-- hidden fields for form -->';
154$fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
155$fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
156$fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
157
158$name = $langs->transcountry($local == 1 ? "LT1ReportByQuarters" : "LT2ReportByQuarters", $mysoc->country_code);
159$calcmode = '';
160if ($modetax == 0) {
161 $calcmode = $langs->trans('OptionVATDefault');
162}
163if ($modetax == 1) {
164 $calcmode = $langs->trans('OptionVATDebitOption');
165}
166if ($modetax == 2) {
167 $calcmode = $langs->trans('OptionPaymentForProductAndServices');
168}
169$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
170// Set period
171$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
172$prevyear = $year_start;
173$q = 0;
174$prevquarter = $q;
175if ($prevquarter > 1) {
176 $prevquarter--;
177} else {
178 $prevquarter = 4;
179 $prevyear--;
180}
181$nextyear = $year_start;
182$nextquarter = $q;
183if ($nextquarter < 4) {
184 $nextquarter++;
185} else {
186 $nextquarter = 1;
187 $nextyear++;
188}
189$description = $fsearch;
190$builddate = dol_now();
191
192/*if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'invoice') $description.=$langs->trans("RulesVATDueProducts");
193if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'payment') $description.=$langs->trans("RulesVATInProducts");
194if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'invoice') $description.='<br>'.$langs->trans("RulesVATDueServices");
195if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'payment') $description.='<br>'.$langs->trans("RulesVATInServices");
196if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
197 $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
198}
199if (! empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
200 $description.='<br>'.$langs->trans("SupplierDepositsAreNotIncluded");
201}
202*/
203if (isModEnabled('accounting')) {
204 $description .= $langs->trans("ThisIsAnEstimatedValue");
205}
206
207// Customers invoices
208$elementcust = $langs->trans("CustomersInvoices");
209$productcust = $langs->trans("ProductOrService");
210$amountcust = $langs->trans("AmountHT");
211$vatcust = $langs->trans("VATReceived");
212$namecust = $langs->trans("Name");
213if ($mysoc->tva_assuj) {
214 $vatcust .= ' ('.$langs->trans("StatusToPay").')';
215}
216
217// Suppliers invoices
218$elementsup = $langs->trans("SuppliersInvoices");
219$productsup = $productcust;
220$amountsup = $amountcust;
221$vatsup = $langs->trans("VATPaid");
222$namesup = $namecust;
223if ($mysoc->tva_assuj) {
224 $vatsup .= ' ('.$langs->trans("ToGetBack").')';
225}
226
227$periodlink = '';
228$exportlink = '';
229
230report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
231
232if ($local == 1) {
233 $vatcust = $langs->transcountry("LT1", $mysoc->country_code);
234 $vatsup = $langs->transcountry("LT1", $mysoc->country_code);
235 $vatexpensereport = $langs->transcountry("LT1", $mysoc->country_code);
236} else {
237 $vatcust = $langs->transcountry("LT2", $mysoc->country_code);
238 $vatsup = $langs->transcountry("LT2", $mysoc->country_code);
239 $vatexpensereport = $langs->transcountry("LT2", $mysoc->country_code);
240}
241
242// VAT Received and paid
243print '<div class="div-table-responsive">';
244echo '<table class="noborder centpercent">';
245
246$y = $year_current;
247$total = 0;
248$i = 0;
249$columns = 4;
250
251// Load arrays of datas
252$x_coll = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
253$x_paye = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
254
255if (!is_array($x_coll) || !is_array($x_paye)) {
256 $langs->load("errors");
257 if ($x_coll == -1) {
258 print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
259 } elseif ($x_coll == -2) {
260 print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
261 } else {
262 print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
263 }
264} else {
265 $x_both = array();
266
267 //now, from these two arrays, get another array with one rate per line
268 foreach (array_keys($x_coll) as $my_coll_rate) {
269 $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
270 $x_both[$my_coll_rate]['coll']['localtax'.$local] = $x_coll[$my_coll_rate]['localtax'.$local];
271 $x_both[$my_coll_rate]['paye']['totalht'] = 0;
272 $x_both[$my_coll_rate]['paye']['localtax'.$local] = 0;
273 $x_both[$my_coll_rate]['coll']['links'] = '';
274 $x_both[$my_coll_rate]['coll']['detail'] = array();
275 foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
276 $invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
277 $invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
278 $invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
279 $company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
280 $x_both[$my_coll_rate]['coll']['detail'][] = array(
281 'id' => $x_coll[$my_coll_rate]['facid'][$id],
282 'descr' => $x_coll[$my_coll_rate]['descr'][$id],
283 'pid' => $x_coll[$my_coll_rate]['pid'][$id],
284 'pref' => $x_coll[$my_coll_rate]['pref'][$id],
285 'ptype' => $x_coll[$my_coll_rate]['ptype'][$id],
286 'payment_id' => $x_coll[$my_coll_rate]['payment_id'][$id],
287 'payment_amount' => $x_coll[$my_coll_rate]['payment_amount'][$id],
288 'ftotal_ttc' => $x_coll[$my_coll_rate]['ftotal_ttc'][$id],
289 'dtotal_ttc' => $x_coll[$my_coll_rate]['dtotal_ttc'][$id],
290 'dtype' => $x_coll[$my_coll_rate]['dtype'][$id],
291 'datef' => $x_coll[$my_coll_rate]['datef'][$id],
292 'datep' => $x_coll[$my_coll_rate]['datep'][$id],
293 'company_link' => $company_static->getNomUrl(1, '', 20),
294 'ddate_start' => $x_coll[$my_coll_rate]['ddate_start'][$id],
295 'ddate_end' => $x_coll[$my_coll_rate]['ddate_end'][$id],
296 'totalht' => $x_coll[$my_coll_rate]['totalht_list'][$id],
297 'localtax1' => $x_coll[$my_coll_rate]['localtax1_list'][$id],
298 'localtax2' => $x_coll[$my_coll_rate]['localtax2_list'][$id],
299 'vat' => $x_coll[$my_coll_rate]['vat_list'][$id],
300 'link' => $invoice_customer->getNomUrl(1, '', 12)
301 );
302 }
303 }
304 // tva paid
305 foreach (array_keys($x_paye) as $my_paye_rate) {
306 $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
307 $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
308 if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
309 $x_both[$my_paye_rate]['coll']['totalht'] = 0;
310 $x_both[$my_paye_rate]['coll']['vat'] = 0;
311 }
312 $x_both[$my_paye_rate]['paye']['links'] = '';
313 $x_both[$my_paye_rate]['paye']['detail'] = array();
314
315 foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
316 $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
317 $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
318 $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
319 $x_both[$my_paye_rate]['paye']['detail'][] = array(
320 'id' => $x_paye[$my_paye_rate]['facid'][$id],
321 'descr' => $x_paye[$my_paye_rate]['descr'][$id],
322 'pid' => $x_paye[$my_paye_rate]['pid'][$id],
323 'pref' => $x_paye[$my_paye_rate]['pref'][$id],
324 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
325 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
326 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
327 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
328 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
329 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
330 'datef' => $x_paye[$my_paye_rate]['datef'][$id],
331 'datep' => $x_paye[$my_paye_rate]['datep'][$id],
332 'company_link' => $company_static->getNomUrl(1, '', 20),
333 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
334 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
335 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
336 'localtax1' => $x_paye[$my_paye_rate]['localtax1_list'][$id],
337 'localtax2' => $x_paye[$my_paye_rate]['localtax2_list'][$id],
338 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
339 'link' => $invoice_supplier->getNomUrl(1, '', 12)
340 );
341 }
342 }
343 //now we have an array (x_both) indexed by rates for coll and paye
344
345 //print table headers for this quadri - incomes first
346
347 $x_coll_sum = 0;
348 $x_coll_ht = 0;
349 $x_paye_sum = 0;
350 $x_paye_ht = 0;
351
352 $span = $columns - 1;
353 if ($modetax != 2) {
354 $span += 1;
355 }
356 if ($modetax != 1) {
357 $span += 1;
358 }
359
360 // Customers invoices
361 print '<tr class="liste_titre">';
362 print '<td class="left">'.$elementcust.'</td>';
363 print '<td class="left">'.$productcust.'</td>';
364 if ($modetax != 2) {
365 print '<td class="right">'.$amountcust.'</td>';
366 }
367 if ($modetax != 1) {
368 print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
369 }
370 print '<td class="right">'.$langs->trans("BI").'</td>';
371 print '<td class="right">'.$vatcust.'</td>';
372 print '</tr>';
373
374
375 $LT = 0;
376 $sameLT = false;
377 foreach (array_keys($x_coll) as $rate) {
378 $subtot_coll_total_ht = 0;
379 $subtot_coll_vat = 0;
380
381 if (is_array($x_both[$rate]['coll']['detail'])) {
382 // VAT Rate
383 if ($rate != 0) {
384 print "<tr>";
385 print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
386 print '</tr>'."\n";
387 }
388 foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
389 if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
390 // Define type
391 $type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
392 // Try to enhance type detection using date_start and date_end for free lines where type
393 // was not saved.
394 if (!empty($fields['ddate_start'])) {
395 $type = 1;
396 }
397 if (!empty($fields['ddate_end'])) {
398 $type = 1;
399 }
400
401
402 print '<tr class="oddeven">';
403
404 // Ref
405 print '<td class="nowrap left">'.$fields['link'].'</td>';
406
407 // Description
408 print '<td class="left">';
409 if ($fields['pid']) {
410 $product_static->id = $fields['pid'];
411 $product_static->ref = $fields['pref'];
412 $product_static->type = $fields['ptype'];
413 print $product_static->getNomUrl(1);
414 if (dol_string_nohtmltag($fields['descr'])) {
415 print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
416 }
417 } else {
418 if ($type) {
419 $text = img_object($langs->trans('Service'), 'service');
420 } else {
421 $text = img_object($langs->trans('Product'), 'product');
422 }
423 if (preg_match('/^\‍((.*)\‍)$/', $fields['descr'], $reg)) {
424 if ($reg[1] == 'DEPOSIT') {
425 $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
426 } elseif ($reg[1] == 'CREDIT_NOTE') {
427 $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
428 } else {
429 $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
430 }
431 }
432 print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
433
434 // Show range
435 print_date_range($fields['ddate_start'], $fields['ddate_end']);
436 }
437 print '</td>';
438
439 // Total HT
440 if ($modetax != 2) {
441 print '<td class="nowrap right">';
442 print price($fields['totalht']);
443 if (price2num($fields['ftotal_ttc'])) {
444 $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
445 }
446 print '</td>';
447 }
448
449 // Payment
450 $ratiopaymentinvoice = 1;
451 if ($modetax != 1) {
452 if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
453 $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
454 }
455 print '<td class="nowrap right">';
456 if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
457 $payment_static->id = $fields['payment_id'];
458 print $payment_static->getNomUrl(2);
459 }
460 if ($type == 0) {
461 print $langs->trans("NotUsedForGoods");
462 } else {
463 print price($fields['payment_amount']);
464 if (isset($fields['payment_amount'])) {
465 print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
466 }
467 }
468 print '</td>';
469 }
470
471 // Total collected
472 print '<td class="nowrap right">';
473 $temp_ht = $fields['totalht'];
474 if ($type == 1) {
475 $temp_ht = (float) $fields['totalht'] * $ratiopaymentinvoice;
476 }
477 print price(price2num($temp_ht, 'MT'));
478 print '</td>';
479
480 // Localtax
481 print '<td class="nowrap right">';
482 $temp_vat = $local == 1 ? $fields['localtax1'] : $fields['localtax2'];
483 print price(price2num($temp_vat, 'MT'));
484 //print price($fields['vat']);
485 print '</td>';
486 print '</tr>';
487
488 $subtot_coll_total_ht += $temp_ht;
489 $subtot_coll_vat += $temp_vat;
490 $x_coll_sum += $temp_vat;
491 }
492 }
493 }
494
495 // Total customers for this vat rate
496 print '<tr class="liste_total">';
497 print '<td></td>';
498 print '<td class="right">'.$langs->trans("Total").':</td>';
499 if ($modetax != 1) {
500 print '<td class="nowrap right">&nbsp;</td>';
501 print '<td class="right">&nbsp;</td>';
502 }
503 print '<td class="right"><span class="amount">'.price(price2num($subtot_coll_total_ht, 'MT')).'</span></td>';
504 print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_coll_vat, 'MT')).'</span></td>';
505 print '</tr>';
506 }
507
508 if (count($x_coll) == 0) { // Show a total line if nothing shown
509 print '<tr class="liste_total">';
510 print '<td>&nbsp;</td>';
511 print '<td class="right">'.$langs->trans("Total").':</td>';
512 if ($modetax == 0) {
513 print '<td class="nowrap right">&nbsp;</td>';
514 print '<td class="right">&nbsp;</td>';
515 }
516 print '<td class="right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
517 print '<td class="nowrap right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
518 print '</tr>';
519 }
520
521 // Blank line
522 print '<tr><td colspan="'.($span + 1).'">&nbsp;</td></tr>';
523 //print '</table>';
524 $diff = $x_coll_sum;
525
526 //echo '<table class="noborder centpercent">';
527 //print table headers for this quadri - expenses now
528 print '<tr class="liste_titre">';
529 print '<td class="left">'.$elementsup.'</td>';
530 print '<td class="left">'.$productsup.'</td>';
531 if ($modetax != 1) {
532 print '<td class="right">'.$amountsup.'</td>';
533 print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
534 }
535 print '<td class="right">'.$langs->trans("BI").'</td>';
536 print '<td class="right">'.$vatsup.'</td>';
537 print '</tr>'."\n";
538
539 foreach (array_keys($x_paye) as $rate) {
540 $subtot_paye_total_ht = 0;
541 $subtot_paye_vat = 0;
542
543 if (is_array($x_both[$rate]['paye']['detail'])) {
544 if ($rate != 0) {
545 print "<tr>";
546 print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
547 print '</tr>'."\n";
548 }
549 foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
550 if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
551 // Define type
552 $type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
553 // Try to enhance type detection using date_start and date_end for free lines where type
554 // was not saved.
555 if (!empty($fields['ddate_start'])) {
556 $type = 1;
557 }
558 if (!empty($fields['ddate_end'])) {
559 $type = 1;
560 }
561
562
563 print '<tr class="oddeven">';
564
565 // Ref
566 print '<td class="nowrap left">'.$fields['link'].'</td>';
567
568 // Description
569 print '<td class="left">';
570 if ($fields['pid']) {
571 $product_static->id = $fields['pid'];
572 $product_static->ref = $fields['pref'];
573 $product_static->type = $fields['ptype'];
574 print $product_static->getNomUrl(1);
575 if (dol_string_nohtmltag($fields['descr'])) {
576 print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
577 }
578 } else {
579 if ($type) {
580 $text = img_object($langs->trans('Service'), 'service');
581 } else {
582 $text = img_object($langs->trans('Product'), 'product');
583 }
584 print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
585
586 // Show range
587 print_date_range($fields['ddate_start'], $fields['ddate_end']);
588 }
589 print '</td>';
590
591 // Total HT
592 if ($modetax != 2) {
593 print '<td class="nowrap right">';
594 print price($fields['totalht']);
595 if (price2num($fields['ftotal_ttc'])) {
596 //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
597 $ratiolineinvoice = ((float) $fields['dtotal_ttc'] / (float) $fields['ftotal_ttc']);
598 //print ' ('.round($ratiolineinvoice*100,2).'%)';
599 }
600 print '</td>';
601 }
602
603 // Payment
604 $ratiopaymentinvoice = 1;
605 if ($modetax != 1) {
606 print '<td class="nowrap right">';
607 if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
608 $ratiopaymentinvoice = ($fields['payment_amount'] / (float) $fields['ftotal_ttc']);
609 }
610 if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
611 $paymentfourn_static->id = $fields['payment_id'];
612 print $paymentfourn_static->getNomUrl(2);
613 }
614 if ($type == 0) {
615 print $langs->trans("NA");
616 } else {
617 print price(price2num($fields['payment_amount'], 'MT'));
618 if (isset($fields['payment_amount'])) {
619 print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
620 }
621 }
622 print '</td>';
623 }
624
625 // VAT paid
626 print '<td class="nowrap right">';
627 $temp_ht = (float) $fields['totalht'] * $ratiopaymentinvoice;
628 print price(price2num($temp_ht, 'MT'), 1);
629 print '</td>';
630
631 // Localtax
632 print '<td class="nowrap right">';
633 $temp_vat = ($local == 1 ? $fields['localtax1'] : $fields['localtax2']) * $ratiopaymentinvoice;
634 print price(price2num($temp_vat, 'MT'), 1);
635 //print price($fields['vat']);
636 print '</td>';
637 print '</tr>';
638
639 $subtot_paye_total_ht += $temp_ht;
640 $subtot_paye_vat += $temp_vat;
641 $x_paye_sum += $temp_vat;
642 }
643 }
644 }
645
646 // Total suppliers for this vat rate
647 print '<tr class="liste_total">';
648 print '<td>&nbsp;</td>';
649 print '<td class="right">'.$langs->trans("Total").':</td>';
650 if ($modetax != 1) {
651 print '<td class="nowrap right">&nbsp;</td>';
652 print '<td class="right">&nbsp;</td>';
653 }
654 print '<td class="right"><span class="amount">'.price(price2num($subtot_paye_total_ht, 'MT')).'</span></td>';
655 print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_paye_vat, 'MT')).'</span></td>';
656 print '</tr>';
657 }
658
659 if (count($x_paye) == 0) { // Show a total line if nothing shown
660 print '<tr class="liste_total">';
661 print '<td>&nbsp;</td>';
662 print '<td class="right">'.$langs->trans("Total").':</td>';
663 if ($modetax != 1) {
664 print '<td class="nowrap right">&nbsp;</td>';
665 print '<td class="right">&nbsp;</td>';
666 }
667 print '<td class="right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
668 print '<td class="nowrap right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
669 print '</tr>';
670 }
671
672 // Total to pay
673 $diff = $x_coll_sum - $x_paye_sum;
674 print '<tr class="liste_total">';
675 print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
676 print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
677 print "</tr>\n";
678
679 $i++;
680}
681
682print '</table>';
683print '</div>';
684
685// End of page
686llxFooter();
687$db->close();
$id
Definition account.php:39
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 Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of expense report.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:596
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:615
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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