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