dolibarr  7.0.0-beta
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 $langs->load("admin");
31 $langs->load("errors");
32 $langs->load('other');
33 $langs->load('bills');
34 $langs->load('orders');
35 
36 
37 if (! $user->admin) accessforbidden();
38 
39 $action = GETPOST('action','alpha');
40 $value = GETPOST('value','alpha');
41 $label = GETPOST('label','alpha');
42 $scandir = GETPOST('scan_dir','alpha');
43 $type='supplier_payment';
44 
45 
46 /*
47  * Actions
48  */
49 
50 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
51 
52 if ($action == 'updateMask')
53 {
54  $maskconstsupplierpayment=GETPOST('maskconstsupplierpayment','alpha');
55  $masksupplierpayment=GETPOST('masksupplierpayment','alpha');
56  if ($maskconstsupplierpayment) $res = dolibarr_set_const($db,$maskconstsupplierpayment,$masksupplierpayment,'chaine',0,'',$conf->entity);
57 
58  if (! $res > 0) $error++;
59 
60  if (! $error)
61  {
62  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
63  }
64  else
65  {
66  setEventMessages($langs->trans("Error"), null, 'errors');
67  }
68 }else if ($action == 'setmod')
69 {
70  dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
71 }
72 
73 // Activate a model
74 else if ($action == 'set')
75 {
76  $ret = addDocumentModel($value, $type, $label, $scandir);
77 }
78 
79 else if ($action == 'del')
80 {
81  $ret = delDocumentModel($value, $type);
82  if ($ret > 0)
83  {
84  if ($conf->global->FACTURE_ADDON_PDF == "$value") dolibarr_del_const($db, 'SUPPLIER_PAYMENT_ADDON_PDF',$conf->entity);
85  }
86 }
87 
88 // Set default model
89 else if ($action == 'setdoc')
90 {
91  if (dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
92  {
93  // La constante qui a ete lue en avant du nouveau set
94  // on passe donc par une variable pour avoir un affichage coherent
95  $conf->global->FACTURE_ADDON_PDF = $value;
96  }
97 
98  // On active le modele
99  $ret = delDocumentModel($value, $type);
100  if ($ret > 0)
101  {
102  $ret = addDocumentModel($value, $type, $label, $scandir);
103  }
104 }
105 
106 else if ($action == 'specimen')
107 {
108  $modele=GETPOST('module','alpha');
109 
110  $paiementFourn = new PaiementFourn($db);
111  $paiementFourn->initAsSpecimen();
112 
113  // Search template files
114  $file=''; $classname=''; $filefound=0;
115  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
116  foreach($dirmodels as $reldir)
117  {
118  $file=dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php",0);
119  if (file_exists($file))
120  {
121  $filefound=1;
122  $classname = "pdf_".$modele;
123  break;
124  }
125  }
126 
127  if ($filefound)
128  {
129  require_once $file;
130 
131  $module = new $classname($db);
132 
133  if ($module->write_file($paiementFourn,$langs) > 0)
134  {
135  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
136  return;
137  }
138  else
139  {
140  setEventMessages($module->error, $module->errors, 'errors');
141  dol_syslog($module->error, LOG_ERR);
142  }
143  }
144  else
145  {
146  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
147  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
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">'.$langs->trans("BackToModuleList").'</a>';
163 print load_fiche_titre($langs->trans("SupplierPaymentSetup"),$linkback,'title_setup');
164 
165 print "<br>";
166 
168 dol_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 = '".$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 }
196 else
197 {
198  dol_print_error($db);
199 }
200 
201 print '<table class="noborder" width="100%">';
202 print '<tr class="liste_titre">';
203 print '<td>'.$langs->trans("Name").'</td>';
204 print '<td>'.$langs->trans("Description").'</td>';
205 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
206 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
207 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
208 print '</tr>'."\n";
209 
210 clearstatcache();
211 
212 foreach ($dirmodels as $reldir)
213 {
214  $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
215  if (is_dir($dir))
216  {
217  $handle = opendir($dir);
218  if (is_resource($handle))
219  {
220  $var=true;
221 
222  while (($file = readdir($handle))!==false)
223  {
224  if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
225  {
226  $filebis = $file;
227  $classname = preg_replace('/\.php$/','',$file);
228  // For compatibility
229  if (! is_file($dir.$filebis))
230  {
231  $filebis = $file."/".$file.".modules.php";
232  $classname = "mod_supplier_payment_".$file;
233  }
234  // Check if there is a filter on country
235  preg_match('/\-(.*)_(.*)$/',$classname,$reg);
236  if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
237 
238  $classname = preg_replace('/\-.*$/','',$classname);
239  if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
240  {
241  // Charging the numbering class
242  require_once $dir.$filebis;
243 
244  $module = new $classname($db);
245 
246  // Show modules according to features level
247  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
248  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
249 
250  if ($module->isEnabled())
251  {
252  $var = !$var;
253  print '<tr class="oddeven"><td width="100">';
254  echo preg_replace('/\-.*$/','',preg_replace('/mod_supplier_payment_/','',preg_replace('/\.php$/','',$file)));
255  print "</td><td>\n";
256 
257  print $module->info();
258 
259  print '</td>';
260 
261  // Show example of numbering module
262  print '<td class="nowrap">';
263  $tmp=$module->getExample();
264  if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
265  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
266  else print $tmp;
267  print '</td>'."\n";
268 
269  print '<td align="center">';
270  //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
271  if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || $conf->global->SUPPLIER_PAYMENT_ADDON.'.php' == $file)
272  {
273  print img_picto($langs->trans("Activated"),'switch_on');
274  }
275  else
276  {
277  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>';
278  }
279  print '</td>';
280 
281  $payment=new PaiementFourn($db);
282  $payment->initAsSpecimen();
283 
284  // Example
285  $htmltooltip='';
286  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
287  $nextval=$module->getNextValue($mysoc,$payment);
288  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
289  $htmltooltip.=$langs->trans("NextValue").': ';
290  if ($nextval) {
291  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
292  $nextval = $langs->trans($nextval);
293  $htmltooltip.=$nextval.'<br>';
294  } else {
295  $htmltooltip.=$langs->trans($module->error).'<br>';
296  }
297  }
298 
299  print '<td align="center">';
300  print $form->textwithpicto('',$htmltooltip,1,0);
301 
302  if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
303  {
304  if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
305  }
306 
307  print '</td>';
308 
309  print "</tr>\n";
310 
311  }
312  }
313  }
314  }
315  closedir($handle);
316  }
317  }
318 }
319 
320 print '</table>';
321 
322 
323 /*
324  * Document templates generators
325  */
326 print '<br>';
327 print load_fiche_titre($langs->trans("PaymentsPDFModules"),'','');
328 
329 print '<table class="noborder" width="100%">'."\n";
330 print '<tr class="liste_titre">'."\n";
331 print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
332 print '<td>'.$langs->trans("Description").'</td>'."\n";
333 print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
334 print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
335 print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
336 print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
337 print '</tr>'."\n";
338 
339 clearstatcache();
340 
341 foreach ($dirmodels as $reldir)
342 {
343  $dir = dol_buildpath($reldir."core/modules/supplier_payment/doc/");
344 
345  if (is_dir($dir))
346  {
347 
348  $handle=opendir($dir);
349 
350 
351  if (is_resource($handle))
352  {
353  while (($file = readdir($handle))!==false)
354  {
355  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
356  {
357  $name = substr($file, 4, dol_strlen($file) -16);
358  $classname = substr($file, 0, dol_strlen($file) -12);
359 
360  require_once $dir.'/'.$file;
361  $module = new $classname($db, new PaiementFourn($db));
362 
363 
364  print "<tr class=\"oddeven\">\n";
365  print "<td>";
366  print (empty($module->name)?$name:$module->name);
367  print "</td>\n";
368  print "<td>\n";
369  require_once $dir.$file;
370  $module = new $classname($db,$specimenthirdparty);
371  if (method_exists($module,'info')) print $module->info($langs);
372  else print $module->description;
373 
374  print "</td>\n";
375 
376  // Active
377  if (in_array($name, $def))
378  {
379  print '<td align="center">'."\n";
380  //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
381  //{
382  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
383  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
384  print img_picto($langs->trans("Enabled"),'switch_on');
385  print '</a>';
386  /*}
387  else
388  {
389  print img_picto($langs->trans("Enabled"),'switch_on');
390  }*/
391  print "</td>";
392  }
393  else
394  {
395  print '<td align="center">'."\n";
396  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>';
397  print "</td>";
398  }
399 
400  // Default
401  print '<td align="center">';
402  if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF == "$name")
403  {
404  //print img_picto($langs->trans("Default"),'on');
405  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
406  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>';
407  }
408  else
409  {
410  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>';
411  }
412  print '</td>';
413 
414  // Info
415  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
416  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
417  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
418  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
419  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
420  print '<td align="center">';
421  print $form->textwithpicto('',$htmltooltip,1,0);
422  print '</td>';
423  print '<td align="center">';
424  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
425  print '</td>';
426 
427  print "</tr>\n";
428  }
429  }
430 
431  closedir($handle);
432  }
433  }
434 }
435 
436 print '</table>';
437 
438 dol_fiche_end();
439 
440 
441 llxFooter();
442 
443 $db->close();
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1540
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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:485
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1506
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
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray='', $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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'une constante dans la base de donnees.
Definition: admin.lib.php:410
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print
Draft customers invoices.
Definition: index.php:91
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:1013
Class to manage payments for supplier invoices.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.