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