dolibarr 23.0.3
clients.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
4 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
42
43// Load translation files required by the page
44$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
45
46include 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 int $date_start_month
62@phan-var-force int $date_start_year
63@phan-var-force int $date_start_day
64@phan-var-force int $date_end_month
65@phan-var-force int $date_end_year
66@phan-var-force int $date_end_day
67@phan-var-force int $year_current
68';
69
70$local = GETPOSTINT('localTaxType');
71
72$min = price2num(GETPOST("min", "alpha"));
73if (empty($min)) {
74 $min = 0;
75}
76
77// Define modetax (0 or 1)
78// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
79$modetax = getDolGlobalInt('TAX_MODE');
80if (GETPOSTISSET("modetax")) {
81 $modetax = GETPOSTINT("modetax");
82}
83if (empty($modetax)) {
84 $modetax = 0;
85}
86
87// Security check
88$socid = GETPOSTINT('socid');
89if ($user->socid) {
90 $socid = $user->socid;
91}
92
93// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
94$hookmanager->initHooks(['customerlocaltaxlist']);
95
96$result = restrictedArea($user, 'tax', '', '', 'charges');
97
98if (empty($local)) {
99 accessforbidden('Parameter localTaxType is missing');
100}
101
102$builddate = dol_now();
103$calc = 0;
104$calcmode = "Unknown";
105$find = '';
106$replace = '';
107$period = '';
108
109
110/*
111 * View
112 */
113
114$form = new Form($db);
115$company_static = new Societe($db);
116
117$morequerystring = '';
118$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
119foreach ($listofparams as $param) {
120 if (GETPOST($param) != '') {
121 $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
122 }
123}
124
125$name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code);
126
127llxHeader('', $name, '', '', 0, 0, '', '', $morequerystring);
128
129
130$fsearch = '<!-- hidden fields for form -->';
131$fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
132$fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
133$fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
134$fsearch .= $langs->trans("SalesTurnoverMinimum").': ';
135$fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" class="width75 right">';
136
137// Show report header
138$calc = getDolGlobalString('MAIN_INFO_LOCALTAX_CALC').$local;
139$description = '';
140if ($calc == 0 || $calc == 1) { // Calculate on invoice for goods and services
141 $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
142 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
143 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
144 if (isModEnabled('comptabilite')) {
145 $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
146 }
147 $description .= $fsearch;
148 $description .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
149
150 $elementcust = $langs->trans("CustomersInvoices");
151 $productcust = $langs->trans("Description");
152 $amountcust = $langs->trans("AmountHT");
153 $elementsup = $langs->trans("SuppliersInvoices");
154 $productsup = $langs->trans("Description");
155 $amountsup = $langs->trans("AmountHT");
156}
157if ($calc == 2) { // Invoice for goods, payment for services
158 $calcmode = $langs->trans("CalcModeLT2Debt");
159 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
160 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
161 if (isModEnabled('comptabilite')) {
162 $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
163 }
164 $description .= $fsearch;
165 $description .= '<span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
166
167 $elementcust = $langs->trans("CustomersInvoices");
168 $productcust = $langs->trans("Description");
169 $amountcust = $langs->trans("AmountHT");
170 $elementsup = $langs->trans("SuppliersInvoices");
171 $productsup = $langs->trans("Description");
172 $amountsup = $langs->trans("AmountHT");
173}
174// Set period
175$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
176
177$builddate = dol_now();
178
179$periodlink = '';
180$exportlink = '';
181
182report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
183
184$vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
185$vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
186
187// VAT Received
188print '<div class="div-table-responsive">';
189print '<table class="noborder centpercent">';
190
191$x_coll_sum = 0; // Initialize value
192$x_paye_sum = 0; // Initialize value
193
194// IRPF that the customer has retained me
195if ($calc == 0 || $calc == 2) {
196 print '<tr class="liste_titre">';
197 print '<td>'.$langs->trans("Num").'</td>';
198 print '<td>'.$langs->trans("Customer").'</td>';
199 print '<td>'.$langs->trans("VATIntraShort").'</td>';
200 print '<td class="right">'.$langs->trans("TotalHT").'</td>';
201 print '<td class="right">'.$vatcust.'</td>';
202 print "</tr>\n";
203
204 $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'sell');
205
206 $action = "tvaclient";
207 $object = &$coll_list;
208 $parameters["mode"] = $modetax;
209 $parameters["start"] = $date_start;
210 $parameters["end"] = $date_end;
211 $parameters["direction"] = 'sell';
212 $parameters["type"] = 'localtax'.$local;
213
214 // Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
215 $hookmanager->initHooks(array('externalbalance'));
216 $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
217
218 if (is_array($coll_list)) {
219 $total = 0;
220 $totalamount = 0;
221 $i = 1;
222 foreach ($coll_list as $coll_key => $coll_obj) {
223 if (($min == 0 || ($min > 0 && $coll_obj['totalht'] > $min)) && ($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']) != 0) {
224 $company_static->fetch($coll_key);
225
226 $intra = str_replace($find, $replace, $company_static->tva_intra);
227
228 print '<tr class="oddeven">';
229 print '<td class="nowrap">'.$i."</td>";
230 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
231 $find = array(' ', '.');
232 $replace = array('', '');
233 print '<td class="nowrap">'.$intra.'</td>';
234 print '<td class="nowrap right">'.price($coll_obj['totalht']).'</td>';
235 print '<td class="nowrap right">'.price($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']).'</td>';
236 $totalamount += $coll_obj['totalht'];
237 $total += ($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']);
238 print "</tr>\n";
239 $i++;
240 }
241 }
242 $x_coll_sum = $total;
243
244 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
245 print '<td class="nowrap right">'.price($totalamount).'</td>';
246 print '<td class="nowrap right">'.price($total).'</td>';
247 print '</tr>';
248 } else {
249 $langs->load("errors");
250 if ($coll_list == -1) {
251 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
252 } elseif ($coll_list == -2) {
253 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
254 } else {
255 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
256 }
257 }
258}
259
260// IRPF I retained my supplier
261if ($calc == 0 || $calc == 1) {
262 print '<tr class="liste_titre">';
263 print '<td>'.$langs->trans("Num")."</td>";
264 print '<td>'.$langs->trans("Supplier")."</td>";
265 print '<td>'.$langs->trans("VATIntraShort").'</td>';
266 print '<td class="right">'.$langs->trans("TotalHT").'</td>';
267 print '<td class="right">'.$vatsup.'</td>';
268 print "</tr>\n";
269
270 $company_static = new Societe($db);
271
272 $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy');
273 $parameters["direction"] = 'buy';
274 $parameters["type"] = 'localtax'.$local;
275
276 $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
277 if (is_array($coll_list)) {
278 $total = 0;
279 $totalamount = 0;
280 $i = 1;
281 foreach ($coll_list as $coll_key => $coll_obj) {
282 if (($min == 0 || ($min > 0 && $coll_obj['totalht'] > $min)) && ($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']) != 0) {
283 $company_static->fetch($coll_key);
284
285 $intra = str_replace($find, $replace, $company_static->tva_intra);
286
287 print '<tr class="oddeven">';
288 print '<td class="nowrap">'.$i."</td>";
289 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
290 $find = array(' ', '.');
291 $replace = array('', '');
292 print '<td class="nowrap">'.$intra."</td>";
293 print '<td class="nowrap right">'.price($coll_obj['totalht']).'</td>';
294 print '<td class="nowrap right">'.price($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']).'</td>';
295 $totalamount += $coll_obj['totalht'];
296 $total += ($local == 1 ? $coll_obj['localtax1'] : $coll_obj['localtax2']);
297 print "</tr>\n";
298 $i++;
299 }
300 }
301 $x_paye_sum = $total;
302
303 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
304 print '<td class="nowrap right">'.price($totalamount).'</td>';
305 print '<td class="nowrap right">'.price($total).'</td>';
306 print '</tr>';
307 } else {
308 $langs->load("errors");
309 if ($coll_list == -1) {
310 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
311 } elseif ($coll_list == -2) {
312 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
313 } else {
314 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
315 }
316 }
317}
318
319if ($calc == 0) {
320 // Total to pay
321 print '<tr><td colspan="5"></td></tr>';
322
323 $diff = $x_coll_sum - $x_paye_sum;
324 print '<tr class="liste_total">';
325 print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").'</td>';
326 print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
327 print "</tr>\n";
328}
329
330print '</table>';
331print '</div>';
332
333
334// End of page
335llxFooter();
336$db->close();
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 generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
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