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