dolibarr  16.0.1
quadri_detail.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-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2006-2015 Yannick Warnier <ywarnier@beeznest.org>
6  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
9  * Copyright (C) 2021-2022 Open-Dsi <support@open-dsi.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
47 
48 $refresh = (GETPOSTISSET('submit') || GETPOSTISSET('vat_rate_show') || GETPOSTISSET('invoice_type')) ? true : false;
49 $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : '';
50 $vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'alphanohtml') : -1;
51 
52 include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php';
53 
54 $min = price2num(GETPOST("min", "alpha"));
55 if (empty($min)) {
56  $min = 0;
57 }
58 
59 // Define modetax (0 or 1)
60 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
61 $modetax = (empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE);
62 if (GETPOSTISSET("modetax")) {
63  $modetax = GETPOSTINT("modetax");
64 }
65 if (empty($modetax)) {
66  $modetax = 0;
67 }
68 
69 $object = new Tva($db);
70 
71 // Security check
72 $socid = GETPOSTINT('socid');
73 if ($user->socid) {
74  $socid = $user->socid;
75 }
76 $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
77 
78 
79 /*
80  * View
81  */
82 
83 $form = new Form($db);
84 $company_static = new Societe($db);
85 $invoice_customer = new Facture($db);
86 $invoice_supplier = new FactureFournisseur($db);
87 $expensereport = new ExpenseReport($db);
88 $product_static = new Product($db);
89 $payment_static = new Paiement($db);
90 $paymentfourn_static = new PaiementFourn($db);
91 $paymentexpensereport_static = new PaymentExpenseReport($db);
92 
93 $morequerystring = '';
94 $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
95 foreach ($listofparams as $param) {
96  if (GETPOST($param) != '') {
97  $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
98  }
99 }
100 
101 $title = $langs->trans("VATReport")." ".dol_print_date($date_start, '', 'tzserver')." -> ".dol_print_date($date_end, '', 'tzserver');
102 llxHeader('', $title, '', '', 0, 0, '', '', $morequerystring);
103 
104 
105 //print load_fiche_titre($langs->trans("VAT"),"");
106 
107 //$fsearch.='<br>';
108 $fsearch = '<!-- hidden fields for form -->';
109 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
110 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
111 //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
112 //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
113 
114 
115 // Show report header
116 $name = $langs->trans("VATReportByRates");
117 $calcmode = '';
118 if ($modetax == 0) {
119  $calcmode = $langs->trans('OptionVATDefault');
120 }
121 if ($modetax == 1) {
122  $calcmode = $langs->trans('OptionVATDebitOption');
123 }
124 if ($modetax == 2) {
125  $calcmode = $langs->trans('OptionPaymentForProductAndServices');
126 }
127 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
128 // Set period
129 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
130 $period .= ' - ';
131 $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
132 $prevyear = $date_start_year;
133 $prevquarter = $q;
134 if ($prevquarter > 1) {
135  $prevquarter--;
136 } else {
137  $prevquarter = 4;
138  $prevyear--;
139 }
140 $nextyear = $date_start_year;
141 $nextquarter = $q;
142 if ($nextquarter < 4) {
143  $nextquarter++;
144 } else {
145  $nextquarter = 1;
146  $nextyear++;
147 }
148 $description .= $fsearch;
149 $builddate = dol_now();
150 
151 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') {
152  $description .= $langs->trans("RulesVATDueProducts");
153 }
154 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
155  $description .= $langs->trans("RulesVATInProducts");
156 }
157 if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') {
158  $description .= '<br>'.$langs->trans("RulesVATDueServices");
159 }
160 if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
161  $description .= '<br>'.$langs->trans("RulesVATInServices");
162 }
163 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
164  $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
165 }
166 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
167  $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
168 }
169 
170 // Customers invoices
171 $elementcust = $langs->trans("CustomersInvoices");
172 $productcust = $langs->trans("ProductOrService");
173 $amountcust = $langs->trans("AmountHT");
174 $vatcust = $langs->trans("VATReceived");
175 $namecust = $langs->trans("Name");
176 if ($mysoc->tva_assuj) {
177  $vatcust .= ' ('.$langs->trans("VATToPay").')';
178 }
179 
180 // Suppliers invoices
181 $elementsup = $langs->trans("SuppliersInvoices");
182 $productsup = $productcust;
183 $amountsup = $amountcust;
184 $vatsup = $langs->trans("VATPaid");
185 $namesup = $namecust;
186 if ($mysoc->tva_assuj) {
187  $vatsup .= ' ('.$langs->trans("ToGetBack").')';
188 }
189 
190 $optioncss = GETPOST('optioncss', 'alpha');
191 if ($optioncss != "print") {
192  report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
193 }
194 
195 $vatcust = $langs->trans("VATReceived");
196 $vatsup = $langs->trans("VATPaid");
197 $vatexpensereport = $langs->trans("VATPaid");
198 
199 
200 // VAT Received and paid
201 print '<div class="div-table-responsive">';
202 print '<table class="noborder centpercent">';
203 
204 $y = $year_current;
205 $i = 0;
206 
207 $columns = 7;
208 $span = $columns;
209 if ($modetax != 1) {
210  $span += 2;
211 }
212 
213 // Load arrays of datas
214 $x_coll = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
215 $x_paye = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
216 
217 if (!is_array($x_coll) || !is_array($x_paye)) {
218  $langs->load("errors");
219  if ($x_coll == -1) {
220  print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
221  } elseif ($x_coll == -2) {
222  print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
223  } else {
224  print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
225  }
226 } else {
227  $x_both = array();
228  //now, from these two arrays, get another array with one rate per line
229  foreach (array_keys($x_coll) as $my_coll_rate) {
230  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
231  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
232  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
233  $x_both[$my_coll_rate]['paye']['vat'] = 0;
234  $x_both[$my_coll_rate]['coll']['links'] = '';
235  $x_both[$my_coll_rate]['coll']['detail'] = array();
236  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
237  $invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
238  $invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
239  $invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
240 
241  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
242  $company_static->id = $x_coll[$my_coll_rate]['company_id'][$id];
243  $company_static->name = $x_coll[$my_coll_rate]['company_name'][$id];
244  $company_static->name_alias = $x_coll[$my_coll_rate]['company_alias'][$id];
245  $company_static->email = $x_coll[$my_coll_rate]['company_email'][$id];
246  $company_static->tva_intra = $x_coll[$my_coll_rate]['tva_intra'][$id];
247  $company_static->client = $x_coll[$my_coll_rate]['company_client'][$id];
248  $company_static->fournisseur = $x_coll[$my_coll_rate]['company_fournisseur'][$id];
249  $company_static->status = $x_coll[$my_coll_rate]['company_status'][$id];
250  $company_static->code_client = $x_coll[$my_coll_rate]['company_customer_code'][$id];
251  $company_static->code_compta_client = $x_coll[$my_coll_rate]['company_customer_accounting_code'][$id];
252  $company_static->code_fournisseur = $x_coll[$my_coll_rate]['company_supplier_code'][$id];
253  $company_static->code_compta_fournisseur = $x_coll[$my_coll_rate]['company_supplier_accounting_code'][$id];
254 
255  $x_both[$my_coll_rate]['coll']['detail'][] = array(
256  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
257  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
258  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
259  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
260  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
261  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
262  'payment_ref'=>$x_coll[$my_coll_rate]['payment_ref'][$id],
263  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
264  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
265  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
266  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
267  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
268  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
269 
270  'company_link'=>$company_static->getNomUrl(1, '', 20),
271 
272  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
273  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
274  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
275  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
276  'link' =>$invoice_customer->getNomUrl(1, '', 12)
277  );
278  }
279  }
280  // tva paid
281  foreach (array_keys($x_paye) as $my_paye_rate) {
282  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
283  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
284  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
285  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
286  $x_both[$my_paye_rate]['coll']['vat'] = 0;
287  }
288  $x_both[$my_paye_rate]['paye']['links'] = '';
289  $x_both[$my_paye_rate]['paye']['detail'] = array();
290 
291  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
292  // ExpenseReport
293  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
294  $expensereport->id = $x_paye[$my_paye_rate]['facid'][$id];
295  $expensereport->ref = $x_paye[$my_paye_rate]['facnum'][$id];
296  $expensereport->type = $x_paye[$my_paye_rate]['type'][$id];
297 
298  $x_both[$my_paye_rate]['paye']['detail'][] = array(
299  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
300  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
301  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
302  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
303  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
304  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
305  'payment_ref' =>$x_paye[$my_paye_rate]['payment_ref'][$id],
306  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
307  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
308  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
309  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
310  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
311  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
312  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
313  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
314  'link' =>$expensereport->getNomUrl(1)
315  );
316  } else {
317  $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
318  $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
319  $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
320 
321  $company_static->id = $x_paye[$my_paye_rate]['company_id'][$id];
322  $company_static->name = $x_paye[$my_paye_rate]['company_name'][$id];
323  $company_static->name_alias = $x_paye[$my_paye_rate]['company_alias'][$id];
324  $company_static->email = $x_paye[$my_paye_rate]['company_email'][$id];
325  $company_static->tva_intra = $x_paye[$my_paye_rate]['tva_intra'][$id];
326  $company_static->client = $x_paye[$my_paye_rate]['company_client'][$id];
327  $company_static->fournisseur = $x_paye[$my_paye_rate]['company_fournisseur'][$id];
328  $company_static->status = $x_paye[$my_paye_rate]['company_status'][$id];
329  $company_static->code_client = $x_paye[$my_paye_rate]['company_customer_code'][$id];
330  $company_static->code_compta_client = $x_paye[$my_paye_rate]['company_customer_accounting_code'][$id];
331  $company_static->code_fournisseur = $x_paye[$my_paye_rate]['company_supplier_code'][$id];
332  $company_static->code_compta_fournisseur = $x_paye[$my_paye_rate]['company_supplier_accounting_code'][$id];
333 
334  $x_both[$my_paye_rate]['paye']['detail'][] = array(
335  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
336  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
337  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
338  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
339  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
340  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
341  'payment_ref'=>$x_paye[$my_paye_rate]['payment_ref'][$id],
342  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
343  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
344  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
345  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
346  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
347  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
348 
349  'company_link'=>$company_static->getNomUrl(1, '', 20),
350 
351  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
352  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
353  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
354  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
355  'link' =>$invoice_supplier->getNomUrl(1, '', 12)
356  );
357  }
358  }
359  }
360  //now we have an array (x_both) indexed by rates for coll and paye
361 
362 
363  //print table headers for this quadri - incomes first
364 
365  $x_coll_sum = 0;
366  $x_coll_ht = 0;
367  $x_paye_sum = 0;
368  $x_paye_ht = 0;
369 
370  //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
371 
372  // Customers invoices
373  print '<tr class="liste_titre">';
374  print '<td class="left">'.$elementcust.'</td>';
375  print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
376  if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
377  print '<td class="left">'.$langs->trans("DatePayment").'</td>';
378  } else {
379  print '<td></td>';
380  }
381  print '<td class="left">'.$namecust.'</td>';
382  print '<td class="left">'.$productcust.'</td>';
383  if ($modetax != 1) {
384  print '<td class="right">'.$amountcust.'</td>';
385  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
386  }
387  print '<td class="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
388  print '<td class="right">'.$vatcust.'</td>';
389  print '</tr>';
390 
391  $action = "tvadetail";
392  $parameters["mode"] = $modetax;
393  $parameters["start"] = $date_start;
394  $parameters["end"] = $date_end;
395  $parameters["type"] = 'vat';
396 
397  $object = array(&$x_coll, &$x_paye, &$x_both);
398  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
399  $hookmanager->initHooks(array('externalbalance'));
400  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
401 
402  foreach (array_keys($x_coll) as $rate) {
403  $subtot_coll_total_ht = 0;
404  $subtot_coll_vat = 0;
405 
406  if (is_array($x_both[$rate]['coll']['detail'])) {
407  // VAT Rate
408  print "<tr>";
409  print '<td class="tax_rate" colspan="' . ($span+1) . '">';
410  print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
411  print ' - <a href="'.DOL_URL_ROOT.'/compta/tva/quadri_detail.php?invoice_type=customer';
412  if ($invoice_type != 'customer' || !GETPOSTISSET('vat_rate_show') || GETPOST('vat_rate_show') != $rate) {
413  print '&amp;vat_rate_show='.urlencode($rate);
414  }
415  print '&amp;date_startyear='.urlencode($date_start_year).'&amp;date_startmonth='.urlencode($date_start_month).'&amp;date_startday='.urlencode($date_start_day).'&amp;date_endyear='.urlencode($date_end_year).'&amp;date_endmonth='.urlencode($date_end_month).'&amp;date_endday='.urlencode($date_end_day).'">' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '</a>';
416  print '</td>';
417  print '</tr>'."\n";
418 
419  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
420  // Define type
421  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
422  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
423  // Try to enhance type detection using date_start and date_end for free lines where type
424  // was not saved.
425  if (!empty($fields['ddate_start'])) {
426  $type = 1;
427  }
428  if (!empty($fields['ddate_end'])) {
429  $type = 1;
430  }
431 
432  // Payment
433  $ratiopaymentinvoice=1;
434  if ($modetax != 1) {
435  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
436  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
437  } else {
438  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
439  $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
440  }
441  }
442  }
443 
444  // Total collected
445  $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
446 
447  // VAT
448  $temp_vat=$fields['vat']*$ratiopaymentinvoice;
449 
450  $subtot_coll_total_ht += $temp_ht;
451  $subtot_coll_vat += $temp_vat;
452  $x_coll_sum += $temp_vat;
453  }
454  }
455 
456  if ($invoice_type == 'customer' && $vat_rate_show == $rate) {
457  if (is_array($x_both[$rate]['coll']['detail'])) {
458  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
459  /*$company_static->id = $fields['company_id'];
460  $company_static->name = $fields['company_name'];
461  $company_static->name_alias = $fields['company_alias'];
462  $company_static->email = $fields['company_email'];
463  $company_static->tva_intra = $fields['tva_intra'];
464  $company_static->client = $fields['company_client'];
465  $company_static->fournisseur = $fields['company_fournisseur'];
466  $company_static->status = $fields['company_status'];
467  $company_static->code_client = $fields['company_client'];
468  $company_static->code_compta_client = $fields['company_customer_code'];
469  $company_static->code_fournisseur = $fields['company_customer_accounting_code'];
470  $company_static->code_compta_fournisseur = $fields['company_supplier_accounting_code'];*/
471 
472  // Define type
473  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
474  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
475  // Try to enhance type detection using date_start and date_end for free lines where type
476  // was not saved.
477  if (!empty($fields['ddate_start'])) {
478  $type = 1;
479  }
480  if (!empty($fields['ddate_end'])) {
481  $type = 1;
482  }
483 
484 
485  print '<tr class="oddeven">';
486 
487  // Ref
488  print '<td class="nowrap left">' . $fields['link'] . '</td>';
489 
490  // Invoice date
491  print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
492 
493  // Payment date
494  if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
495  else print '<td></td>';
496 
497  // Company name
498  print '<td class="tdmaxoverflow150">';
499  //print $company_static->getNomUrl(1);
500  print $fields['company_link'];
501  print '</td>';
502 
503  // Description
504  print '<td class="left">';
505  if ($fields['pid']) {
506  $product_static->id = $fields['pid'];
507  $product_static->ref = $fields['pref'];
508  $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
509  print $product_static->getNomUrl(1);
510  if (dol_string_nohtmltag($fields['descr'])) {
511  print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
512  }
513  } else {
514  if ($type) {
515  $text = img_object($langs->trans('Service'), 'service');
516  } else {
517  $text = img_object($langs->trans('Product'), 'product');
518  }
519  if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
520  if ($reg[1] == 'DEPOSIT') {
521  $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
522  } elseif ($reg[1] == 'CREDIT_NOTE') {
523  $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
524  } else {
525  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
526  }
527  }
528  print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
529 
530  // Show range
531  print_date_range($fields['ddate_start'], $fields['ddate_end']);
532  }
533  print '</td>';
534 
535  // Total HT
536  if ($modetax != 1) {
537  print '<td class="nowrap right">';
538  print price($fields['totalht']);
539  if (price2num($fields['ftotal_ttc'])) {
540  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
541  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
542  //print ' ('.round($ratiolineinvoice*100,2).'%)';
543  }
544  print '</td>';
545  }
546 
547  // Payment
548  $ratiopaymentinvoice = 1;
549  if ($modetax != 1) {
550  print '<td class="nowrap right">';
551  //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
552  if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
553  $payment_static->id = $fields['payment_id'];
554  $payment_static->ref = $fields['payment_ref'];
555  print $payment_static->getNomUrl(2, '', '', 0).' ';
556  }
557  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
558  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
559  print $langs->trans("NA");
560  } else {
561  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
562  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
563  }
564  print price(price2num($fields['payment_amount'], 'MT'));
565  if (isset($fields['payment_amount'])) {
566  print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
567  }
568  }
569  print '</td>';
570  }
571 
572  // Total collected
573  print '<td class="nowrap right">';
574  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
575  print price(price2num($temp_ht, 'MT'), 1);
576  print '</td>';
577 
578  // VAT
579  print '<td class="nowrap right">';
580  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
581  print price(price2num($temp_vat, 'MT'), 1);
582  //print price($fields['vat']);
583  print '</td>';
584  print '</tr>';
585 
586  //$subtot_coll_total_ht += $temp_ht;
587  //$subtot_coll_vat += $temp_vat;
588  //$x_coll_sum += $temp_vat;
589  }
590  }
591  }
592  // Total customers for this vat rate
593  print '<tr class="liste_total">';
594  print '<td colspan="4"></td>';
595  print '<td class="right">'.$langs->trans("Total").':</td>';
596  if ($modetax != 1) {
597  print '<td class="nowrap right">&nbsp;</td>';
598  print '<td class="right">&nbsp;</td>';
599  }
600  print '<td class="right"><span class="amount">'.price(price2num($subtot_coll_total_ht, 'MT')).'</span></td>';
601  print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_coll_vat, 'MT')).'</span></td>';
602  print '</tr>';
603  }
604 
605  if (count($x_coll) == 0) { // Show a total line if nothing shown
606  print '<tr class="liste_total">';
607  print '<td colspan="4"></td>';
608  print '<td class="right">'.$langs->trans("Total").':</td>';
609  if ($modetax != 1) {
610  print '<td class="nowrap right">&nbsp;</td>';
611  print '<td class="right">&nbsp;</td>';
612  }
613  print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
614  print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
615  print '</tr>';
616  }
617 
618  // Blank line
619  print '<tr><td colspan="'.($span+2).'">&nbsp;</td></tr>';
620 
621  // Print table headers for this quadri - expenses
622  print '<tr class="liste_titre liste_titre_topborder">';
623  print '<td class="left">'.$elementsup.'</td>';
624  print '<td class="left">'.$langs->trans("DateInvoice").'</td>';
625  if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>';
626  else print '<td></td>';
627  print '<td class="left">'.$namesup.'</td>';
628  print '<td class="left">'.$productsup.'</td>';
629  if ($modetax != 1) {
630  print '<td class="right">'.$amountsup.'</td>';
631  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
632  }
633  print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
634  print '<td class="right">'.$vatsup.'</td>';
635  print '</tr>'."\n";
636 
637  foreach (array_keys($x_paye) as $rate) {
638  $subtot_paye_total_ht = 0;
639  $subtot_paye_vat = 0;
640 
641  if (is_array($x_both[$rate]['paye']['detail'])) {
642  print "<tr>";
643  print '<td class="tax_rate" colspan="' . ($span+1) . '">';
644  print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%';
645  print ' - <a href="'.DOL_URL_ROOT.'/compta/tva/quadri_detail.php?invoice_type=supplier';
646  if ($invoice_type != 'supplier' || !GETPOSTISSET('vat_rate_show') || GETPOST('vat_rate_show') != $rate) {
647  print '&amp;vat_rate_show='.urlencode($rate);
648  }
649  print '&amp;date_startyear='.urlencode($date_start_year).'&amp;date_startmonth='.urlencode($date_start_month).'&amp;date_startday='.urlencode($date_start_day).'&amp;date_endyear='.urlencode($date_end_year).'&amp;date_endmonth='.urlencode($date_end_month).'&amp;date_endday='.urlencode($date_end_day).'">' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '</a>';
650  print '</td>';
651  print '</tr>'."\n";
652 
653  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
654  // Define type
655  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
656  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
657  // Try to enhance type detection using date_start and date_end for free lines where type
658  // was not saved.
659  if (!empty($fields['ddate_start'])) {
660  $type = 1;
661  }
662  if (!empty($fields['ddate_end'])) {
663  $type = 1;
664  }
665 
666  // Payment
667  $ratiopaymentinvoice = 1;
668  if ($modetax != 1) {
669  if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
670  || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
671  } else {
672  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
673  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
674  }
675  }
676  }
677 
678  // VAT paid
679  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
680 
681  // VAT
682  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
683 
684  $subtot_paye_total_ht += $temp_ht;
685  $subtot_paye_vat += $temp_vat;
686  $x_paye_sum += $temp_vat;
687  }
688 
689  if ($invoice_type == 'supplier' && $vat_rate_show == $rate) {
690  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
691  /*$company_static->id = $fields['company_id'];
692  $company_static->name = $fields['company_name'];
693  $company_static->name_alias = $fields['company_alias'];
694  $company_static->email = $fields['company_email'];
695  $company_static->tva_intra = $fields['tva_intra'];
696  $company_static->client = $fields['company_client'];
697  $company_static->fournisseur = $fields['company_fournisseur'];
698  $company_static->status = $fields['company_status'];
699  $company_static->code_client = $fields['company_client'];
700  $company_static->code_compta_client = $fields['company_customer_code'];
701  $company_static->code_fournisseur = $fields['company_customer_accounting_code'];
702  $company_static->code_compta_fournisseur = $fields['company_supplier_accounting_code'];*/
703 
704  // Define type
705  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
706  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
707  // Try to enhance type detection using date_start and date_end for free lines where type
708  // was not saved.
709  if (!empty($fields['ddate_start'])) {
710  $type = 1;
711  }
712  if (!empty($fields['ddate_end'])) {
713  $type = 1;
714  }
715 
716 
717  print '<tr class="oddeven">';
718 
719  // Ref
720  print '<td class="nowrap left">' . $fields['link'] . '</td>';
721 
722  // Invoice date
723  print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
724 
725  // Payment date
726  if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') {
727  print '<td class="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
728  } else {
729  print '<td></td>';
730  }
731 
732  // Company name
733  print '<td class="tdmaxoverflow150">';
734  //print $company_static->getNomUrl(1);
735  print $fields['company_link'];
736  print '</td>';
737 
738  // Description
739  print '<td class="left">';
740  if ($fields['pid']) {
741  $product_static->id = $fields['pid'];
742  $product_static->ref = $fields['pref'];
743  $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
744  print $product_static->getNomUrl(1);
745  if (dol_string_nohtmltag($fields['descr'])) {
746  print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
747  }
748  } else {
749  if ($type) {
750  $text = img_object($langs->trans('Service'), 'service');
751  } else {
752  $text = img_object($langs->trans('Product'), 'product');
753  }
754  if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
755  if ($reg[1] == 'DEPOSIT') {
756  $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
757  } elseif ($reg[1] == 'CREDIT_NOTE') {
758  $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
759  } else {
760  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
761  }
762  }
763  print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
764 
765  // Show range
766  print_date_range($fields['ddate_start'], $fields['ddate_end']);
767  }
768  print '</td>';
769 
770  // Total HT
771  if ($modetax != 1) {
772  print '<td class="nowrap right">';
773  print price($fields['totalht']);
774  if (price2num($fields['ftotal_ttc'])) {
775  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
776  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
777  //print ' ('.round($ratiolineinvoice*100,2).'%)';
778  }
779  print '</td>';
780  }
781 
782  // Payment
783  $ratiopaymentinvoice = 1;
784  if ($modetax != 1) {
785  print '<td class="nowrap right">';
786  if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
787  $paymentfourn_static->id = $fields['payment_id'];
788  $paymentfourn_static->ref = $fields['payment_ref'];
789  print $paymentfourn_static->getNomUrl(2, '', '', 0).' ';
790  }
791 
792  if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
793  || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
794  print $langs->trans("NA");
795  } else {
796  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
797  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
798  }
799  print price(price2num($fields['payment_amount'], 'MT'));
800  if (isset($fields['payment_amount'])) {
801  print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
802  }
803  }
804  print '</td>';
805  }
806 
807  // VAT paid
808  print '<td class="nowrap right">';
809  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
810  print price(price2num($temp_ht, 'MT'), 1);
811  print '</td>';
812 
813  // VAT
814  print '<td class="nowrap right">';
815  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
816  print price(price2num($temp_vat, 'MT'), 1);
817  //print price($fields['vat']);
818  print '</td>';
819  print '</tr>';
820 
821  //$subtot_paye_total_ht += $temp_ht;
822  //$subtot_paye_vat += $temp_vat;
823  //$x_paye_sum += $temp_vat;
824  }
825  }
826  }
827 
828  // Total suppliers for this vat rate
829  print '<tr class="liste_total">';
830  print '<td colspan="4"></td>';
831  print '<td class="right">'.$langs->trans("Total").':</td>';
832  if ($modetax != 1) {
833  print '<td class="nowrap right">&nbsp;</td>';
834  print '<td class="right">&nbsp;</td>';
835  }
836  print '<td class="right"><span class="amount">'.price(price2num($subtot_paye_total_ht, 'MT')).'</span></td>';
837  print '<td class="nowrap right"><span class="amount">'.price(price2num($subtot_paye_vat, 'MT')).'</span></td>';
838  print '</tr>';
839  }
840 
841  if (count($x_paye) == 0) { // Show a total line if nothing shown
842  print '<tr class="liste_total">';
843  print '<td colspan="4"></td>';
844  print '<td class="right">'.$langs->trans("Total").':</td>';
845  if ($modetax != 1) {
846  print '<td class="nowrap right">&nbsp;</td>';
847  print '<td class="right">&nbsp;</td>';
848  }
849  print '<td class="right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
850  print '<td class="nowrap right"><span class="amount">'.price(price2num(0, 'MT')).'</span></td>';
851  print '</tr>';
852  }
853 
854  print '</table>';
855  print '</div>';
856 
857  // Total to pay
858  print '<br><br>';
859  print '<table class="noborder centpercent">';
860  $diff = $x_coll_sum - $x_paye_sum;
861  print '<tr class="liste_total">';
862  print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
863  print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
864  print "</tr>\n";
865 
866  $i++;
867 }
868 print '</table>';
869 
870 llxFooter();
871 $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
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
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.
Put here description of your class.
Definition: tva.class.php:35
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.
tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets Tax to collect for the given year (and given quarter or month) The function gets the Tax in spli...
Definition: tax.lib.php:667
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;...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
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.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...