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