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