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