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