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