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