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