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