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