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