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