dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2026 Pierre Ardoin <developpeur@lesmetiersdubatiment.fr>
12 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../../main.inc.php';
36
46require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
48if (getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
49 require_once DOL_DOCUMENT_ROOT . '/core/lib/supplier_invoice.lib.php';
50} else {
51 require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
52}
53require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
54require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
55
56// Load translation files required by the page
57$langs->loadLangs(array("admin", "other", "orders"));
58
59$action = GETPOST('action', 'aZ09');
60
61$type = GETPOST('type', 'alpha');
62$value = GETPOST('value', 'alpha');
63$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
64
65$label = GETPOST('label', 'alpha');
66$scandir = GETPOST('scan_dir', 'alpha');
67
68$specimenthirdparty = new Societe($db);
69$specimenthirdparty->initAsSpecimen();
70
71$error = 0;
72
73if (!$user->admin) {
75}
76
77
78/*
79 * Actions
80 */
81
82include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
83
84if ($action == 'updateMask') {
85 $maskconstinvoice = GETPOST('maskconstinvoice', 'aZ09');
86 $maskconstcredit = GETPOST('maskconstcredit', 'aZ09');
87 $maskconstdeposit = GETPOST('maskconstdeposit', 'aZ09');
88 $maskinvoice = GETPOST('maskinvoice', 'alpha');
89 $maskcredit = GETPOST('maskcredit', 'alpha');
90 $maskdeposit = GETPOST('maskdeposit', 'alpha');
91 $res = 0;
92
93 if ($maskconstinvoice && preg_match('/_MASK$/', $maskconstinvoice)) {
94 $res = dolibarr_set_const($db, $maskconstinvoice, $maskinvoice, 'chaine', 0, '', $conf->entity);
95 }
96 if ($maskconstcredit && preg_match('/_MASK$/', $maskconstcredit)) {
97 $res = dolibarr_set_const($db, $maskconstcredit, $maskcredit, 'chaine', 0, '', $conf->entity);
98 }
99 if ($maskconstdeposit && preg_match('/_MASK$/', $maskconstdeposit)) {
100 $res = dolibarr_set_const($db, $maskconstdeposit, $maskdeposit, 'chaine', 0, '', $conf->entity);
101 }
102
103 if (!($res > 0)) {
104 $error++;
105 }
106
107 if (!$error) {
108 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
109 } else {
110 setEventMessages($langs->trans("Error"), null, 'errors');
111 }
112}
113
114if ($action == 'specimen') { // For invoices
115 $modele = GETPOST('module', 'alpha');
116
117 $facture = new FactureFournisseur($db);
118 $facture->initAsSpecimen();
119 $facture->thirdparty = $specimenthirdparty; // Define who should has build the invoice (so the supplier)
120
121 // Search template files
122 $file = '';
123 $classname = '';
124 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
125 foreach ($dirmodels as $reldir) {
126 $file = dol_buildpath($reldir."core/modules/supplier_invoice/doc/pdf_".$modele.".modules.php", 0);
127 if (file_exists($file)) {
128 $classname = "pdf_".$modele;
129 break;
130 }
131 }
132
133 if ($classname !== '') {
134 require_once $file;
135
136 $module = new $classname($db, $facture);
137 '@phan-var-force ModelePDFSuppliersInvoices $module';
138
139 if ($module->write_file($facture, $langs) > 0) {
140 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf");
141 return;
142 } else {
143 setEventMessages($module->error, $module->errors, 'errors');
144 dol_syslog($module->error, LOG_ERR);
145 }
146 } else {
147 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
148 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
149 }
150} elseif ($action == 'set') {
151 // Activate a model
152 $ret = addDocumentModel($value, $type, $label, $scandir);
153} elseif ($action == 'del') {
154 $ret = delDocumentModel($value, $type);
155 if ($ret > 0) {
156 if (getDolGlobalString('INVOICE_SUPPLIER_ADDON_PDF') == "$value") {
157 dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF', $conf->entity);
158 }
159 }
160} elseif ($action == 'setdoc') {
161 // Set default model
162 if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
163 // The constant that was read before the new set
164 // so we go through a variable to get a consistent display
165 $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
166 }
167
168 // On active le modele
169 $ret = delDocumentModel($value, $type);
170 if ($ret > 0) {
171 $ret = addDocumentModel($value, $type, $label, $scandir);
172 }
173} elseif ($action == 'unsetdoc') {
174 dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
175}
176
177if ($action == 'setmod') {
178 // TODO Verify if the chosen numbering module can be activated
179 // by calling method canBeActivated
180
181 dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
182}
183
184if ($action == 'addcat') {
185 $fourn = new Fournisseur($db);
186 $fourn->CreateCategory($user, GETPOST('cat', 'alphanohtml'));
187}
188
189if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') {
190 $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
191
192 $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
193
194 if (!($res > 0)) {
195 $error++;
196 }
197
198 if (!$error) {
199 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
200 } else {
201 setEventMessages($langs->trans("Error"), null, 'errors');
202 }
203}
204
205
206/*
207 * View
208 */
209
210$form = new Form($db);
211
212$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
213
214llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-supplier_invoice');
215
216$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
217
218print load_fiche_titre($langs->trans("SuppliersSetup"), $linkback, 'title_setup');
219
220if (getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
222} else {
224}
225
226print dol_get_fiche_head($head, 'invoice', $langs->trans("Suppliers"), -1, 'company');
227
228
229// Supplier invoice numbering module
230
231$invoice = new FactureFournisseur($db);
232$invoice->initAsSpecimen();
233
234printNumberingModuleList('supplier_invoice', 'mod_facture_fournisseur_', 'INVOICE_SUPPLIER_ADDON_NUMBER', $langs->trans("SuppliersInvoiceNumberingModel"), $invoice);
235
236print '<br>';
237
238
239
240
241/*
242 * Documents models for supplier invoices
243 */
244
245print load_fiche_titre($langs->trans("BillsPDFModules"), '', '');
246
247// Define array def of model
248$def = array();
249
250$sql = "SELECT nom";
251$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
252$sql .= " WHERE type = 'invoice_supplier'";
253$sql .= " AND entity = ".((int) $conf->entity);
254
255$resql = $db->query($sql);
256if ($resql) {
257 $i = 0;
258 $num_rows = $db->num_rows($resql);
259 while ($i < $num_rows) {
260 $array = $db->fetch_array($resql);
261 if (is_array($array)) {
262 array_push($def, $array[0]);
263 }
264 $i++;
265 }
266} else {
267 dol_print_error($db);
268}
269
270print '<div class="div-table-responsive-no-min">';
271print '<table class="noborder centpercent">'."\n";
272print '<tr class="liste_titre">'."\n";
273print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
274print '<td>'.$langs->trans("Description").'</td>'."\n";
275print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
276print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
277print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
278print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
279print '</tr>'."\n";
280
281clearstatcache();
282
283foreach ($dirmodels as $reldir) {
284 $realpath = $reldir."core/modules/supplier_invoice/doc";
285 $dir = dol_buildpath($realpath);
286
287 if (is_dir($dir)) {
288 $handle = opendir($dir);
289
290
291 if (is_resource($handle)) {
292 while (($file = readdir($handle)) !== false) {
293 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
294 $name = dol_substr($file, 4, dol_strlen($file) - 16);
295 $classname = dol_substr($file, 0, dol_strlen($file) - 12);
296
297 require_once $dir.'/'.$file;
298 $module = new $classname($db, new FactureFournisseur($db));
299
300 '@phan-var-force ModelePDFSuppliersInvoices $module';
301
302
303 print "<tr class=\"oddeven\">\n";
304 print "<td>";
305 print(empty($module->name) ? $name : $module->name);
306 print "</td>\n";
307 print "<td>\n";
308 require_once $dir.'/'.$file;
309 $module = new $classname($db, $specimenthirdparty);
310 '@phan-var-force ModelePDFSuppliersInvoices $module';
311 if (method_exists($module, 'info')) {
312 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
313 } else {
314 print $module->description;
315 }
316
317 print "</td>\n";
318
319 // Active
320 if (in_array($name, $def)) {
321 print '<td class="center">'."\n";
322 //if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
323 //{
324 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
325 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=invoice_supplier">';
326 print img_picto($langs->trans("Enabled"), 'switch_on');
327 print '</a>';
328 /*}
329 else
330 {
331 print img_picto($langs->trans("Enabled"),'switch_on');
332 }*/
333 print "</td>";
334 } else {
335 print '<td class="center">'."\n";
336 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=invoice_supplier">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
337 print "</td>";
338 }
339
340 // Default
341 print '<td class="center">';
342 if (getDolGlobalString("INVOICE_SUPPLIER_ADDON_PDF") == "$name") {
343 //print img_picto($langs->trans("Default"),'on');
344 // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
345 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
346 } else {
347 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
348 }
349 print '</td>';
350
351 // Info
352 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
353 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
354 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
355 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
356
357 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
358 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
359 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
360 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
361 print '<td class="center">';
362 print $form->textwithpicto('', $htmltooltip, 1, 'info');
363 print '</td>';
364 print '<td class="center">';
365 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
366 print '</td>';
367
368 print "</tr>\n";
369 }
370 }
371
372 closedir($handle);
373 }
374 }
375}
376
377print '</table></div><br>';
378
379/*
380 * Other options
381 */
382
383print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
384print '<input type="hidden" name="token" value="'.newToken().'">';
385print '<input type="hidden" name="action" value="set_SUPPLIER_INVOICE_FREE_TEXT">';
386
387print load_fiche_titre($langs->trans("OtherOptions"), '', '');
388
389print '<div class="div-table-responsive-no-min">';
390print '<table class="noborder centpercent">';
391print '<tr class="liste_titre">';
392print '<td>'.$langs->trans("Parameter").'</td>';
393print '<td></td>';
394print '<td width="80">&nbsp;</td>';
395print "</tr>\n";
396
397$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
398$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
399$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
400foreach ($substitutionarray as $key => $val) {
401 $htmltext .= $key.'<br>';
402}
403$htmltext .= '</i>';
404
405print '<tr class="oddeven"><td colspan="2">';
406print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
407$variablename = 'SUPPLIER_INVOICE_FREE_TEXT';
408if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
409 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
410} else {
411 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
412 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
413 print $doleditor->Create();
414}
415print '</td><td class="right">';
416print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
417print "</td></tr>\n";
418
419// Allow external download
420print '<tr class="oddeven">';
421print '<td>'.$langs->trans("AllowExternalDownload").'</td>';
422print '<td class="left" colspan="2">';
423print ajax_constantonoff('SUPPLIER_INVOICE_ALLOW_EXTERNAL_DOWNLOAD', array(), null, 0, 0, 0, 2, 0, 1);
424print '</td></tr>';
425
426// Notifications
427print '<tr class="oddeven">';
428print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
429print '<td colspan="2">';
430print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
431print '</td></tr>';
432
433// More PDF options
434/*
435print '<tr class="oddeven">';
436print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
437print '<td colspan="2">';
438print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
439print '</td></tr>';
440*/
441
442print '</table></div><br>';
443
444print '</form>';
445
446print '</table>';
447print '</div>';
448
449// End of page
450llxFooter();
451$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage suppliers invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage suppliers.
Class to manage third parties objects (customers, suppliers, prospects...)
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object information.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
supplier_invoice_admin_prepare_head()
Prepare array with list of tabs.