dolibarr 24.0.0-beta
demandes.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/modules/modPrelevement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
48
49// Security check
50$socid = GETPOSTINT('socid');
51$status = GETPOSTINT('status');
52
53$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
54$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
55$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
56
57$type = GETPOST('type', 'aZ09');
58$sourcetype = GETPOST('sourcetype', 'aZ');
59
60$search_facture = GETPOST('search_facture', 'alpha');
61$search_societe = GETPOST('search_societe', 'alpha');
62
63// Load variable for pagination
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
68$toselect = GETPOST('toselect', 'array:int');
69$massaction = GETPOST('massaction', 'alpha');
70
71if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
72 $page = 0;
73} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
74$offset = $limit * $page;
75$pageprev = $page - 1;
76$pagenext = $page + 1;
77if (!$sortorder) {
78 $sortorder = "DESC";
79}
80if (!$sortfield) {
81 $sortfield = "f.ref";
82}
83
84$massactionbutton = '';
85
86$hookmanager->initHooks(array('withdrawalstodolist'));
87
88if ($user->socid) {
89 $socid = $user->socid;
90}
91if ($type == 'bank-transfer') {
92 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
93} else {
94 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
95}
96
97
98/*
99 * Actions
100 */
101
102$parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
103$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
104if ($reshook < 0) {
105 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
106}
107
108// Purge search criteria
109if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
110 $search_facture = '';
111 $search_societe = '';
112 $search_array_options = array();
113}
114
115
116
117/*
118 * View
119 */
120
121$form = new Form($db);
122
123if ($type != 'bank-transfer') {
124 if (!$status) {
125 $title = $langs->trans("RequestStandingOrderToTreat");
126 } else {
127 $title = $langs->trans("RequestStandingOrderTreated");
128 }
129} else {
130 if (!$status) {
131 $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
132 } else {
133 $title = $langs->trans("RequestPaymentsByBankTransferTreated");
134 }
135}
136
137llxHeader('', $title);
138
139$thirdpartystatic = new Societe($db);
140if ($type == 'bank-transfer') {
141 $invoicestatic = new FactureFournisseur($db);
142} else {
143 $invoicestatic = new Facture($db);
144}
145
146// List of requests
147if ($sourcetype != 'salary') {
148 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
149 $sql .= " s.nom as name, s.rowid as socid,";
150 $sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande";
151 if ($type != 'bank-transfer') {
152 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
153 } else {
154 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
155 }
156 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
157 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
158 if (!$user->hasRight('societe', 'client', 'voir')) {
159 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
160 }
161 $sql .= " WHERE s.rowid = f.fk_soc";
162 $sql .= " AND f.entity IN (".getEntity('invoice').")";
163 if (!$user->hasRight('societe', 'client', 'voir')) {
164 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
165 }
166 if ($socid) {
167 $sql .= " AND f.fk_soc = ".((int) $socid);
168 }
169 if (!$status) {
170 $sql .= " AND pd.traite = 0";
171 }
172 $sql .= " AND pd.ext_payment_id IS NULL";
173 if ($status) {
174 $sql .= " AND pd.traite = ".((int) $status);
175 }
176 $sql .= " AND f.total_ttc > 0";
177 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
178 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
179 }
180 if ($type != 'bank-transfer') {
181 $sql .= " AND pd.fk_facture = f.rowid";
182 } else {
183 $sql .= " AND pd.fk_facture_fourn = f.rowid";
184 }
185 if ($search_facture) {
186 $sql .= natural_search("f.ref", $search_facture);
187 }
188 if ($search_societe) {
189 $sql .= natural_search("s.nom", $search_societe);
190 }
191 $sql .= $db->order($sortfield, $sortorder);
192} else {
193 $sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,";
194 $sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom";
195 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,";
196 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
197 $sql .= " WHERE s.rowid = pd.fk_salary";
198 $sql .= " AND u.rowid = s.fk_user";
199 $sql .= " AND s.entity IN (".getEntity("salary").")";
200 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
201 $sql .= " AND s.statut = ".Salary::STATUS_UNPAID;
202 }*/
203 if (!$status) {
204 $sql .= " AND pd.traite = 0";
205 }
206 $sql .= " AND pd.ext_payment_id IS NULL";
207 if ($status) {
208 $sql .= " AND pd.traite = ".((int) $status);
209 }
210 $sql .= " AND s.amount > 0";
211 $sql .= " AND s.paye = ".Salary::STATUS_UNPAID;
212 if ($search_facture) {
213 $sql .= natural_search("s.rowid", $search_facture);
214 }
215 if ($search_societe) {
216 $sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe);
217 }
218 //print $sql;
219}
220// Count total nb of records
221$nbtotalofrecords = '';
222$resql = null;
223if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
224 $resql = $db->query($sql);
225 $nbtotalofrecords = $db->num_rows($resql);
226 if (($page * $limit) > (int) $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
227 $page = 0;
228 $offset = 0;
229 }
230}
231// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
232if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
233 $num = $nbtotalofrecords;
234} else {
235 $sql .= $db->plimit($limit + 1, $offset);
236
237 $resql = $db->query($sql);
238 if (!$resql) {
240 exit;
241 }
242
243 $num = $db->num_rows($resql);
244}
245
246
247
248$newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("GoBack").'</a>';
249if ($type == 'bank-transfer') {
250 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("GoBack").'</a>';
251}
252if ($sourcetype != 'salary') {
253 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
254} else {
255 print '<form action="'.$_SERVER["PHP_SELF"].'?status=0&type=bank-transfer&sourcetype='.$sourcetype.'" method="POST" id="searchFormList" name="searchFormList">';
256}
257if ($optioncss != '') {
258 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
259}
260print '<input type="hidden" name="token" value="'.newToken().'">';
261print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
262print '<input type="hidden" name="action" value="list">';
263print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
264print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
265print '<input type="hidden" name="page" value="'.$page.'">';
266print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
267
268$param = '';
269
270$label = 'NewStandingOrder';
271$typefilter = '';
272if ($type == 'bank-transfer') {
273 $label = 'NewPaymentByBankTransfer';
274 $typefilter = 'type='.$type;
275}
276$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '').($sourcetype ? '&sourcetype='.$sourcetype : ''));
277
278print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
279
280print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
281print '<table class="liste centpercent">';
282
283print '<tr class="liste_titre">';
284// Action column
285if ($conf->main_checkbox_left_column) {
286 print '<td class="liste_titre maxwidthsearch">';
287 $searchpicto = $form->showFilterButtons();
288 print $searchpicto;
289 print '</td>';
290}
291print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
292print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
293print '<td class="liste_titre"></td>';
294print '<td class="liste_titre"></td>';
295// Action column
296if (!$conf->main_checkbox_left_column) {
297 print '<td class="liste_titre maxwidthsearch">';
298 $searchpicto = $form->showFilterButtons();
299 print $searchpicto;
300 print '</td>';
301}
302print '</tr>';
303
304print '<tr class="liste_titre">';
305if ($conf->main_checkbox_left_column) {
307}
308print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
309print_liste_field_titre(($sourcetype ? "Employee" : "Company"), $_SERVER["PHP_SELF"]);
310print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
311print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
312if (!$conf->main_checkbox_left_column) {
314}
315print '</tr>';
316
317$userstatic = new User($db);
318$salarystatic = new Salary($db);
319
320$i = 0;
321while ($i < min($num, $limit) && $resql !== null) {
322 $obj = $db->fetch_object($resql);
323 if (empty($obj)) {
324 break; // Should not happen
325 }
326 if ($sourcetype != 'salary') {
327 $invoicestatic->fetch($obj->rowid);
328 } else {
329 $salarystatic->fetch($obj->fk_salary);
330 $userstatic->fetch($obj->fk_user);
331 }
332 print '<tr class="oddeven">';
333
334 // Action column
335 if ($conf->main_checkbox_left_column) {
336 print '<td class="right"></td>';
337 }
338
339 // Ref facture
340 print '<td class="tdoverflowmax125">';
341 if ($sourcetype != 'salary') {
342 print $invoicestatic->getNomUrl(1, 'withdraw');
343 } else {
344 print $salarystatic->getNomUrl(1, 'withdraw');
345 }
346 print '</td>';
347
348 print '<td class="tdoverflowmax150">';
349 if ($sourcetype != 'salary') {
350 $thirdpartystatic->id = $obj->socid;
351 $thirdpartystatic->name = $obj->name;
352 print $thirdpartystatic->getNomUrl(1, 'customer');
353 } else {
354 print $userstatic->getNomUrl(-1, 'accountancy');
355 }
356 print '</td>';
357
358 print '<td class="right">';
359 print '<span class="amount">';
360 if ($obj->amount != $obj->total_ttc) {
361 print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
362 } else {
363 print price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
364 }
365 print '</span>';
366 print '</td>';
367
368 print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
369
370 // Action column
371 if (!$conf->main_checkbox_left_column) {
372 print '<td class="right"></td>';
373 }
374
375 print '</tr>';
376 $i++;
377}
378
379// If no record found
380if ($num == 0) {
381 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
382}
383
384print "</table>";
385print "</div>";
386print "<br>";
387
388print '</form>';
389
390
391// End of page
392llxFooter();
393$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 suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.