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