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