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