dolibarr  9.0.0
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("admin","withdrawals"));
34 
35 // Security check
36 if (!$user->admin) accessforbidden();
37 
38 $action = GETPOST('action','alpha');
39 $type = 'paymentorder';
40 
41 
42 /*
43  * Actions
44  */
45 
46 if ($action == "set")
47 {
48  $db->begin();
49 
50  $id=GETPOST('PRELEVEMENT_ID_BANKACCOUNT','int');
51  $account = new Account($db);
52  if($account->fetch($id)>0)
53  {
54  $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id,'chaine',0,'',$conf->entity);
55  if (! $res > 0) $error++;
56  /*
57  $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
58  if (! $res > 0) $error++;
59  $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
60  if (! $res > 0) $error++;
61  $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
62  if (! $res > 0) $error++;
63  $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
64  if (! $res > 0) $error++;
65  $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
66  if (! $res > 0) $error++;
67  $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
68  if (! $res > 0) $error++;
69  $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
70  if (! $res > 0) $error++;
71  */
72  }
73  else $error++;
74 
75  $res = dolibarr_set_const($db, "PRELEVEMENT_ICS", GETPOST("PRELEVEMENT_ICS"),'chaine',0,'',$conf->entity);
76  if (! $res > 0) $error++;
77 
78  if (GETPOST("PRELEVEMENT_USER") > 0)
79  {
80  $res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"),'chaine',0,'',$conf->entity);
81  if (! $res > 0) $error++;
82  }
83  if (GETPOST("PRELEVEMENT_END_TO_END") || GETPOST("PRELEVEMENT_END_TO_END")=="")
84  {
85  $res = dolibarr_set_const($db, "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  {
90  $res = dolibarr_set_const($db, "USTRD", GETPOST("PRELEVEMENT_USTRD"),'chaine',0,'',$conf->entity);
91  if (! $res > 0) $error++;
92  }
93 
94  if (! $error)
95  {
96  $db->commit();
97  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
98  }
99  else
100  {
101  $db->rollback();
102  setEventMessages($langs->trans("Error"), null, 'errors');
103  }
104 }
105 
106 if ($action == "addnotif")
107 {
108  $bon = new BonPrelevement($db);
109  $bon->AddNotification($db,GETPOST('user','int'),$action);
110 
111  header("Location: prelevement.php");
112  exit;
113 }
114 
115 if ($action == "deletenotif")
116 {
117  $bon = new BonPrelevement($db);
118  $bon->DeleteNotificationById(GETPOST('notif','int'));
119 
120  header("Location: prelevement.php");
121  exit;
122 }
123 
124 /*
125 if ($action == 'specimen')
126 {
127  $modele=GETPOST('module','alpha');
128 
129  $commande = new Commande($db);
130  $commande->initAsSpecimen();
131 
132  // Search template files
133  $file=''; $classname=''; $filefound=0;
134  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
135  foreach($dirmodels as $reldir)
136  {
137  $file=dol_buildpath($reldir."core/modules/paymentorders/doc/pdf_".$modele.".modules.php",0);
138  if (file_exists($file))
139  {
140  $filefound=1;
141  $classname = "pdf_".$modele;
142  break;
143  }
144  }
145 
146  if ($filefound)
147  {
148  require_once $file;
149 
150  $module = new $classname($db);
151 
152  if ($module->write_file($commande,$langs) > 0)
153  {
154  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=paymentorders&file=SPECIMEN.pdf");
155  return;
156  }
157  else
158  {
159  setEventMessages($module->error, null, 'errors');
160  dol_syslog($module->error, LOG_ERR);
161  }
162  }
163  else
164  {
165  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
166  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
167  }
168 }
169 
170 // Set default model
171 else if ($action == 'setdoc')
172 {
173  if (dolibarr_set_const($db, "PAYMENTORDER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
174  {
175  // The constant that was read before the new set
176  // We therefore requires a variable to have a coherent view
177  $conf->global->PAYMENTORDER_ADDON_PDF = $value;
178  }
179 
180  // On active le modele
181  $ret = delDocumentModel($value, $type);
182  if ($ret > 0)
183  {
184  $ret = addDocumentModel($value, $type, $label, $scandir);
185  }
186 }
187 */
188 
189 
190 /*
191  * View
192  */
193 
194 $form=new Form($db);
195 
196 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
197 
198 llxHeader('',$langs->trans("WithdrawalsSetup"));
199 
200 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
201 
202 print load_fiche_titre($langs->trans("WithdrawalsSetup"),$linkback,'title_setup');
203 print '<br>';
204 
205 print '<form method="post" action="prelevement.php?action=set">';
206 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
207 
208 print '<table class="noborder" width="100%">';
209 
210 print '<tr class="liste_titre">';
211 print '<td width="30%">'.$langs->trans("Parameter").'</td>';
212 print '<td width="40%">'.$langs->trans("Value").'</td>';
213 print "</tr>";
214 
215 // Bank account (from Banks module)
216 print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("BankToReceiveWithdraw").'</td>';
217 print '<td align="left">';
218 $form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT,'PRELEVEMENT_ID_BANKACCOUNT',0,"courant=1",1);
219 print '</td></tr>';
220 
221 // ICS
222 print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("ICS").'</td>';
223 print '<td align="left">';
224 print '<input type="text" name="PRELEVEMENT_ICS" value="'.$conf->global->PRELEVEMENT_ICS.'" size="15" ></td>';
225 print '</td></tr>';
226 
227 //User
228 print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
229 print '<td align="left">';
230 print $form->select_dolusers($conf->global->PRELEVEMENT_USER, 'PRELEVEMENT_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
231 print '</td>';
232 print '</tr>';
233 
234 //EntToEnd
235 print '<tr class="pair"><td>'.$langs->trans("END_TO_END").'</td>';
236 print '<td align="left">';
237 print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->END_TO_END.'" size="15" ></td>';
238 print '</td></tr>';
239 
240 //USTRD
241 print '<tr class="pair"><td>'.$langs->trans("USTRD").'</td>';
242 print '<td align="left">';
243 print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->USTRD.'" size="15" ></td>';
244 print '</td></tr>';
245 
246 print '</table>';
247 print '<br>';
248 
249 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
250 
251 print '</form>';
252 
253 
254 print '<br>';
255 
256 
257 /*
258  * Document templates generators
259  */
260 /*
261 print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
262 
263 // Load array def with activated templates
264 $def = array();
265 $sql = "SELECT nom";
266 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
267 $sql.= " WHERE type = '".$type."'";
268 $sql.= " AND entity = ".$conf->entity;
269 $resql=$db->query($sql);
270 if ($resql)
271 {
272  $i = 0;
273  $num_rows=$db->num_rows($resql);
274  while ($i < $num_rows)
275  {
276  $array = $db->fetch_array($resql);
277  array_push($def, $array[0]);
278  $i++;
279  }
280 }
281 else
282 {
283  dol_print_error($db);
284 }
285 
286 
287 print "<table class=\"noborder\" width=\"100%\">\n";
288 print "<tr class=\"liste_titre\">\n";
289 print '<td>'.$langs->trans("Name").'</td>';
290 print '<td>'.$langs->trans("Description").'</td>';
291 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
292 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
293 print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
294 print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
295 print "</tr>\n";
296 
297 clearstatcache();
298 
299 foreach ($dirmodels as $reldir)
300 {
301  foreach (array('','/doc') as $valdir)
302  {
303  $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
304 
305  if (is_dir($dir))
306  {
307  $handle=opendir($dir);
308  if (is_resource($handle))
309  {
310  while (($file = readdir($handle))!==false)
311  {
312  $filelist[]=$file;
313  }
314  closedir($handle);
315  arsort($filelist);
316 
317  foreach($filelist as $file)
318  {
319  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
320  {
321 
322  if (file_exists($dir.'/'.$file))
323  {
324  $name = substr($file, 4, dol_strlen($file) -16);
325  $classname = substr($file, 0, dol_strlen($file) -12);
326 
327  require_once $dir.'/'.$file;
328  $module = new $classname($db);
329 
330  $modulequalified=1;
331  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
332  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
333 
334  if ($modulequalified)
335  {
336  $var = !$var;
337  print '<tr class="oddeven"><td width="100">';
338  print (empty($module->name)?$name:$module->name);
339  print "</td><td>\n";
340  if (method_exists($module,'info')) print $module->info($langs);
341  else print $module->description;
342  print '</td>';
343 
344  // Active
345  if (in_array($name, $def))
346  {
347  print '<td align="center">'."\n";
348  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
349  print img_picto($langs->trans("Enabled"),'switch_on');
350  print '</a>';
351  print '</td>';
352  }
353  else
354  {
355  print '<td align="center">'."\n";
356  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
357  print "</td>";
358  }
359 
360  // Default
361  print '<td align="center">';
362  if ($conf->global->PAYMENTORDER_ADDON_PDF == $name)
363  {
364  print img_picto($langs->trans("Default"),'on');
365  }
366  else
367  {
368  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
369  }
370  print '</td>';
371 
372  // Info
373  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
374  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
375  if ($module->type == 'pdf')
376  {
377  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
378  }
379  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
380  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
381  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
382  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
383  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
384  //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
385  //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
386  $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
387 
388 
389  print '<td align="center">';
390  print $form->textwithpicto('',$htmltooltip,1,0);
391  print '</td>';
392 
393  // Preview
394  print '<td align="center">';
395  if ($module->type == 'pdf')
396  {
397  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'bill').'</a>';
398  }
399  else
400  {
401  print img_object($langs->trans("PreviewNotAvailable"),'generic');
402  }
403  print '</td>';
404 
405  print "</tr>\n";
406  }
407  }
408  }
409  }
410  }
411  }
412  }
413 }
414 
415 */
416 
417 
418 dol_fiche_end();
419 
420 print '<br>';
421 
422 
423 /*
424  * Notifications
425  */
426 
427 /* Disable this, there is no trigger with elementtype 'withdraw'
428 if (! empty($conf->global->MAIN_MODULE_NOTIFICATION))
429 {
430  $langs->load("mails");
431  print load_fiche_titre($langs->trans("Notifications"));
432 
433  $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
434  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
435  $sql.= " WHERE entity IN (".getEntity('facture').")";
436 
437  $resql=$db->query($sql);
438  if ($resql)
439  {
440  $num = $db->num_rows($resql);
441  $i = 0;
442  while ($i < $num)
443  {
444  $obj = $db->fetch_object($resql);
445 
446  if (!$obj->fk_soc)
447  {
448  $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
449  $internalusers[$obj->rowid] = $username;
450  }
451 
452  $i++;
453  }
454  $db->free($resql);
455  }
456 
457  // Get list of triggers for module withdraw
458  $sql = "SELECT rowid, code, label";
459  $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
460  $sql.= " WHERE elementtype = 'withdraw'";
461  $sql.= " ORDER BY rang ASC";
462 
463  $resql = $db->query($sql);
464  if ($resql)
465  {
466  $num = $db->num_rows($resql);
467  $i = 0;
468  while ($i < $num)
469  {
470  $obj = $db->fetch_object($resql);
471  $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
472  $actions[$obj->rowid]=$label;
473  $i++;
474  }
475  $db->free($resql);
476  }
477 
478 
479  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
480  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
481  print '<table class="noborder" width="100%">';
482  print '<tr class="liste_titre">';
483  print '<td>'.$langs->trans("User").'</td>';
484  print '<td>'.$langs->trans("Value").'</td>';
485  print '<td align="right">'.$langs->trans("Action").'</td>';
486  print "</tr>\n";
487 
488  print '<tr class="impair"><td align="left">';
489  print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
490  print '</td>';
491 
492  print '<td>';
493  print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
494  print '</td>';
495 
496  print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
497 
498  // List of current notifications for objet_type='withdraw'
499  $sql = "SELECT u.lastname, u.firstname,";
500  $sql.= " nd.rowid, ad.code, ad.label";
501  $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
502  $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
503  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
504  $sql.= " WHERE u.rowid = nd.fk_user";
505  $sql.= " AND nd.fk_action = ad.rowid";
506  $sql.= " AND u.entity IN (0,".$conf->entity.")";
507 
508  $resql = $db->query($sql);
509  if ($resql)
510  {
511  $num = $db->num_rows($resql);
512  $i = 0;
513  while ($i < $num)
514  {
515  $obj = $db->fetch_object($resql);
516 
517 
518  print '<tr class="oddeven">';
519  print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
520  $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
521  print '<td>'.$label.'</td>';
522  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&amp;notif='.$obj->rowid.'">'.img_delete().'</a></td>';
523  print '</tr>';
524  $i++;
525  }
526  $db->free($resql);
527  }
528 
529  print '</table>';
530  print '</form>';
531 }
532 */
533 
534 // End of page
535 llxFooter();
536 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:510
Class to manage bank accounts.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
Class to manage withdrawal receipts.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44