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