dolibarr 19.0.4
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 *
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/modules/modPrelevement.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
38
39// Security check
40$socid = GETPOST('socid', 'int');
41$status = GETPOST('status', 'int');
42
43$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
44$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
45$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
46
47$type = GETPOST('type', 'aZ09');
48$sourcetype = GETPOST('sourcetype', 'aZ');
49
50$search_facture = GETPOST('search_facture', 'alpha');
51$search_societe = GETPOST('search_societe', 'alpha');
52
53// Load variable for pagination
54$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
55$sortfield = GETPOST('sortfield', 'aZ09comma');
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
58if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
59 $page = 0;
60} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
61$offset = $limit * $page;
62$pageprev = $page - 1;
63$pagenext = $page + 1;
64if (!$sortorder) {
65 $sortorder = "DESC";
66}
67if (!$sortfield) {
68 $sortfield = "f.ref";
69}
70
71$massactionbutton = '';
72
73$hookmanager->initHooks(array('withdrawalstodolist'));
74
75if ($user->socid) {
76 $socid = $user->socid;
77}
78if ($type == 'bank-transfer') {
79 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
80} else {
81 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
82}
83
84
85/*
86 * Actions
87 */
88
89$parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
90$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
91if ($reshook < 0) {
92 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
93}
94
95// Purge search criteria
96if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
97 $search_facture = '';
98 $search_societe = '';
99 $search_array_options = array();
100}
101
102
103
104/*
105 * View
106 */
107
108if ($type != 'bank-transfer') {
109 if (!$status) {
110 $title = $langs->trans("RequestStandingOrderToTreat");
111 } else {
112 $title = $langs->trans("RequestStandingOrderTreated");
113 }
114} else {
115 if (!$status) {
116 $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
117 } else {
118 $title = $langs->trans("RequestPaymentsByBankTransferTreated");
119 }
120}
121
122llxHeader('', $title);
123
124$thirdpartystatic = new Societe($db);
125if ($type == 'bank-transfer') {
126 $invoicestatic = new FactureFournisseur($db);
127} else {
128 $invoicestatic = new Facture($db);
129}
130
131// List of requests
132if ($sourcetype != 'salary') {
133 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
134 $sql .= " s.nom as name, s.rowid as socid,";
135 $sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande";
136 if ($type != 'bank-transfer') {
137 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
138 } else {
139 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
140 }
141 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
142 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
143 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
144 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
145 }
146 $sql .= " WHERE s.rowid = f.fk_soc";
147 $sql .= " AND f.entity IN (".getEntity('invoice').")";
148 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
149 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
150 }
151 if ($socid) {
152 $sql .= " AND f.fk_soc = ".((int) $socid);
153 }
154 if (!$status) {
155 $sql .= " AND pd.traite = 0";
156 }
157 $sql .= " AND pd.ext_payment_id IS NULL";
158 if ($status) {
159 $sql .= " AND pd.traite = ".((int) $status);
160 }
161 $sql .= " AND f.total_ttc > 0";
162 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
163 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
164 }
165 if ($type != 'bank-transfer') {
166 $sql .= " AND pd.fk_facture = f.rowid";
167 } else {
168 $sql .= " AND pd.fk_facture_fourn = f.rowid";
169 }
170 if ($search_facture) {
171 $sql .= natural_search("f.ref", $search_facture);
172 }
173 if ($search_societe) {
174 $sql .= natural_search("s.nom", $search_societe);
175 }
176 $sql .= $db->order($sortfield, $sortorder);
177} else {
178 $sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,";
179 $sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom";
180 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,";
181 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
182 $sql .= " WHERE s.rowid = pd.fk_salary";
183 $sql .= " AND u.rowid = s.fk_user";
184 $sql .= " AND s.entity IN (".getEntity("salary").")";
185 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
186 $sql .= " AND s.statut = ".Salary::STATUS_UNPAID;
187 }*/
188 if (!$status) {
189 $sql .= " AND pd.traite = 0";
190 }
191 $sql .= " AND pd.ext_payment_id IS NULL";
192 if ($status) {
193 $sql .= " AND pd.traite = ".((int) $status);
194 }
195 $sql .= " AND s.amount > 0";
196 $sql .= " AND s.paye = ".Salary::STATUS_UNPAID;
197 if ($search_facture) {
198 $sql .= natural_search("s.rowid", $search_facture);
199 }
200 if ($search_societe) {
201 $sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe);
202 }
203 //print $sql;
204}
205// Count total nb of records
206$nbtotalofrecords = '';
207if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
208 $resql = $db->query($sql);
209 $nbtotalofrecords = $db->num_rows($resql);
210 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
211 $page = 0;
212 $offset = 0;
213 }
214}
215// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
216if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
217 $num = $nbtotalofrecords;
218} else {
219 $sql .= $db->plimit($limit + 1, $offset);
220
221 $resql = $db->query($sql);
222 if (!$resql) {
223 dol_print_error($db);
224 exit;
225 }
226
227 $num = $db->num_rows($resql);
228}
229
230
231
232$newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
233if ($type == 'bank-transfer') {
234 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
235}
236if ($sourcetype != 'salary') {
237 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
238} else {
239 print '<form action="'.$_SERVER["PHP_SELF"].'?status=0&type=bank-transfer&sourcetype='.$sourcetype.'" method="POST" id="searchFormList" name="searchFormList">';
240}
241if ($optioncss != '') {
242 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
243}
244print '<input type="hidden" name="token" value="'.newToken().'">';
245print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
246print '<input type="hidden" name="action" value="list">';
247print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
248print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
249print '<input type="hidden" name="page" value="'.$page.'">';
250print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
251
252$param = '';
253
254$label = 'NewStandingOrder';
255$typefilter = '';
256if ($type == 'bank-transfer') {
257 $label = 'NewPaymentByBankTransfer';
258 $typefilter = 'type='.$type;
259}
260$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '').($sourcetype ? '&sourcetype='.$sourcetype : ''));
261
262print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
263
264print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
265print '<table class="liste centpercent">';
266
267print '<tr class="liste_titre">';
268// Action column
269if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
270 print '<td class="liste_titre maxwidthsearch">';
271 $searchpicto = $form->showFilterButtons();
272 print $searchpicto;
273 print '</td>';
274}
275print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
276print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
277print '<td class="liste_titre"></td>';
278print '<td class="liste_titre"></td>';
279// Action column
280if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
281 print '<td class="liste_titre maxwidthsearch">';
282 $searchpicto = $form->showFilterButtons();
283 print $searchpicto;
284 print '</td>';
285}
286print '</tr>';
287
288print '<tr class="liste_titre">';
289if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
291}
292print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
293print_liste_field_titre(($sourcetype ? "Employee" : "Company"), $_SERVER["PHP_SELF"]);
294print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
295print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
296if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
298}
299print '</tr>';
300
301$userstatic = new User($db);
302$salarystatic = new Salary($db);
303
304$i = 0;
305while ($i < min($num, $limit)) {
306 $obj = $db->fetch_object($resql);
307 if (empty($obj)) {
308 break; // Should not happen
309 }
310 if ($sourcetype != 'salary') {
311 $invoicestatic->fetch($obj->rowid);
312 } else {
313 $salarystatic->fetch($obj->fk_salary);
314 $userstatic->fetch($obj->fk_user);
315 }
316 print '<tr class="oddeven">';
317
318 // Action column
319 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
320 print '<td class="right"></td>';
321 }
322
323 // Ref facture
324 print '<td>';
325 if ($sourcetype != 'salary') {
326 print $invoicestatic->getNomUrl(1, 'withdraw');
327 } else {
328 print $salarystatic->getNomUrl(1, 'withdraw');
329 }
330 print '</td>';
331
332 print '<td>';
333 if ($sourcetype != 'salary') {
334 $thirdpartystatic->id = $obj->socid;
335 $thirdpartystatic->name = $obj->name;
336 print $thirdpartystatic->getNomUrl(1, 'customer');
337 } else {
338 print $userstatic->getNomUrl(-1, 'accountancy');
339 }
340 print '</td>';
341
342 print '<td class="right">';
343 print '<span class="amount">';
344 print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
345 print '</span>';
346 print '</td>';
347
348 print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
349
350 // Action column
351 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
352 print '<td class="right"></td>';
353 }
354
355 print '</tr>';
356 $i++;
357}
358
359print "</table>";
360print "</div>";
361print "<br>";
362
363print '</form>';
364
365
366// End of page
367llxFooter();
368$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return 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.