dolibarr 23.0.3
prelevement.php
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2019 Markus Welters <markus@welters.de>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array("admin", "withdrawals"));
46
47// Security check
48if (!$user->admin) {
50}
51
52$action = GETPOST('action', 'aZ09');
53$type = 'paymentorder';
54
55$error = 0;
56
57
58/*
59 * Actions
60 */
61
62if ($action == "set") {
63 $db->begin();
64
65 $id = GETPOSTINT('PRELEVEMENT_ID_BANKACCOUNT');
66 $account = new Account($db);
67 if ($account->fetch($id) > 0) {
68 $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id, 'chaine', 0, '', $conf->entity);
69 if (!($res > 0)) {
70 $error++;
71 }
72 /*
73 $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
74 if (! $res > 0) $error++;
75 $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
76 if (! $res > 0) $error++;
77 $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
78 if (! $res > 0) $error++;
79 $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
80 if (! $res > 0) $error++;
81 $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
82 if (! $res > 0) $error++;
83 $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
84 if (! $res > 0) $error++;
85 $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->owner_address,'chaine',0,'',$conf->entity);
86 if (! $res > 0) $error++;
87 */
88 } else {
89 $error++;
90 }
91
92 /* Moved to account
93 $res = dolibarr_set_const($db, "PRELEVEMENT_ICS", GETPOST("PRELEVEMENT_ICS"), 'chaine', 0, '', $conf->entity);
94 if (!($res > 0)) $error++;
95 */
96 if (GETPOST("PRELEVEMENT_USER") > 0) {
97 $res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"), 'chaine', 0, '', $conf->entity);
98 if (!($res > 0)) {
99 $error++;
100 }
101 }
102 if (GETPOST("PRELEVEMENT_END_TO_END") || GETPOST("PRELEVEMENT_END_TO_END") == "") {
103 $res = dolibarr_set_const($db, "PRELEVEMENT_END_TO_END", GETPOST("PRELEVEMENT_END_TO_END"), 'chaine', 0, '', $conf->entity);
104 if (!($res > 0)) {
105 $error++;
106 }
107 }
108 if (GETPOST("PRELEVEMENT_USTRD") || GETPOST("PRELEVEMENT_USTRD") == "") {
109 $res = dolibarr_set_const($db, "PRELEVEMENT_USTRD", GETPOST("PRELEVEMENT_USTRD"), 'chaine', 0, '', $conf->entity);
110 if (!($res > 0)) {
111 $error++;
112 }
113 }
114
115 $res = dolibarr_set_const($db, "PRELEVEMENT_ADDDAYS", GETPOST("PRELEVEMENT_ADDDAYS"), 'chaine', 0, '', $conf->entity);
116 if (!($res > 0)) {
117 $error++;
118 }
119
120 if (!$error) {
121 $db->commit();
122 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
123 } else {
124 $db->rollback();
125 setEventMessages($langs->trans("Error"), null, 'errors');
126 }
127}
128
129if ($action == "addnotif") {
130 $bon = new BonPrelevement($db);
131 $bon->addNotification($db, GETPOSTINT('user'), $action);
132
133 header("Location: ".$_SERVER["PHP_SELF"]);
134 exit;
135}
136
137if ($action == "deletenotif") {
138 $bon = new BonPrelevement($db);
139 $bon->deleteNotificationById(GETPOSTINT('notif'));
140
141 header("Location: ".$_SERVER["PHP_SELF"]);
142 exit;
143}
144
145
146/*
147 * View
148 */
149
150$form = new Form($db);
151
152$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
153
154llxHeader('', $langs->trans("WithdrawalsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-prelevement');
155
156$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
157
158print load_fiche_titre($langs->trans("WithdrawalsSetup"), $linkback, 'title_setup');
159print '<br>';
160
161print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=set">';
162print '<input type="hidden" name="token" value="'.newToken().'">';
163
164print '<table class="noborder centpercent">';
165
166print '<tr class="liste_titre">';
167print '<td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td>';
168print '<td></td>';
169print "</tr>";
170
171
172// Bank account (from Banks module)
173print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("BankToReceiveWithdraw").'</td>';
174print '<td>';
175print img_picto('', 'bank_account', 'class="pictofixedwidth"');
176print $form->select_comptes(getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'), 'PRELEVEMENT_ID_BANKACCOUNT', 0, "courant=1", 1, '', 0, 'minwidth200 widthcentpercentminusxx maxwidth300', 1);
177// TODO Add plus to add a bank account
178print ' <a href="'.DOL_URL_ROOT.'/compta/bank/card.php?action=create&backtopage='.DOL_URL_ROOT.'/admin/prelevement.php"><span class="fa fa-plus-circle"></span></a>';
179print '</td></tr>';
180
181/* Moved to bank account data
182// ICS
183
184print '<tr class="oddeven"><td class="fieldrequired">';
185$htmltext = $langs->trans("AskThisIDToYourBank");
186print $form->textwithpicto($langs->trans("ICS"), $htmltext);
187print '</td>';
188print '<td class="left">';
189print '<input type="text" name="PRELEVEMENT_ICS" value="'.$conf->global->PRELEVEMENT_ICS.'" size="15" >';
190print '</td>';
191print '</td></tr>';
192*/
193
194//User
195print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
196print '<td>';
197print img_picto('', 'user', 'class="pictofixedwidth"');
198print $form->select_dolusers(getDolGlobalInt('PRELEVEMENT_USER'), 'PRELEVEMENT_USER', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'minwidth200 maxwidth500');
199print '</td>';
200print '</tr>';
201
202//EntToEnd
203print '<tr class="oddeven"><td>';
204$htmltext = $langs->trans("KeepThisEmptyInMostCases");
205print $form->textwithpicto($langs->trans("END_TO_END"), $htmltext);
206print '</td>';
207print '<td>';
208print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.getDolGlobalString('PRELEVEMENT_END_TO_END').'" class="width100"></td>';
209print '</td></tr>';
210
211//USTRD
212print '<tr class="oddeven"><td>';
213$htmltext = $langs->trans("KeepThisEmptyInMostCases");
214print $form->textwithpicto($langs->trans("USTRD"), $htmltext);
215print '</td>';
216print '<td class="left">';
217print '<input type="text" name="PRELEVEMENT_USTRD" value="'.getDolGlobalString('PRELEVEMENT_USTRD').'" class="width100"></td>';
218print '</td></tr>';
219
220//ADDDAYS
221print '<tr class="oddeven"><td>'.$langs->trans("ADDDAYS").'</td>';
222print '<td>';
223if (!getDolGlobalString('PRELEVEMENT_ADDDAYS')) {
224 $conf->global->PRELEVEMENT_ADDDAYS = 0;
225}
226print '<input type="text" name="PRELEVEMENT_ADDDAYS" value="'.getDolGlobalString('PRELEVEMENT_ADDDAYS').'" class="width50"></td>';
227print '</td></tr>';
228
229print '</table>';
230
231print $form->buttonsSaveCancel("Save", '');
232
233print '</form>';
234
235
236print '<br>';
237
238
239/*
240 * Document templates generators
241 */
242/*
243print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
244
245// Load array def with activated templates
246$def = array();
247$sql = "SELECT nom";
248$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
249$sql.= " WHERE type = '".$db->escape($type)."'";
250$sql.= " AND entity = ".((int) $conf->entity);
251$resql=$db->query($sql);
252if ($resql)
253{
254 $i = 0;
255 $num_rows=$db->num_rows($resql);
256 while ($i < $num_rows)
257 {
258 $array = $db->fetch_array($resql);
259 array_push($def, $array[0]);
260 $i++;
261 }
262}
263else
264{
265 dol_print_error($db);
266}
267
268
269print "<table class=\"noborder\" width=\"100%\">\n";
270print "<tr class=\"liste_titre\">\n";
271print '<td>'.$langs->trans("Name").'</td>';
272print '<td>'.$langs->trans("Description").'</td>';
273print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
274print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
275print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
276print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
277print "</tr>\n";
278
279clearstatcache();
280
281foreach ($dirmodels as $reldir)
282{
283 foreach (array('','/doc') as $valdir)
284 {
285 $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
286
287 if (is_dir($dir))
288 {
289 $handle=opendir($dir);
290 if (is_resource($handle))
291 {
292 while (($file = readdir($handle))!==false)
293 {
294 $filelist[]=$file;
295 }
296 closedir($handle);
297 arsort($filelist);
298
299 foreach($filelist as $file)
300 {
301 if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
302 {
303
304 if (file_exists($dir.'/'.$file))
305 {
306 $name = substr($file, 4, dol_strlen($file) -16);
307 $classname = substr($file, 0, dol_strlen($file) -12);
308
309 require_once $dir.'/'.$file;
310 $module = new $classname($db);
311
312 $modulequalified=1;
313 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
314 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
315
316 if ($modulequalified) {
317 print '<tr class="oddeven"><td width="100">';
318 print (empty($module->name)?$name:$module->name);
319 print "</td><td>\n";
320 if (method_exists($module,'info')) print $module->info($langs);
321 else print $module->description;
322 print '</td>';
323
324 // Active
325 if (in_array($name, $def))
326 {
327 print '<td class="center">'."\n";
328 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
329 print img_picto($langs->trans("Enabled"),'switch_on');
330 print '</a>';
331 print '</td>';
332 }
333 else
334 {
335 print '<td class="center">'."\n";
336 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
337 print "</td>";
338 }
339
340 // Default
341 print '<td class="center">';
342 if (getDolGlobalString('PAYMENTORDER_ADDON_PDF') == $name)
343 {
344 print img_picto($langs->trans("Default"),'on');
345 }
346 else
347 {
348 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
349 }
350 print '</td>';
351
352 // Info
353 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
354 $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
355 if ($module->type == 'pdf')
356 {
357 $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
358 }
359 $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
360 $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
361 $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
362 $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
363 $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
364 //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
365 //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
366 $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
367
368
369 print '<td class="center">';
370 print $form->textwithpicto('',$htmltooltip,1,0);
371 print '</td>';
372
373 // Preview
374 print '<td class="center">';
375 if ($module->type == 'pdf')
376 {
377 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
378 }
379 else
380 {
381 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"),'generic');
382 }
383 print '</td>';
384
385 print "</tr>\n";
386 }
387 }
388 }
389 }
390 }
391 }
392 }
393}
394
395*/
396
397
398print dol_get_fiche_end();
399
400print '<br>';
401
402
403/*
404 * Notifications
405 */
406
407/* Disable this, there is no trigger with elementtype 'withdraw'
408if (isModEnabled('notification') )
409{
410 $langs->load("mails");
411 print load_fiche_titre($langs->trans("Notifications"));
412
413 $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
414 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
415 $sql.= " WHERE entity IN (".getEntity('invoice').")";
416
417 $resql=$db->query($sql);
418 if ($resql)
419 {
420 $num = $db->num_rows($resql);
421 $i = 0;
422 while ($i < $num)
423 {
424 $obj = $db->fetch_object($resql);
425
426 if (!$obj->fk_soc)
427 {
428 $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
429 $internalusers[$obj->rowid] = $username;
430 }
431
432 $i++;
433 }
434 $db->free($resql);
435 }
436
437 // Get list of triggers for module withdraw
438 $sql = "SELECT rowid, code, label";
439 $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
440 $sql.= " WHERE elementtype = 'withdraw'";
441 $sql.= " ORDER BY rang ASC";
442
443 $resql = $db->query($sql);
444 if ($resql)
445 {
446 $num = $db->num_rows($resql);
447 $i = 0;
448 while ($i < $num)
449 {
450 $obj = $db->fetch_object($resql);
451 $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
452 $actions[$obj->rowid]=$label;
453 $i++;
454 }
455 $db->free($resql);
456 }
457
458
459 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif&token='.newToken().'">';
460 print '<input type="hidden" name="token" value="'.newToken().'">';
461 print '<table class="noborder centpercent">';
462 print '<tr class="liste_titre">';
463 print '<td>'.$langs->trans("User").'</td>';
464 print '<td></td>';
465 print '<td class="right">'.$langs->trans("Action").'</td>';
466 print "</tr>\n";
467
468 print '<tr class="impair"><td class="left">';
469 print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
470 print '</td>';
471
472 print '<td>';
473 print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
474 print '</td>';
475
476 print '<td class="right"><input type="submit" class="button button-add" value="'.$langs->trans("Add").'"></td></tr>';
477
478 // List of current notifications for objet_type='withdraw'
479 $sql = "SELECT u.lastname, u.firstname,";
480 $sql.= " nd.rowid, ad.code, ad.label";
481 $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
482 $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
483 $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
484 $sql.= " WHERE u.rowid = nd.fk_user";
485 $sql.= " AND nd.fk_action = ad.rowid";
486 $sql.= " AND u.entity IN (0,".$conf->entity.")";
487
488 $resql = $db->query($sql);
489 if ($resql)
490 {
491 $num = $db->num_rows($resql);
492 $i = 0;
493 while ($i < $num)
494 {
495 $obj = $db->fetch_object($resql);
496
497
498 print '<tr class="oddeven">';
499 print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
500 $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
501 print '<td>'.$label.'</td>';
502 print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&token='.newToken().'&notif='.$obj->rowid.'">'.img_delete().'</a></td>';
503 print '</tr>';
504 $i++;
505 }
506 $db->free($resql);
507 }
508
509 print '</table>';
510 print '</form>';
511}
512*/
513
514// End of page
515llxFooter();
516$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.