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