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