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