dolibarr  17.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
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
30 require_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 
35 if (!$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 
52 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
53 
54 if ($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 = ''; $classname = ''; $filefound = 0;
105  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
106  foreach ($dirmodels as $reldir) {
107  $file = dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php", 0);
108  if (file_exists($file)) {
109  $filefound = 1;
110  $classname = "pdf_".$modele;
111  break;
112  }
113  }
114 
115  if ($filefound) {
116  require_once $file;
117 
118  $module = new $classname($db);
119 
120  if ($module->write_file($paiementFourn, $langs) > 0) {
121  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
122  return;
123  } else {
124  setEventMessages($module->error, $module->errors, 'errors');
125  dol_syslog($module->error, LOG_ERR);
126  }
127  } else {
128  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
129  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
130  }
131 } elseif ($action == 'setparams') {
132  $res = dolibarr_set_const($db, "PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
133  if (!($res > 0)) {
134  $error++;
135  }
136 
137  if ($error) {
138  setEventMessages($langs->trans("Error"), null, 'errors');
139  }
140  if (!$error) {
141  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
142  }
143 }
144 
145 /*
146  * View
147  */
148 
149 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
150 
151 llxHeader("", $langs->trans("SupplierPaymentSetup"), 'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur');
152 
153 $form = new Form($db);
154 
155 
156 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
157 print load_fiche_titre($langs->trans("SupplierPaymentSetup"), $linkback, 'title_setup');
158 
159 print "<br>";
160 
162 print dol_get_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
163 
164 /*
165  * Numbering module
166  */
167 
168 if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
169  $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
170 }
171 
172 print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
173 
174 // Load array def with activated templates
175 $def = array();
176 $sql = "SELECT nom";
177 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
178 $sql .= " WHERE type = '".$db->escape($type)."'";
179 $sql .= " AND entity = ".$conf->entity;
180 $resql = $db->query($sql);
181 if ($resql) {
182  $i = 0;
183  $num_rows = $db->num_rows($resql);
184  while ($i < $num_rows) {
185  $array = $db->fetch_array($resql);
186  array_push($def, $array[0]);
187  $i++;
188  }
189 } else {
190  dol_print_error($db);
191 }
192 
193 print '<table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print '<td>'.$langs->trans("Name").'</td>';
196 print '<td>'.$langs->trans("Description").'</td>';
197 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
198 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
199 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
200 print '</tr>'."\n";
201 
202 clearstatcache();
203 
204 foreach ($dirmodels as $reldir) {
205  $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
206  if (is_dir($dir)) {
207  $handle = opendir($dir);
208  if (is_resource($handle)) {
209  while (($file = readdir($handle)) !== false) {
210  if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
211  $filebis = $file;
212  $classname = preg_replace('/\.php$/', '', $file);
213  // For compatibility
214  if (!is_file($dir.$filebis)) {
215  $filebis = $file."/".$file.".modules.php";
216  $classname = "mod_supplier_payment_".$file;
217  }
218  // Check if there is a filter on country
219  preg_match('/\-(.*)_(.*)$/', $classname, $reg);
220  if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
221  continue;
222  }
223 
224  $classname = preg_replace('/\-.*$/', '', $classname);
225  if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
226  // Charging the numbering class
227  require_once $dir.$filebis;
228 
229  $module = new $classname($db);
230 
231  // Show modules according to features level
232  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
233  continue;
234  }
235  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
236  continue;
237  }
238 
239  if ($module->isEnabled()) {
240  print '<tr class="oddeven"><td width="100">';
241  echo preg_replace('/\-.*$/', '', preg_replace('/mod_supplier_payment_/', '', preg_replace('/\.php$/', '', $file)));
242  print "</td><td>\n";
243 
244  print $module->info();
245 
246  print '</td>';
247 
248  // Show example of numbering module
249  print '<td class="nowrap">';
250  $tmp = $module->getExample();
251  if (preg_match('/^Error/', $tmp)) {
252  $langs->load("errors");
253  print '<div class="error">'.$langs->trans($tmp).'</div>';
254  } elseif ($tmp == 'NotConfigured') {
255  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
256  } else {
257  print $tmp;
258  }
259  print '</td>'."\n";
260 
261  print '<td class="center">';
262  //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
263  if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || $conf->global->SUPPLIER_PAYMENT_ADDON.'.php' == $file) {
264  print img_picto($langs->trans("Activated"), 'switch_on');
265  } else {
266  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>';
267  }
268  print '</td>';
269 
270  $payment = new PaiementFourn($db);
271  $payment->initAsSpecimen();
272 
273  // Example
274  $htmltooltip = '';
275  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
276  $nextval = $module->getNextValue($mysoc, $payment);
277  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
278  $htmltooltip .= $langs->trans("NextValue").': ';
279  if ($nextval) {
280  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
281  $nextval = $langs->trans($nextval);
282  }
283  $htmltooltip .= $nextval.'<br>';
284  } else {
285  $htmltooltip .= $langs->trans($module->error).'<br>';
286  }
287  }
288 
289  print '<td class="center">';
290  print $form->textwithpicto('', $htmltooltip, 1, 0);
291 
292  if (getDolGlobalString("PAYMENT_ADDON").'.php' == $file) { // If module is the one used, we show existing errors
293  if (!empty($module->error)) {
294  dol_htmloutput_mesg($module->error, '', 'error', 1);
295  }
296  }
297 
298  print '</td>';
299 
300  print "</tr>\n";
301  }
302  }
303  }
304  }
305  closedir($handle);
306  }
307  }
308 }
309 
310 print '</table>';
311 
312 
313 /*
314  * Document templates generators
315  */
316 print '<br>';
317 print load_fiche_titre($langs->trans("PaymentsPDFModules"), '', '');
318 
319 print '<table class="noborder centpercent">'."\n";
320 print '<tr class="liste_titre">'."\n";
321 print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
322 print '<td>'.$langs->trans("Description").'</td>'."\n";
323 print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
324 print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
325 print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
326 print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
327 print '</tr>'."\n";
328 
329 clearstatcache();
330 
331 foreach ($dirmodels as $reldir) {
332  $realpath = $reldir."core/modules/supplier_payment/doc";
333  $dir = dol_buildpath($realpath);
334 
335  if (is_dir($dir)) {
336  $handle = opendir($dir);
337 
338 
339  if (is_resource($handle)) {
340  while (($file = readdir($handle)) !== false) {
341  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
342  $name = substr($file, 4, dol_strlen($file) - 16);
343  $classname = substr($file, 0, dol_strlen($file) - 12);
344 
345  require_once $dir.'/'.$file;
346  $module = new $classname($db, new PaiementFourn($db));
347 
348  print "<tr class=\"oddeven\">\n";
349  print "<td>";
350  print (empty($module->name) ? $name : $module->name);
351  print "</td>\n";
352  print "<td>\n";
353  require_once $dir.'/'.$file;
354  $module = new $classname($db, new Societe($db));
355  if (method_exists($module, 'info')) {
356  print $module->info($langs);
357  } else {
358  print $module->description;
359  }
360 
361  print "</td>\n";
362 
363  // Active
364  if (in_array($name, $def)) {
365  print '<td class="center">'."\n";
366  //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
367  //{
368  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
369  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
370  print img_picto($langs->trans("Enabled"), 'switch_on');
371  print '</a>';
372  /*}
373  else
374  {
375  print img_picto($langs->trans("Enabled"),'switch_on');
376  }*/
377  print "</td>";
378  } else {
379  print '<td class="center">'."\n";
380  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>';
381  print "</td>";
382  }
383 
384  // Default
385  print '<td class="center">';
386  if (getDolGlobalString("SUPPLIER_PAYMENT_ADDON_PDF") == "$name") {
387  //print img_picto($langs->trans("Default"),'on');
388  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
389  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>';
390  } else {
391  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>';
392  }
393  print '</td>';
394 
395  // Info
396  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
397  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
398  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
399  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
400 
401  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
402  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
403  print '<td class="center">';
404  print $form->textwithpicto('', $htmltooltip, 1, 0);
405  print '</td>';
406  print '<td class="center">';
407  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
408  print '</td>';
409 
410  print "</tr>\n";
411  }
412  }
413 
414  closedir($handle);
415  }
416  }
417 }
418 
419 print '</table>';
420 
421 /*
422  * Other Options
423  */
424 
425 print "<br>";
426 
427 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
428 
429 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
430 print '<input type="hidden" name="token" value="'.newToken().'" />';
431 print '<input type="hidden" name="action" value="setparams" />';
432 
433 print '<div class="div-table-responsive-no-min">';
434 print '<table class="noborder centpercent">';
435 print '<tr class="liste_titre">';
436 print '<td>'.$langs->trans("Parameter").'</td>';
437 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
438 print '<td width="80">&nbsp;</td>';
439 print "</tr>\n";
440 
441 // Allow to group payments by mod in rapports
442 print '<tr class="oddeven"><td>';
443 print $langs->trans("GroupPaymentsByModOnReports");
444 print '</td><td width="60" align="center">';
445 print $form->selectyesno("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", getDolGlobalString("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD"), 1);
446 print '</td><td class="right">';
447 print "</td></tr>\n";
448 
449 print '</table>';
450 
451 print dol_get_fiche_end();
452 
453 print '<br>';
454 print '<div class="center">';
455 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
456 print '</div>';
457 print '<br>';
458 
459 print '</form>';
460 
461 // End of page
462 llxFooter();
463 $db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1888
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).
Definition: admin.lib.php:632
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:556
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1919
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: fourn.lib.php:251
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.