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