dolibarr  9.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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("admin", "errors", "other", "bills", "orders"));
32 
33 if (! $user->admin) accessforbidden();
34 
35 $action = GETPOST('action','alpha');
36 $value = GETPOST('value','alpha');
37 $label = GETPOST('label','alpha');
38 $scandir = GETPOST('scan_dir','alpha');
39 $type='supplier_payment';
40 
41 
42 /*
43  * Actions
44  */
45 
46 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
47 
48 if ($action == 'updateMask')
49 {
50  $maskconstsupplierpayment=GETPOST('maskconstsupplierpayment','alpha');
51  $masksupplierpayment=GETPOST('masksupplierpayment','alpha');
52  if ($maskconstsupplierpayment) $res = dolibarr_set_const($db,$maskconstsupplierpayment,$masksupplierpayment,'chaine',0,'',$conf->entity);
53 
54  if (! $res > 0) $error++;
55 
56  if (! $error)
57  {
58  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
59  }
60  else
61  {
62  setEventMessages($langs->trans("Error"), null, 'errors');
63  }
64 }else if ($action == 'setmod')
65 {
66  dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
67 }
68 
69 // Activate a model
70 else if ($action == 'set')
71 {
72  $ret = addDocumentModel($value, $type, $label, $scandir);
73 }
74 
75 else if ($action == 'del')
76 {
77  $ret = delDocumentModel($value, $type);
78  if ($ret > 0)
79  {
80  if ($conf->global->FACTURE_ADDON_PDF == "$value") dolibarr_del_const($db, 'SUPPLIER_PAYMENT_ADDON_PDF',$conf->entity);
81  }
82 }
83 
84 // Set default model
85 else if ($action == 'setdoc')
86 {
87  if (dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
88  {
89  // La constante qui a ete lue en avant du nouveau set
90  // on passe donc par une variable pour avoir un affichage coherent
91  $conf->global->FACTURE_ADDON_PDF = $value;
92  }
93 
94  // On active le modele
95  $ret = delDocumentModel($value, $type);
96  if ($ret > 0)
97  {
98  $ret = addDocumentModel($value, $type, $label, $scandir);
99  }
100 }
101 
102 else if ($action == 'specimen')
103 {
104  $modele=GETPOST('module','alpha');
105 
106  $paiementFourn = new PaiementFourn($db);
107  $paiementFourn->initAsSpecimen();
108 
109  // Search template files
110  $file=''; $classname=''; $filefound=0;
111  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
112  foreach($dirmodels as $reldir)
113  {
114  $file=dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php",0);
115  if (file_exists($file))
116  {
117  $filefound=1;
118  $classname = "pdf_".$modele;
119  break;
120  }
121  }
122 
123  if ($filefound)
124  {
125  require_once $file;
126 
127  $module = new $classname($db);
128 
129  if ($module->write_file($paiementFourn,$langs) > 0)
130  {
131  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
132  return;
133  }
134  else
135  {
136  setEventMessages($module->error, $module->errors, 'errors');
137  dol_syslog($module->error, LOG_ERR);
138  }
139  }
140  else
141  {
142  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
143  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
144  }
145 }
146 
147 /*
148  * View
149  */
150 
151 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
152 
153 llxHeader("",$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>';
159 print load_fiche_titre($langs->trans("SupplierPaymentSetup"),$linkback,'title_setup');
160 
161 print "<br>";
162 
164 dol_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
165 
166 /*
167  * Numbering module
168  */
169 
170 if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
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 = '".$type."'";
179 $sql.= " AND entity = ".$conf->entity;
180 $resql=$db->query($sql);
181 if ($resql)
182 {
183  $i = 0;
184  $num_rows=$db->num_rows($resql);
185  while ($i < $num_rows)
186  {
187  $array = $db->fetch_array($resql);
188  array_push($def, $array[0]);
189  $i++;
190  }
191 }
192 else
193 {
194  dol_print_error($db);
195 }
196 
197 print '<table class="noborder" width="100%">';
198 print '<tr class="liste_titre">';
199 print '<td>'.$langs->trans("Name").'</td>';
200 print '<td>'.$langs->trans("Description").'</td>';
201 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
202 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
203 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
204 print '</tr>'."\n";
205 
206 clearstatcache();
207 
208 foreach ($dirmodels as $reldir)
209 {
210  $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
211  if (is_dir($dir))
212  {
213  $handle = opendir($dir);
214  if (is_resource($handle))
215  {
216 
217  while (($file = readdir($handle))!==false)
218  {
219  if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
220  {
221  $filebis = $file;
222  $classname = preg_replace('/\.php$/','',$file);
223  // For compatibility
224  if (! is_file($dir.$filebis))
225  {
226  $filebis = $file."/".$file.".modules.php";
227  $classname = "mod_supplier_payment_".$file;
228  }
229  // Check if there is a filter on country
230  preg_match('/\-(.*)_(.*)$/',$classname,$reg);
231  if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
232 
233  $classname = preg_replace('/\-.*$/','',$classname);
234  if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
235  {
236  // Charging the numbering class
237  require_once $dir.$filebis;
238 
239  $module = new $classname($db);
240 
241  // Show modules according to features level
242  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
243  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
244 
245  if ($module->isEnabled())
246  {
247  print '<tr class="oddeven"><td width="100">';
248  echo preg_replace('/\-.*$/','',preg_replace('/mod_supplier_payment_/','',preg_replace('/\.php$/','',$file)));
249  print "</td><td>\n";
250 
251  print $module->info();
252 
253  print '</td>';
254 
255  // Show example of numbering module
256  print '<td class="nowrap">';
257  $tmp=$module->getExample();
258  if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
259  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
260  else print $tmp;
261  print '</td>'."\n";
262 
263  print '<td align="center">';
264  //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
265  if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || $conf->global->SUPPLIER_PAYMENT_ADDON.'.php' == $file)
266  {
267  print img_picto($langs->trans("Activated"),'switch_on');
268  }
269  else
270  {
271  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scan_dir='.$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  $htmltooltip.=$nextval.'<br>';
288  } else {
289  $htmltooltip.=$langs->trans($module->error).'<br>';
290  }
291  }
292 
293  print '<td align="center">';
294  print $form->textwithpicto('',$htmltooltip,1,0);
295 
296  if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
297  {
298  if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
299  }
300 
301  print '</td>';
302 
303  print "</tr>\n";
304  }
305  }
306  }
307  }
308  closedir($handle);
309  }
310  }
311 }
312 
313 print '</table>';
314 
315 
316 /*
317  * Document templates generators
318  */
319 print '<br>';
320 print load_fiche_titre($langs->trans("PaymentsPDFModules"),'','');
321 
322 print '<table class="noborder" width="100%">'."\n";
323 print '<tr class="liste_titre">'."\n";
324 print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
325 print '<td>'.$langs->trans("Description").'</td>'."\n";
326 print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
327 print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
328 print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
329 print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
330 print '</tr>'."\n";
331 
332 clearstatcache();
333 
334 foreach ($dirmodels as $reldir)
335 {
336  $dir = dol_buildpath($reldir."core/modules/supplier_payment/doc/");
337 
338  if (is_dir($dir))
339  {
340 
341  $handle=opendir($dir);
342 
343 
344  if (is_resource($handle))
345  {
346  while (($file = readdir($handle))!==false)
347  {
348  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
349  {
350  $name = substr($file, 4, dol_strlen($file) -16);
351  $classname = substr($file, 0, dol_strlen($file) -12);
352 
353  require_once $dir.'/'.$file;
354  $module = new $classname($db, new PaiementFourn($db));
355 
356  print "<tr class=\"oddeven\">\n";
357  print "<td>";
358  print (empty($module->name)?$name:$module->name);
359  print "</td>\n";
360  print "<td>\n";
361  require_once $dir.$file;
362  $module = new $classname($db,$specimenthirdparty);
363  if (method_exists($module,'info')) print $module->info($langs);
364  else print $module->description;
365 
366  print "</td>\n";
367 
368  // Active
369  if (in_array($name, $def))
370  {
371  print '<td align="center">'."\n";
372  //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
373  //{
374  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
375  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
376  print img_picto($langs->trans("Enabled"),'switch_on');
377  print '</a>';
378  /*}
379  else
380  {
381  print img_picto($langs->trans("Enabled"),'switch_on');
382  }*/
383  print "</td>";
384  }
385  else
386  {
387  print '<td align="center">'."\n";
388  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
389  print "</td>";
390  }
391 
392  // Default
393  print '<td align="center">';
394  if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF == "$name")
395  {
396  //print img_picto($langs->trans("Default"),'on');
397  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
398  print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&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>';
399  }
400  else
401  {
402  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&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>';
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><br><u>'.$langs->trans("FeaturesSupported").':</u>';
411  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
412  print '<td align="center">';
413  print $form->textwithpicto('',$htmltooltip,1,0);
414  print '</td>';
415  print '<td align="center">';
416  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
417  print '</td>';
418 
419  print "</tr>\n";
420  }
421  }
422 
423  closedir($handle);
424  }
425  }
426 }
427 
428 print '</table>';
429 
430 dol_fiche_end();
431 
432 // End of page
433 llxFooter();
434 $db->close();
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1643
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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:510
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1609
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: fourn.lib.php:180
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
Class to manage payments for supplier invoices.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).