dolibarr 25.0.0-alpha
expedition.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
47
48// Load translation files required by the page
49$langs->loadLangs(array("admin", "sendings", "other"));
50
51if (!$user->admin) {
53}
54
55$action = GETPOST('action', 'aZ09');
56$value = GETPOST('value', 'alpha');
57$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
58
59$label = GETPOST('label', 'alpha');
60$scandir = GETPOST('scan_dir', 'alpha');
61$type = 'shipping';
62
63if (!getDolGlobalString('EXPEDITION_ADDON_NUMBER')) {
64 $conf->global->EXPEDITION_ADDON_NUMBER = 'mod_expedition_safor';
65}
66
67
68/*
69 * Actions
70 */
71$error = 0;
72
73include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
74
75if ($action == 'updateMask') {
76 $maskconst = GETPOST('maskconstexpedition', 'aZ09');
77 $maskvalue = GETPOST('maskexpedition', 'alpha');
78 if (!empty($maskconst) && preg_match('/_MASK$/', $maskconst)) {
79 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
80 }
81
82 if (isset($res)) {
83 if ($res > 0) {
84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
85 } else {
86 setEventMessages($langs->trans("Error"), null, 'errors');
87 }
88 }
89} elseif ($action == 'set_param') {
90 $freetext = GETPOST('SHIPPING_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
91 $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
92 if ($res <= 0) {
93 $error++;
94 setEventMessages($langs->trans("Error"), null, 'errors');
95 }
96
97 $draft = GETPOST('SHIPPING_DRAFT_WATERMARK', 'alpha');
98 $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
99 if ($res <= 0) {
100 $error++;
101 setEventMessages($langs->trans("Error"), null, 'errors');
102 }
103
104 if (!$error) {
105 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
106 }
107} elseif ($action == 'specimen') {
108 $modele = GETPOST('module', 'alpha');
109
110 $exp = new Expedition($db);
111 $exp->initAsSpecimen();
112
113 // Search template files
114 $file = '';
115 $classname = '';
116 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
117 foreach ($dirmodels as $reldir) {
118 $file = dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php", 0);
119 if (file_exists($file)) {
120 $classname = "pdf_".$modele;
121 break;
122 }
123 }
124
125 if ($classname !== '') {
126 require_once $file;
127
128 $module = new $classname($db);
129 '@phan-var-force ModelePdfExpedition $module';
130
131 if ($module->write_file($exp, $langs) > 0) {
132 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
133 return;
134 } else {
135 setEventMessages($module->error, $module->errors, 'errors');
136 dol_syslog($module->error, LOG_ERR);
137 }
138 } else {
139 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
140 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
141 }
142} elseif ($action == 'set') {
143 // Activate a model
144 $ret = addDocumentModel($value, $type, $label, $scandir);
145} elseif ($action == 'del') {
146 $ret = delDocumentModel($value, $type);
147 if ($ret > 0) {
148 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == "$value") {
149 dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF', $conf->entity);
150 }
151 }
152} elseif ($action == 'setdoc') {
153 // Set default model
154 if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
155 // The constant that was read before the new set
156 // so we go through a variable to get a consistent display
157 $conf->global->EXPEDITION_ADDON_PDF = $value;
158 }
159
160 // On active le modele
161 $ret = delDocumentModel($value, $type);
162 if ($ret > 0) {
163 $ret = addDocumentModel($value, $type, $label, $scandir);
164 }
165} elseif ($action == 'setmodel') {
166 dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
167}
168
169
170/*
171 * View
172 */
173
174$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
175
176$form = new Form($db);
177
178llxHeader("", $langs->trans("SendingsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expedition');
179
180$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>';
181
182print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
183
185
186print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
187
188// Shipment numbering model
189
190$expedition = new Expedition($db);
191$expedition->initAsSpecimen();
192
193printNumberingModuleList('expedition', 'mod_expedition_', 'EXPEDITION_ADDON_NUMBER', $langs->trans("SendingsNumberingModules"), $expedition, 'setmodel');
194
195print '<br>';
196
197
198/*
199 * Documents models for Sendings Receipt
200 */
201printDocumentModelList('shipping', 'expedition', 'EXPEDITION_ADDON_PDF', $langs->trans("SendingsReceiptModel"), array(
202 'Logo' => 'option_logo',
203 'PaymentMode' => 'option_modereg',
204 'PaymentConditions' => 'option_condreg',
205 'MultiLanguage' => 'option_multilang',
206 'WatermarkOnDraftOrders' => 'option_draft_watermark',
207));
208
209
210/*
211 * Other options
212 */
213
214print load_fiche_titre($langs->trans("OtherOptions"), '', '');
215
216print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
217print '<input type="hidden" name="token" value="'.newToken().'">';
218print '<input type="hidden" name="action" value="set_param">';
219
220print '<table class="noborder centpercent">';
221print '<tr class="liste_titre">';
222print "<td>".$langs->trans("Parameter")."</td>\n";
223print "<td></td>\n";
224print '</tr>';
225
226print '<tr class="oddeven">';
227print '<td>'.$langs->trans('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
228print '</td>';
229print '<td>';
230print ajax_constantonoff('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
231print '</td></tr>';
232
233print '<tr class="oddeven">';
234print '<td>'.$langs->trans('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
235print '</td>';
236print '<td>';
237print ajax_constantonoff('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
238print '</td></tr>';
239
240// Allow shipments without sales order. It can't be disabled while such shipments exist, otherwise their lines could no longer be shown nor edited.
241// The feature is not stable yet: the option only shows up on experimental installs (MAIN_FEATURES_LEVEL >= 2)
242// or when the constant is already set (via Home - Setup - Other), so it can be inspected and cleared.
243if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || getDolGlobalString('SHIPMENT_STANDALONE')) {
244 $nbstandalone = 0;
245 if (getDolGlobalString('SHIPMENT_STANDALONE')) {
246 $staticshipment = new Expedition($db);
247 $nbstandalone = $staticshipment->countStandalone();
248 if ($nbstandalone < 0) {
249 setEventMessages($staticshipment->error, $staticshipment->errors, 'errors');
250 }
251 }
252 print '<tr class="oddeven">';
253 print '<td>'.$langs->trans('SHIPMENT_STANDALONE').' <span class="opacitymedium">('.$langs->trans("VersionExperimental").')</span>';
254 if ($nbstandalone > 0) {
255 print '<br><span class="opacitymedium">'.$langs->trans("ShipmentStandaloneCantBeDisabled", $nbstandalone).'</span>';
256 }
257 print '</td>';
258 print '<td>';
259 print ajax_constantonoff('SHIPMENT_STANDALONE', array(), null, 0, 0, 0, 2, 0, 0, '', '', 'inline-block', 0, '', ($nbstandalone != 0 ? 1 : 0));
260 print '</td></tr>';
261}
262
263$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
264$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
265$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
266foreach ($substitutionarray as $key => $val) {
267 $htmltext .= $key.'<br>';
268}
269$htmltext .= '</i>';
270
271print '<tr><td colspan="2">';
272print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
273$variablename = 'SHIPPING_FREE_TEXT';
274if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
275 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
276} else {
277 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
278 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
279 print $doleditor->Create();
280}
281print "</td></tr>\n";
282
283print '<tr><td>';
284print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip');
285print '</td><td>';
286print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
287print "</td></tr>\n";
288
289// Allow OnLine Sign
290print '<tr class="oddeven">';
291print '<td>'.$langs->trans("AllowOnLineSign");
292print '</td>';
293print '<td>';
294print ajax_constantonoff('EXPEDITION_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->transnoentitiesnoconv("WarningOnlineSignature", 'https://www.dolistore.com'));
295print '</td></tr>';
296
297// Pre fill shipment qty option
298print '<tr class="oddeven">';
299print '<td>'.$langs->trans("DontPrefillShipmentQty");
300print '</td>';
301print '<td>';
302print ajax_constantonoff('SHIPMENT_DONT_PREFILL_QTY', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, '');
303print '</td></tr>';
304
305
306// Notifications
307print '<tr class="oddeven">';
308print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
309print '<td>';
310print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
311print '</td></tr>';
312
313// More PDF options
314print '<tr class="oddeven">';
315print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
316print '<td>';
317print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
318print '</td></tr>';
319
320print '</table>';
321
322print $form->buttonsSaveCancel("Modify", '');
323
324print '</form>';
325
326// End of page
327llxFooter();
328$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 generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
expedition_admin_prepare_head()
Return array head with list of tabs to view object information.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.