dolibarr  7.0.0-beta
payment.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
28 
29 $langs->load("admin");
30 $langs->load("errors");
31 $langs->load('other');
32 $langs->load('bills');
33 
34 if (! $user->admin) accessforbidden();
35 
36 $action = GETPOST('action','alpha');
37 $value = GETPOST('value','alpha');
38 $label = GETPOST('label','alpha');
39 $scandir = GETPOST('scan_dir','alpha');
40 $type='invoice';
41 
42 if (empty($conf->global->PAYMENT_ADDON)) $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
43 
44 
45 /*
46  * Actions
47  */
48 
49 if ($action == 'updateMask')
50 {
51  $maskconstpayment=GETPOST('maskconstpayment','alpha');
52  $maskpayment=GETPOST('maskpayment','alpha');
53  if ($maskconstpayment) $res = dolibarr_set_const($db,$maskconstpayment,$maskpayment,'chaine',0,'',$conf->entity);
54 
55  if (! $res > 0) $error++;
56 
57  if (! $error)
58  {
59  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
60  }
61  else
62  {
63  setEventMessages($langs->trans("Error"), null, 'errors');
64  }
65 }
66 
67 if ($action == 'setmod')
68 {
69  dolibarr_set_const($db, "PAYMENT_ADDON",$value,'chaine',0,'',$conf->entity);
70 }
71 
72 if ($action == 'setparams')
73 {
74  $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS','none'); // No alpha here, we want exact string
75 
76  $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity);
77 
78  if (! $res > 0) $error++;
79 
80  if ($error)
81  {
82  setEventMessages($langs->trans("Error"), null, 'errors');
83  }
84  if (! $error)
85  {
86  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87  }
88 
89 }
90 
91 
92 /*
93  * View
94  */
95 
96 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
97 
98 llxHeader("",$langs->trans("BillsSetup"),'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
99 
100 $form=new Form($db);
101 
102 
103 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
104 print load_fiche_titre($langs->trans("BillsSetup"),$linkback,'title_setup');
105 
107 dol_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
108 
109 /*
110  * Numbering module
111  */
112 
113 print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
114 
115 print '<table class="noborder" width="100%">';
116 print '<tr class="liste_titre">';
117 print '<td>'.$langs->trans("Name").'</td>';
118 print '<td>'.$langs->trans("Description").'</td>';
119 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
120 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
121 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
122 print '</tr>'."\n";
123 
124 clearstatcache();
125 
126 foreach ($dirmodels as $reldir)
127 {
128  $dir = dol_buildpath($reldir."core/modules/payment/");
129  if (is_dir($dir))
130  {
131  $handle = opendir($dir);
132  if (is_resource($handle))
133  {
134  $var=true;
135 
136  while (($file = readdir($handle))!==false)
137  {
138  if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
139  {
140  $filebis = $file;
141  $classname = preg_replace('/\.php$/','',$file);
142  // For compatibility
143  if (! is_file($dir.$filebis))
144  {
145  $filebis = $file."/".$file.".modules.php";
146  $classname = "mod_payment_".$file;
147  }
148  // Check if there is a filter on country
149  preg_match('/\-(.*)_(.*)$/',$classname,$reg);
150  if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
151 
152  $classname = preg_replace('/\-.*$/','',$classname);
153  if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
154  {
155  // Charging the numbering class
156  require_once $dir.$filebis;
157 
158  $module = new $classname($db);
159 
160  // Show modules according to features level
161  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
162  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
163 
164  if ($module->isEnabled())
165  {
166  $var = !$var;
167  print '<tr class="oddeven"><td width="100">';
168  echo preg_replace('/\-.*$/','',preg_replace('/mod_payment_/','',preg_replace('/\.php$/','',$file)));
169  print "</td><td>\n";
170 
171  print $module->info();
172 
173  print '</td>';
174 
175  // Show example of numbering module
176  print '<td class="nowrap">';
177  $tmp=$module->getExample();
178  if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
179  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
180  else print $tmp;
181  print '</td>'."\n";
182 
183  print '<td align="center">';
184  //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
185  if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file)
186  {
187  print img_picto($langs->trans("Activated"),'switch_on');
188  }
189  else
190  {
191  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
192  }
193  print '</td>';
194 
195  $payment=new Paiement($db);
196  $payment->initAsSpecimen();
197 
198  // Example
199  $htmltooltip='';
200  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
201  $nextval=$module->getNextValue($mysoc,$payment);
202  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
203  $htmltooltip.=$langs->trans("NextValue").': ';
204  if ($nextval) {
205  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
206  $nextval = $langs->trans($nextval);
207  $htmltooltip.=$nextval.'<br>';
208  } else {
209  $htmltooltip.=$langs->trans($module->error).'<br>';
210  }
211  }
212 
213  print '<td align="center">';
214  print $form->textwithpicto('',$htmltooltip,1,0);
215 
216  if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
217  {
218  if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
219  }
220 
221  print '</td>';
222 
223  print "</tr>\n";
224 
225  }
226  }
227  }
228  }
229  closedir($handle);
230  }
231  }
232 }
233 
234 print '</table>';
235 
236 print "<br>";
237 
238 print load_fiche_titre($langs->trans("OtherOptions"),'','');
239 
240 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
241 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
242 print '<input type="hidden" name="action" value="setparams" />';
243 
244 print '<table class="noborder" width="100%">';
245 print '<tr class="liste_titre">';
246 print '<td>'.$langs->trans("Parameter").'</td>';
247 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
248 print '<td width="80">&nbsp;</td>';
249 print "</tr>\n";
250 
251 // Allow payments on different thirdparties bills but same parent company
252 $var=! $var;
253 print '<tr class="oddeven"><td>';
254 print $langs->trans("PaymentOnDifferentThirdBills");
255 print '</td><td width="60" align="center">';
256 print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1);
257 print '</td><td align="right">';
258 print "</td></tr>\n";
259 
260 // Add js auto fill amount on paiement form
261 /* always on now
262 $var=! $var;
263 print '<tr class="oddeven"><td>';
264 print $langs->trans("JSOnPaimentBill");
265 print '</td><td width="60" align="center">';
266 print $form->selectyesno("INVOICE_AUTO_FILLJS",$conf->global->INVOICE_AUTO_FILLJS,1);
267 print '</td><td align="right">';
268 print "</td></tr>\n";
269 */
270 
271 print '</table>';
272 
273 print '<center>';
274 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
275 print '</center>';
276 
277 print '</form>';
278 
279 dol_fiche_end();
280 
281 
282 llxFooter();
283 
284 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
dol_htmloutput_mesg($mesgstring='', $mesgarray='', $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage payments of customer invoices.
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
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.