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