dolibarr  7.0.0-beta
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-2007 Yannick Warnier <ywarnier@beeznest.org>
6  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
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 
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/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 $langs->load("bills");
44 $langs->load("compta");
45 $langs->load("companies");
46 $langs->load("products");
47 $langs->load("trips");
48 $langs->load("other");
49 
50 // Date range
51 $year=GETPOST("year","int");
52 if (empty($year))
53 {
54  $year_current = strftime("%Y",dol_now());
55  $year_start = $year_current;
56 } else {
57  $year_current = $year;
58  $year_start = $year;
59 }
60 $date_start=dol_mktime(0,0,0,GETPOST("date_startmonth"),GETPOST("date_startday"),GETPOST("date_startyear"));
61 $date_end=dol_mktime(23,59,59,GETPOST("date_endmonth"),GETPOST("date_endday"),GETPOST("date_endyear"));
62 // Quarter
63 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
64 {
65  $q=GETPOST("q");
66  if (empty($q))
67  {
68  if (GETPOST("month")) { $date_start=dol_get_first_day($year_start,GETPOST("month"),false); $date_end=dol_get_last_day($year_start,GETPOST("month"),false); }
69  else
70  {
71  $month_current = strftime("%m",dol_now());
72  if ($month_current >= 10) $q=4;
73  elseif ($month_current >= 7) $q=3;
74  elseif ($month_current >= 4) $q=2;
75  else $q=1;
76  }
77  }
78  if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
79  if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
80  if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
81  if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
82 }
83 
84 $min = GETPOST("min");
85 if (empty($min)) $min = 0;
86 
87 // Define modetax (0 or 1)
88 // 0=normal, 1=option vat for services is on debit
89 $modetax = $conf->global->TAX_MODE;
90 if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
91 if (empty($modetax)) $modetax=0;
92 
93 // Security check
94 $socid = GETPOST('socid','int');
95 if ($user->societe_id) $socid=$user->societe_id;
96 $result = restrictedArea($user, 'tax', '', '', 'charges');
97 
98 
99 
100 /*
101  * View
102  */
103 
104 $morequerystring='';
105 $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
106 foreach($listofparams as $param)
107 {
108  if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
109 }
110 
111 llxHeader('',$langs->trans("VATReport"),'','',0,0,'','',$morequerystring);
112 
113 $form=new Form($db);
114 
115 $company_static=new Societe($db);
116 $invoice_customer=new Facture($db);
117 $invoice_supplier=new FactureFournisseur($db);
118 $expensereport=new ExpenseReport($db);
119 $product_static=new Product($db);
120 $payment_static=new Paiement($db);
121 $paymentfourn_static=new PaiementFourn($db);
122 $paymentexpensereport_static=new PaymentExpenseReport($db);
123 
124 //print load_fiche_titre($langs->trans("VAT"),"");
125 
126 //$fsearch.='<br>';
127 $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
128 $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
129 //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
130 //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
131 
132 
133 // Affiche en-tete du rapport
134 if ($modetax==1) // Calculate on invoice for goods and services
135 {
136  $name=$langs->trans("VATReportByQuartersInDueDebtMode");
137  $calcmode=$langs->trans("CalcModeVATDebt");
138  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
139  $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);
140  $prevyear=$year_start; $prevquarter=$q;
141  if ($prevquarter > 1) $prevquarter--;
142  else { $prevquarter=4; $prevyear--; }
143  $nextyear=$year_start; $nextquarter=$q;
144  if ($nextquarter < 4) $nextquarter++;
145  else { $nextquarter=1; $nextyear++; }
146  //$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
147  $description=$langs->trans("RulesVATDueServices");
148  $description.='<br>';
149  $description.=$langs->trans("RulesVATDueProducts");
150  //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
151  //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
152  if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
153  else $description.='<br>'.$langs->trans("DepositsAreIncluded");
154  $description.=$fsearch;
155  $builddate=dol_now();
156  //$exportlink=$langs->trans("NotYetAvailable");
157 
158  // Customers invoices
159  $elementcust=$langs->trans("CustomersInvoices");
160  $productcust=$langs->trans("ProductOrService");
161  $amountcust=$langs->trans("AmountHT");
162  $vatcust=$langs->trans("VATReceived");
163  if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
164 
165  // Suppliers invoices
166  $elementsup=$langs->trans("SuppliersInvoices");
167  $productsup=$langs->trans("ProductOrService");
168  $amountsup=$langs->trans("AmountHT");
169  $vatsup=$langs->trans("VATPaid");
170  if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
171 
172 }
173 if ($modetax==0) // Invoice for goods, payment for services
174 {
175  $name=$langs->trans("VATReportByQuartersInInputOutputMode");
176  $calcmode=$langs->trans("CalcModeVATEngagement");
177  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
178  $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);
179  $prevyear=$year_start; $prevquarter=$q;
180  if ($prevquarter > 1) $prevquarter--;
181  else { $prevquarter=4; $prevyear--; }
182  $nextyear=$year_start; $nextquarter=$q;
183  if ($nextquarter < 4) $nextquarter++;
184  else { $nextquarter=1; $nextyear++; }
185  //$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
186  $description=$langs->trans("RulesVATInServices");
187  $description.=' '.$langs->trans("DepositsAreIncluded");
188  $description.='<br>';
189  $description.=$langs->trans("RulesVATInProducts");
190  if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
191  else $description.=' '.$langs->trans("DepositsAreIncluded");
192  //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
193  //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
194  $description.=$fsearch;
195  $builddate=dol_now();
196  //$exportlink=$langs->trans("NotYetAvailable");
197 
198  // Customers invoices
199  $elementcust=$langs->trans("CustomersInvoices");
200  $productcust=$langs->trans("ProductOrService");
201  $amountcust=$langs->trans("AmountHT");
202  $vatcust=$langs->trans("VATReceived");
203  if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
204 
205  // Suppliers invoices
206  $elementsup=$langs->trans("SuppliersInvoices");
207  $productsup=$langs->trans("ProductOrService");
208  $amountsup=$langs->trans("AmountHT");
209  $vatsup=$langs->trans("VATPaid");
210  if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
211 
212 }
213 report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
214 
215 $vatcust=$langs->trans("VATReceived");
216 $vatsup=$langs->trans("VATPaid");
217 $vatexpensereport=$langs->trans("VATPaid");
218 
219 // VAT Received and paid
220 print '<table class="noborder" width="100%">';
221 
222 $y = $year_current;
223 $total = 0;
224 $i=0;
225 
226 // Load arrays of datas
227 $x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
228 $x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
229 
230 if (! is_array($x_coll) || ! is_array($x_paye))
231 {
232  $langs->load("errors");
233  if ($x_coll == -1)
234  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
235  else if ($x_coll == -2)
236  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
237  else
238  print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
239 }
240 else
241 {
242  $x_both = array();
243  //now, from these two arrays, get another array with one rate per line
244  foreach(array_keys($x_coll) as $my_coll_rate)
245  {
246  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
247  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
248  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
249  $x_both[$my_coll_rate]['paye']['vat'] = 0;
250  $x_both[$my_coll_rate]['coll']['links'] = '';
251  $x_both[$my_coll_rate]['coll']['detail'] = array();
252  foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
253  {
254  $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
255  $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
256  $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
257  $x_both[$my_coll_rate]['coll']['detail'][] = array(
258  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
259  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
260  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
261  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
262  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
263  'payment_id' =>$x_coll[$my_coll_rate]['payment_id'][$id],
264  'payment_amount' =>$x_coll[$my_coll_rate]['payment_amount'][$id],
265  'ftotal_ttc' =>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
266  'dtotal_ttc' =>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
267  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
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  // tva paid
276  foreach(array_keys($x_paye) as $my_paye_rate){
277  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
278  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
279  if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
280  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
281  $x_both[$my_paye_rate]['coll']['vat'] = 0;
282  }
283  $x_both[$my_paye_rate]['paye']['links'] = '';
284  $x_both[$my_paye_rate]['paye']['detail'] = array();
285 
286  foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
287  {
288  // ExpenseReport
289  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
290  {
291  $expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
292  $expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
293  $expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
294 
295  $x_both[$my_paye_rate]['paye']['detail'][] = array(
296  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
297  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
298  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
299  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
300  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
301  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
302  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
303  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
304  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
305  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
306  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
307  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
308  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
309  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
310  'link' =>$expensereport->getNomUrl(1)
311  );
312  }
313  else
314  {
315  $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
316  $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
317  $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$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  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
330  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
331  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
332  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
333  'link' =>$invoice_supplier->getNomUrl(1,'',12)
334  );
335  }
336  }
337  }
338  //now we have an array (x_both) indexed by rates for coll and paye
339 
340 
341  //print table headers for this quadri - incomes first
342 
343  $x_coll_sum = 0;
344  $x_coll_ht = 0;
345  $x_paye_sum = 0;
346  $x_paye_ht = 0;
347 
348  $span=3;
349  if ($modetax == 0) $span+=2;
350 
351  //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
352 
353  // Customers invoices
354  print '<tr class="liste_titre">';
355  print '<td align="left">'.$elementcust.'</td>';
356  print '<td align="left">'.$productcust.'</td>';
357  if ($modetax == 0)
358  {
359  print '<td align="right">'.$amountcust.'</td>';
360  print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
361  }
362  print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
363  print '<td align="right">'.$vatcust.'</td>';
364  print '</tr>';
365 
366  $action = "tvadetail";
367  $parameters["mode"] = $modetax;
368  $parameters["start"] = $date_start;
369  $parameters["end"] = $date_end;
370  $parameters["type"] = 'vat';
371 
372  $object = array(&$x_coll, &$x_paye, &$x_both);
373  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
374  $hookmanager->initHooks(array('externalbalance'));
375  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
376 
377  foreach(array_keys($x_coll) as $rate)
378  {
379  $subtot_coll_total_ht = 0;
380  $subtot_coll_vat = 0;
381 
382  if (is_array($x_both[$rate]['coll']['detail']))
383  {
384  // VAT Rate
385  $var=true;
386  print "<tr>";
387  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
388  print '</tr>'."\n";
389 
390  foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
391  {
392  // Define type
393  $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
394  // Try to enhance type detection using date_start and date_end for free lines where type
395  // was not saved.
396  if (! empty($fields['ddate_start'])) $type=1;
397  if (! empty($fields['ddate_end'])) $type=1;
398 
399 
400  print '<tr class="oddeven">';
401 
402  // Ref
403  print '<td class="nowrap" align="left">'.$fields['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['ptype'];
412  print $product_static->getNomUrl(1);
413  if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
414  }
415  else
416  {
417  if ($type) $text = img_object($langs->trans('Service'),'service');
418  else $text = img_object($langs->trans('Product'),'product');
419  if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg))
420  {
421  if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
422  elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
423  else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
424  }
425  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
426 
427  // Show range
428  print_date_range($fields['ddate_start'],$fields['ddate_end']);
429  }
430  print '</td>';
431 
432  // Total HT
433  if ($modetax == 0)
434  {
435  print '<td class="nowrap" align="right">';
436  print price($fields['totalht']);
437  if (price2num($fields['ftotal_ttc']))
438  {
439  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
440  $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
441  //print ' ('.round($ratiolineinvoice*100,2).'%)';
442  }
443  print '</td>';
444  }
445 
446  // Payment
447  $ratiopaymentinvoice=1;
448  if ($modetax == 0)
449  {
450  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
451  print '<td class="nowrap" align="right">';
452  //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
453  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
454  {
455  $payment_static->id=$fields['payment_id'];
456  print $payment_static->getNomUrl(2);
457  }
458  if ($type == 0)
459  {
460  print $langs->trans("NotUsedForGoods");
461  }
462  else {
463  print price($fields['payment_amount']);
464  if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
465  }
466  print '</td>';
467  }
468 
469  // Total collected
470  print '<td class="nowrap" align="right">';
471  $temp_ht=$fields['totalht'];
472  if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
473  print price(price2num($temp_ht,'MT'),1);
474  print '</td>';
475 
476  // VAT
477  print '<td class="nowrap" align="right">';
478  $temp_vat=$fields['vat'];
479  if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
480  print price(price2num($temp_vat,'MT'),1);
481  //print price($fields['vat']);
482  print '</td>';
483  print '</tr>';
484 
485  $subtot_coll_total_ht += $temp_ht;
486  $subtot_coll_vat += $temp_vat;
487  $x_coll_sum += $temp_vat;
488  }
489  }
490  // Total customers for this vat rate
491  print '<tr class="liste_total">';
492  print '<td></td>';
493  print '<td align="right">'.$langs->trans("Total").':</td>';
494  if ($modetax == 0)
495  {
496  print '<td class="nowrap" align="right">&nbsp;</td>';
497  print '<td align="right">&nbsp;</td>';
498  }
499  print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
500  print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
501  print '</tr>';
502  }
503 
504  if (count($x_coll) == 0) // Show a total ine if nothing shown
505  {
506  print '<tr class="liste_total">';
507  print '<td>&nbsp;</td>';
508  print '<td align="right">'.$langs->trans("Total").':</td>';
509  if ($modetax == 0)
510  {
511  print '<td class="nowrap" align="right">&nbsp;</td>';
512  print '<td align="right">&nbsp;</td>';
513  }
514  print '<td align="right">'.price(price2num(0,'MT')).'</td>';
515  print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
516  print '</tr>';
517  }
518 
519  // Blank line
520  print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
521 
522  //print table headers for this quadri - expenses now
523  //imprime les en-tete de tables pour ce quadri - maintenant les d�penses
524  print '<tr class="liste_titre liste_titre_topborder">';
525  print '<td align="left">'.$elementsup.'</td>';
526  print '<td align="left">'.$productsup.'</td>';
527  if ($modetax == 0)
528  {
529  print '<td align="right">'.$amountsup.'</td>';
530  print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
531  }
532  print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
533  print '<td align="right">'.$vatsup.'</td>';
534  print '</tr>'."\n";
535 
536  foreach(array_keys($x_paye) as $rate)
537  {
538  $subtot_paye_total_ht = 0;
539  $subtot_paye_vat = 0;
540 
541  if(is_array($x_both[$rate]['paye']['detail']))
542  {
543  $var=true;
544  print "<tr>";
545  print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
546  print '</tr>'."\n";
547  foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
548  {
549  // Define type
550  $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
551  // Try to enhance type detection using date_start and date_end for free lines where type
552  // was not saved.
553  if (! empty($fields['ddate_start'])) $type=1;
554  if (! empty($fields['ddate_end'])) $type=1;
555 
556 
557  print '<tr class="oddeven">';
558 
559  // Ref
560  print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
561 
562  // Description
563  print '<td align="left">';
564  if ($fields['pid'])
565  {
566  $product_static->id=$fields['pid'];
567  $product_static->ref=$fields['pref'];
568  $product_static->type=$fields['ptype'];
569  print $product_static->getNomUrl(1);
570  if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
571  }
572  else
573  {
574  if ($type) $text = img_object($langs->trans('Service'),'service');
575  else $text = img_object($langs->trans('Product'),'product');
576  print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
577 
578  // Show range
579  print_date_range($fields['ddate_start'],$fields['ddate_end']);
580  }
581  print '</td>';
582 
583  // Total HT
584  if ($modetax == 0)
585  {
586  print '<td class="nowrap" align="right">';
587  print price($fields['totalht']);
588  if (price2num($fields['ftotal_ttc']))
589  {
590  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
591  $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
592  //print ' ('.round($ratiolineinvoice*100,2).'%)';
593  }
594  print '</td>';
595  }
596 
597  // Payment
598  $ratiopaymentinvoice=1;
599  if ($modetax == 0)
600  {
601  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
602  print '<td class="nowrap" align="right">';
603  if ($fields['payment_amount'] && $fields['ftotal_ttc'])
604  {
605  $paymentfourn_static->id=$fields['payment_id'];
606  print $paymentfourn_static->getNomUrl(2);
607  }
608  if ($type == 0)
609  {
610  print $langs->trans("NotUsedForGoods");
611  }
612  else
613  {
614  print price($fields['payment_amount']);
615  if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
616  }
617  print '</td>';
618  }
619 
620  // VAT paid
621  print '<td class="nowrap" align="right">';
622  $temp_ht=$fields['totalht'];
623  if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
624  print price(price2num($temp_ht,'MT'),1);
625  print '</td>';
626 
627  // VAT
628  print '<td class="nowrap" align="right">';
629  $temp_vat=$fields['vat'];
630  if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
631  print price(price2num($temp_vat,'MT'),1);
632  //print price($fields['vat']);
633  print '</td>';
634  print '</tr>';
635 
636  $subtot_paye_total_ht += $temp_ht;
637  $subtot_paye_vat += $temp_vat;
638  $x_paye_sum += $temp_vat;
639  }
640  }
641  // Total suppliers for this vat rate
642  print '<tr class="liste_total">';
643  print '<td>&nbsp;</td>';
644  print '<td align="right">'.$langs->trans("Total").':</td>';
645  if ($modetax == 0)
646  {
647  print '<td class="nowrap" align="right">&nbsp;</td>';
648  print '<td align="right">&nbsp;</td>';
649  }
650  print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
651  print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
652  print '</tr>';
653  }
654 
655  if (count($x_paye) == 0) // Show a total line if nothing shown
656  {
657  print '<tr class="liste_total">';
658  print '<td>&nbsp;</td>';
659  print '<td align="right">'.$langs->trans("Total").':</td>';
660  if ($modetax == 0)
661  {
662  print '<td class="nowrap" align="right">&nbsp;</td>';
663  print '<td align="right">&nbsp;</td>';
664  }
665  print '<td align="right">'.price(price2num(0,'MT')).'</td>';
666  print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
667  print '</tr>';
668  }
669 
670  print '</table>';
671 
672  // Total to pay
673  print '<br><br>';
674  print '<table class="noborder" width="100%">';
675  $diff = $x_coll_sum - $x_paye_sum;
676  print '<tr class="liste_total">';
677  print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
678  print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
679  print "</tr>\n";
680 
681  $i++;
682 }
683 echo '</table>';
684 
685 llxFooter();
686 $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.
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_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
Class to manage payments of expense report.
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.
vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets VAT to collect for the given year (and given quarter or month) The function gets the VAT in spli...
Definition: tax.lib.php:643