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