dolibarr  16.0.5
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 if (! empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
197  $description.='<br>'.$langs->trans("SupplierDepositsAreNotIncluded");
198 }
199 */
200 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
201  $description .= $langs->trans("ThisIsAnEstimatedValue");
202 }
203 
204 // Customers invoices
205 $elementcust = $langs->trans("CustomersInvoices");
206 $productcust = $langs->trans("ProductOrService");
207 $amountcust = $langs->trans("AmountHT");
208 $vatcust = $langs->trans("VATReceived");
209 $namecust = $langs->trans("Name");
210 if ($mysoc->tva_assuj) {
211  $vatcust .= ' ('.$langs->trans("StatusToPay").')';
212 }
213 
214 // Suppliers invoices
215 $elementsup = $langs->trans("SuppliersInvoices");
216 $productsup = $productcust;
217 $amountsup = $amountcust;
218 $vatsup = $langs->trans("VATPaid");
219 $namesup = $namecust;
220 if ($mysoc->tva_assuj) {
221  $vatsup .= ' ('.$langs->trans("ToGetBack").')';
222 }
223 
224 
225 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
226 
227 if ($local == 1) {
228  $vatcust = $langs->transcountry("LT1", $mysoc->country_code);
229  $vatsup = $langs->transcountry("LT1", $mysoc->country_code);
230  $vatexpensereport = $langs->transcountry("LT1", $mysoc->country_code);
231 } else {
232  $vatcust = $langs->transcountry("LT2", $mysoc->country_code);
233  $vatsup = $langs->transcountry("LT2", $mysoc->country_code);
234  $vatexpensereport = $langs->transcountry("LT2", $mysoc->country_code);
235 }
236 
237 // VAT Received and paid
238 print '<div class="div-table-responsive">';
239 echo '<table class="noborder centpercent">';
240 
241 $y = $year_current;
242 $total = 0;
243 $i = 0;
244 $columns = 4;
245 
246 // Load arrays of datas
247 $x_coll = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
248 $x_paye = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
249 
250 if (!is_array($x_coll) || !is_array($x_paye)) {
251  $langs->load("errors");
252  if ($x_coll == -1) {
253  print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
254  } elseif ($x_coll == -2) {
255  print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
256  } else {
257  print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
258  }
259 } else {
260  $x_both = array();
261 
262  //now, from these two arrays, get another array with one rate per line
263  foreach (array_keys($x_coll) as $my_coll_rate) {
264  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
265  $x_both[$my_coll_rate]['coll']['localtax'.$local] = $x_coll[$my_coll_rate]['localtax'.$local];
266  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
267  $x_both[$my_coll_rate]['paye']['localtax'.$local] = 0;
268  $x_both[$my_coll_rate]['coll']['links'] = '';
269  $x_both[$my_coll_rate]['coll']['detail'] = array();
270  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
271  $invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
272  $invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
273  $invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
274  $company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
275  $x_both[$my_coll_rate]['coll']['detail'][] = array(
276  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
277  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
278  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
279  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
280  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
281  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
282  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
283  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
284  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
285  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
286  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
287  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
288  'company_link'=>$company_static->getNomUrl(1, '', 20),
289  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
290  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
291  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
292  'localtax1'=> $x_coll[$my_coll_rate]['localtax1_list'][$id],
293  'localtax2'=> $x_coll[$my_coll_rate]['localtax2_list'][$id],
294  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
295  'link' =>$invoice_customer->getNomUrl(1, '', 12)
296  );
297  }
298  }
299  // tva paid
300  foreach (array_keys($x_paye) as $my_paye_rate) {
301  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
302  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
303  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
304  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
305  $x_both[$my_paye_rate]['coll']['vat'] = 0;
306  }
307  $x_both[$my_paye_rate]['paye']['links'] = '';
308  $x_both[$my_paye_rate]['paye']['detail'] = array();
309 
310  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
311  $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
312  $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
313  $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
314  $x_both[$my_paye_rate]['paye']['detail'][] = array(
315  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
316  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
317  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
318  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
319  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
320  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
321  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
322  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
323  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
324  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
325  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
326  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
327  'company_link'=>$company_static->getNomUrl(1, '', 20),
328  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
329  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
330  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
331  'localtax1'=> $x_paye[$my_paye_rate]['localtax1_list'][$id],
332  'localtax2'=> $x_paye[$my_paye_rate]['localtax2_list'][$id],
333  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
334  'link' =>$invoice_supplier->getNomUrl(1, '', 12)
335  );
336  }
337  }
338  //now we have an array (x_both) indexed by rates for coll and paye
339 
340  //print table headers for this quadri - incomes first
341 
342  $x_coll_sum = 0;
343  $x_coll_ht = 0;
344  $x_paye_sum = 0;
345  $x_paye_ht = 0;
346 
347  $span = $columns - 1;
348  if ($modetax != 2) {
349  $span += 1;
350  }
351  if ($modetax != 1) {
352  $span += 1;
353  }
354 
355  // Customers invoices
356  print '<tr class="liste_titre">';
357  print '<td class="left">'.$elementcust.'</td>';
358  print '<td class="left">'.$productcust.'</td>';
359  if ($modetax != 2) {
360  print '<td class="right">'.$amountcust.'</td>';
361  }
362  if ($modetax != 1) {
363  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
364  }
365  print '<td class="right">'.$langs->trans("BI").'</td>';
366  print '<td class="right">'.$vatcust.'</td>';
367  print '</tr>';
368 
369 
370  $LT = 0;
371  $sameLT = false;
372  foreach (array_keys($x_coll) as $rate) {
373  $subtot_coll_total_ht = 0;
374  $subtot_coll_vat = 0;
375 
376  if (is_array($x_both[$rate]['coll']['detail'])) {
377  // VAT Rate
378  if ($rate != 0) {
379  print "<tr>";
380  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
381  print '</tr>'."\n";
382  }
383  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
384  if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
385  // Define type
386  $type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
387  // Try to enhance type detection using date_start and date_end for free lines where type
388  // was not saved.
389  if (!empty($fields['ddate_start'])) {
390  $type = 1;
391  }
392  if (!empty($fields['ddate_end'])) {
393  $type = 1;
394  }
395 
396 
397  print '<tr class="oddeven">';
398 
399  // Ref
400  print '<td class="nowrap left">'.$fields['link'].'</td>';
401 
402  // Description
403  print '<td class="left">';
404  if ($fields['pid']) {
405  $product_static->id = $fields['pid'];
406  $product_static->ref = $fields['pref'];
407  $product_static->type = $fields['ptype'];
408  print $product_static->getNomUrl(1);
409  if (dol_string_nohtmltag($fields['descr'])) {
410  print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
411  }
412  } else {
413  if ($type) {
414  $text = img_object($langs->trans('Service'), 'service');
415  } else {
416  $text = img_object($langs->trans('Product'), 'product');
417  }
418  if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
419  if ($reg[1] == 'DEPOSIT') {
420  $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
421  } elseif ($reg[1] == 'CREDIT_NOTE') {
422  $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
423  } else {
424  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
425  }
426  }
427  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
428 
429  // Show range
430  print_date_range($fields['ddate_start'], $fields['ddate_end']);
431  }
432  print '</td>';
433 
434  // Total HT
435  if ($modetax != 2) {
436  print '<td class="nowrap right">';
437  print price($fields['totalht']);
438  if (price2num($fields['ftotal_ttc'])) {
439  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
440  }
441  print '</td>';
442  }
443 
444  // Payment
445  $ratiopaymentinvoice = 1;
446  if ($modetax != 1) {
447  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
448  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
449  }
450  print '<td class="nowrap right">';
451  if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
452  $payment_static->id = $fields['payment_id'];
453  print $payment_static->getNomUrl(2);
454  }
455  if ($type == 0) {
456  print $langs->trans("NotUsedForGoods");
457  } else {
458  print price($fields['payment_amount']);
459  if (isset($fields['payment_amount'])) {
460  print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
461  }
462  }
463  print '</td>';
464  }
465 
466  // Total collected
467  print '<td class="nowrap right">';
468  $temp_ht = $fields['totalht'];
469  if ($type == 1) {
470  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
471  }
472  print price(price2num($temp_ht, 'MT'));
473  print '</td>';
474 
475  // Localtax
476  print '<td class="nowrap right">';
477  $temp_vat = $local == 1 ? $fields['localtax1'] : $fields['localtax2'];
478  print price(price2num($temp_vat, 'MT'));
479  //print price($fields['vat']);
480  print '</td>';
481  print '</tr>';
482 
483  $subtot_coll_total_ht += $temp_ht;
484  $subtot_coll_vat += $temp_vat;
485  $x_coll_sum += $temp_vat;
486  }
487  }
488  }
489 
490  // Total customers for this vat rate
491  print '<tr class="liste_total">';
492  print '<td></td>';
493  print '<td class="right">'.$langs->trans("Total").':</td>';
494  if ($modetax != 1) {
495  print '<td class="nowrap right">&nbsp;</td>';
496  print '<td class="right">&nbsp;</td>';
497  }
498  print '<td class="right"><span class="amount">'.price(price2num($subtot_coll_total_ht, 'MT')).'</span></td>';
499  print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_coll_vat, 'MT')).'</span></td>';
500  print '</tr>';
501  }
502 
503  if (count($x_coll) == 0) { // Show a total ine if nothing shown
504  print '<tr class="liste_total">';
505  print '<td>&nbsp;</td>';
506  print '<td class="right">'.$langs->trans("Total").':</td>';
507  if ($modetax == 0) {
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(0, 'MT')).'</span></td>';
512  print '<td class="nowrap right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
513  print '</tr>';
514  }
515 
516  // Blank line
517  print '<tr><td colspan="'.($span + 1).'">&nbsp;</td></tr>';
518  //print '</table>';
519  $diff = $x_coll_sum;
520 
521  //echo '<table class="noborder centpercent">';
522  //print table headers for this quadri - expenses now
523  print '<tr class="liste_titre">';
524  print '<td class="left">'.$elementsup.'</td>';
525  print '<td class="left">'.$productsup.'</td>';
526  if ($modetax != 1) {
527  print '<td class="right">'.$amountsup.'</td>';
528  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
529  }
530  print '<td class="right">'.$langs->trans("BI").'</td>';
531  print '<td class="right">'.$vatsup.'</td>';
532  print '</tr>'."\n";
533 
534  foreach (array_keys($x_paye) as $rate) {
535  $subtot_paye_total_ht = 0;
536  $subtot_paye_vat = 0;
537 
538  if (is_array($x_both[$rate]['paye']['detail'])) {
539  if ($rate != 0) {
540  print "<tr>";
541  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
542  print '</tr>'."\n";
543  }
544  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
545  if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
546  // Define type
547  $type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
548  // Try to enhance type detection using date_start and date_end for free lines where type
549  // was not saved.
550  if (!empty($fields['ddate_start'])) {
551  $type = 1;
552  }
553  if (!empty($fields['ddate_end'])) {
554  $type = 1;
555  }
556 
557 
558  print '<tr class="oddeven">';
559 
560  // Ref
561  print '<td class="nowrap left">'.$fields['link'].'</td>';
562 
563  // Description
564  print '<td class="left">';
565  if ($fields['pid']) {
566  $product_static->id = $fields['pid'];
567  $product_static->ref = $fields['pref'];
568  $product_static->type = $fields['ptype'];
569  print $product_static->getNomUrl(1);
570  if (dol_string_nohtmltag($fields['descr'])) {
571  print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
572  }
573  } else {
574  if ($type) {
575  $text = img_object($langs->trans('Service'), 'service');
576  } else {
577  $text = img_object($langs->trans('Product'), 'product');
578  }
579  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
580 
581  // Show range
582  print_date_range($fields['ddate_start'], $fields['ddate_end']);
583  }
584  print '</td>';
585 
586  // Total HT
587  if ($modetax != 2) {
588  print '<td class="nowrap right">';
589  print price($fields['totalht']);
590  if (price2num($fields['ftotal_ttc'])) {
591  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
592  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
593  //print ' ('.round($ratiolineinvoice*100,2).'%)';
594  }
595  print '</td>';
596  }
597 
598  // Payment
599  $ratiopaymentinvoice = 1;
600  if ($modetax != 1) {
601  print '<td class="nowrap right">';
602  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
603  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
604  }
605  if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
606  $paymentfourn_static->id = $fields['payment_id'];
607  print $paymentfourn_static->getNomUrl(2);
608  }
609  if ($type == 0) {
610  print $langs->trans("NA");
611  } else {
612  print price(price2num($fields['payment_amount'], 'MT'));
613  if (isset($fields['payment_amount'])) {
614  print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
615  }
616  }
617  print '</td>';
618  }
619 
620  // VAT paid
621  print '<td class="nowrap right">';
622  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
623  print price(price2num($temp_ht, 'MT'), 1);
624  print '</td>';
625 
626  // Localtax
627  print '<td class="nowrap right">';
628  $temp_vat = ($local == 1 ? $fields['localtax1'] : $fields['localtax2']) * $ratiopaymentinvoice;
629  print price(price2num($temp_vat, 'MT'), 1);
630  //print price($fields['vat']);
631  print '</td>';
632  print '</tr>';
633 
634  $subtot_paye_total_ht += $temp_ht;
635  $subtot_paye_vat += $temp_vat;
636  $x_paye_sum += $temp_vat;
637  }
638  }
639  }
640 
641  // Total suppliers for this vat rate
642  print '<tr class="liste_total">';
643  print '<td>&nbsp;</td>';
644  print '<td class="right">'.$langs->trans("Total").':</td>';
645  if ($modetax != 1) {
646  print '<td class="nowrap right">&nbsp;</td>';
647  print '<td class="right">&nbsp;</td>';
648  }
649  print '<td class="right"><span class="amount">'.price(price2num($subtot_paye_total_ht, 'MT')).'</span></td>';
650  print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_paye_vat, 'MT')).'</span></td>';
651  print '</tr>';
652  }
653 
654  if (count($x_paye) == 0) { // Show a total line if nothing shown
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(0, 'MT')).'</span></td>';
663  print '<td class="nowrap right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
664  print '</tr>';
665  }
666 
667  // Total to pay
668  $diff = $x_coll_sum - $x_paye_sum;
669  print '<tr class="liste_total">';
670  print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
671  print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
672  print "</tr>\n";
673 
674  $i++;
675 }
676 
677 print '</table>';
678 print '</div>';
679 
680 // End of page
681 llxFooter();
682 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_trunc
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.
Definition: functions.lib.php:3791
restrictedArea
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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
tax_by_rate
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
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5647
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6680
PaymentExpenseReport
Class to manage payments of expense report.
Definition: paymentexpensereport.class.php:31
dol_get_first_day
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
dol_get_last_day
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
print_date_range
print_date_range($date_start, $date_end, $format='', $outputlangs='')
Format output for start and end date.
Definition: functions.lib.php:8002
PaiementFourn
Class to manage payments for supplier invoices.
Definition: paiementfourn.class.php:37
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4197
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2831
price
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.
Definition: functions.lib.php:5527
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2743
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
llxHeader
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
vatrate
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.
Definition: functions.lib.php:5478