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