dolibarr 25.0.0-alpha
supplier_payment.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31
41require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
42if (getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
43 require_once DOL_DOCUMENT_ROOT . '/core/lib/supplier_invoice.lib.php';
44} else {
45 require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
46}
47require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
48
49// Load translation files required by the page
50$langs->loadLangs(array("admin", "other", "bills", "orders"));
51
52if (!$user->admin) {
54}
55
56$action = GETPOST('action', 'aZ09');
57$value = GETPOST('value', 'alpha');
58$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
59
60$label = GETPOST('label', 'alpha');
61$scandir = GETPOST('scandir', 'alpha');
62$type = 'supplier_payment';
63$error = 0;
64
65/*
66 * Actions
67 */
68
69include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
70
71if ($action == 'updateMask') {
72 $maskconstsupplierpayment = GETPOST('maskconstsupplierpayment', 'aZ09');
73 $masksupplierpayment = GETPOST('masksupplierpayment', 'alpha');
74
75 $res = 0;
76
77 if ($maskconstsupplierpayment && preg_match('/_MASK$/', $maskconstsupplierpayment)) {
78 $res = dolibarr_set_const($db, $maskconstsupplierpayment, $masksupplierpayment, 'chaine', 0, '', $conf->entity);
79 }
80
81 if (!($res > 0)) {
82 $error++;
83 }
84
85 if (!$error) {
86 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87 } else {
88 setEventMessages($langs->trans("Error"), null, 'errors');
89 }
90} elseif ($action == 'setmod') {
91 dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
92} elseif ($action == 'set') {
93 // Activate a model
94 $ret = addDocumentModel($value, $type, $label, $scandir);
95} elseif ($action == 'del') {
96 $ret = delDocumentModel($value, $type);
97 if ($ret > 0) {
98 if (getDolGlobalString("FACTURE_ADDON_PDF") == "$value") {
99 dolibarr_del_const($db, 'SUPPLIER_PAYMENT_ADDON_PDF', $conf->entity);
100 }
101 }
102} elseif ($action == 'setdoc') {
103 // Set default model
104 if (dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
105 // The constant that was read before the new set
106 // so we go through a variable to get a consistent display
107 $conf->global->FACTURE_ADDON_PDF = $value;
108 }
109
110 // On active le modele
111 $ret = delDocumentModel($value, $type);
112 if ($ret > 0) {
113 $ret = addDocumentModel($value, $type, $label, $scandir);
114 }
115} elseif ($action == 'unsetdoc') {
116 dolibarr_del_const($db, "SUPPLIER_PAYMENT_ADDON_PDF", $conf->entity);
117} elseif ($action == 'specimen') {
118 $modele = GETPOST('module', 'alpha');
119
120 $paiementFourn = new PaiementFourn($db);
121 $paiementFourn->initAsSpecimen();
122
123 // Search template files
124 $file = '';
125 $classname = '';
126 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
127 foreach ($dirmodels as $reldir) {
128 $file = dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php", 0);
129 if (file_exists($file)) {
130 $classname = "pdf_".$modele;
131 break;
132 }
133 }
134
135 if ($classname !== '') {
136 require_once $file;
137
138 $module = new $classname($db);
139 '@phan-var-force ModelePDFSuppliersPayments $module';
140
141 if ($module->write_file($paiementFourn, $langs) > 0) {
142 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
143 return;
144 } else {
145 setEventMessages($module->error, $module->errors, 'errors');
146 dol_syslog($module->error, LOG_ERR);
147 }
148 } else {
149 $langs->load('errors');
150 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
151 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
152 }
153} elseif ($action == 'setparams') {
154 $res = dolibarr_set_const($db, "PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", GETPOSTINT('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'), 'chaine', 0, '', $conf->entity);
155 if (!($res > 0)) {
156 $error++;
157 }
158
159 if ($error) {
160 setEventMessages($langs->trans("Error"), null, 'errors');
161 }
162 if (!$error) {
163 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
164 }
165}
166
167
168/*
169 * View
170 */
171
172$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
173
174llxHeader('', $langs->trans("SupplierPaymentSetup"), 'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur', '', 0, 0, '', '', '', 'mod-admin page-supplier_payment');
175
176$form = new Form($db);
177
178
179$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>';
180
181print load_fiche_titre($langs->trans("SuppliersSetup"), $linkback, 'title_setup');
182
183if (getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
185} else {
187}
188print dol_get_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
189
190/*
191 * Numbering module
192 */
193
194if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
195 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
196}
197
198print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
199
200// Load array def with activated templates
201$def = array();
202$sql = "SELECT nom";
203$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
204$sql .= " WHERE type = '".$db->escape($type)."'";
205$sql .= " AND entity = ".((int) $conf->entity);
206$resql = $db->query($sql);
207if ($resql) {
208 $i = 0;
209 $num_rows = $db->num_rows($resql);
210 while ($i < $num_rows) {
211 $array = $db->fetch_array($resql);
212 if (is_array($array)) {
213 array_push($def, $array[0]);
214 }
215 $i++;
216 }
217} else {
218 dol_print_error($db);
219}
220
221print '<table class="noborder centpercent">';
222print '<tr class="liste_titre">';
223print '<td>'.$langs->trans("Name").'</td>';
224print '<td>'.$langs->trans("Description").'</td>';
225print '<td class="nowrap">'.$langs->trans("Example").'</td>';
226print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
227print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
228print '</tr>'."\n";
229
230clearstatcache();
231
232foreach ($dirmodels as $reldir) {
233 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
234 if (is_dir($dir)) {
235 $handle = opendir($dir);
236 if (is_resource($handle)) {
237 while (($file = readdir($handle)) !== false) {
238 if (!is_dir($dir.$file) || (dol_substr($file, 0, 1) != '.' && dol_substr($file, 0, 3) != 'CVS')) {
239 $filebis = $file;
240 $classname = preg_replace('/\.php$/', '', $file);
241 // For compatibility
242 if (!is_file($dir.$filebis)) {
243 $filebis = $file."/".$file.".modules.php";
244 $classname = "mod_supplier_payment_".$file;
245 }
246 // Check if there is a filter on country
247 $reg = array();
248 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
249 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
250 continue;
251 }
252
253 $classname = preg_replace('/\-.*$/', '', $classname);
254 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && dol_substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
255 // Charging the numbering class
256 require_once $dir.$filebis;
257
258 $module = new $classname($db);
259
260 '@phan-var-force ModeleNumRefSupplierPayments $module';
261
262 // Show modules according to features level
263 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
264 continue;
265 }
266 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
267 continue;
268 }
269
270 if ($module->isEnabled()) {
271 print '<tr class="oddeven"><td width="100">';
272 echo preg_replace('/\-.*$/', '', preg_replace('/mod_supplier_payment_/', '', preg_replace('/\.php$/', '', $file)));
273 print "</td><td>\n";
274
275 print $module->info($langs);
276
277 print '</td>';
278
279 // Show example of numbering module
280 print '<td class="nowrap">';
281 $tmp = $module->getExample();
282 if (preg_match('/^Error/', $tmp)) {
283 $langs->load("errors");
284 print '<div class="error">'.$langs->trans($tmp).'</div>';
285 } elseif ($tmp == 'NotConfigured') {
286 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
287 } else {
288 print $tmp;
289 }
290 print '</td>'."\n";
291
292 print '<td class="center">';
293 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == $file || getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . '.php' == $file) {
294 print img_picto($langs->trans("Activated"), 'switch_on');
295 } else {
296 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
297 }
298 print '</td>';
299
300 $payment = new PaiementFourn($db);
301 $payment->initAsSpecimen();
302
303 // Example
304 $htmltooltip = '';
305 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
306 $nextval = $module->getNextValue($mysoc, $payment);
307 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
308 $htmltooltip .= $langs->trans("NextValue").': ';
309 if ($nextval) {
310 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
311 $langs->load('errors');
312 $nextval = $langs->trans($nextval);
313 }
314 $htmltooltip .= $nextval.'<br>';
315 } else {
316 $langs->load('errors');
317 $htmltooltip .= $langs->trans($module->error).'<br>';
318 }
319 }
320
321 print '<td class="center">';
322 print $form->textwithpicto('', $htmltooltip, 1, 'info');
323
324 if (getDolGlobalString("PAYMENT_ADDON").'.php' == $file) { // If module is the one used, we show existing errors
325 if (!empty($module->error)) {
326 dol_htmloutput_mesg($module->error, array(), 'error', 1);
327 }
328 }
329
330 print '</td>';
331
332 print "</tr>\n";
333 }
334 }
335 }
336 }
337 closedir($handle);
338 }
339 }
340}
341
342print '</table>';
343
344
345/*
346 * Document templates generators
347 */
348
349print '<br>';
350print load_fiche_titre($langs->trans("PaymentsPDFModules"), '', '');
351
352print '<table class="noborder centpercent">'."\n";
353print '<tr class="liste_titre">'."\n";
354print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
355print '<td>'.$langs->trans("Description").'</td>'."\n";
356print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
357print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
358print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
359print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
360print '</tr>'."\n";
361
362clearstatcache();
363
364foreach ($dirmodels as $reldir) {
365 $realpath = $reldir."core/modules/supplier_payment/doc";
366 $dir = dol_buildpath($realpath);
367
368 if (is_dir($dir)) {
369 $handle = opendir($dir);
370
371
372 if (is_resource($handle)) {
373 while (($file = readdir($handle)) !== false) {
374 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
375 $name = dol_substr($file, 4, dol_strlen($file) - 16);
376 $classname = dol_substr($file, 0, dol_strlen($file) - 12);
377
378 require_once $dir.'/'.$file;
379 $module = new $classname($db);
380 '@phan-var-force ModelePDFSuppliersPayments $module';
381
382 print '<tr class="oddeven">'."\n";
383 print "<td>";
384 print(empty($module->name) ? $name : $module->name);
385 print "</td>\n";
386 print "<td>\n";
387 if (method_exists($module, 'info')) {
388 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
389 } else {
390 print $module->description;
391 }
392
393 print "</td>\n";
394
395 // Active
396 if (in_array($name, $def)) {
397 print '<td class="center">'."\n";
398 //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
399 //{
400 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
401 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
402 print img_picto($langs->trans("Enabled"), 'switch_on');
403 print '</a>';
404 /*}
405 else
406 {
407 print img_picto($langs->trans("Enabled"),'switch_on');
408 }*/
409 print "</td>";
410 } else {
411 print '<td class="center">'."\n";
412 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
413 print "</td>";
414 }
415
416 // Default
417 print '<td class="center">';
418 if (getDolGlobalString("SUPPLIER_PAYMENT_ADDON_PDF") == "$name") {
419 //print img_picto($langs->trans("Default"),'on');
420 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
421 print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
422 } else {
423 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
424 }
425 print '</td>';
426
427 // Info
428 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
429 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
430 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
431 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
432
433 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
434 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
435 print '<td class="center">';
436 print $form->textwithpicto('', $htmltooltip, 1, 'info');
437 print '</td>';
438 print '<td class="center">';
439 print '<a href="'.dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'specimen', 'module' => $name], true).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
440 print '</td>';
441
442 print "</tr>\n";
443 }
444 }
445
446 closedir($handle);
447 }
448 }
449}
450
451print '</table>';
452
453/*
454 * Other Options
455 */
456
457print "<br>";
458
459print load_fiche_titre($langs->trans("OtherOptions"), '', '');
460
461print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
462print '<input type="hidden" name="token" value="'.newToken().'" />';
463print '<input type="hidden" name="action" value="setparams" />';
464
465print '<div class="div-table-responsive-no-min">';
466print '<table class="noborder centpercent">';
467print '<tr class="liste_titre">';
468print '<td>'.$langs->trans("Parameter").'</td>';
469print '<td align="center" width="60"></td>';
470print '<td width="80">&nbsp;</td>';
471print "</tr>\n";
472
473// Allow to group payments by mod in rapports
474print '<tr class="oddeven"><td>';
475print $langs->trans("GroupPaymentsByModOnReports");
476print '</td><td width="60" align="center">';
477print $form->selectyesno("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", getDolGlobalString("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD"), 1);
478print '</td><td class="right">';
479print "</td></tr>\n";
480
481print '</table>';
482
483print dol_get_fiche_end();
484
485print '<br>';
486print '<div class="center">';
487print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
488print '</div>';
489print '<br>';
490
491print '</form>';
492
493// End of page
494llxFooter();
495$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
Class to manage payments for supplier invoices.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
global $mysoc
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object information.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
supplier_invoice_admin_prepare_head()
Prepare array with list of tabs.