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