dolibarr 21.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 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");
68if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
69 $page = 0;
70} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74if (!$sortorder) {
75 $sortorder = "DESC";
76}
77if (!$sortfield) {
78 $sortfield = "f.ref";
79}
80
81$massactionbutton = '';
82
83$hookmanager->initHooks(array('withdrawalstodolist'));
84
85if ($user->socid) {
86 $socid = $user->socid;
87}
88if ($type == 'bank-transfer') {
89 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
90} else {
91 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
92}
93
94
95/*
96 * Actions
97 */
98
99$parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
100$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
101if ($reshook < 0) {
102 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
103}
104
105// Purge search criteria
106if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
107 $search_facture = '';
108 $search_societe = '';
109 $search_array_options = array();
110}
111
112
113
114/*
115 * View
116 */
117
118$form = new Form($db);
119
120if ($type != 'bank-transfer') {
121 if (!$status) {
122 $title = $langs->trans("RequestStandingOrderToTreat");
123 } else {
124 $title = $langs->trans("RequestStandingOrderTreated");
125 }
126} else {
127 if (!$status) {
128 $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
129 } else {
130 $title = $langs->trans("RequestPaymentsByBankTransferTreated");
131 }
132}
133
134llxHeader('', $title);
135
136$thirdpartystatic = new Societe($db);
137if ($type == 'bank-transfer') {
138 $invoicestatic = new FactureFournisseur($db);
139} else {
140 $invoicestatic = new Facture($db);
141}
142
143// List of requests
144if ($sourcetype != 'salary') {
145 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
146 $sql .= " s.nom as name, s.rowid as socid,";
147 $sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande";
148 if ($type != 'bank-transfer') {
149 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
150 } else {
151 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
152 }
153 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
154 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
155 if (!$user->hasRight('societe', 'client', 'voir')) {
156 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
157 }
158 $sql .= " WHERE s.rowid = f.fk_soc";
159 $sql .= " AND f.entity IN (".getEntity('invoice').")";
160 if (!$user->hasRight('societe', 'client', 'voir')) {
161 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
162 }
163 if ($socid) {
164 $sql .= " AND f.fk_soc = ".((int) $socid);
165 }
166 if (!$status) {
167 $sql .= " AND pd.traite = 0";
168 }
169 $sql .= " AND pd.ext_payment_id IS NULL";
170 if ($status) {
171 $sql .= " AND pd.traite = ".((int) $status);
172 }
173 $sql .= " AND f.total_ttc > 0";
174 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
175 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
176 }
177 if ($type != 'bank-transfer') {
178 $sql .= " AND pd.fk_facture = f.rowid";
179 } else {
180 $sql .= " AND pd.fk_facture_fourn = f.rowid";
181 }
182 if ($search_facture) {
183 $sql .= natural_search("f.ref", $search_facture);
184 }
185 if ($search_societe) {
186 $sql .= natural_search("s.nom", $search_societe);
187 }
188 $sql .= $db->order($sortfield, $sortorder);
189} else {
190 $sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,";
191 $sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom";
192 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,";
193 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
194 $sql .= " WHERE s.rowid = pd.fk_salary";
195 $sql .= " AND u.rowid = s.fk_user";
196 $sql .= " AND s.entity IN (".getEntity("salary").")";
197 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
198 $sql .= " AND s.statut = ".Salary::STATUS_UNPAID;
199 }*/
200 if (!$status) {
201 $sql .= " AND pd.traite = 0";
202 }
203 $sql .= " AND pd.ext_payment_id IS NULL";
204 if ($status) {
205 $sql .= " AND pd.traite = ".((int) $status);
206 }
207 $sql .= " AND s.amount > 0";
208 $sql .= " AND s.paye = ".Salary::STATUS_UNPAID;
209 if ($search_facture) {
210 $sql .= natural_search("s.rowid", $search_facture);
211 }
212 if ($search_societe) {
213 $sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe);
214 }
215 //print $sql;
216}
217// Count total nb of records
218$nbtotalofrecords = '';
219$resql = null;
220if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
221 $resql = $db->query($sql);
222 $nbtotalofrecords = $db->num_rows($resql);
223 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
224 $page = 0;
225 $offset = 0;
226 }
227}
228// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
229if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
230 $num = $nbtotalofrecords;
231} else {
232 $sql .= $db->plimit($limit + 1, $offset);
233
234 $resql = $db->query($sql);
235 if (!$resql) {
236 dol_print_error($db);
237 exit;
238 }
239
240 $num = $db->num_rows($resql);
241}
242
243
244
245$newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
246if ($type == 'bank-transfer') {
247 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
248}
249if ($sourcetype != 'salary') {
250 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
251} else {
252 print '<form action="'.$_SERVER["PHP_SELF"].'?status=0&type=bank-transfer&sourcetype='.$sourcetype.'" method="POST" id="searchFormList" name="searchFormList">';
253}
254if ($optioncss != '') {
255 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
256}
257print '<input type="hidden" name="token" value="'.newToken().'">';
258print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
259print '<input type="hidden" name="action" value="list">';
260print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
261print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
262print '<input type="hidden" name="page" value="'.$page.'">';
263print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
264
265$param = '';
266
267$label = 'NewStandingOrder';
268$typefilter = '';
269if ($type == 'bank-transfer') {
270 $label = 'NewPaymentByBankTransfer';
271 $typefilter = 'type='.$type;
272}
273$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '').($sourcetype ? '&sourcetype='.$sourcetype : ''));
274
275print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
276
277print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
278print '<table class="liste centpercent">';
279
280print '<tr class="liste_titre">';
281// Action column
282if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
283 print '<td class="liste_titre maxwidthsearch">';
284 $searchpicto = $form->showFilterButtons();
285 print $searchpicto;
286 print '</td>';
287}
288print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
289print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
290print '<td class="liste_titre"></td>';
291print '<td class="liste_titre"></td>';
292// Action column
293if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
294 print '<td class="liste_titre maxwidthsearch">';
295 $searchpicto = $form->showFilterButtons();
296 print $searchpicto;
297 print '</td>';
298}
299print '</tr>';
300
301print '<tr class="liste_titre">';
302if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
304}
305print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
306print_liste_field_titre(($sourcetype ? "Employee" : "Company"), $_SERVER["PHP_SELF"]);
307print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
308print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
309if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
311}
312print '</tr>';
313
314$userstatic = new User($db);
315$salarystatic = new Salary($db);
316
317$i = 0;
318while ($i < min($num, $limit)) {
319 $obj = $db->fetch_object($resql);
320 if (empty($obj)) {
321 break; // Should not happen
322 }
323 if ($sourcetype != 'salary') {
324 $invoicestatic->fetch($obj->rowid);
325 } else {
326 $salarystatic->fetch($obj->fk_salary);
327 $userstatic->fetch($obj->fk_user);
328 }
329 print '<tr class="oddeven">';
330
331 // Action column
332 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
333 print '<td class="right"></td>';
334 }
335
336 // Ref facture
337 print '<td>';
338 if ($sourcetype != 'salary') {
339 print $invoicestatic->getNomUrl(1, 'withdraw');
340 } else {
341 print $salarystatic->getNomUrl(1, 'withdraw');
342 }
343 print '</td>';
344
345 print '<td>';
346 if ($sourcetype != 'salary') {
347 $thirdpartystatic->id = $obj->socid;
348 $thirdpartystatic->name = $obj->name;
349 print $thirdpartystatic->getNomUrl(1, 'customer');
350 } else {
351 print $userstatic->getNomUrl(-1, 'accountancy');
352 }
353 print '</td>';
354
355 print '<td class="right">';
356 print '<span class="amount">';
357 if ($obj->amount != $obj->total_ttc) {
358 print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
359 } else {
360 print price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
361 }
362 print '</span>';
363 print '</td>';
364
365 print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
366
367 // Action column
368 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
369 print '<td class="right"></td>';
370 }
371
372 print '</tr>';
373 $i++;
374}
375
376// If no record found
377if ($num == 0) {
378 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
379}
380
381print "</table>";
382print "</div>";
383print "<br>";
384
385print '</form>';
386
387
388// End of page
389llxFooter();
390$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 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.
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.