dolibarr  13.0.2
quadri_detail.php
Go to the documentation of this file.
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-2015 Yannick Warnier <ywarnier@beeznest.org>
6  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
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 $now = dol_now();
48 $current_date = dol_getdate($now);
49 if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
50 
51 // Date range
52 $year = GETPOST("year", "int");
53 if (empty($year))
54 {
55  $year_current = $current_date['year'];
56  $year_start = $year_current;
57 } else {
58  $year_current = $year;
59  $year_start = $year;
60 }
61 $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
62 $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
63 // Set default period if not defined
64 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
65 {
66  $q = GETPOST("q", "int");
67  if (empty($q))
68  {
69  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 {
70  if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter
71  $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm');
72  $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
73  } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat
74  if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) {
75  if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year
76  $year_start--;
77  }
78  } else {
79  if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year
80  $year_start--;
81  }
82  }
83  $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false);
84  $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
85  } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month
86  $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm');
87  $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
88  }
89  }
90  } else {
91  if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
92  if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
93  if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
94  if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
95  }
96 }
97 
98 $min = price2num(GETPOST("min", "alpha"));
99 if (empty($min)) $min = 0;
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 if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
105 if (empty($modetax)) $modetax = 0;
106 
107 // Security check
108 $socid = GETPOST('socid', 'int');
109 if ($user->socid) $socid = $user->socid;
110 $result = restrictedArea($user, 'tax', '', '', 'charges');
111 
112 
113 
114 /*
115  * View
116  */
117 
118 $form = new Form($db);
119 $company_static = new Societe($db);
120 $invoice_customer = new Facture($db);
121 $invoice_supplier = new FactureFournisseur($db);
122 $expensereport = new ExpenseReport($db);
123 $product_static = new Product($db);
124 $payment_static = new Paiement($db);
125 $paymentfourn_static = new PaiementFourn($db);
126 $paymentexpensereport_static = new PaymentExpenseReport($db);
127 
128 $morequerystring = '';
129 $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
130 foreach ($listofparams as $param)
131 {
132  if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
133 }
134 
135 $title = $langs->trans("VATReport")." ".dol_print_date($date_start)." -> ".dol_print_date($date_end);
136 llxHeader('', $title, '', '', 0, 0, '', '', $morequerystring);
137 
138 
139 //print load_fiche_titre($langs->trans("VAT"),"");
140 
141 //$fsearch.='<br>';
142 $fsearch = '<!-- hidden fields for form -->';
143 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
144 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
145 //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
146 //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
147 
148 
149 // Show report header
150 $name = $langs->trans("VATReportByRates");
151 $calcmode = '';
152 if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault');
153 if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption');
154 if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices');
155 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
156 // Set period
157 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
158 $prevyear = $year_start; $prevquarter = $q;
159 if ($prevquarter > 1) {
160  $prevquarter--;
161 } else {
162  $prevquarter = 4;
163  $prevyear--;
164 }
165 $nextyear = $year_start;
166 $nextquarter = $q;
167 if ($nextquarter < 4) {
168  $nextquarter++;
169 } else {
170  $nextquarter = 1;
171  $nextyear++;
172 }
173 $description .= $fsearch;
174 $builddate = dol_now();
175 
176 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description .= $langs->trans("RulesVATDueProducts");
177 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description .= $langs->trans("RulesVATInProducts");
178 if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description .= '<br>'.$langs->trans("RulesVATDueServices");
179 if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description .= '<br>'.$langs->trans("RulesVATInServices");
180 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
181  $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
182 }
183 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
184 
185 // Customers invoices
186 $elementcust = $langs->trans("CustomersInvoices");
187 $productcust = $langs->trans("ProductOrService");
188 $amountcust = $langs->trans("AmountHT");
189 $vatcust = $langs->trans("VATReceived");
190 $namecust = $langs->trans("Name");
191 if ($mysoc->tva_assuj) {
192  $vatcust .= ' ('.$langs->trans("VATToPay").')';
193 }
194 
195 // Suppliers invoices
196 $elementsup = $langs->trans("SuppliersInvoices");
197 $productsup = $productcust;
198 $amountsup = $amountcust;
199 $vatsup = $langs->trans("VATPaid");
200 $namesup = $namecust;
201 if ($mysoc->tva_assuj) {
202  $vatsup .= ' ('.$langs->trans("ToGetBack").')';
203 }
204 
205 $optioncss = GETPOST('optioncss');
206 if ($optioncss != "print") {
207  report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
208 }
209 
210 $vatcust = $langs->trans("VATReceived");
211 $vatsup = $langs->trans("VATPaid");
212 $vatexpensereport = $langs->trans("VATPaid");
213 
214 
215 // VAT Received and paid
216 print '<div class="div-table-responsive">';
217 print '<table class="noborder centpercent">';
218 
219 $y = $year_current;
220 $total = 0;
221 $i = 0;
222 $columns = 5;
223 
224 // Load arrays of datas
225 $x_coll = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
226 $x_paye = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
227 
228 if (!is_array($x_coll) || !is_array($x_paye))
229 {
230  $langs->load("errors");
231  if ($x_coll == -1) {
232  print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
233  } elseif ($x_coll == -2) {
234  print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
235  } else {
236  print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
237  }
238 } else {
239  $x_both = array();
240  //now, from these two arrays, get another array with one rate per line
241  foreach (array_keys($x_coll) as $my_coll_rate)
242  {
243  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
244  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
245  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
246  $x_both[$my_coll_rate]['paye']['vat'] = 0;
247  $x_both[$my_coll_rate]['coll']['links'] = '';
248  $x_both[$my_coll_rate]['coll']['detail'] = array();
249  foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
250  $invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
251  $invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
252  $invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
253  $company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
254  $x_both[$my_coll_rate]['coll']['detail'][] = array(
255  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
256  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
257  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
258  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
259  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
260  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
261  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
262  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
263  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
264  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
265  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
266  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
267  'company_link'=>$company_static->getNomUrl(1, '', 20),
268  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
269  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
270  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
271  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
272  'link' =>$invoice_customer->getNomUrl(1, '', 12)
273  );
274  }
275  }
276  // tva paid
277  foreach (array_keys($x_paye) as $my_paye_rate) {
278  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
279  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
280  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
281  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
282  $x_both[$my_paye_rate]['coll']['vat'] = 0;
283  }
284  $x_both[$my_paye_rate]['paye']['links'] = '';
285  $x_both[$my_paye_rate]['paye']['detail'] = array();
286 
287  foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
288  {
289  // ExpenseReport
290  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
291  {
292  $expensereport->id = $x_paye[$my_paye_rate]['facid'][$id];
293  $expensereport->ref = $x_paye[$my_paye_rate]['facnum'][$id];
294  $expensereport->type = $x_paye[$my_paye_rate]['type'][$id];
295 
296  $x_both[$my_paye_rate]['paye']['detail'][] = array(
297  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
298  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
299  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
300  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
301  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
302  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
303  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
304  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
305  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
306  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
307  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
308  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
309  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
310  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
311  'link' =>$expensereport->getNomUrl(1)
312  );
313  } else {
314  $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
315  $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
316  $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
317  $company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
318  $x_both[$my_paye_rate]['paye']['detail'][] = array(
319  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
320  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
321  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
322  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
323  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
324  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
325  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
326  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
327  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
328  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
329  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
330  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
331  'company_link'=>$company_static->getNomUrl(1, '', 20),
332  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
333  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
334  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
335  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
336  'link' =>$invoice_supplier->getNomUrl(1, '', 12)
337  );
338  }
339  }
340  }
341  //now we have an array (x_both) indexed by rates for coll and paye
342 
343 
344  //print table headers for this quadri - incomes first
345 
346  $x_coll_sum = 0;
347  $x_coll_ht = 0;
348  $x_paye_sum = 0;
349  $x_paye_ht = 0;
350 
351  $span = $columns;
352  if ($modetax != 1) $span += 2;
353 
354  //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
355 
356  // Customers invoices
357  print '<tr class="liste_titre">';
358  print '<td class="left">'.$elementcust.'</td>';
359  print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
360  if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
361  else print '<td></td>';
362  print '<td class="left">'.$namecust.'</td>';
363  print '<td class="left">'.$productcust.'</td>';
364  if ($modetax != 1)
365  {
366  print '<td class="right">'.$amountcust.'</td>';
367  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
368  }
369  print '<td class="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
370  print '<td class="right">'.$vatcust.'</td>';
371  print '</tr>';
372 
373  $action = "tvadetail";
374  $parameters["mode"] = $modetax;
375  $parameters["start"] = $date_start;
376  $parameters["end"] = $date_end;
377  $parameters["type"] = 'vat';
378 
379  $object = array(&$x_coll, &$x_paye, &$x_both);
380  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
381  $hookmanager->initHooks(array('externalbalance'));
382  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
383 
384  foreach (array_keys($x_coll) as $rate) {
385  $subtot_coll_total_ht = 0;
386  $subtot_coll_vat = 0;
387 
388  if (is_array($x_both[$rate]['coll']['detail']))
389  {
390  // VAT Rate
391  print "<tr>";
392  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>';
393  print '</tr>'."\n";
394 
395  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
396  // Define type
397  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
398  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
399  // Try to enhance type detection using date_start and date_end for free lines where type
400  // was not saved.
401  if (!empty($fields['ddate_start'])) {
402  $type = 1;
403  }
404  if (!empty($fields['ddate_end'])) {
405  $type = 1;
406  }
407 
408 
409  print '<tr class="oddeven">';
410 
411  // Ref
412  print '<td class="nowrap left">'.$fields['link'].'</td>';
413 
414  // Invoice date
415  print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>';
416 
417  // Payment date
418  if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>';
419  else print '<td></td>';
420 
421  // Company name
422  print '<td class="left">'.$fields['company_link'].'</td>';
423 
424  // Description
425  print '<td class="left">';
426  if ($fields['pid'])
427  {
428  $product_static->id = $fields['pid'];
429  $product_static->ref = $fields['pref'];
430  $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
431  print $product_static->getNomUrl(1);
432  if (dol_string_nohtmltag($fields['descr'])) {
433  print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
434  }
435  } else {
436  if ($type) {
437  $text = img_object($langs->trans('Service'), 'service');
438  } else {
439  $text = img_object($langs->trans('Product'), 'product');
440  }
441  if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
442  if ($reg[1] == 'DEPOSIT') {
443  $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
444  } elseif ($reg[1] == 'CREDIT_NOTE') {
445  $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
446  } else {
447  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
448  }
449  }
450  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
451 
452  // Show range
453  print_date_range($fields['ddate_start'], $fields['ddate_end']);
454  }
455  print '</td>';
456 
457  // Total HT
458  if ($modetax != 1)
459  {
460  print '<td class="nowrap right">';
461  print price($fields['totalht']);
462  if (price2num($fields['ftotal_ttc']))
463  {
464  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
465  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
466  //print ' ('.round($ratiolineinvoice*100,2).'%)';
467  }
468  print '</td>';
469  }
470 
471  // Payment
472  $ratiopaymentinvoice = 1;
473  if ($modetax != 1)
474  {
475  print '<td class="nowrap right">';
476  //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
477  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
478  {
479  $payment_static->id = $fields['payment_id'];
480  print $payment_static->getNomUrl(2);
481  }
482  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
483  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
484  {
485  print $langs->trans("NA");
486  } else {
487  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
488  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
489  }
490  print price(price2num($fields['payment_amount'], 'MT'));
491  if (isset($fields['payment_amount'])) {
492  print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
493  }
494  }
495  print '</td>';
496  }
497 
498  // Total collected
499  print '<td class="nowrap right">';
500  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
501  print price(price2num($temp_ht, 'MT'), 1);
502  print '</td>';
503 
504  // VAT
505  print '<td class="nowrap right">';
506  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
507  print price(price2num($temp_vat, 'MT'), 1);
508  //print price($fields['vat']);
509  print '</td>';
510  print '</tr>';
511 
512  $subtot_coll_total_ht += $temp_ht;
513  $subtot_coll_vat += $temp_vat;
514  $x_coll_sum += $temp_vat;
515  }
516  }
517  // Total customers for this vat rate
518  print '<tr class="liste_total">';
519  print '<td colspan="4"></td>';
520  print '<td class="right">'.$langs->trans("Total").':</td>';
521  if ($modetax != 1) {
522  print '<td class="nowrap right">&nbsp;</td>';
523  print '<td class="right">&nbsp;</td>';
524  }
525  print '<td class="right">'.price(price2num($subtot_coll_total_ht, 'MT')).'</td>';
526  print '<td class="nowrap right">'.price(price2num($subtot_coll_vat, 'MT')).'</td>';
527  print '</tr>';
528  }
529 
530  if (count($x_coll) == 0) // Show a total line if nothing shown
531  {
532  print '<tr class="liste_total">';
533  print '<td colspan="4"></td>';
534  print '<td class="right">'.$langs->trans("Total").':</td>';
535  if ($modetax != 1) {
536  print '<td class="nowrap right">&nbsp;</td>';
537  print '<td class="right">&nbsp;</td>';
538  }
539  print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
540  print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
541  print '</tr>';
542  }
543 
544  // Blank line
545  print '<tr><td colspan="'.($span + 2).'">&nbsp;</td></tr>';
546 
547  // Print table headers for this quadri - expenses now
548  print '<tr class="liste_titre liste_titre_topborder">';
549  print '<td class="left">'.$elementsup.'</td>';
550  print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
551  if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
552  else print '<td></td>';
553  print '<td class="left">'.$namesup.'</td>';
554  print '<td class="left">'.$productsup.'</td>';
555  if ($modetax != 1) {
556  print '<td class="right">'.$amountsup.'</td>';
557  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
558  }
559  print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
560  print '<td class="right">'.$vatsup.'</td>';
561  print '</tr>'."\n";
562 
563  foreach (array_keys($x_paye) as $rate)
564  {
565  $subtot_paye_total_ht = 0;
566  $subtot_paye_vat = 0;
567 
568  if (is_array($x_both[$rate]['paye']['detail']))
569  {
570  print "<tr>";
571  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span + 1).'"></td>';
572  print '</tr>'."\n";
573 
574  foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
575  // Define type
576  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
577  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
578  // Try to enhance type detection using date_start and date_end for free lines where type
579  // was not saved.
580  if (!empty($fields['ddate_start'])) {
581  $type = 1;
582  }
583  if (!empty($fields['ddate_end'])) {
584  $type = 1;
585  }
586 
587 
588  print '<tr class="oddeven">';
589 
590  // Ref
591  print '<td class="nowrap left">'.$fields['link'].'</td>';
592 
593  // Invoice date
594  print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>';
595 
596  // Payment date
597  if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>';
598  else print '<td></td>';
599 
600  // Company name
601  print '<td class="left">'.$fields['company_link'].'</td>';
602 
603  // Description
604  print '<td class="left">';
605  if ($fields['pid'])
606  {
607  $product_static->id = $fields['pid'];
608  $product_static->ref = $fields['pref'];
609  $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
610  print $product_static->getNomUrl(1);
611  if (dol_string_nohtmltag($fields['descr'])) {
612  print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
613  }
614  } else {
615  if ($type) {
616  $text = img_object($langs->trans('Service'), 'service');
617  } else {
618  $text = img_object($langs->trans('Product'), 'product');
619  }
620  if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
621  if ($reg[1] == 'DEPOSIT') {
622  $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
623  } elseif ($reg[1] == 'CREDIT_NOTE') {
624  $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
625  } else {
626  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
627  }
628  }
629  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
630 
631  // Show range
632  print_date_range($fields['ddate_start'], $fields['ddate_end']);
633  }
634  print '</td>';
635 
636  // Total HT
637  if ($modetax != 1)
638  {
639  print '<td class="nowrap right">';
640  print price($fields['totalht']);
641  if (price2num($fields['ftotal_ttc']))
642  {
643  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
644  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
645  //print ' ('.round($ratiolineinvoice*100,2).'%)';
646  }
647  print '</td>';
648  }
649 
650  // Payment
651  $ratiopaymentinvoice = 1;
652  if ($modetax != 1)
653  {
654  print '<td class="nowrap right">';
655  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
656  {
657  $paymentfourn_static->id = $fields['payment_id'];
658  print $paymentfourn_static->getNomUrl(2);
659  }
660 
661  if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
662  || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
663  {
664  print $langs->trans("NA");
665  } else {
666  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
667  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
668  }
669  print price(price2num($fields['payment_amount'], 'MT'));
670  if (isset($fields['payment_amount'])) {
671  print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
672  }
673  }
674  print '</td>';
675  }
676 
677  // VAT paid
678  print '<td class="nowrap right">';
679  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
680  print price(price2num($temp_ht, 'MT'), 1);
681  print '</td>';
682 
683  // VAT
684  print '<td class="nowrap right">';
685  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
686  print price(price2num($temp_vat, 'MT'), 1);
687  //print price($fields['vat']);
688  print '</td>';
689  print '</tr>';
690 
691  $subtot_paye_total_ht += $temp_ht;
692  $subtot_paye_vat += $temp_vat;
693  $x_paye_sum += $temp_vat;
694  }
695  }
696  // Total suppliers for this vat rate
697  print '<tr class="liste_total">';
698  print '<td colspan="4"></td>';
699  print '<td class="right">'.$langs->trans("Total").':</td>';
700  if ($modetax != 1) {
701  print '<td class="nowrap right">&nbsp;</td>';
702  print '<td class="right">&nbsp;</td>';
703  }
704  print '<td class="right">'.price(price2num($subtot_paye_total_ht, 'MT')).'</td>';
705  print '<td class="nowrap right">'.price(price2num($subtot_paye_vat, 'MT')).'</td>';
706  print '</tr>';
707  }
708 
709  if (count($x_paye) == 0) { // Show a total line if nothing shown
710  print '<tr class="liste_total">';
711  print '<td colspan="4"></td>';
712  print '<td class="right">'.$langs->trans("Total").':</td>';
713  if ($modetax != 1) {
714  print '<td class="nowrap right">&nbsp;</td>';
715  print '<td class="right">&nbsp;</td>';
716  }
717  print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
718  print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
719  print '</tr>';
720  }
721 
722  print '</table>';
723  print '</div>';
724 
725  // Total to pay
726  print '<br><br>';
727  print '<table class="noborder centpercent">';
728  $diff = $x_coll_sum - $x_paye_sum;
729  print '<tr class="liste_total">';
730  print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
731  print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
732  print "</tr>\n";
733 
734  $i++;
735 }
736 print '</table>';
737 
738 llxFooter();
739 $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.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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.
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
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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