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