dolibarr  7.0.0-beta
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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
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/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 
41 $langs->load("bills");
42 $langs->load("compta");
43 $langs->load("companies");
44 $langs->load("products");
45 
46 $local=GETPOST('localTaxType', 'int');
47 // Date range
48 $year=GETPOST("year");
49 if (empty($year))
50 {
51  $year_current = strftime("%Y",dol_now());
52  $year_start = $year_current;
53 } else {
54  $year_current = $year;
55  $year_start = $year;
56 }
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");
64  if (empty($q))
65  {
66  if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false); $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false); }
67  else
68  {
69  $month_current = strftime("%m",dol_now());
70  if ($month_current >= 10) $q=4;
71  elseif ($month_current >= 7) $q=3;
72  elseif ($month_current >= 4) $q=2;
73  else $q=1;
74  }
75  }
76  if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
77  if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
78  if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
79  if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
80 }
81 
82 $min = GETPOST("min");
83 if (empty($min)) $min = 0;
84 
85 // Define modetax (0 or 1)
86 // 0=normal, 1=option vat for services is on debit
87 $modetax = $conf->global->TAX_MODE;
88 if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
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 
99 $morequerystring='';
100 $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
101 foreach($listofparams as $param)
102 {
103  if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
104 }
105 
106 llxHeader('','','','',0,0,'','',$morequerystring);
107 
108 $form=new Form($db);
109 
110 $company_static=new Societe($db);
111 $invoice_customer=new Facture($db);
112 $invoice_supplier=new FactureFournisseur($db);
113 $product_static=new Product($db);
114 $payment_static=new Paiement($db);
115 $paymentfourn_static=new PaiementFourn($db);
116 
117 $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
118 $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
119 $fsearch.=' <input type="hidden" name="localTaxType" value="'.$local.'">';
120 
121 $calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
122 
123 if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice for goods and services
124 {
125  $nom=$langs->trans($local==1?"LT1ReportByQuartersInDueDebtMode":"LT2ReportByQuartersInDueDebtMode");
126  $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
127  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
128  $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
129  $prevyear=$year_start; $prevquarter=$q;
130  if ($prevquarter > 1) $prevquarter--;
131  else { $prevquarter=4; $prevyear--; }
132  $nextyear=$year_start; $nextquarter=$q;
133  if ($nextquarter < 4) $nextquarter++;
134  else { $nextquarter=1; $nextyear++; }
135 
136  if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
137  else $description.='<br>'.$langs->trans("DepositsAreIncluded");
138  $description.=$fsearch;
139  $builddate=dol_now();
140 
141  $elementcust=$langs->trans("CustomersInvoices");
142  $productcust=$langs->trans("ProductOrService");
143  $amountcust=$langs->trans("AmountHT");
144  $vatcust=$langs->trans("VATReceived");
145  if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
146  $elementsup=$langs->trans("SuppliersInvoices");
147  $productsup=$langs->trans("ProductOrService");
148  $amountsup=$langs->trans("AmountHT");
149  $vatsup=$langs->trans("VATPaid");
150  if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
151 }
152 if ($conf->global->$calc==2) // Invoice for goods, payment for services
153 {
154  $nom=$langs->trans($local==1?"LT1ReportByQuartersInInputOutputMode":"LT2ReportByQuartersInInputOutputMode");
155  $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
156  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
157  $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
158  $prevyear=$year_start; $prevquarter=$q;
159  if ($prevquarter > 1) $prevquarter--;
160  else { $prevquarter=4; $prevyear--; }
161  $nextyear=$year_start; $nextquarter=$q;
162  if ($nextquarter < 4) $nextquarter++;
163  else { $nextquarter=1; $nextyear++; }
164  if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
165  else $description.=' '.$langs->trans("DepositsAreIncluded");
166  $description.=$fsearch;
167  $builddate=dol_now();
168 
169  $elementcust=$langs->trans("CustomersInvoices");
170  $productcust=$langs->trans("ProductOrService");
171  $amountcust=$langs->trans("AmountHT");
172  $vatcust=$langs->trans("VATReceived");
173  if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
174  $elementsup=$langs->trans("SuppliersInvoices");
175  $productsup=$langs->trans("ProductOrService");
176  $amountsup=$langs->trans("AmountHT");
177  $vatsup=$langs->trans("VATPaid");
178  if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
179 }
180 report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
181 
182 
183 if($local==1){
184  $vatcust=$langs->transcountry("LocalTax1", $mysoc->country_code);
185  $vatsup=$langs->transcountry("LocalTax1", $mysoc->country_code);
186 }else{
187  $vatcust=$langs->transcountry("LocalTax2", $mysoc->country_code);
188  $vatsup=$langs->transcountry("LocalTax2", $mysoc->country_code);
189 }
190 
191 // VAT Received and paid
192 
193 $y = $year_current;
194 $total = 0;
195 $i=0;
196 
197 // Load arrays of datas
198 $x_coll = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
199 $x_paye = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
200 
201 echo '<table class="noborder" width="100%">';
202 
203 if (! is_array($x_coll) || ! is_array($x_paye))
204 {
205  $langs->load("errors");
206  if ($x_coll == -1)
207  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
208  else if ($x_coll == -2)
209  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
210  else
211  print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
212 }
213 else
214 {
215  $x_both = array();
216 
217  //now, from these two arrays, get another array with one rate per line
218  foreach(array_keys($x_coll) as $my_coll_rate)
219  {
220  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
221  $x_both[$my_coll_rate]['coll']['localtax'.$local] = $x_coll[$my_coll_rate]['localtax'.$local];
222  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
223  $x_both[$my_coll_rate]['paye']['localtax'.$local] = 0;
224  $x_both[$my_coll_rate]['coll']['links'] = '';
225  $x_both[$my_coll_rate]['coll']['detail'] = array();
226  foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
227  {
228  $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
229  $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
230  $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
231  $x_both[$my_coll_rate]['coll']['detail'][] = array(
232  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
233  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
234  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
235  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
236  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
237  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
238  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
239  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
240  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
241  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
242  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
243  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
244  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
245  'localtax1'=> $x_coll[$my_coll_rate]['localtax1_list'][$id],
246  'localtax2'=> $x_coll[$my_coll_rate]['localtax2_list'][$id],
247  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
248  'link' =>$invoice_customer->getNomUrl(1,'',12));
249  }
250  }
251  // tva paid
252  foreach(array_keys($x_paye) as $my_paye_rate){
253  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
254  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
255  if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
256  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
257  $x_both[$my_paye_rate]['coll']['vat'] = 0;
258  }
259  $x_both[$my_paye_rate]['paye']['links'] = '';
260  $x_both[$my_paye_rate]['paye']['detail'] = array();
261 
262  foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
263  {
264  $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
265  $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
266  $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
267  $x_both[$my_paye_rate]['paye']['detail'][] = array(
268  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
269  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
270  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
271  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
272  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
273  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
274  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
275  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
276  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
277  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
278  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
279  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
280  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
281  'localtax1'=> $x_paye[$my_paye_rate]['localtax1_list'][$id],
282  'localtax2'=> $x_paye[$my_paye_rate]['localtax2_list'][$id],
283  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
284  'link' =>$invoice_supplier->getNomUrl(1,'',12));
285  }
286  }
287  //now we have an array (x_both) indexed by rates for coll and paye
288 
289  $x_coll_sum = 0;
290  $x_coll_ht = 0;
291  $x_paye_sum = 0;
292  $x_paye_ht = 0;
293 
294  $span=3;
295  if ($modetax == 0) $span+=2;
296 
297  if($conf->global->$calc ==0 || $conf->global->$calc == 2){
298  // Customers invoices
299  print '<tr class="liste_titre">';
300  print '<td align="left">'.$elementcust.'</td>';
301  print '<td align="left">'.$productcust.'</td>';
302  if ($modetax == 0)
303  {
304  print '<td align="right">'.$amountcust.'</td>';
305  print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
306  }
307  print '<td align="right">'.$langs->trans("BI").'</td>';
308  print '<td align="right">'.$vatcust.'</td>';
309  print '</tr>';
310 
311 
312  $LT=0;
313  $sameLT=false;
314  foreach(array_keys($x_coll) as $rate)
315  {
316  $subtot_coll_total_ht = 0;
317  $subtot_coll_vat = 0;
318 
319  if (is_array($x_both[$rate]['coll']['detail']))
320  {
321  // VAT Rate
322  $var=true;
323 
324  if($rate!=0){
325  print "<tr>";
326  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
327  print '</tr>'."\n";
328  }
329  foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
330  {
331  if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){
332  // Define type
333  $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
334  // Try to enhance type detection using date_start and date_end for free lines where type
335  // was not saved.
336  if (! empty($fields['ddate_start'])) $type=1;
337  if (! empty($fields['ddate_end'])) $type=1;
338 
339 
340  print '<tr class="oddeven">';
341 
342  // Ref
343  print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
344 
345  // Description
346  print '<td align="left">';
347  if ($fields['pid'])
348  {
349  $product_static->id=$fields['pid'];
350  $product_static->ref=$fields['pref'];
351  $product_static->type=$fields['ptype'];
352  print $product_static->getNomUrl(1);
353  if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
354  }
355  else
356  {
357  if ($type) $text = img_object($langs->trans('Service'),'service');
358  else $text = img_object($langs->trans('Product'),'product');
359  if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg))
360  {
361  if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
362  elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
363  else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
364  }
365  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
366 
367  // Show range
368  print_date_range($fields['ddate_start'],$fields['ddate_end']);
369  }
370  print '</td>';
371 
372  // Total HT
373  if ($modetax == 0)
374  {
375  print '<td class="nowrap" align="right">';
376  print price($fields['totalht']);
377  if (price2num($fields['ftotal_ttc']))
378  {
379  $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
380  }
381  print '</td>';
382  }
383 
384  // Payment
385  $ratiopaymentinvoice=1;
386  if ($modetax == 0)
387  {
388  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
389  print '<td class="nowrap" align="right">';
390  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
391  {
392  $payment_static->id=$fields['payment_id'];
393  print $payment_static->getNomUrl(2);
394  }
395  if ($type == 0)
396  {
397  print $langs->trans("NotUsedForGoods");
398  }
399  else {
400  print price($fields['payment_amount']);
401  if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
402  }
403  print '</td>';
404  }
405 
406  // Total collected
407  print '<td class="nowrap" align="right">';
408  $temp_ht=$fields['totalht'];
409  if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
410  print price(price2num($temp_ht,'MT'));
411  print '</td>';
412 
413  // Localtax
414  print '<td class="nowrap" align="right">';
415  $temp_vat= $local==1?$fields['localtax1']:$fields['localtax2'];
416  print price(price2num($temp_vat,'MT'));
417  //print price($fields['vat']);
418  print '</td>';
419  print '</tr>';
420 
421  $subtot_coll_total_ht += $temp_ht;
422  $subtot_coll_vat += $temp_vat;
423  $x_coll_sum += $temp_vat;
424  }
425  }
426  }
427  if($rate!=0){
428  // Total customers for this vat rate
429  print '<tr class="liste_total">';
430  print '<td></td>';
431  print '<td align="right">'.$langs->trans("Total").':</td>';
432  if ($modetax == 0)
433  {
434  print '<td class="nowrap" align="right">&nbsp;</td>';
435  print '<td align="right">&nbsp;</td>';
436  }
437  print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
438  print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
439  print '</tr>';
440  }
441  }
442 
443  if (count($x_coll) == 0) // Show a total ine if nothing shown
444  {
445  print '<tr class="liste_total">';
446  print '<td>&nbsp;</td>';
447  print '<td align="right">'.$langs->trans("Total").':</td>';
448  if ($modetax == 0)
449  {
450  print '<td class="nowrap" align="right">&nbsp;</td>';
451  print '<td align="right">&nbsp;</td>';
452  }
453  print '<td align="right">'.price(price2num(0,'MT')).'</td>';
454  print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
455  print '</tr>';
456  }
457 
458  // Blank line
459  print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
460  print '</table>';
461  $diff=$x_coll_sum;
462  }
463 
464  if($conf->global->$calc ==0 || $conf->global->$calc == 1){
465  echo '<table class="noborder" width="100%">';
466  //print table headers for this quadri - expenses now
467  print '<tr class="liste_titre">';
468  print '<td align="left">'.$elementsup.'</td>';
469  print '<td align="left">'.$productsup.'</td>';
470  if ($modetax == 0)
471  {
472  print '<td align="right">'.$amountsup.'</td>';
473  print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
474  }
475  print '<td align="right">'.$langs->trans("BI").'</td>';
476  print '<td align="right">'.$vatsup.'</td>';
477  print '</tr>'."\n";
478 
479  foreach(array_keys($x_paye) as $rate)
480  {
481  $subtot_paye_total_ht = 0;
482  $subtot_paye_vat = 0;
483 
484  if(is_array($x_both[$rate]['paye']['detail']))
485  {
486  $var=true;
487  if($rate!=0){
488  print "<tr>";
489  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
490  print '</tr>'."\n";
491  }
492  foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
493  {
494  if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){
495  // Define type
496  $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
497  // Try to enhance type detection using date_start and date_end for free lines where type
498  // was not saved.
499  if (! empty($fields['ddate_start'])) $type=1;
500  if (! empty($fields['ddate_end'])) $type=1;
501 
502 
503  print '<tr class="oddeven">';
504 
505  // Ref
506  print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
507 
508  // Description
509  print '<td align="left">';
510  if ($fields['pid'])
511  {
512  $product_static->id=$fields['pid'];
513  $product_static->ref=$fields['pref'];
514  $product_static->type=$fields['ptype'];
515  print $product_static->getNomUrl(1);
516  if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
517  }
518  else
519  {
520  if ($type) $text = img_object($langs->trans('Service'),'service');
521  else $text = img_object($langs->trans('Product'),'product');
522  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
523 
524  // Show range
525  print_date_range($fields['ddate_start'],$fields['ddate_end']);
526  }
527  print '</td>';
528 
529  // Total HT
530  if ($modetax == 0)
531  {
532  print '<td class="nowrap" align="right">';
533  print price($fields['totalht']);
534  if (price2num($fields['ftotal_ttc']))
535  {
536  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
537  $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
538  //print ' ('.round($ratiolineinvoice*100,2).'%)';
539  }
540  print '</td>';
541  }
542 
543  // Payment
544  $ratiopaymentinvoice=1;
545  if ($modetax == 0)
546  {
547  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
548  print '<td class="nowrap" align="right">';
549  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
550  {
551  $paymentfourn_static->id=$fields['payment_id'];
552  print $paymentfourn_static->getNomUrl(2);
553  }
554  if ($type == 0)
555  {
556  print $langs->trans("NotUsedForGoods");
557  }
558  else
559  {
560  print price($fields['payment_amount']);
561  if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
562  }
563  print '</td>';
564  }
565 
566  // VAT paid
567  print '<td class="nowrap" align="right">';
568  $temp_ht=$fields['totalht'];
569  if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
570  print price(price2num($temp_ht,'MT'));
571  print '</td>';
572 
573  // Localtax
574  print '<td class="nowrap" align="right">';
575  $temp_vat= $local==1?$fields['localtax1']:$fields['localtax2'];
576  print price(price2num($temp_vat,'MT'));
577  //print price($fields['vat']);
578  print '</td>';
579  print '</tr>';
580 
581  $subtot_paye_total_ht += $temp_ht;
582  $subtot_paye_vat += $temp_vat;
583  $x_paye_sum += $temp_vat;
584  }
585  }
586  }
587  if($rate!=0){
588  // Total suppliers for this vat rate
589  print '<tr class="liste_total">';
590  print '<td>&nbsp;</td>';
591  print '<td align="right">'.$langs->trans("Total").':</td>';
592  if ($modetax == 0)
593  {
594  print '<td class="nowrap" align="right">&nbsp;</td>';
595  print '<td align="right">&nbsp;</td>';
596  }
597  print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
598  print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
599  print '</tr>';
600  }
601  }
602 
603  if (count($x_paye) == 0) // Show a total ine if nothing shown
604  {
605  print '<tr class="liste_total">';
606  print '<td>&nbsp;</td>';
607  print '<td align="right">'.$langs->trans("Total").':</td>';
608  if ($modetax == 0)
609  {
610  print '<td class="nowrap" align="right">&nbsp;</td>';
611  print '<td align="right">&nbsp;</td>';
612  }
613  print '<td align="right">'.price(price2num(0,'MT')).'</td>';
614  print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
615  print '</tr>';
616  }
617 
618  print '</table>';
619  $diff=$x_paye_sum;
620  }
621 
622  if($conf->global->$calc ==0){$diff=$x_coll_sum - $x_paye_sum;}
623  echo '<table class="noborder" width="100%">';
624  // Total to pay
625  print '<br><br>';
626  print '<table class="noborder" width="100%">';
627  //$diff = $local==1?$x_coll_sum:$x_paye_sum;
628  print '<tr class="liste_total">';
629  print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
630  print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
631  print "</tr>\n";
632 
633  echo '</table>';
634 
635  $i++;
636 }
637 
638 llxFooter();
639 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
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...
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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:445
Class to manage suppliers invoices.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage payments of customer invoices.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='gmt')
Return date for now.
tax_by_date($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:200
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_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8')
Clean a string from all HTML tags and entities.
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:459
print
Draft customers invoices.
Definition: index.php:91
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.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.