dolibarr  13.0.2
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 if ($user->socid) $socid = $user->socid;
41 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
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 
49 $search_facture = GETPOST('search_facture', 'alpha');
50 $search_societe = GETPOST('search_societe', 'alpha');
51 
52 // Load variable for pagination
53 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
54 $sortfield = GETPOST("sortfield", 'alpha');
55 $sortorder = GETPOST("sortorder", 'alpha');
56 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
57 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // 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) $sortorder = "DESC";
62 if (!$sortfield) $sortfield = "f.ref";
63 
64 $massactionbutton = '';
65 
66 $hookmanager->initHooks(array('withdrawalstodolist'));
67 
68 
69 /*
70  * Actions
71  */
72 
73 $parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
74 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
75 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
76 
77 // Purge search criteria
78 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
79 {
80  $search_facture = '';
81  $search_societe = '';
82  $search_array_options = array();
83 }
84 
85 
86 
87 /*
88  * View
89  */
90 
91 if ($type != 'bank-transfer') {
92  if (!$status) {
93  $title = $langs->trans("RequestStandingOrderToTreat");
94  } else {
95  $title = $langs->trans("RequestStandingOrderTreated");
96  }
97 } else {
98  if (!$status) {
99  $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
100  } else {
101  $title = $langs->trans("RequestPaymentsByBankTransferTreated");
102  }
103 }
104 
105 llxHeader('', $title);
106 
107 $thirdpartystatic = new Societe($db);
108 if ($type == 'bank-transfer') {
109  $invoicestatic = new FactureFournisseur($db);
110 } else {
111  $invoicestatic = new Facture($db);
112 }
113 
114 // List of requests
115 
116 $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
117 $sql .= " s.nom as name, s.rowid as socid,";
118 $sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande";
119 if ($type != 'bank-transfer') {
120  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
121 } else {
122  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
123 }
124 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
125 $sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
126 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
127 $sql .= " WHERE s.rowid = f.fk_soc";
128 $sql .= " AND f.entity IN (".getEntity('invoice').")";
129 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
130 if ($socid) $sql .= " AND f.fk_soc = ".$socid;
131 if (!$status) $sql .= " AND pfd.traite = 0";
132 $sql .= " AND pfd.ext_payment_id IS NULL";
133 if ($status) $sql .= " AND pfd.traite = ".$status;
134 $sql .= " AND f.total_ttc > 0";
135 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
136 {
137  $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
138 }
139 if ($type != 'bank-transfer') {
140  $sql .= " AND pfd.fk_facture = f.rowid";
141 } else {
142  $sql .= " AND pfd.fk_facture_fourn = f.rowid";
143 }
144 if ($search_facture) $sql .= natural_search("f.ref", $search_facture);
145 if ($search_societe) $sql .= natural_search("s.nom", $search_societe);
146 $sql .= $db->order($sortfield, $sortorder);
147 
148 // Count total nb of records
149 $nbtotalofrecords = '';
150 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
151 {
152  $resql = $db->query($sql);
153  $nbtotalofrecords = $db->num_rows($resql);
154  if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
155  {
156  $page = 0;
157  $offset = 0;
158  }
159 }
160 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
161 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
162 {
163  $num = $nbtotalofrecords;
164 } else {
165  $sql .= $db->plimit($limit + 1, $offset);
166 
167  $resql = $db->query($sql);
168  if (!$resql)
169  {
170  dol_print_error($db);
171  exit;
172  }
173 
174  $num = $db->num_rows($resql);
175 }
176 
177 
178 
179 $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
180 if ($type == 'bank-transfer') {
181  $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
182 }
183 
184 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
185 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
186 print '<input type="hidden" name="token" value="'.newToken().'">';
187 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
188 print '<input type="hidden" name="action" value="list">';
189 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
190 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
191 print '<input type="hidden" name="page" value="'.$page.'">';
192 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
193 
194 $param = '';
195 
196 $label = 'NewStandingOrder';
197 $typefilter = '';
198 if ($type == 'bank-transfer') {
199  $label = 'NewPaymentByBankTransfer';
200  $typefilter = 'type='.$type;
201 }
202 $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : ''));
203 
204 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
205 
206 print '<table class="liste centpercent">';
207 
208 print '<tr class="liste_titre">';
209 print_liste_field_titre("Bill", $_SERVER["PHP_SELF"]);
210 print_liste_field_titre("Company", $_SERVER["PHP_SELF"]);
211 print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
212 print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
214 print '</tr>';
215 
216 print '<tr class="liste_titre">';
217 print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
218 print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
219 print '<td class="liste_titre"></td>';
220 print '<td class="liste_titre"></td>';
221 // Action column
222 print '<td class="liste_titre maxwidthsearch">';
223 $searchpicto = $form->showFilterButtons();
224 print $searchpicto;
225 print '</td>';
226 print '</tr>';
227 
228 $i = 0;
229 while ($i < min($num, $limit))
230 {
231  $obj = $db->fetch_object($resql);
232  if (empty($obj)) break; // Should not happen
233 
234  $invoicestatic->fetch($obj->rowid);
235 
236  print '<tr class="oddeven">';
237 
238  // Ref facture
239  print '<td>';
240  print $invoicestatic->getNomUrl(1, 'withdraw');
241  print '</td>';
242 
243  print '<td>';
244  $thirdpartystatic->id = $obj->socid;
245  $thirdpartystatic->name = $obj->name;
246  print $thirdpartystatic->getNomUrl(1, 'customer');
247  print '</td>';
248 
249  print '<td class="right">';
250  print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
251  print '</td>';
252 
253  print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
254 
255  print '<td class="right"></td>';
256 
257  print '</tr>';
258  $i++;
259 }
260 
261 print "</table><br>";
262 
263 print '</form>';
264 
265 
266 // End of page
267 llxFooter();
268 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Class to manage suppliers invoices.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59