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