dolibarr 24.0.0-beta
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-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 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", "errors", "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 // La constante qui a ete lue en avant du nouveau set
106 // on passe donc par une variable pour avoir un affichage coherent
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 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
150 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
151 }
152} elseif ($action == 'setparams') {
153 $res = dolibarr_set_const($db, "PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", GETPOSTINT('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'), 'chaine', 0, '', $conf->entity);
154 if (!($res > 0)) {
155 $error++;
156 }
157
158 if ($error) {
159 setEventMessages($langs->trans("Error"), null, 'errors');
160 }
161 if (!$error) {
162 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
163 }
164}
165
166
167/*
168 * View
169 */
170
171$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
172
173llxHeader('', $langs->trans("SupplierPaymentSetup"), 'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur', '', 0, 0, '', '', '', 'mod-admin page-supplier_payment');
174
175$form = new Form($db);
176
177
178$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>';
179
180print load_fiche_titre($langs->trans("SuppliersSetup"), $linkback, 'title_setup');
181
182print "<br>";
183
184if (getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
186} else {
188}
189print dol_get_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
190
191/*
192 * Numbering module
193 */
194
195if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
196 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
197}
198
199print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
200
201// Load array def with activated templates
202$def = array();
203$sql = "SELECT nom";
204$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
205$sql .= " WHERE type = '".$db->escape($type)."'";
206$sql .= " AND entity = ".((int) $conf->entity);
207$resql = $db->query($sql);
208if ($resql) {
209 $i = 0;
210 $num_rows = $db->num_rows($resql);
211 while ($i < $num_rows) {
212 $array = $db->fetch_array($resql);
213 if (is_array($array)) {
214 array_push($def, $array[0]);
215 }
216 $i++;
217 }
218} else {
220}
221
222print '<table class="noborder centpercent">';
223print '<tr class="liste_titre">';
224print '<td>'.$langs->trans("Name").'</td>';
225print '<td>'.$langs->trans("Description").'</td>';
226print '<td class="nowrap">'.$langs->trans("Example").'</td>';
227print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
228print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
229print '</tr>'."\n";
230
231clearstatcache();
232
233foreach ($dirmodels as $reldir) {
234 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
235 if (is_dir($dir)) {
236 $handle = opendir($dir);
237 if (is_resource($handle)) {
238 while (($file = readdir($handle)) !== false) {
239 if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
240 $filebis = $file;
241 $classname = preg_replace('/\.php$/', '', $file);
242 // For compatibility
243 if (!is_file($dir.$filebis)) {
244 $filebis = $file."/".$file.".modules.php";
245 $classname = "mod_supplier_payment_".$file;
246 }
247 // Check if there is a filter on country
248 $reg = array();
249 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
250 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
251 continue;
252 }
253
254 $classname = preg_replace('/\-.*$/', '', $classname);
255 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
256 // Charging the numbering class
257 require_once $dir.$filebis;
258
259 $module = new $classname($db);
260
261 '@phan-var-force ModeleNumRefSupplierPayments $module';
262
263 // Show modules according to features level
264 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
265 continue;
266 }
267 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
268 continue;
269 }
270
271 if ($module->isEnabled()) {
272 print '<tr class="oddeven"><td width="100">';
273 echo preg_replace('/\-.*$/', '', preg_replace('/mod_supplier_payment_/', '', preg_replace('/\.php$/', '', $file)));
274 print "</td><td>\n";
275
276 print $module->info($langs);
277
278 print '</td>';
279
280 // Show example of numbering module
281 print '<td class="nowrap">';
282 $tmp = $module->getExample();
283 if (preg_match('/^Error/', $tmp)) {
284 $langs->load("errors");
285 print '<div class="error">'.$langs->trans($tmp).'</div>';
286 } elseif ($tmp == 'NotConfigured') {
287 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
288 } else {
289 print $tmp;
290 }
291 print '</td>'."\n";
292
293 print '<td class="center">';
294 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == $file || getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . '.php' == $file) {
295 print img_picto($langs->trans("Activated"), 'switch_on');
296 } else {
297 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>';
298 }
299 print '</td>';
300
301 $payment = new PaiementFourn($db);
302 $payment->initAsSpecimen();
303
304 // Example
305 $htmltooltip = '';
306 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
307 $nextval = $module->getNextValue($mysoc, $payment);
308 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
309 $htmltooltip .= $langs->trans("NextValue").': ';
310 if ($nextval) {
311 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
312 $nextval = $langs->trans($nextval);
313 }
314 $htmltooltip .= $nextval.'<br>';
315 } else {
316 $htmltooltip .= $langs->trans($module->error).'<br>';
317 }
318 }
319
320 print '<td class="center">';
321 print $form->textwithpicto('', $htmltooltip, 1, 'info');
322
323 if (getDolGlobalString("PAYMENT_ADDON").'.php' == $file) { // If module is the one used, we show existing errors
324 if (!empty($module->error)) {
325 dol_htmloutput_mesg($module->error, array(), 'error', 1);
326 }
327 }
328
329 print '</td>';
330
331 print "</tr>\n";
332 }
333 }
334 }
335 }
336 closedir($handle);
337 }
338 }
339}
340
341print '</table>';
342
343
344/*
345 * Document templates generators
346 */
347
348print '<br>';
349print load_fiche_titre($langs->trans("PaymentsPDFModules"), '', '');
350
351print '<table class="noborder centpercent">'."\n";
352print '<tr class="liste_titre">'."\n";
353print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
354print '<td>'.$langs->trans("Description").'</td>'."\n";
355print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
356print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
357print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
358print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
359print '</tr>'."\n";
360
361clearstatcache();
362
363foreach ($dirmodels as $reldir) {
364 $realpath = $reldir."core/modules/supplier_payment/doc";
365 $dir = dol_buildpath($realpath);
366
367 if (is_dir($dir)) {
368 $handle = opendir($dir);
369
370
371 if (is_resource($handle)) {
372 while (($file = readdir($handle)) !== false) {
373 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
374 $name = substr($file, 4, dol_strlen($file) - 16);
375 $classname = substr($file, 0, dol_strlen($file) - 12);
376
377 require_once $dir.'/'.$file;
378 $module = new $classname($db);
379 '@phan-var-force ModelePDFSuppliersPayments $module';
380
381 print '<tr class="oddeven">'."\n";
382 print "<td>";
383 print(empty($module->name) ? $name : $module->name);
384 print "</td>\n";
385 print "<td>\n";
386 if (method_exists($module, 'info')) {
387 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
388 } else {
389 print $module->description;
390 }
391
392 print "</td>\n";
393
394 // Active
395 if (in_array($name, $def)) {
396 print '<td class="center">'."\n";
397 //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
398 //{
399 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
400 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
401 print img_picto($langs->trans("Enabled"), 'switch_on');
402 print '</a>';
403 /*}
404 else
405 {
406 print img_picto($langs->trans("Enabled"),'switch_on');
407 }*/
408 print "</td>";
409 } else {
410 print '<td class="center">'."\n";
411 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>';
412 print "</td>";
413 }
414
415 // Default
416 print '<td class="center">';
417 if (getDolGlobalString("SUPPLIER_PAYMENT_ADDON_PDF") == "$name") {
418 //print img_picto($langs->trans("Default"),'on');
419 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
420 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>';
421 } else {
422 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>';
423 }
424 print '</td>';
425
426 // Info
427 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
428 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
429 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
430 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
431
432 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
433 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
434 print '<td class="center">';
435 print $form->textwithpicto('', $htmltooltip, 1, 'info');
436 print '</td>';
437 print '<td class="center">';
438 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
439 print '</td>';
440
441 print "</tr>\n";
442 }
443 }
444
445 closedir($handle);
446 }
447 }
448}
449
450print '</table>';
451
452/*
453 * Other Options
454 */
455
456print "<br>";
457
458print load_fiche_titre($langs->trans("OtherOptions"), '', '');
459
460print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
461print '<input type="hidden" name="token" value="'.newToken().'" />';
462print '<input type="hidden" name="action" value="setparams" />';
463
464print '<div class="div-table-responsive-no-min">';
465print '<table class="noborder centpercent">';
466print '<tr class="liste_titre">';
467print '<td>'.$langs->trans("Parameter").'</td>';
468print '<td align="center" width="60"></td>';
469print '<td width="80">&nbsp;</td>';
470print "</tr>\n";
471
472// Allow to group payments by mod in rapports
473print '<tr class="oddeven"><td>';
474print $langs->trans("GroupPaymentsByModOnReports");
475print '</td><td width="60" align="center">';
476print $form->selectyesno("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", getDolGlobalString("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD"), 1);
477print '</td><td class="right">';
478print "</td></tr>\n";
479
480print '</table>';
481
482print dol_get_fiche_end();
483
484print '<br>';
485print '<div class="center">';
486print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
487print '</div>';
488print '<br>';
489
490print '</form>';
491
492// End of page
493llxFooter();
494$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
Class to manage generation of HTML components Only common components must be here.
Class to manage payments for supplier 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.
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object information.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133
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.