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