dolibarr  7.0.0-beta
supplier_invoice.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7  * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2011-2017 Philippe Grand <philippe.grand@atoo-net.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
36 
37 $langs->load("admin");
38 $langs->load("other");
39 $langs->load("orders");
40 
41 if (!$user->admin)
43 
44 $type=GETPOST('type', 'alpha');
45 $value=GETPOST('value', 'alpha');
46 $action=GETPOST('action', 'alpha');
47 $scandir = GETPOST('scan_dir','alpha');
48 
49 $specimenthirdparty=new Societe($db);
50 $specimenthirdparty->initAsSpecimen();
51 
52 
53 /*
54  * Actions
55  */
56 
57 if ($action == 'updateMask')
58 {
59  $maskconstinvoice=GETPOST('maskconstinvoice','alpha');
60  $maskvalue=GETPOST('maskinvoice','alpha');
61 
62  if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskvalue,'chaine',0,'',$conf->entity);
63 
64  if (! $res > 0) $error++;
65 
66  if (! $error)
67  {
68  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
69  }
70  else
71  {
72  setEventMessages($langs->trans("Error"), null, 'errors');
73  }
74 }
75 
76 if ($action == 'specimen') // For invoices
77 {
78  $modele=GETPOST('module','alpha');
79 
80  $facture = new FactureFournisseur($db);
81  $facture->initAsSpecimen();
82  $facture->thirdparty=$specimenthirdparty; // Define who should has build the invoice (so the supplier)
83 
84  // Search template files
85  $file=''; $classname=''; $filefound=0;
86  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
87  foreach($dirmodels as $reldir)
88  {
89  $file=dol_buildpath($reldir."core/modules/supplier_invoice/pdf/pdf_".$modele.".modules.php",0);
90  if (file_exists($file))
91  {
92  $filefound=1;
93  $classname = "pdf_".$modele;
94  break;
95  }
96  }
97 
98  if ($filefound)
99  {
100  require_once $file;
101 
102  $module = new $classname($db,$facture);
103 
104  if ($module->write_file($facture,$langs) > 0)
105  {
106  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf");
107  return;
108  }
109  else
110  {
111  setEventMessages($module->error, $module->errors, 'errors');
112  dol_syslog($module->error, LOG_ERR);
113  }
114  }
115  else
116  {
117  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
118  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
119  }
120 }
121 
122 // Activate a model
123 else if ($action == 'set')
124 {
125  $ret = addDocumentModel($value, $type, $label, $scandir);
126 }
127 
128 else if ($action == 'del')
129 {
130  $ret = delDocumentModel($value, $type);
131  if ($ret > 0)
132  {
133  if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF',$conf->entity);
134  }
135 }
136 
137 // Set default model
138 else if ($action == 'setdoc')
139 {
140  if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
141  {
142  // La constante qui a ete lue en avant du nouveau set
143  // on passe donc par une variable pour avoir un affichage coherent
144  $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
145  }
146 
147  // On active le modele
148  $ret = delDocumentModel($value, $type);
149  if ($ret > 0)
150  {
151  $ret = addDocumentModel($value, $type, $label, $scandir);
152  }
153 }
154 else if ($action == 'unsetdoc')
155 {
156  dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
157 }
158 
159 if ($action == 'setmod')
160 {
161  // TODO Verifier si module numerotation choisi peut etre active
162  // par appel methode canBeActivated
163 
164  dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
165 }
166 
167 if ($action == 'addcat')
168 {
169  $fourn = new Fournisseur($db);
170  $fourn->CreateCategory($user,$_POST["cat"]);
171 }
172 
173 if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT')
174 {
175  $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT','none'); // No alpha here, we want exact string
176 
177  $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
178 
179  if (! $res > 0) $error++;
180 
181  if (! $error)
182  {
183  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
184  }
185  else
186  {
187  setEventMessages($langs->trans("Error"), null, 'errors');
188  }
189 }
190 
191 
192 /*
193  * View
194  */
195 
196 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
197 
198 llxHeader("","");
199 
200 $form=new Form($db);
201 
202 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
203 print load_fiche_titre($langs->trans("SuppliersSetup"),$linkback,'title_setup');
204 
205 print "<br>";
206 
208 
209 dol_fiche_head($head, 'invoice', $langs->trans("Suppliers"), -1, 'company');
210 
211 
212 // Supplier invoice numbering module
213 
214 print load_fiche_titre($langs->trans("SuppliersInvoiceNumberingModel"),'','');
215 
216 print '<table class="noborder" width="100%">';
217 print '<tr class="liste_titre">';
218 print '<td width="100">'.$langs->trans("Name").'</td>';
219 print '<td>'.$langs->trans("Description").'</td>';
220 print '<td>'.$langs->trans("Example").'</td>';
221 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
222 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
223 print "</tr>\n";
224 
225 clearstatcache();
226 
227 foreach ($dirmodels as $reldir)
228 {
229  $dir = dol_buildpath($reldir."core/modules/supplier_invoice/");
230 
231  if (is_dir($dir))
232  {
233  $handle = opendir($dir);
234  if (is_resource($handle))
235  {
236  $var=true;
237 
238  while (($file = readdir($handle))!==false)
239  {
240  if (substr($file, 0, 24) == 'mod_facture_fournisseur_' && substr($file, dol_strlen($file)-3, 3) == 'php')
241  {
242  $file = substr($file, 0, dol_strlen($file)-4);
243 
244  require_once $dir.$file.'.php';
245 
246  $module = new $file;
247 
248  if ($module->isEnabled())
249  {
250  // Show modules according to features level
251  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
252  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
253 
254 
255  print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
256  print $module->info();
257  print '</td>';
258 
259  // Show example of numbering model
260  print '<td class="nowrap">';
261  $tmp=$module->getExample();
262  if (preg_match('/^Error/',$tmp)) {
263  $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
264  }
265  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
266  else print $tmp;
267  print '</td>'."\n";
268 
269  print '<td align="center">';
270  if ($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER == "$file")
271  {
272  print img_picto($langs->trans("Activated"),'switch_on');
273  }
274  else
275  {
276  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
277  }
278  print '</td>';
279 
280  $invoice=new FactureFournisseur($db);
281  $invoice->initAsSpecimen();
282 
283  // Info
284  $htmltooltip='';
285  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
286  $nextval=$module->getNextValue($mysoc,$invoice);
287  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
288  $htmltooltip.=''.$langs->trans("NextValue").': ';
289  if ($nextval) {
290  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
291  $nextval = $langs->trans($nextval);
292  $htmltooltip.=$nextval.'<br>';
293  } else {
294  $htmltooltip.=$langs->trans($module->error).'<br>';
295  }
296  }
297 
298  print '<td align="center">';
299  print $form->textwithpicto('',$htmltooltip,1,0);
300  print '</td>';
301 
302  print '</tr>';
303  }
304  }
305  }
306  closedir($handle);
307  }
308  }
309 }
310 
311 print '</table><br>';
312 
313 
314 
315 
316 /*
317  * Modeles documents for supplier invoices
318  */
319 
320 print load_fiche_titre($langs->trans("BillsPDFModules"),'','');
321 
322 // Defini tableau def de modele
323 $def = array();
324 
325 $sql = "SELECT nom";
326 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
327 $sql.= " WHERE type = 'invoice_supplier'";
328 $sql.= " AND entity = ".$conf->entity;
329 
330 $resql=$db->query($sql);
331 if ($resql)
332 {
333  $i = 0;
334  $num_rows=$db->num_rows($resql);
335  while ($i < $num_rows)
336  {
337  $array = $db->fetch_array($resql);
338  array_push($def, $array[0]);
339  $i++;
340  }
341 }
342 else
343 {
344  dol_print_error($db);
345 }
346 
347 print '<table class="noborder" width="100%">'."\n";
348 print '<tr class="liste_titre">'."\n";
349 print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
350 print '<td>'.$langs->trans("Description").'</td>'."\n";
351 print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
352 print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
353 print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
354 print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
355 print '</tr>'."\n";
356 
357 clearstatcache();
358 
359 foreach ($dirmodels as $reldir)
360 {
361  $dir = dol_buildpath($reldir."core/modules/supplier_invoice/pdf/");
362 
363  if (is_dir($dir))
364  {
365 
366  $handle=opendir($dir);
367 
368 
369  if (is_resource($handle))
370  {
371  while (($file = readdir($handle))!==false)
372  {
373  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
374  {
375  $name = substr($file, 4, dol_strlen($file) -16);
376  $classname = substr($file, 0, dol_strlen($file) -12);
377 
378  require_once $dir.'/'.$file;
379  $module = new $classname($db, new FactureFournisseur($db));
380 
381 
382  print "<tr class=\"oddeven\">\n";
383  print "<td>";
384  print (empty($module->name)?$name:$module->name);
385  print "</td>\n";
386  print "<td>\n";
387  require_once $dir.$file;
388  $module = new $classname($db,$specimenthirdparty);
389  if (method_exists($module,'info')) print $module->info($langs);
390  else print $module->description;
391 
392  print "</td>\n";
393 
394  // Active
395  if (in_array($name, $def))
396  {
397  print '<td align="center">'."\n";
398  //if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
399  //{
400  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
401  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier">';
402  print img_picto($langs->trans("Enabled"),'switch_on');
403  print '</a>';
404  /*}
405  else
406  {
407  print img_picto($langs->trans("Enabled"),'switch_on');
408  }*/
409  print "</td>";
410  }
411  else
412  {
413  print '<td align="center">'."\n";
414  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
415  print "</td>";
416  }
417 
418  // Default
419  print '<td align="center">';
420  if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name")
421  {
422  //print img_picto($langs->trans("Default"),'on');
423  // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
424  print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
425  }
426  else
427  {
428  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
429  }
430  print '</td>';
431 
432  // Info
433  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
434  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
435  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
436  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
437  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
438  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
439  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
440  print '<td align="center">';
441  print $form->textwithpicto('',$htmltooltip,1,0);
442  print '</td>';
443  print '<td align="center">';
444  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
445  print '</td>';
446 
447  print "</tr>\n";
448  }
449  }
450 
451  closedir($handle);
452  }
453  }
454 }
455 
456 print '</table><br>';
457 
458 /*
459  * Other options
460  */
461 
462 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
463 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
464 print '<input type="hidden" name="action" value="set_SUPPLIER_INVOICE_FREE_TEXT">';
465 
466 print load_fiche_titre($langs->trans("OtherOptions"),'','');
467 print '<table class="noborder" width="100%">';
468 print '<tr class="liste_titre">';
469 print '<td>'.$langs->trans("Parameter").'</td>';
470 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
471 print '<td width="80">&nbsp;</td>';
472 print "</tr>\n";
473 
474 $substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
475 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
476 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
477 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
478 $htmltext.='</i>';
479 
480 print '<tr class="oddeven"><td colspan="2">';
481 print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
482 $variablename='SUPPLIER_INVOICE_FREE_TEXT';
483 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
484 {
485  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
486 }
487 else
488 {
489  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
490  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
491  print $doleditor->Create();
492 }
493 print '</td><td align="right">';
494 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
495 print "</td></tr>\n";
496 
497 print '</table><br>';
498 
499 print '</form>';
500 
501 
502 /*
503  * Notifications
504  */
505 
506 print load_fiche_titre($langs->trans("Notifications"),'','');
507 print '<table class="noborder" width="100%">';
508 print '<tr class="liste_titre">';
509 print '<td>'.$langs->trans("Parameter").'</td>';
510 print '<td align="center" width="60"></td>';
511 print '<td width="80">&nbsp;</td>';
512 print "</tr>\n";
513 
514 print '<tr class="oddeven"><td colspan="2">';
515 print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification").'<br>';
516 print '</td><td align="right">';
517 print "</td></tr>\n";
518 
519 print '</table>';
520 
521 
522 llxFooter();
523 
524 $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...
Class to manage suppliers invoices.
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.
Class to manage suppliers.
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.
Class to manage third parties objects (customers, suppliers, prospects...)
dolibarr_del_const($db, $name, $entity=1)
Effacement d'une constante dans la base de donnees.
Definition: admin.lib.php:410
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)
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:603
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 a WYSIWYG editor.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.