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