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