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