dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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 <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
32
42// Load translation files required by the page
43$langs->loadLangs(array("admin", "other", "errors", "bills"));
44
45if (!$user->admin) {
47}
48
49$action = GETPOST('action', 'aZ09');
50$value = GETPOST('value', 'alpha');
51$label = GETPOST('label', 'alpha');
52$scandir = GETPOST('scan_dir', 'alpha');
53$type = 'invoice';
54
55if (!getDolGlobalString('PAYMENT_ADDON')) {
56 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
57}
58
59
60/*
61 * Actions
62 */
63$error = 0;
64
65if ($action == 'updateMask') {
66 $maskconstpayment = GETPOST('maskconstpayment', 'aZ09');
67 $maskpayment = GETPOST('maskpayment', 'alpha');
68
69 $res = 0;
70
71 if ($maskconstpayment && preg_match('/_MASK$/', $maskconstpayment)) {
72 $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, 'chaine', 0, '', $conf->entity);
73 }
74
75 if (!($res > 0)) {
76 $error++;
77 }
78
79 if (!$error) {
80 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
81 } else {
82 setEventMessages($langs->trans("Error"), null, 'errors');
83 }
84}
85
86if ($action == 'setmod') {
87 dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
88}
89
90if ($action == 'setparams') {
91 $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string
92 $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity);
93 if (!($res > 0)) {
94 $error++;
95 }
96
97 $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOSTINT('PAYMENTS_REPORT_GROUP_BY_MOD'), 'chaine', 0, '', $conf->entity);
98 if (!($res > 0)) {
99 $error++;
100 }
101
102 if ($error) {
103 setEventMessages($langs->trans("Error"), null, 'errors');
104 }
105 if (!$error) {
106 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
107 }
108}
109
110
111/*
112 * View
113 */
114
115$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
116
117llxHeader('', $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura', '', 0, 0, '', '', '', 'mod-admin page-payment');
118
119$form = new Form($db);
120
121
122$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
123
124print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
125
127print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'bill');
128
129// Numbering module
130
131print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
132
133print '<div class="div-table-responsive-no-min">';
134print '<table class="noborder centpercent">';
135print '<tr class="liste_titre">';
136print '<td>'.$langs->trans("Name").'</td>';
137print '<td>'.$langs->trans("Description").'</td>';
138print '<td class="nowrap">'.$langs->trans("Example").'</td>';
139print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
140print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
141print '</tr>'."\n";
142
143clearstatcache();
144
145$arrayofmodules = array();
146
147foreach ($dirmodels as $reldir) {
148 $dir = dol_buildpath($reldir."core/modules/payment/");
149 if (is_dir($dir)) {
150 $handle = opendir($dir);
151 if (is_resource($handle)) {
152 while (($file = readdir($handle)) !== false) {
153 if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
154 $filebis = $file;
155 $classname = preg_replace('/\.php$/', '', $file);
156 // For compatibility
157 if (!is_file($dir.$filebis)) {
158 $filebis = $file."/".$file.".modules.php";
159 $classname = "mod_payment_".$file;
160 }
161 // Check if there is a filter on country
162 $reg = array();
163 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
164 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
165 continue;
166 }
167
168 $classname = preg_replace('/\-.*$/', '', $classname);
169 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
170 // Charging the numbering class
171 require_once $dir.$filebis;
172
173 $module = new $classname($db);
175 '@phan-var-force ModeleNumRefPayments $module';
176
177 $arrayofmodules[] = $module;
178 }
179 }
180 }
181 closedir($handle);
182 }
183 }
184}
185
186$arrayofmodules = dol_sort_array($arrayofmodules, 'position');
187
188foreach ($arrayofmodules as $module) {
189 // Show modules according to features level
190 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
191 continue;
192 }
193 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
194 continue;
195 }
196
197 if ($module->isEnabled()) {
198 $file = 'mod_payment_'.strtolower($module->getName($langs)).'.php';
199
200 print '<tr class="oddeven"><td width="100">';
201 print preg_replace('/\-.*$/', '', preg_replace('/mod_payment_/', '', $module->getName($langs)));
202 print "</td><td>\n";
203
204 print $module->info($langs);
205
206 print '</td>';
207
208 // Show example of numbering module
209 print '<td class="nowrap">';
210 $tmp = $module->getExample();
211 if (preg_match('/^Error/', $tmp)) {
212 $langs->load("errors");
213 print '<div class="error">'.$langs->trans($tmp).'</div>';
214 } elseif ($tmp == 'NotConfigured') {
215 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
216 } else {
217 print $tmp;
218 }
219 print '</td>'."\n";
220
221 print '<td class="center">';
222 if (getDolGlobalString('PAYMENT_ADDON') == $file || getDolGlobalString('PAYMENT_ADDON') . '.php' == $file) {
223 print img_picto($langs->trans("Activated"), 'switch_on');
224 } else {
225 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
226 }
227 print '</td>';
228
229 $payment = new Paiement($db);
230 $payment->initAsSpecimen();
231
232 // Example
233 $htmltooltip = '';
234 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
235 $nextval = $module->getNextValue($mysoc, $payment);
236 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
237 $htmltooltip .= $langs->trans("NextValue").': ';
238 if ($nextval) {
239 if (preg_match('/^Error/', $nextval)) {
240 $nextval = $langs->trans($nextval);
241 }
242 $htmltooltip .= $nextval.'<br>';
243 } else {
244 $htmltooltip .= $langs->trans($module->error).'<br>';
245 }
246 }
247
248 print '<td class="center">';
249 print $form->textwithpicto('', $htmltooltip, 1, 'info');
250
251 if (getDolGlobalString('PAYMENT_ADDON').'.php' == $file) { // If module is the one used, we show existing errors
252 if (!empty($module->error)) {
253 dol_htmloutput_mesg($module->error, array(), 'error', 1);
254 }
255 }
256
257 print '</td>';
258
259 print "</tr>\n";
260 }
261}
262
263print '</table>';
264print '</div>';
265
266print "<br>";
267
268print load_fiche_titre($langs->trans("OtherOptions"), '', '');
269
270print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
271print '<input type="hidden" name="token" value="'.newToken().'" />';
272print '<input type="hidden" name="action" value="setparams" />';
273
274print '<div class="div-table-responsive-no-min">';
275print '<table class="noborder centpercent">';
276print '<tr class="liste_titre">';
277print '<td>'.$langs->trans("Parameter").'</td>';
278print '<td align="center" width="60"></td>';
279print '<td width="80">&nbsp;</td>';
280print "</tr>\n";
281
282// Allow payments on different thirdparties bills but same parent company
283/*
284print '<tr class="oddeven"><td>';
285print $langs->trans("PaymentOnDifferentThirdBills");
286print '</td><td width="60" align="center">';
287print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", getDolGlobalInt('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'), 1);
288print '</td><td class="right">';
289print "</td></tr>\n";
290*/
291
292// Allow to group payments by mod in rapports
293print '<tr class="oddeven"><td>';
294print $langs->trans("GroupPaymentsByModOnReports");
295print '</td><td width="60" align="center">';
296print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", getDolGlobalInt('PAYMENTS_REPORT_GROUP_BY_MOD'), 1);
297print '</td><td class="right">';
298print "</td></tr>\n";
299
300print '</table>';
301print '</div>';
302
303print dol_get_fiche_end();
304
305print $form->buttonsSaveCancel("Modify", '');
306
307print '</form>';
308
309// End of page
310llxFooter();
311$db->close();
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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of customer invoices.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
invoice_admin_prepare_head()
Return array head with list of tabs to view object information.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.