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