dolibarr 20.0.0
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 = GETPOSTINT('socid');
41$status = GETPOSTINT('status');
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 = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
55$sortfield = GETPOST('sortfield', 'aZ09comma');
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
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
108$form = new Form($db);
109
110if ($type != 'bank-transfer') {
111 if (!$status) {
112 $title = $langs->trans("RequestStandingOrderToTreat");
113 } else {
114 $title = $langs->trans("RequestStandingOrderTreated");
115 }
116} else {
117 if (!$status) {
118 $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
119 } else {
120 $title = $langs->trans("RequestPaymentsByBankTransferTreated");
121 }
122}
123
124llxHeader('', $title);
125
126$thirdpartystatic = new Societe($db);
127if ($type == 'bank-transfer') {
128 $invoicestatic = new FactureFournisseur($db);
129} else {
130 $invoicestatic = new Facture($db);
131}
132
133// List of requests
134if ($sourcetype != 'salary') {
135 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
136 $sql .= " s.nom as name, s.rowid as socid,";
137 $sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande";
138 if ($type != 'bank-transfer') {
139 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
140 } else {
141 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
142 }
143 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
144 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
145 if (!$user->hasRight('societe', 'client', 'voir')) {
146 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
147 }
148 $sql .= " WHERE s.rowid = f.fk_soc";
149 $sql .= " AND f.entity IN (".getEntity('invoice').")";
150 if (!$user->hasRight('societe', 'client', 'voir')) {
151 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
152 }
153 if ($socid) {
154 $sql .= " AND f.fk_soc = ".((int) $socid);
155 }
156 if (!$status) {
157 $sql .= " AND pd.traite = 0";
158 }
159 $sql .= " AND pd.ext_payment_id IS NULL";
160 if ($status) {
161 $sql .= " AND pd.traite = ".((int) $status);
162 }
163 $sql .= " AND f.total_ttc > 0";
164 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
165 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
166 }
167 if ($type != 'bank-transfer') {
168 $sql .= " AND pd.fk_facture = f.rowid";
169 } else {
170 $sql .= " AND pd.fk_facture_fourn = f.rowid";
171 }
172 if ($search_facture) {
173 $sql .= natural_search("f.ref", $search_facture);
174 }
175 if ($search_societe) {
176 $sql .= natural_search("s.nom", $search_societe);
177 }
178 $sql .= $db->order($sortfield, $sortorder);
179} else {
180 $sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,";
181 $sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom";
182 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,";
183 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
184 $sql .= " WHERE s.rowid = pd.fk_salary";
185 $sql .= " AND u.rowid = s.fk_user";
186 $sql .= " AND s.entity IN (".getEntity("salary").")";
187 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
188 $sql .= " AND s.statut = ".Salary::STATUS_UNPAID;
189 }*/
190 if (!$status) {
191 $sql .= " AND pd.traite = 0";
192 }
193 $sql .= " AND pd.ext_payment_id IS NULL";
194 if ($status) {
195 $sql .= " AND pd.traite = ".((int) $status);
196 }
197 $sql .= " AND s.amount > 0";
198 $sql .= " AND s.paye = ".Salary::STATUS_UNPAID;
199 if ($search_facture) {
200 $sql .= natural_search("s.rowid", $search_facture);
201 }
202 if ($search_societe) {
203 $sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe);
204 }
205 //print $sql;
206}
207// Count total nb of records
208$nbtotalofrecords = '';
209if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
210 $resql = $db->query($sql);
211 $nbtotalofrecords = $db->num_rows($resql);
212 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
213 $page = 0;
214 $offset = 0;
215 }
216}
217// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
218if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
219 $num = $nbtotalofrecords;
220} else {
221 $sql .= $db->plimit($limit + 1, $offset);
222
223 $resql = $db->query($sql);
224 if (!$resql) {
225 dol_print_error($db);
226 exit;
227 }
228
229 $num = $db->num_rows($resql);
230}
231
232
233
234$newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
235if ($type == 'bank-transfer') {
236 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
237}
238if ($sourcetype != 'salary') {
239 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
240} else {
241 print '<form action="'.$_SERVER["PHP_SELF"].'?status=0&type=bank-transfer&sourcetype='.$sourcetype.'" method="POST" id="searchFormList" name="searchFormList">';
242}
243if ($optioncss != '') {
244 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
245}
246print '<input type="hidden" name="token" value="'.newToken().'">';
247print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
248print '<input type="hidden" name="action" value="list">';
249print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
250print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
251print '<input type="hidden" name="page" value="'.$page.'">';
252print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
253
254$param = '';
255
256$label = 'NewStandingOrder';
257$typefilter = '';
258if ($type == 'bank-transfer') {
259 $label = 'NewPaymentByBankTransfer';
260 $typefilter = 'type='.$type;
261}
262$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : '').($sourcetype ? '&sourcetype='.$sourcetype : ''));
263
264print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
265
266print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
267print '<table class="liste centpercent">';
268
269print '<tr class="liste_titre">';
270// Action column
271if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
272 print '<td class="liste_titre maxwidthsearch">';
273 $searchpicto = $form->showFilterButtons();
274 print $searchpicto;
275 print '</td>';
276}
277print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
278print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
279print '<td class="liste_titre"></td>';
280print '<td class="liste_titre"></td>';
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 '</tr>';
289
290print '<tr class="liste_titre">';
291if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
293}
294print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
295print_liste_field_titre(($sourcetype ? "Employee" : "Company"), $_SERVER["PHP_SELF"]);
296print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
297print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
298if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
300}
301print '</tr>';
302
303$userstatic = new User($db);
304$salarystatic = new Salary($db);
305
306$i = 0;
307while ($i < min($num, $limit)) {
308 $obj = $db->fetch_object($resql);
309 if (empty($obj)) {
310 break; // Should not happen
311 }
312 if ($sourcetype != 'salary') {
313 $invoicestatic->fetch($obj->rowid);
314 } else {
315 $salarystatic->fetch($obj->fk_salary);
316 $userstatic->fetch($obj->fk_user);
317 }
318 print '<tr class="oddeven">';
319
320 // Action column
321 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
322 print '<td class="right"></td>';
323 }
324
325 // Ref facture
326 print '<td>';
327 if ($sourcetype != 'salary') {
328 print $invoicestatic->getNomUrl(1, 'withdraw');
329 } else {
330 print $salarystatic->getNomUrl(1, 'withdraw');
331 }
332 print '</td>';
333
334 print '<td>';
335 if ($sourcetype != 'salary') {
336 $thirdpartystatic->id = $obj->socid;
337 $thirdpartystatic->name = $obj->name;
338 print $thirdpartystatic->getNomUrl(1, 'customer');
339 } else {
340 print $userstatic->getNomUrl(-1, 'accountancy');
341 }
342 print '</td>';
343
344 print '<td class="right">';
345 print '<span class="amount">';
346 print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
347 print '</span>';
348 print '</td>';
349
350 print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
351
352 // Action column
353 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
354 print '<td class="right"></td>';
355 }
356
357 print '</tr>';
358 $i++;
359}
360
361// If no record found
362if ($num == 0) {
363 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
364}
365
366print "</table>";
367print "</div>";
368print "<br>";
369
370print '</form>';
371
372
373// End of page
374llxFooter();
375$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()
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 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.
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.
print_barre_liste($title, $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.
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.
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 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.