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