dolibarr 21.0.0-beta
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-2024 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';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
34
44// Load translation files required by the page
45$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
46
47$local = GETPOSTINT('localTaxType');
48
49// Date range
50$year = GETPOSTINT("year");
51if (empty($year)) {
52 $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
53 $year_start = $year_current;
54} else {
55 $year_current = $year;
56 $year_start = $year;
57}
58$date_start = dol_mktime(0, 0, 0, GETPOSTINT("date_startmonth"), GETPOSTINT("date_startday"), GETPOSTINT("date_startyear"));
59$date_end = dol_mktime(23, 59, 59, GETPOSTINT("date_endmonth"), GETPOSTINT("date_endday"), GETPOSTINT("date_endyear"));
60$q = 0;
61// Quarter
62if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
63 $q = GETPOST("q");
64 if (empty($q)) {
65 if (GETPOST("month")) {
66 $date_start = dol_get_first_day($year_start, GETPOSTINT("month"), false);
67 $date_end = dol_get_last_day($year_start, GETPOSTINT("month"), false);
68 } else {
69 $date_start = dol_get_first_day($year_start, !getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
70 if (!getDolGlobalString('MAIN_INFO_VAT_RETURN') || getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 2) {
71 $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
72 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 3) {
73 $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
74 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 1) {
75 $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
76 }
77 }
78 } else {
79 if ($q == 1) {
80 $date_start = dol_get_first_day($year_start, 1, false);
81 $date_end = dol_get_last_day($year_start, 3, false);
82 }
83 if ($q == 2) {
84 $date_start = dol_get_first_day($year_start, 4, false);
85 $date_end = dol_get_last_day($year_start, 6, false);
86 }
87 if ($q == 3) {
88 $date_start = dol_get_first_day($year_start, 7, false);
89 $date_end = dol_get_last_day($year_start, 9, false);
90 }
91 if ($q == 4) {
92 $date_start = dol_get_first_day($year_start, 10, false);
93 $date_end = dol_get_last_day($year_start, 12, false);
94 }
95 }
96}
97
98$min = price2num(GETPOST("min", "alpha"));
99if (empty($min)) {
100 $min = 0;
101}
102
103// Define modetax (0 or 1)
104// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
105$modetax = getDolGlobalString('TAX_MODE');
106if (GETPOSTISSET("modetax")) {
107 $modetax = GETPOSTINT("modetax");
108}
109if (empty($modetax)) {
110 $modetax = 0;
111}
112
113// Security check
114$socid = GETPOSTINT('socid');
115if ($user->socid) {
116 $socid = $user->socid;
117}
118
119// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
120$hookmanager->initHooks(['customerlocaltaxlist']);
121
122$result = restrictedArea($user, 'tax', '', '', 'charges');
123
124if (empty($local)) {
125 accessforbidden('Parameter localTaxType is missing');
126}
127
128$builddate = dol_now();
129$calc = 0;
130$calcmode = "Unknown";
131$find = '';
132$replace = '';
133$period = '';
134/*
135 * View
136 */
137
138$form = new Form($db);
139$company_static = new Societe($db);
140
141$morequerystring = '';
142$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
143foreach ($listofparams as $param) {
144 if (GETPOST($param) != '') {
145 $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
146 }
147}
148
149llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
150
151
152$name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code);
153
154$fsearch = '<!-- hidden fields for form -->';
155$fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
156$fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
157$fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
158$fsearch .= $langs->trans("SalesTurnoverMinimum").': ';
159$fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" size="6">';
160
161$calc = getDolGlobalString('MAIN_INFO_LOCALTAX_CALC').$local;
162// Affiche en-tete du rapport
163$description = '';
164if ($calc == 0 || $calc == 1) { // Calculate on invoice for goods and services
165 $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
166 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
167 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
168 if (isModEnabled('comptabilite')) {
169 $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
170 }
171 $description .= $fsearch;
172 $description .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
173 $builddate = dol_now();
174
175 $elementcust = $langs->trans("CustomersInvoices");
176 $productcust = $langs->trans("Description");
177 $amountcust = $langs->trans("AmountHT");
178 $elementsup = $langs->trans("SuppliersInvoices");
179 $productsup = $langs->trans("Description");
180 $amountsup = $langs->trans("AmountHT");
181}
182if ($calc == 2) { // Invoice for goods, payment for services
183 $calcmode = $langs->trans("CalcModeLT2Debt");
184 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
185 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
186 if (isModEnabled('comptabilite')) {
187 $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
188 }
189 $description .= $fsearch;
190 $description .= '<span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
191 $builddate = dol_now();
192
193 $elementcust = $langs->trans("CustomersInvoices");
194 $productcust = $langs->trans("Description");
195 $amountcust = $langs->trans("AmountHT");
196 $elementsup = $langs->trans("SuppliersInvoices");
197 $productsup = $langs->trans("Description");
198 $amountsup = $langs->trans("AmountHT");
199}
200
201$periodlink = '';
202$exportlink = '';
203
204report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
205
206$vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
207$vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
208
209print '<div class="div-table-responsive">';
210print '<table class="liste noborder centpercent">';
211
212$x_coll_sum = 0; // Initialize value
213$x_paye_sum = 0; // Initialize value
214
215// IRPF that the customer has retained me
216if ($calc == 0 || $calc == 2) {
217 print '<tr class="liste_titre">';
218 print '<td class="left">'.$langs->trans("Num").'</td>';
219 print '<td class="left">'.$langs->trans("Customer").'</td>';
220 print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</td>';
221 print '<td class="right">'.$langs->trans("TotalHT").'</td>';
222 print '<td class="right">'.$vatcust.'</td>';
223 print "</tr>\n";
224
225 $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'sell');
226
227 $action = "tvaclient";
228 $object = &$coll_list;
229 $parameters["mode"] = $modetax;
230 $parameters["start"] = $date_start;
231 $parameters["end"] = $date_end;
232 $parameters["direction"] = 'sell';
233 $parameters["type"] = 'localtax'.$local;
234
235 // Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
236 $hookmanager->initHooks(array('externalbalance'));
237 $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
238
239 if (is_array($coll_list)) {
240 $total = 0;
241 $totalamount = 0;
242 $i = 1;
243 foreach ($coll_list as $coll_obj) {
244 if (($min == 0 || ($min > 0 && $coll_obj->amount > $min)) && ($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2) != 0) {
245 $intra = str_replace($find, $replace, $coll_obj->tva_intra);
246 if (empty($intra)) {
247 if ($coll_obj->assuj == '1') {
248 $intra = $langs->trans('Unknown');
249 } else {
250 $intra = '';
251 }
252 }
253 print '<tr class="oddeven">';
254 print '<td class="nowrap">'.$i."</td>";
255 $company_static->id = $coll_obj->socid;
256 $company_static->name = $coll_obj->name;
257 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
258 $find = array(' ', '.');
259 $replace = array('', '');
260 print '<td class="nowrap">'.$intra.'</td>';
261 print '<td class="nowrap right">'.price($coll_obj->amount).'</td>';
262 print '<td class="nowrap right">'.price($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2).'</td>';
263 $totalamount += $coll_obj->amount;
264 $total += ($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2);
265 print "</tr>\n";
266 $i++;
267 }
268 }
269 $x_coll_sum = $total;
270
271 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
272 print '<td class="nowrap right">'.price($totalamount).'</td>';
273 print '<td class="nowrap right">'.price($total).'</td>';
274 print '</tr>';
275 } else {
276 $langs->load("errors");
277 if ($coll_list == -1) {
278 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
279 } elseif ($coll_list == -2) {
280 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
281 } else {
282 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
283 }
284 }
285}
286
287// IRPF I retained my supplier
288if ($calc == 0 || $calc == 1) {
289 print '<tr class="liste_titre">';
290 print '<td class="left">'.$langs->trans("Num")."</td>";
291 print '<td class="left">'.$langs->trans("Supplier")."</td>";
292 print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</td>';
293 print '<td class="right">'.$langs->trans("TotalHT").'</td>';
294 print '<td class="right">'.$vatsup.'</td>';
295 print "</tr>\n";
296
297 $company_static = new Societe($db);
298
299 $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy');
300 $parameters["direction"] = 'buy';
301 $parameters["type"] = 'localtax'.$local;
302
303 $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
304 if (is_array($coll_list)) {
305 $total = 0;
306 $totalamount = 0;
307 $i = 1;
308 foreach ($coll_list as $coll_obj) {
309 if (($min == 0 || ($min > 0 && $coll_obj->amount > $min)) && ($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2) != 0) {
310 $intra = str_replace($find, $replace, $coll_obj->tva_intra);
311 if (empty($intra)) {
312 if ($coll_obj->assuj == '1') {
313 $intra = $langs->trans('Unknown');
314 } else {
315 $intra = '';
316 }
317 }
318 print '<tr class="oddeven">';
319 print '<td class="nowrap">'.$i."</td>";
320 $company_static->id = $coll_obj->socid;
321 $company_static->name = $coll_obj->name;
322 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
323 $find = array(' ', '.');
324 $replace = array('', '');
325 print '<td class="nowrap">'.$intra."</td>";
326 print '<td class="nowrap right">'.price($coll_obj->amount).'</td>';
327 print '<td class="nowrap right">'.price($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2).'</td>';
328 $totalamount += $coll_obj->amount;
329 $total += ($local == 1 ? $coll_obj->localtax1 : $coll_obj->localtax2);
330 print "</tr>\n";
331 $i++;
332 }
333 }
334 $x_paye_sum = $total;
335
336 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
337 print '<td class="nowrap right">'.price($totalamount).'</td>';
338 print '<td class="nowrap right">'.price($total).'</td>';
339 print '</tr>';
340 } else {
341 $langs->load("errors");
342 if ($coll_list == -1) {
343 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
344 } elseif ($coll_list == -2) {
345 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
346 } else {
347 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
348 }
349 }
350}
351
352if ($calc == 0) {
353 // Total to pay
354 print '<tr><td colspan="5"></td></tr>';
355
356 $diff = $x_coll_sum - $x_paye_sum;
357 print '<tr class="liste_total">';
358 print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
359 print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
360 print "</tr>\n";
361}
362
363print '</table>';
364print '</div>';
365
366
367// End of page
368llxFooter();
369$db->close();
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 generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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 '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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