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