dolibarr  16.0.5
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/modPrelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
36 
37 // Security check
38 $socid = GETPOST('socid', 'int');
39 $status = GETPOST('status', 'int');
40 
41 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
43 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
44 
45 $type = GETPOST('type', 'aZ09');
46 
47 $search_facture = GETPOST('search_facture', 'alpha');
48 $search_societe = GETPOST('search_societe', 'alpha');
49 
50 // Load variable for pagination
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 $sortfield = GETPOST('sortfield', 'aZ09comma');
53 $sortorder = GETPOST('sortorder', 'aZ09comma');
54 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
55 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
56  $page = 0;
57 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
61 if (!$sortorder) {
62  $sortorder = "DESC";
63 }
64 if (!$sortfield) {
65  $sortfield = "f.ref";
66 }
67 
68 $massactionbutton = '';
69 
70 $hookmanager->initHooks(array('withdrawalstodolist'));
71 
72 if ($user->socid) {
73  $socid = $user->socid;
74 }
75 if ($type == 'bank-transfer') {
76  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
77 } else {
78  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
79 }
80 
81 
82 /*
83  * Actions
84  */
85 
86 $parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
87 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
88 if ($reshook < 0) {
89  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
90 }
91 
92 // Purge search criteria
93 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
94  $search_facture = '';
95  $search_societe = '';
96  $search_array_options = array();
97 }
98 
99 
100 
101 /*
102  * View
103  */
104 
105 if ($type != 'bank-transfer') {
106  if (!$status) {
107  $title = $langs->trans("RequestStandingOrderToTreat");
108  } else {
109  $title = $langs->trans("RequestStandingOrderTreated");
110  }
111 } else {
112  if (!$status) {
113  $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
114  } else {
115  $title = $langs->trans("RequestPaymentsByBankTransferTreated");
116  }
117 }
118 
119 llxHeader('', $title);
120 
121 $thirdpartystatic = new Societe($db);
122 if ($type == 'bank-transfer') {
123  $invoicestatic = new FactureFournisseur($db);
124 } else {
125  $invoicestatic = new Facture($db);
126 }
127 
128 // List of requests
129 
130 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
131 $sql .= " s.nom as name, s.rowid as socid,";
132 $sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande";
133 if ($type != 'bank-transfer') {
134  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
135 } else {
136  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
137 }
138 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
139 $sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
140 if (empty($user->rights->societe->client->voir) && !$socid) {
141  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
142 }
143 $sql .= " WHERE s.rowid = f.fk_soc";
144 $sql .= " AND f.entity IN (".getEntity('invoice').")";
145 if (empty($user->rights->societe->client->voir) && !$socid) {
146  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
147 }
148 if ($socid) {
149  $sql .= " AND f.fk_soc = ".((int) $socid);
150 }
151 if (!$status) {
152  $sql .= " AND pfd.traite = 0";
153 }
154 $sql .= " AND pfd.ext_payment_id IS NULL";
155 if ($status) {
156  $sql .= " AND pfd.traite = ".((int) $status);
157 }
158 $sql .= " AND f.total_ttc > 0";
159 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
160  $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
161 }
162 if ($type != 'bank-transfer') {
163  $sql .= " AND pfd.fk_facture = f.rowid";
164 } else {
165  $sql .= " AND pfd.fk_facture_fourn = f.rowid";
166 }
167 if ($search_facture) {
168  $sql .= natural_search("f.ref", $search_facture);
169 }
170 if ($search_societe) {
171  $sql .= natural_search("s.nom", $search_societe);
172 }
173 $sql .= $db->order($sortfield, $sortorder);
174 
175 // Count total nb of records
176 $nbtotalofrecords = '';
177 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
178  $resql = $db->query($sql);
179  $nbtotalofrecords = $db->num_rows($resql);
180  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
181  $page = 0;
182  $offset = 0;
183  }
184 }
185 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
186 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
187  $num = $nbtotalofrecords;
188 } else {
189  $sql .= $db->plimit($limit + 1, $offset);
190 
191  $resql = $db->query($sql);
192  if (!$resql) {
193  dol_print_error($db);
194  exit;
195  }
196 
197  $num = $db->num_rows($resql);
198 }
199 
200 
201 
202 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
203 if ($type == 'bank-transfer') {
204  $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
205 }
206 
207 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
208 if ($optioncss != '') {
209  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
210 }
211 print '<input type="hidden" name="token" value="'.newToken().'">';
212 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
213 print '<input type="hidden" name="action" value="list">';
214 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
215 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
216 print '<input type="hidden" name="page" value="'.$page.'">';
217 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
218 
219 $param = '';
220 
221 $label = 'NewStandingOrder';
222 $typefilter = '';
223 if ($type == 'bank-transfer') {
224  $label = 'NewPaymentByBankTransfer';
225  $typefilter = 'type='.$type;
226 }
227 $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : ''));
228 
229 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
230 
231 print '<table class="liste centpercent">';
232 
233 print '<tr class="liste_titre">';
234 print_liste_field_titre("Bill", $_SERVER["PHP_SELF"]);
235 print_liste_field_titre("Company", $_SERVER["PHP_SELF"]);
236 print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
237 print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
239 print '</tr>';
240 
241 print '<tr class="liste_titre">';
242 print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
243 print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
244 print '<td class="liste_titre"></td>';
245 print '<td class="liste_titre"></td>';
246 // Action column
247 print '<td class="liste_titre maxwidthsearch">';
248 $searchpicto = $form->showFilterButtons();
249 print $searchpicto;
250 print '</td>';
251 print '</tr>';
252 
253 $i = 0;
254 while ($i < min($num, $limit)) {
255  $obj = $db->fetch_object($resql);
256  if (empty($obj)) {
257  break; // Should not happen
258  }
259 
260  $invoicestatic->fetch($obj->rowid);
261 
262  print '<tr class="oddeven">';
263 
264  // Ref facture
265  print '<td>';
266  print $invoicestatic->getNomUrl(1, 'withdraw');
267  print '</td>';
268 
269  print '<td>';
270  $thirdpartystatic->id = $obj->socid;
271  $thirdpartystatic->name = $obj->name;
272  print $thirdpartystatic->getNomUrl(1, 'customer');
273  print '</td>';
274 
275  print '<td class="right">';
276  print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
277  print '</td>';
278 
279  print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
280 
281  print '<td class="right"></td>';
282 
283  print '</tr>';
284  $i++;
285 }
286 
287 print "</table><br>";
288 
289 print '</form>';
290 
291 
292 // End of page
293 llxFooter();
294 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
print_barre_liste
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.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59