dolibarr 18.0.6
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// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array("admin", "other", "errors", "bills"));
33
34if (!$user->admin) {
36}
37
38$action = GETPOST('action', 'aZ09');
39$value = GETPOST('value', 'alpha');
40$label = GETPOST('label', 'alpha');
41$scandir = GETPOST('scan_dir', 'alpha');
42$type = 'invoice';
43
44if (empty($conf->global->PAYMENT_ADDON)) {
45 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
46}
47
48
49/*
50 * Actions
51 */
52
53if ($action == 'updateMask') {
54 $maskconstpayment = GETPOST('maskconstpayment', 'aZ09');
55 $maskpayment = GETPOST('maskpayment', 'alpha');
56 if ($maskconstpayment && preg_match('/_MASK$/', $maskconstpayment)) {
57 $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, 'chaine', 0, '', $conf->entity);
58 }
59
60 if (!($res > 0)) {
61 $error++;
62 }
63
64 if (!$error) {
65 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
66 } else {
67 setEventMessages($langs->trans("Error"), null, 'errors');
68 }
69}
70
71if ($action == 'setmod') {
72 dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
73}
74
75if ($action == 'setparams') {
76 $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string
77 $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity);
78 if (!($res > 0)) {
79 $error++;
80 }
81
82 $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
83 if (!($res > 0)) {
84 $error++;
85 }
86
87 if ($error) {
88 setEventMessages($langs->trans("Error"), null, 'errors');
89 }
90 if (!$error) {
91 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
92 }
93}
94
95
96/*
97 * View
98 */
99
100$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
101
102llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
103
104$form = new Form($db);
105
106
107$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
108print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
109
111print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
112
113/*
114 * Numbering module
115 */
116
117print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
118
119print '<div class="div-table-responsive-no-min">';
120print '<table class="noborder centpercent">';
121print '<tr class="liste_titre">';
122print '<td>'.$langs->trans("Name").'</td>';
123print '<td>'.$langs->trans("Description").'</td>';
124print '<td class="nowrap">'.$langs->trans("Example").'</td>';
125print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
126print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
127print '</tr>'."\n";
128
129clearstatcache();
130
131foreach ($dirmodels as $reldir) {
132 $dir = dol_buildpath($reldir."core/modules/payment/");
133 if (is_dir($dir)) {
134 $handle = opendir($dir);
135 if (is_resource($handle)) {
136 while (($file = readdir($handle)) !== false) {
137 if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
138 $filebis = $file;
139 $classname = preg_replace('/\.php$/', '', $file);
140 // For compatibility
141 if (!is_file($dir.$filebis)) {
142 $filebis = $file."/".$file.".modules.php";
143 $classname = "mod_payment_".$file;
144 }
145 // Check if there is a filter on country
146 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
147 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
148 continue;
149 }
150
151 $classname = preg_replace('/\-.*$/', '', $classname);
152 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
153 // Charging the numbering class
154 require_once $dir.$filebis;
155
156 $module = new $classname($db);
157
158 // Show modules according to features level
159 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
160 continue;
161 }
162 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
163 continue;
164 }
165
166 if ($module->isEnabled()) {
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)) {
179 $langs->load("errors");
180 print '<div class="error">'.$langs->trans($tmp).'</div>';
181 } elseif ($tmp == 'NotConfigured') {
182 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
183 } else {
184 print $tmp;
185 }
186 print '</td>'."\n";
187
188 print '<td class="center">';
189 //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
190 if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file) {
191 print img_picto($langs->trans("Activated"), 'switch_on');
192 } else {
193 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>';
194 }
195 print '</td>';
196
197 $payment = new Paiement($db);
198 $payment->initAsSpecimen();
199
200 // Example
201 $htmltooltip = '';
202 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
203 $nextval = $module->getNextValue($mysoc, $payment);
204 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
205 $htmltooltip .= $langs->trans("NextValue").': ';
206 if ($nextval) {
207 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
208 $nextval = $langs->trans($nextval);
209 }
210 $htmltooltip .= $nextval.'<br>';
211 } else {
212 $htmltooltip .= $langs->trans($module->error).'<br>';
213 }
214 }
215
216 print '<td class="center">';
217 print $form->textwithpicto('', $htmltooltip, 1, 0);
218
219 if ($conf->global->PAYMENT_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
220 if (!empty($module->error)) {
221 dol_htmloutput_mesg($module->error, '', 'error', 1);
222 }
223 }
224
225 print '</td>';
226
227 print "</tr>\n";
228 }
229 }
230 }
231 }
232 closedir($handle);
233 }
234 }
235}
236
237print '</table>';
238print '</div>';
239
240print "<br>";
241
242print load_fiche_titre($langs->trans("OtherOptions"), '', '');
243
244print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
245print '<input type="hidden" name="token" value="'.newToken().'" />';
246print '<input type="hidden" name="action" value="setparams" />';
247
248print '<div class="div-table-responsive-no-min">';
249print '<table class="noborder centpercent">';
250print '<tr class="liste_titre">';
251print '<td>'.$langs->trans("Parameter").'</td>';
252print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
253print '<td width="80">&nbsp;</td>';
254print "</tr>\n";
255
256// Allow payments on different thirdparties bills but same parent company
257print '<tr class="oddeven"><td>';
258print $langs->trans("PaymentOnDifferentThirdBills");
259print '</td><td width="60" align="center">';
260print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", getDolGlobalInt('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'), 1);
261print '</td><td class="right">';
262print "</td></tr>\n";
263
264// Allow to group payments by mod in rapports
265print '<tr class="oddeven"><td>';
266print $langs->trans("GroupPaymentsByModOnReports");
267print '</td><td width="60" align="center">';
268print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", getDolGlobalInt('PAYMENTS_REPORT_GROUP_BY_MOD'), 1);
269print '</td><td class="right">';
270print "</td></tr>\n";
271
272print '</table>';
273print '</div>';
274
275print dol_get_fiche_end();
276
277print $form->buttonsSaveCancel("Modify", '');
278
279print '</form>';
280
281// End of page
282llxFooter();
283$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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of customer invoices.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.