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