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 Frédéric France <frederic.france@netlogic.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
36
37$local = GETPOSTINT('localTaxType');
38
39// Date range
40$year = GETPOSTINT("year");
41if (empty($year)) {
42 $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
43 $year_start = $year_current;
44} else {
45 $year_current = $year;
46 $year_start = $year;
47}
48$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
49$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
50// Quarter
51if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
52 $q = GETPOST("q");
53 if (empty($q)) {
54 if (GETPOST("month")) {
55 $date_start = dol_get_first_day($year_start, GETPOST("month"), false);
56 $date_end = dol_get_last_day($year_start, GETPOST("month"), false);
57 } else {
58 $date_start = dol_get_first_day($year_start, !getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
59 if (!getDolGlobalString('MAIN_INFO_VAT_RETURN') || getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 2) {
60 $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
61 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 3) {
62 $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
63 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 1) {
64 $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
65 }
66 }
67 } else {
68 if ($q == 1) {
69 $date_start = dol_get_first_day($year_start, 1, false);
70 $date_end = dol_get_last_day($year_start, 3, false);
71 }
72 if ($q == 2) {
73 $date_start = dol_get_first_day($year_start, 4, false);
74 $date_end = dol_get_last_day($year_start, 6, false);
75 }
76 if ($q == 3) {
77 $date_start = dol_get_first_day($year_start, 7, false);
78 $date_end = dol_get_last_day($year_start, 9, false);
79 }
80 if ($q == 4) {
81 $date_start = dol_get_first_day($year_start, 10, false);
82 $date_end = dol_get_last_day($year_start, 12, false);
83 }
84 }
85}
86
87$min = price2num(GETPOST("min", "alpha"));
88if (empty($min)) {
89 $min = 0;
90}
91
92// Define modetax (0 or 1)
93// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
94$modetax = getDolGlobalString('TAX_MODE');
95if (GETPOSTISSET("modetax")) {
96 $modetax = GETPOSTINT("modetax");
97}
98if (empty($modetax)) {
99 $modetax = 0;
100}
101
102// Security check
103$socid = GETPOSTINT('socid');
104if ($user->socid) {
105 $socid = $user->socid;
106}
107$result = restrictedArea($user, 'tax', '', '', 'charges');
108
109if (empty($local)) {
110 accessforbidden('Parameter localTaxType is missing');
111 exit;
112}
113$hookmanager->initHooks(['customerlocaltaxlist']);
114
115$calc = 0;
116/*
117 * View
118 */
119
120$form = new Form($db);
121$company_static = new Societe($db);
122
123$morequerystring = '';
124$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
125foreach ($listofparams as $param) {
126 if (GETPOST($param) != '') {
127 $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
128 }
129}
130
131llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
132
133
134$name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code);
135
136$fsearch = '<!-- hidden fields for form -->';
137$fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
138$fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
139$fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
140$fsearch .= $langs->trans("SalesTurnoverMinimum").': ';
141$fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" size="6">';
142
143$calc = getDolGlobalString('MAIN_INFO_LOCALTAX_CALC').$local;
144// Affiche en-tete du rapport
145$description='';
146if ($calc == 0 || $calc == 1) { // Calculate on invoice for goods and services
147 $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
148 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
149 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
150 if (isModEnabled('comptabilite')) {
151 $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
152 }
153 $description .= $fsearch;
154 $description .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
155 $builddate = dol_now();
156
157 $elementcust = $langs->trans("CustomersInvoices");
158 $productcust = $langs->trans("Description");
159 $amountcust = $langs->trans("AmountHT");
160 $elementsup = $langs->trans("SuppliersInvoices");
161 $productsup = $langs->trans("Description");
162 $amountsup = $langs->trans("AmountHT");
163}
164if ($calc == 2) { // Invoice for goods, payment for services
165 $calcmode = $langs->trans("CalcModeLT2Debt");
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}
182
183$periodlink = '';
184$exportlink = '';
185
186report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
187
188$vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
189$vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
190
191print '<div class="div-table-responsive">';
192print '<table class="liste noborder centpercent">';
193
194// IRPF that the customer has retained me
195if ($calc == 0 || $calc == 2) {
196 print '<tr class="liste_titre">';
197 print '<td class="left">'.$langs->trans("Num").'</td>';
198 print '<td class="left">'.$langs->trans("Customer").'</td>';
199 print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</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) {
223 if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) {
224 $intra = str_replace($find, $replace, $coll->tva_intra);
225 if (empty($intra)) {
226 if ($coll->assuj == '1') {
227 $intra = $langs->trans('Unknown');
228 } else {
229 $intra = '';
230 }
231 }
232 print '<tr class="oddeven">';
233 print '<td class="nowrap">'.$i."</td>";
234 $company_static->id = $coll->socid;
235 $company_static->name = $coll->name;
236 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
237 $find = array(' ', '.');
238 $replace = array('', '');
239 print '<td class="nowrap">'.$intra.'</td>';
240 print '<td class="nowrap right">'.price($coll->amount).'</td>';
241 print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
242 $totalamount = $totalamount + $coll->amount;
243 $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
244 print "</tr>\n";
245 $i++;
246 }
247 }
248 $x_coll_sum = $total;
249
250 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
251 print '<td class="nowrap right">'.price($totalamount).'</td>';
252 print '<td class="nowrap right">'.price($total).'</td>';
253 print '</tr>';
254 } else {
255 $langs->load("errors");
256 if ($coll_list == -1) {
257 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
258 } elseif ($coll_list == -2) {
259 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
260 } else {
261 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
262 }
263 }
264}
265
266// IRPF I retained my supplier
267if ($calc == 0 || $calc == 1) {
268 print '<tr class="liste_titre">';
269 print '<td class="left">'.$langs->trans("Num")."</td>";
270 print '<td class="left">'.$langs->trans("Supplier")."</td>";
271 print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</td>';
272 print '<td class="right">'.$langs->trans("TotalHT").'</td>';
273 print '<td class="right">'.$vatsup.'</td>';
274 print "</tr>\n";
275
276 $company_static = new Societe($db);
277
278 $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy');
279 $parameters["direction"] = 'buy';
280 $parameters["type"] = 'localtax'.$local;
281
282 $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
283 if (is_array($coll_list)) {
284 $total = 0;
285 $totalamount = 0;
286 $i = 1;
287 foreach ($coll_list as $coll) {
288 if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) {
289 $intra = str_replace($find, $replace, $coll->tva_intra);
290 if (empty($intra)) {
291 if ($coll->assuj == '1') {
292 $intra = $langs->trans('Unknown');
293 } else {
294 $intra = '';
295 }
296 }
297 print '<tr class="oddeven">';
298 print '<td class="nowrap">'.$i."</td>";
299 $company_static->id = $coll->socid;
300 $company_static->name = $coll->name;
301 print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
302 $find = array(' ', '.');
303 $replace = array('', '');
304 print '<td class="nowrap">'.$intra."</td>";
305 print '<td class="nowrap right">'.price($coll->amount).'</td>';
306 print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
307 $totalamount = $totalamount + $coll->amount;
308 $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
309 print "</tr>\n";
310 $i++;
311 }
312 }
313 $x_paye_sum = $total;
314
315 print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
316 print '<td class="nowrap right">'.price($totalamount).'</td>';
317 print '<td class="nowrap right">'.price($total).'</td>';
318 print '</tr>';
319 } else {
320 $langs->load("errors");
321 if ($coll_list == -1) {
322 print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
323 } elseif ($coll_list == -2) {
324 print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
325 } else {
326 print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
327 }
328 }
329}
330
331if ($calc == 0) {
332 // Total to pay
333 print '<tr><td colspan="5"></td></tr>';
334
335 $diff = $x_coll_sum - $x_paye_sum;
336 print '<tr class="liste_total">';
337 print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
338 print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
339 print "</tr>\n";
340}
341
342print '</table>';
343print '</div>';
344
345
346// End of page
347llxFooter();
348$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:594
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:124
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:613
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 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:113