dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("admin");
33 $langs->load("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 
84  if (! $error)
85  {
86  $db->commit();
87  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88  }
89  else
90  {
91  $db->rollback();
92  setEventMessages($langs->trans("Error"), null, 'errors');
93  }
94 }
95 
96 if ($action == "addnotif")
97 {
98  $bon = new BonPrelevement($db);
99  $bon->AddNotification($db,GETPOST('user','int'),$action);
100 
101  header("Location: prelevement.php");
102  exit;
103 }
104 
105 if ($action == "deletenotif")
106 {
107  $bon = new BonPrelevement($db);
108  $bon->DeleteNotificationById(GETPOST('notif','int'));
109 
110  header("Location: prelevement.php");
111  exit;
112 }
113 
114 /*
115 if ($action == 'specimen')
116 {
117  $modele=GETPOST('module','alpha');
118 
119  $commande = new Commande($db);
120  $commande->initAsSpecimen();
121 
122  // Search template files
123  $file=''; $classname=''; $filefound=0;
124  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
125  foreach($dirmodels as $reldir)
126  {
127  $file=dol_buildpath($reldir."core/modules/paymentorders/doc/pdf_".$modele.".modules.php",0);
128  if (file_exists($file))
129  {
130  $filefound=1;
131  $classname = "pdf_".$modele;
132  break;
133  }
134  }
135 
136  if ($filefound)
137  {
138  require_once $file;
139 
140  $module = new $classname($db);
141 
142  if ($module->write_file($commande,$langs) > 0)
143  {
144  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=paymentorders&file=SPECIMEN.pdf");
145  return;
146  }
147  else
148  {
149  setEventMessages($module->error, null, 'errors');
150  dol_syslog($module->error, LOG_ERR);
151  }
152  }
153  else
154  {
155  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
156  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
157  }
158 }
159 
160 // Set default model
161 else if ($action == 'setdoc')
162 {
163  if (dolibarr_set_const($db, "PAYMENTORDER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
164  {
165  // The constant that was read before the new set
166  // We therefore requires a variable to have a coherent view
167  $conf->global->PAYMENTORDER_ADDON_PDF = $value;
168  }
169 
170  // On active le modele
171  $ret = delDocumentModel($value, $type);
172  if ($ret > 0)
173  {
174  $ret = addDocumentModel($value, $type, $label, $scandir);
175  }
176 }
177 */
178 
179 
180 /*
181  * View
182  */
183 
184 $form=new Form($db);
185 
186 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
187 
188 llxHeader('',$langs->trans("WithdrawalsSetup"));
189 
190 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
191 
192 print load_fiche_titre($langs->trans("WithdrawalsSetup"),$linkback,'title_setup');
193 print '<br>';
194 
195 print '<form method="post" action="prelevement.php?action=set">';
196 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
197 
198 print '<table class="noborder" width="100%">';
199 
200 print '<tr class="liste_titre">';
201 print '<td width="30%">'.$langs->trans("Parameter").'</td>';
202 print '<td width="40%">'.$langs->trans("Value").'</td>';
203 print "</tr>";
204 
205 // Bank account (from Banks module)
206 print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("BankToReceiveWithdraw").'</td>';
207 print '<td align="left">';
208 $form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT,'PRELEVEMENT_ID_BANKACCOUNT',0,"courant=1",1);
209 print '</td></tr>';
210 
211 // ICS
212 print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("ICS").'</td>';
213 print '<td align="left">';
214 print '<input type="text" name="PRELEVEMENT_ICS" value="'.$conf->global->PRELEVEMENT_ICS.'" size="15" ></td>';
215 print '</td></tr>';
216 
217 //User
218 print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
219 print '<td align="left">';
220 print $form->select_dolusers($conf->global->PRELEVEMENT_USER, 'PRELEVEMENT_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
221 print '</td>';
222 print '</tr>';
223 
224 print '</table>';
225 print '<br>';
226 
227 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
228 
229 print '</form>';
230 
231 
232 print '<br>';
233 
234 
235 /*
236  * Document templates generators
237  */
238 /*
239 print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
240 
241 // Load array def with activated templates
242 $def = array();
243 $sql = "SELECT nom";
244 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
245 $sql.= " WHERE type = '".$type."'";
246 $sql.= " AND entity = ".$conf->entity;
247 $resql=$db->query($sql);
248 if ($resql)
249 {
250  $i = 0;
251  $num_rows=$db->num_rows($resql);
252  while ($i < $num_rows)
253  {
254  $array = $db->fetch_array($resql);
255  array_push($def, $array[0]);
256  $i++;
257  }
258 }
259 else
260 {
261  dol_print_error($db);
262 }
263 
264 
265 print "<table class=\"noborder\" width=\"100%\">\n";
266 print "<tr class=\"liste_titre\">\n";
267 print '<td>'.$langs->trans("Name").'</td>';
268 print '<td>'.$langs->trans("Description").'</td>';
269 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
270 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
271 print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
272 print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
273 print "</tr>\n";
274 
275 clearstatcache();
276 
277 $var=true;
278 foreach ($dirmodels as $reldir)
279 {
280  foreach (array('','/doc') as $valdir)
281  {
282  $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
283 
284  if (is_dir($dir))
285  {
286  $handle=opendir($dir);
287  if (is_resource($handle))
288  {
289  while (($file = readdir($handle))!==false)
290  {
291  $filelist[]=$file;
292  }
293  closedir($handle);
294  arsort($filelist);
295 
296  foreach($filelist as $file)
297  {
298  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
299  {
300 
301  if (file_exists($dir.'/'.$file))
302  {
303  $name = substr($file, 4, dol_strlen($file) -16);
304  $classname = substr($file, 0, dol_strlen($file) -12);
305 
306  require_once $dir.'/'.$file;
307  $module = new $classname($db);
308 
309  $modulequalified=1;
310  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
311  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
312 
313  if ($modulequalified)
314  {
315  $var = !$var;
316  print '<tr class="oddeven"><td width="100">';
317  print (empty($module->name)?$name:$module->name);
318  print "</td><td>\n";
319  if (method_exists($module,'info')) print $module->info($langs);
320  else print $module->description;
321  print '</td>';
322 
323  // Active
324  if (in_array($name, $def))
325  {
326  print '<td align="center">'."\n";
327  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
328  print img_picto($langs->trans("Enabled"),'switch_on');
329  print '</a>';
330  print '</td>';
331  }
332  else
333  {
334  print '<td align="center">'."\n";
335  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>';
336  print "</td>";
337  }
338 
339  // Default
340  print '<td align="center">';
341  if ($conf->global->PAYMENTORDER_ADDON_PDF == $name)
342  {
343  print img_picto($langs->trans("Default"),'on');
344  }
345  else
346  {
347  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>';
348  }
349  print '</td>';
350 
351  // Info
352  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
353  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
354  if ($module->type == 'pdf')
355  {
356  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
357  }
358  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
359  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
360  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
361  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
362  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
363  //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
364  //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
365  $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
366 
367 
368  print '<td align="center">';
369  print $form->textwithpicto('',$htmltooltip,1,0);
370  print '</td>';
371 
372  // Preview
373  print '<td align="center">';
374  if ($module->type == 'pdf')
375  {
376  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'bill').'</a>';
377  }
378  else
379  {
380  print img_object($langs->trans("PreviewNotAvailable"),'generic');
381  }
382  print '</td>';
383 
384  print "</tr>\n";
385  }
386  }
387  }
388  }
389  }
390  }
391  }
392 }
393 
394 */
395 
396 
397 dol_fiche_end();
398 
399 print '<br>';
400 
401 
402 /*
403  * Notifications
404  */
405 
406 /* Disable this, there is no trigger with elementtype 'withdraw'
407 if (! empty($conf->global->MAIN_MODULE_NOTIFICATION))
408 {
409  $langs->load("mails");
410  print load_fiche_titre($langs->trans("Notifications"));
411 
412  $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
413  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
414  $sql.= " WHERE entity IN (".getEntity('facture').")";
415 
416  $resql=$db->query($sql);
417  if ($resql)
418  {
419  $num = $db->num_rows($resql);
420  $var = true;
421  $i = 0;
422  while ($i < $num)
423  {
424  $obj = $db->fetch_object($resql);
425 
426  if (!$obj->fk_soc)
427  {
428  $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
429  $internalusers[$obj->rowid] = $username;
430  }
431 
432  $i++;
433  }
434  $db->free($resql);
435  }
436 
437  // Get list of triggers for module withdraw
438  $sql = "SELECT rowid, code, label";
439  $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
440  $sql.= " WHERE elementtype = 'withdraw'";
441  $sql.= " ORDER BY rang ASC";
442 
443  $resql = $db->query($sql);
444  if ($resql)
445  {
446  $num = $db->num_rows($resql);
447  $i = 0;
448  $var = false;
449  while ($i < $num)
450  {
451  $obj = $db->fetch_object($resql);
452  $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
453  $actions[$obj->rowid]=$label;
454  $i++;
455  }
456  $db->free($resql);
457  }
458 
459 
460  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
461  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
462  print '<table class="noborder" width="100%">';
463  print '<tr class="liste_titre">';
464  print '<td>'.$langs->trans("User").'</td>';
465  print '<td>'.$langs->trans("Value").'</td>';
466  print '<td align="right">'.$langs->trans("Action").'</td>';
467  print "</tr>\n";
468 
469  print '<tr class="impair"><td align="left">';
470  print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
471  print '</td>';
472 
473  print '<td>';
474  print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
475  print '</td>';
476 
477  print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
478 
479  // List of current notifications for objet_type='withdraw'
480  $sql = "SELECT u.lastname, u.firstname,";
481  $sql.= " nd.rowid, ad.code, ad.label";
482  $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
483  $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
484  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
485  $sql.= " WHERE u.rowid = nd.fk_user";
486  $sql.= " AND nd.fk_action = ad.rowid";
487  $sql.= " AND u.entity IN (0,".$conf->entity.")";
488 
489  $resql = $db->query($sql);
490  if ($resql)
491  {
492  $num = $db->num_rows($resql);
493  $i = 0;
494  $var = false;
495  while ($i < $num)
496  {
497  $obj = $db->fetch_object($resql);
498 
499 
500  print '<tr class="oddeven">';
501  print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
502  $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
503  print '<td>'.$label.'</td>';
504  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&amp;notif='.$obj->rowid.'">'.img_delete().'</a></td>';
505  print '</tr>';
506  $i++;
507  }
508  $db->free($resql);
509  }
510 
511  print '</table>';
512  print '</form>';
513 }
514 */
515 
516 llxFooter();
517 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage bank accounts.
GETPOST($paramname, $check='none', $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)
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.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91