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