dolibarr  16.0.5
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) {
35 }
36 
37 $action = GETPOST('action', 'aZ09');
38 $value = GETPOST('value', 'alpha');
39 $label = GETPOST('label', 'alpha');
40 $scandir = GETPOST('scan_dir', 'alpha');
41 $type = 'invoice';
42 
43 if (empty($conf->global->PAYMENT_ADDON)) {
44  $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
45 }
46 
47 
48 /*
49  * Actions
50  */
51 
52 if ($action == 'updateMask') {
53  $maskconstpayment = GETPOST('maskconstpayment', 'alpha');
54  $maskpayment = GETPOST('maskpayment', 'alpha');
55  if ($maskconstpayment) {
56  $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, 'chaine', 0, '', $conf->entity);
57  }
58 
59  if (!($res > 0)) {
60  $error++;
61  }
62 
63  if (!$error) {
64  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
65  } else {
66  setEventMessages($langs->trans("Error"), null, 'errors');
67  }
68 }
69 
70 if ($action == 'setmod') {
71  dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
72 }
73 
74 if ($action == 'setparams') {
75  $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string
76  $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity);
77  if (!($res > 0)) {
78  $error++;
79  }
80 
81  $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
82  if (!($res > 0)) {
83  $error++;
84  }
85 
86  if ($error) {
87  setEventMessages($langs->trans("Error"), null, 'errors');
88  }
89  if (!$error) {
90  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
91  }
92 }
93 
94 
95 /*
96  * View
97  */
98 
99 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
100 
101 llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
102 
103 $form = new Form($db);
104 
105 
106 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
107 print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
108 
110 print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
111 
112 /*
113  * Numbering module
114  */
115 
116 print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
117 
118 print '<div class="div-table-responsive-no-min">';
119 print '<table class="noborder centpercent">';
120 print '<tr class="liste_titre">';
121 print '<td>'.$langs->trans("Name").'</td>';
122 print '<td>'.$langs->trans("Description").'</td>';
123 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
124 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
125 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
126 print '</tr>'."\n";
127 
128 clearstatcache();
129 
130 foreach ($dirmodels as $reldir) {
131  $dir = dol_buildpath($reldir."core/modules/payment/");
132  if (is_dir($dir)) {
133  $handle = opendir($dir);
134  if (is_resource($handle)) {
135  while (($file = readdir($handle)) !== false) {
136  if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
137  $filebis = $file;
138  $classname = preg_replace('/\.php$/', '', $file);
139  // For compatibility
140  if (!is_file($dir.$filebis)) {
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)) {
147  continue;
148  }
149 
150  $classname = preg_replace('/\-.*$/', '', $classname);
151  if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
152  // Charging the numbering class
153  require_once $dir.$filebis;
154 
155  $module = new $classname($db);
156 
157  // Show modules according to features level
158  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
159  continue;
160  }
161  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
162  continue;
163  }
164 
165  if ($module->isEnabled()) {
166  print '<tr class="oddeven"><td width="100">';
167  echo preg_replace('/\-.*$/', '', preg_replace('/mod_payment_/', '', preg_replace('/\.php$/', '', $file)));
168  print "</td><td>\n";
169 
170  print $module->info();
171 
172  print '</td>';
173 
174  // Show example of numbering module
175  print '<td class="nowrap">';
176  $tmp = $module->getExample();
177  if (preg_match('/^Error/', $tmp)) {
178  $langs->load("errors");
179  print '<div class="error">'.$langs->trans($tmp).'</div>';
180  } elseif ($tmp == 'NotConfigured') {
181  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
182  } else {
183  print $tmp;
184  }
185  print '</td>'."\n";
186 
187  print '<td class="center">';
188  //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
189  if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file) {
190  print img_picto($langs->trans("Activated"), 'switch_on');
191  } else {
192  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&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>';
193  }
194  print '</td>';
195 
196  $payment = new Paiement($db);
197  $payment->initAsSpecimen();
198 
199  // Example
200  $htmltooltip = '';
201  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
202  $nextval = $module->getNextValue($mysoc, $payment);
203  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
204  $htmltooltip .= $langs->trans("NextValue").': ';
205  if ($nextval) {
206  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
207  $nextval = $langs->trans($nextval);
208  }
209  $htmltooltip .= $nextval.'<br>';
210  } else {
211  $htmltooltip .= $langs->trans($module->error).'<br>';
212  }
213  }
214 
215  print '<td class="center">';
216  print $form->textwithpicto('', $htmltooltip, 1, 0);
217 
218  if ($conf->global->PAYMENT_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
219  if (!empty($module->error)) {
220  dol_htmloutput_mesg($module->error, '', 'error', 1);
221  }
222  }
223 
224  print '</td>';
225 
226  print "</tr>\n";
227  }
228  }
229  }
230  }
231  closedir($handle);
232  }
233  }
234 }
235 
236 print '</table>';
237 print '</div>';
238 
239 print "<br>";
240 
241 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
242 
243 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
244 print '<input type="hidden" name="token" value="'.newToken().'" />';
245 print '<input type="hidden" name="action" value="setparams" />';
246 
247 print '<div class="div-table-responsive-no-min">';
248 print '<table class="noborder centpercent">';
249 print '<tr class="liste_titre">';
250 print '<td>'.$langs->trans("Parameter").'</td>';
251 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
252 print '<td width="80">&nbsp;</td>';
253 print "</tr>\n";
254 
255 // Allow payments on different thirdparties bills but same parent company
256 print '<tr class="oddeven"><td>';
257 print $langs->trans("PaymentOnDifferentThirdBills");
258 print '</td><td width="60" align="center">';
259 print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS, 1);
260 print '</td><td class="right">';
261 print "</td></tr>\n";
262 
263 // Allow to group payments by mod in rapports
264 print '<tr class="oddeven"><td>';
265 print $langs->trans("GroupPaymentsByModOnReports");
266 print '</td><td width="60" align="center">';
267 print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", $conf->global->PAYMENTS_REPORT_GROUP_BY_MOD, 1);
268 print '</td><td class="right">';
269 print "</td></tr>\n";
270 
271 print '</table>';
272 print '</div>';
273 
274 print dol_get_fiche_end();
275 
276 print $form->buttonsSaveCancel("Modify", '');
277 
278 print '</form>';
279 
280 // End of page
281 llxFooter();
282 $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
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
invoice_admin_prepare_head
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: invoice.lib.php:136
$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
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dol_htmloutput_mesg
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
Definition: functions.lib.php:8299
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
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
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