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