dolibarr  20.0.0-beta
virement_request.php
1 <?php
2 /* Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
4  * Copyright (C) 2017-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
6  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
40 
41 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
44 
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
47 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
54 if (isModEnabled('project')) {
55  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
57 }
58 
59 // Load translation files required by the page
60 $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm", "withdrawals"));
61 
62 $id = GETPOSTINT('id');
63 $ref = GETPOST('ref', 'alpha');
64 $action = GETPOST('action', 'aZ09');
65 $type = 'salaire';
66 
67 $label = GETPOST('label', 'alphanohtml');
68 $projectid = (GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project'));
69 
70 // Security check
71 $socid = GETPOSTINT('socid');
72 if ($user->socid) {
73  $socid = $user->socid;
74 }
75 
76 
77 
78 $object = new Salary($db);
79 $extrafields = new ExtraFields($db);
80 
81 $childids = $user->getAllChildIds(1);
82 
83 // fetch optionals attributes and labels
84 $extrafields->fetch_name_optionals_label($object->table_element);
85 
86 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87 $hookmanager->initHooks(array('salaryinfo', 'globalcard'));
88 
89 $object = new Salary($db);
90 if ($id > 0 || !empty($ref)) {
91  $object->fetch($id, $ref);
92 
93  // Check current user can read this salary
94  $canread = 0;
95  if ($user->hasRight('salaries', 'readall')) {
96  $canread = 1;
97  }
98  if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
99  $canread = 1;
100  }
101  if (!$canread) {
102  accessforbidden();
103  }
104 }
105 
106 $permissiontoread = $user->hasRight('salaries', 'read');
107 $permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
108 $permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
109 
110 $moreparam = '';
111 if ($type == 'bank-transfer') {
112  $obj = new FactureFournisseur($db);
113  $moreparam = '&type='.$type;
114 } else {
115  $obj = new Facture($db);
116 }
117 
118 // Load object
119 if ($id > 0 || !empty($ref)) {
120  $ret = $object->fetch($id, $ref);
121  $isdraft = (($obj->status == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
122  if ($ret > 0) {
123  $object->fetch_thirdparty();
124  }
125 }
126 
127 $hookmanager->initHooks(array('directdebitcard', 'globalcard'));
128 
129 restrictedArea($user, 'salaries', $object->id, 'salary', '');
130 
131 
132 /*
133  * Actions
134  */
135 
136 // Link to a project
137 if ($action == 'classin' && $user->hasRight('banque', 'modifier')) {
138  $object->fetch($id);
139  $object->setProject($projectid);
140 }
141 
142 // set label
143 if ($action == 'setlabel' && $user->hasRight('salaries', 'write')) {
144  $object->fetch($id);
145  $object->label = $label;
146  $object->update($user);
147 }
148 
149 $parameters = array('socid' => $socid);
150 $reshook = $hookmanager->executeHooks('doActions', $parameters, $obj, $action); // Note that $action and $object may have been modified by some hooks
151 if ($reshook < 0) {
152  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
153 }
154 
155 
156 if ($action == "new") {
157  //var_dump($object);exit;
158  if ($object->id > 0) {
159  $db->begin();
160 
161  $sourcetype = 'salaire';
162  $newtype = 'salaire';
163  $paymentservice = GETPOST('paymentservice');
164  $result = $object->demande_prelevement($user, price2num(GETPOST('request_transfer', 'alpha')), $newtype, $sourcetype);
165 
166  if ($result > 0) {
167  $db->commit();
168 
169  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
170  } else {
171  dol_print_error($db, $error);
172  $db->rollback();
173  setEventMessages($obj->error, $obj->errors, 'errors');
174  }
175  }
176  $action = '';
177 }
178 
179 if ($action == "delete" && $permissiontodelete) {
180  if ($object->id > 0) {
181  $result = $object->demande_prelevement_delete($user, GETPOSTINT('did'));
182  if ($result == 0) {
183  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
184  exit;
185  }
186  }
187 }
188 
189 
190 
191 
192 /*
193  * View
194  */
195 
196 if (isModEnabled('project')) {
197  $formproject = new FormProjets($db);
198 }
199 
200 $title = $langs->trans('Salary')." - ".$langs->trans('Info');
201 $help_url = "";
202 llxHeader("", $title, $help_url);
203 
204 $object->fetch($id);
205 $object->info($id);
206 
207 $head = salaries_prepare_head($object);
208 
209 print dol_get_fiche_head($head, 'request_virement', $langs->trans("SalaryPayment"), -1, 'salary');
210 
211 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
212 
213 $morehtmlref = '<div class="refidno">';
214 
215 $userstatic = new User($db);
216 $userstatic->fetch($object->fk_user);
217 
218 
219 // Label
220 if ($action != 'editlabel') {
221  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
222  $morehtmlref .= $object->label;
223 } else {
224  $morehtmlref .= $langs->trans('Label').' :&nbsp;';
225  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
226  $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
227  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
228  $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
229  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
230  $morehtmlref .= '</form>';
231 }
232 
233 $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
234 
235 $usercancreate = $permissiontoadd;
236 
237 // Project
238 if (isModEnabled('project')) {
239  $langs->load("projects");
240  $morehtmlref .= '<br>';
241  if ($usercancreate) {
242  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
243  if ($action != 'classify') {
244  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
245  }
246  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
247  } else {
248  if (!empty($object->fk_project)) {
249  $proj = new Project($db);
250  $proj->fetch($object->fk_project);
251  $morehtmlref .= $proj->getNomUrl(1);
252  if ($proj->title) {
253  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
254  }
255  }
256  }
257 }
258 
259 $morehtmlref .= '</div>';
260 
261 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
262 
263 print '<div class="fichecenter">';
264 print '<div class="fichehalfleft">';
265 
266 print '<div class="underbanner clearboth"></div>';
267 
268 
269 print '<table class="border centpercent tableforfield">';
270 
271 if ($action == 'edit') {
272  print '<tr><td class="titlefield">'.$langs->trans("DateStartPeriod")."</td><td>";
273  print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
274  print "</td></tr>";
275 } else {
276  print "<tr>";
277  print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
278  print dol_print_date($object->datesp, 'day');
279  print '</td></tr>';
280 }
281 
282 if ($action == 'edit') {
283  print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
284  print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
285  print "</td></tr>";
286 } else {
287  print "<tr>";
288  print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
289  print dol_print_date($object->dateep, 'day');
290  print '</td></tr>';
291 }
292 if ($action == 'edit') {
293  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
294 } else {
295  print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
296 }
297 
298 // Default mode of payment
299 print '<tr><td>';
300 print '<table class="nobordernopadding" width="100%"><tr><td>';
301 print $langs->trans('DefaultPaymentMode');
302 print '</td>';
303 if ($action != 'editmode') {
304  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
305 }
306 print '</tr></table>';
307 print '</td><td>';
308 
309 if ($action == 'editmode') {
310  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
311 } else {
312  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
313 }
314 print '</td></tr>';
315 
316 // Default Bank Account
317 if (isModEnabled("bank")) {
318  print '<tr><td class="nowrap">';
319  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
320  print $langs->trans('DefaultBankAccount');
321  print '<td>';
322  if ($action != 'editbankaccount' && $user->hasRight('salaries', 'write')) {
323  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
324  }
325  print '</tr></table>';
326  print '</td><td>';
327  if ($action == 'editbankaccount') {
328  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
329  } else {
330  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
331  }
332  print '</td>';
333  print '</tr>';
334 }
335 
336 // Other attributes
337 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
338 
339 print '</table>';
340 print '</div>';
341 
342 $user_perms = $user->hasRight('virement', 'bons', 'creer');
343 $buttonlabel = $langs->trans("MakeTransferRequest");
344 $user_perms = $user->hasRight('paymentbybanktransfer', 'create');
345 
346 print '<div class="fichehalfright">';
347 /*
348  * Payments
349  */
350 $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
351 $sql .= " c.code as type_code,c.libelle as paiement_type,";
352 $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
353 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
354 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
355 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
356 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
357 $sql .= ", ".MAIN_DB_PREFIX."salary as s";
358 $sql .= " WHERE p.fk_salary = ".((int) $id);
359 $sql .= " AND p.fk_salary = s.rowid";
360 $sql .= " AND s.entity IN (".getEntity('tax').")";
361 $sql .= " ORDER BY dp DESC";
362 
363 //print $sql;
364 $resql = $db->query($sql);
365 if ($resql) {
366  $totalpaid = 0;
367 
368  $num = $db->num_rows($resql);
369 
370  $i = 0;
371  $total = 0;
372 
373  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
374  print '<table class="noborder paymenttable">';
375  print '<tr class="liste_titre">';
376  print '<td>'.$langs->trans("RefPayment").'</td>';
377  print '<td>'.$langs->trans("Date").'</td>';
378  print '<td>'.$langs->trans("Type").'</td>';
379  if (isModEnabled("bank")) {
380  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
381  }
382  print '<td class="right">'.$langs->trans("Amount").'</td>';
383  print '</tr>';
384 
385  if ($num > 0) {
386  $bankaccountstatic = new Account($db);
387  while ($i < $num) {
388  $objp = $db->fetch_object($resql);
389 
390  print '<tr class="oddeven"><td>';
391  print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
392  print '<td>'.dol_print_date($db->jdate($objp->dp), 'dayhour', 'tzuserrel')."</td>\n";
393  $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
394  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
395  if (isModEnabled("bank")) {
396  $bankaccountstatic->id = $objp->baid;
397  $bankaccountstatic->ref = $objp->baref;
398  $bankaccountstatic->label = $objp->baref;
399  $bankaccountstatic->number = $objp->banumber;
400  $bankaccountstatic->currency_code = $objp->bacurrency_code;
401 
402  if (isModEnabled('accounting')) {
403  $bankaccountstatic->account_number = $objp->account_number;
404 
405  $accountingjournal = new AccountingJournal($db);
406  $accountingjournal->fetch($objp->fk_accountancy_journal);
407  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
408  }
409 
410  print '<td class="right">';
411  if ($bankaccountstatic->id) {
412  print $bankaccountstatic->getNomUrl(1, 'transactions');
413  }
414  print '</td>';
415  }
416  print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
417  print "</tr>";
418  $totalpaid += $objp->amount;
419  $i++;
420  }
421  } else {
422  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
423  print '<td></td><td></td><td></td><td></td>';
424  print '</tr>';
425  }
426 
427  // print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowrap amountcard">'.price($totalpaid)."</td></tr>\n";
428  // print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowrap amountcard">'.price($object->amount)."</td></tr>\n";
429 
430  $resteapayer = $object->amount - $totalpaid;
431  // $cssforamountpaymentcomplete = 'amountpaymentcomplete';
432 
433  // print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
434  // print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
435 
436  print "</table>";
437  print '</div>';
438 
439  $db->free($resql);
440 } else {
441  dol_print_error($db);
442 }
443 print '</div>';
444 print '</div>';
445 print '<div class="clearboth"></div>';
446 
447 
448 print dol_get_fiche_end();
449 
451 print '<div class="tabsAction">'."\n";
452 
453 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
454 $sql .= " pfd.date_traite as date_traite, pfd.amount, pfd.fk_prelevement_bons,";
455 $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.amount as pb_amount,";
456 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
457 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
458 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
459 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
460 if ($type == 'salaire') {
461  $sql .= " WHERE pfd.fk_salary = ".((int) $object->id);
462 } else {
463  $sql .= " WHERE fk_facture = ".((int) $object->id);
464 }
465 $sql .= " AND pfd.traite = 0";
466 $sql .= " AND pfd.type = 'ban'";
467 $sql .= " ORDER BY pfd.date_demande DESC";
468 $resql = $db->query($sql);
469 
470 $hadRequest = $db->num_rows($resql);
471 if ($object->paye == 0 && $hadRequest == 0) {
472  if ($resteapayer > 0) {
473  if ($user_perms) {
474  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
475  print '<input type="hidden" name="token" value="'.newToken().'" />';
476  print '<input type="hidden" name="id" value="'.$object->id.'" />';
477  print '<input type="hidden" name="type" value="'.$type.'" />';
478  print '<input type="hidden" name="action" value="new" />';
479  print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
480  print '<input type="text" id="withdraw_request_amount" name="request_transfer" value="'.price($resteapayer, 0, $langs, 1, -1, -1).'" size="9" />';
481  print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />';
482  print '</form>';
483 
484  if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT_SHOW_OLD_BUTTON')) { // This is hidden, prefer to use mode enabled with STRIPE_SEPA_DIRECT_DEBIT
485  // TODO Replace this with a checkbox for each payment mode: "Send request to XXX immediately..."
486  print "<br>";
487  //add stripe sepa button
488  $buttonlabel = $langs->trans("MakeWithdrawRequestStripe");
489  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
490  print '<input type="hidden" name="token" value="'.newToken().'" />';
491  print '<input type="hidden" name="id" value="'.$object->id.'" />';
492  print '<input type="hidden" name="type" value="'.$type.'" />';
493  print '<input type="hidden" name="action" value="new" />';
494  print '<input type="hidden" name="paymenservice" value="stripesepa" />';
495  print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
496  print '<input type="text" id="withdraw_request_amount" name="request_transfer" value="'.price($resteapayer, 0, $langs, 1, -1, -1).'" size="9" />';
497  print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />';
498  print '</form>';
499  }
500  } else {
501  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>';
502  }
503  } else {
504  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
505  }
506 } else {
507  if ($hadRequest == 0) {
508  if ($object->paye > 0) {
509  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
510  } else {
511  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
512  }
513  } else {
514  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
515  }
516 }
517 
518 print '</div>';
519 
520 print '<div>';
521 
522 
523 /*
524  * Withdraw receipts
525  */
526 $bprev = new BonPrelevement($db);
527 
528 /*
529  * Withdrawals
530  */
531 
532 print '<div class="div-table-responsive-no-min">';
533 print '<table class="noborder centpercent">';
534 
535 print '<tr class="liste_titre">';
536 // Action column
537 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
538  print '<td>&nbsp;</td>';
539 }
540 print '<td class="left">'.$langs->trans("DateRequest").'</td>';
541 print '<td>'.$langs->trans("User").'</td>';
542 print '<td class="center">'.$langs->trans("Amount").'</td>';
543 print '<td class="center">'.$langs->trans("DateProcess").'</td>';
544 if ($type == 'bank-transfer') {
545  print '<td class="center">'.$langs->trans("BankTransferReceipt").'</td>';
546 } else {
547  print '<td class="center">'.$langs->trans("WithdrawalReceipt").'</td>';
548 }
549 print '<td>&nbsp;</td>';
550 // Action column
551 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
552  print '<td>&nbsp;</td>';
553 }
554 print '</tr>';
555 
556 $num = 0;
557 if ($resql) {
558  $i = 0;
559 
560  $tmpuser = new User($db);
561 
562  $num = $db->num_rows($result);
563  if ($num > 0) {
564  while ($i < $num) {
565  $obj = $db->fetch_object($resql);
566 
567  $tmpuser->id = $obj->user_id;
568  $tmpuser->login = $obj->login;
569  $tmpuser->ref = $obj->login;
570  $tmpuser->email = $obj->email;
571  $tmpuser->lastname = $obj->lastname;
572  $tmpuser->firstname = $obj->firstname;
573  $tmpuser->statut = $obj->user_status;
574  $tmpuser->status = $obj->user_status;
575 
576  print '<tr class="oddeven">';
577 
578  // Action column
579  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
580  print '<td class="right">';
581  print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
582  print img_delete();
583  print '</a></td>';
584  }
585 
586  // Date
587  print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
588 
589  // User
590  print '<td class="tdoverflowmax125">';
591  print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
592  print '</td>';
593 
594  // Amount
595  print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
596 
597  // Date process
598  print '<td class="center"><span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span></td>';
599 
600  // Link to make payment now
601  print '<td class="minwidth75">';
602  if ($obj->fk_prelevement_bons > 0) {
603  $withdrawreceipt = new BonPrelevement($db);
604  $withdrawreceipt->id = $obj->fk_prelevement_bons;
605  $withdrawreceipt->ref = $obj->ref;
606  $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
607  $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
608  $withdrawreceipt->date_creation = $db->jdate($obj->datec);
609  $withdrawreceipt->statut = $obj->status;
610  $withdrawreceipt->status = $obj->status;
611  $withdrawreceipt->amount = $obj->pb_amount;
612  //$withdrawreceipt->credite = $db->jdate($obj->credite);
613 
614  print $withdrawreceipt->getNomUrl(1);
615  }
616 
617  if (!in_array($type, array('bank-transfer', 'salaire', 'salary'))) {
618  if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
619  $langs->load("stripe");
620  if ($obj->fk_prelevement_bons > 0) {
621  print ' &nbsp; ';
622  }
623  print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripedirectdebit&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequestDirectDebitWithStripe").'</a>';
624  }
625  } else {
626  if (getDolGlobalString('STRIPE_SEPA_CREDIT_TRANSFER')) {
627  $langs->load("stripe");
628  if ($obj->fk_prelevement_bons > 0) {
629  print ' &nbsp; ';
630  }
631  print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripecredittransfer&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequesCreditTransferWithStripe").'</a>';
632  }
633  }
634  print '</td>';
635 
636  //
637  print '<td class="center">-</td>';
638 
639  // Action column
640  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
641  print '<td class="right">';
642  print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
643  print img_delete();
644  print '</a></td>';
645  }
646 
647  print "</tr>\n";
648  $i++;
649  }
650  }
651 
652  $db->free($resql);
653 } else {
654  dol_print_error($db);
655 }
656 
657 // Past requests when bon prelevement
658 
659 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
660 $sql .= " pfd.date_traite as date_traite, pfd.amount, pfd.fk_prelevement_bons,";
661 $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.amount as pb_amount,";
662 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
663 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
664 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
665 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
666 if ($type == 'salaire') {
667  $sql .= " WHERE pfd.fk_salary = ".((int) $object->id);
668 } else {
669  $sql .= " WHERE fk_facture = ".((int) $object->id);
670 }
671 $sql .= " AND pfd.traite = 1";
672 $sql .= " AND pfd.type = 'ban'";
673 $sql .= " ORDER BY pfd.date_demande DESC";
674 
675 $resql = $db->query($sql);
676 if ($resql) {
677  $numOfBp = $db->num_rows($resql);
678  $i = 0;
679  $tmpuser = new User($db);
680  if ($numOfBp > 0) {
681  while ($i < $numOfBp) {
682  $obj = $db->fetch_object($resql);
683 
684  $tmpuser->id = $obj->user_id;
685  $tmpuser->login = $obj->login;
686  $tmpuser->ref = $obj->login;
687  $tmpuser->email = $obj->email;
688  $tmpuser->lastname = $obj->lastname;
689  $tmpuser->firstname = $obj->firstname;
690  $tmpuser->statut = $obj->user_status;
691  $tmpuser->status = $obj->user_status;
692 
693  print '<tr class="oddeven">';
694 
695  // Action column
696  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
697  print '<td>&nbsp;</td>';
698  }
699 
700  // Date
701  print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
702 
703  // User
704  print '<td class="tdoverflowmax125">';
705  print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
706  print '</td>';
707 
708  // Amount
709  print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
710 
711  // Date process
712  print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_traite), 'dayhour', 'tzuserrel')."</td>\n";
713 
714  // Link to payment request done
715  print '<td class="center minwidth75">';
716  if ($obj->fk_prelevement_bons > 0) {
717  $withdrawreceipt = new BonPrelevement($db);
718  $withdrawreceipt->id = $obj->fk_prelevement_bons;
719  $withdrawreceipt->ref = $obj->ref;
720  $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
721  $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
722  $withdrawreceipt->date_creation = $db->jdate($obj->datec);
723  $withdrawreceipt->statut = $obj->status;
724  $withdrawreceipt->status = $obj->status;
725  $withdrawreceipt->fk_bank_account = $obj->fk_bank_account;
726  $withdrawreceipt->amount = $obj->pb_amount;
727  //$withdrawreceipt->credite = $db->jdate($obj->credite);
728 
729  print $withdrawreceipt->getNomUrl(1);
730  print ' ';
731  print $withdrawreceipt->getLibStatut(2);
732 
733  // Show the bank account
734  $fk_bank_account = $withdrawreceipt->fk_bank_account;
735  if (empty($fk_bank_account)) {
736  $fk_bank_account = ($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
737  }
738  if ($fk_bank_account > 0) {
739  $bankaccount = new Account($db);
740  $result = $bankaccount->fetch($fk_bank_account);
741  if ($result > 0) {
742  print ' - ';
743  print $bankaccount->getNomUrl(1);
744  }
745  }
746  }
747  print "</td>\n";
748 
749  //
750  print '<td>&nbsp;</td>';
751 
752  // Action column
753  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
754  print '<td>&nbsp;</td>';
755  }
756 
757  print "</tr>\n";
758  $i++;
759  }
760  }
761  $db->free($resql);
762 } else {
763  dol_print_error($db);
764 }
765 
766 if ($num == 0 && $numOfBp == 0) {
767  print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
768 }
769 
770 print "</table>";
771 print '</div>';
772 
773 // End of page
774 llxFooter();
775 $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 bank accounts.
Class to manage accounting journals.
Class to manage withdrawal receipts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage building of HTML components.
Class to manage projects.
Class to manage salary payments.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.