1<?php
2/* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2008-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@inodbox.com>
5 * Copyright (C) 2012-2013 Juanjo Menent		<jmenent@2byte.es>
6 * Copyright (C) 2013-2018 Philippe Grand       <philippe.grand@atoo-net.com>
7 * Copyright (C) 2013      Florian Henry        <florian.henry@open-concept.pro>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23/**
24 *	\file       htdocs/admin/stock.php
25 *	\ingroup    stock
26 *	\brief      Page to setup module stock
27 */
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array("admin", "stocks"));
35
36// Securit check
37if (!$user->admin) {
38	accessforbidden();
39}
40
41$action = GETPOST('action', 'aZ09');
42$value = GETPOST('value', 'alpha');
43$label = GETPOST('label', 'alpha');
44$scandir = GETPOST('scan_dir', 'alpha');
45$type = 'stock';
46
47
48/*
49 * Action
50 */
51
52$reg = array();
53
54if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
55	$code = $reg[1];
56
57	// If constant is for a unique choice, delete other choices
58	if (in_array($code, array('STOCK_CALCULATE_ON_BILL', 'STOCK_CALCULATE_ON_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_SHIPMENT', 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE'))) {
59		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_BILL', $conf->entity);
60		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_VALIDATE_ORDER', $conf->entity);
61		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT', $conf->entity);
62		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE', $conf->entity);
63	}
64	if (in_array($code, array('STOCK_CALCULATE_ON_SUPPLIER_BILL', 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_RECEPTION', 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER'))) {
65		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_BILL', $conf->entity);
66		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', $conf->entity);
67		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION', $conf->entity);
68		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', $conf->entity);
69		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', $conf->entity);
70	}
71
72	if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
73		header("Location: ".$_SERVER["PHP_SELF"]);
74		exit;
75	} else {
76		dol_print_error($db);
77	}
78}
79
80if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
81	$code = $reg[1];
82	if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
83		header("Location: ".$_SERVER["PHP_SELF"]);
84		exit;
85	} else {
86		dol_print_error($db);
87	}
88}
89
90if ($action == 'warehouse') {
91	$value = GETPOST('default_warehouse', 'alpha');
92	$res = dolibarr_set_const($db, "MAIN_DEFAULT_WAREHOUSE", $value, 'chaine', 0, '', $conf->entity);
93	if ($value == -1 || empty($value) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
94		$res = dolibarr_del_const($db, "MAIN_DEFAULT_WAREHOUSE", $conf->entity);
95	}
96	if (!($res > 0)) {
97		$error++;
98	}
99}
100
101if ($action == 'specimen') {
102	$modele = GETPOST('module', 'alpha');
103
104	$object = new Entrepot($db);
105	$object->initAsSpecimen();
106
107	// Search template files
108	$file = ''; $classname = ''; $filefound = 0;
109	$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
110	foreach ($dirmodels as $reldir) {
111		$file = dol_buildpath($reldir."core/modules/stock/doc/pdf_".$modele.".modules.php", 0);
112		if (file_exists($file)) {
113			$filefound = 1;
114			$classname = "pdf_".$modele;
115			break;
116		}
117	}
118
119	if ($filefound) {
120		require_once $file;
121
122		$module = new $classname($db);
123
124		if ($module->write_file($object, $langs) > 0) {
125			header("Location: ".DOL_URL_ROOT."/document.php?modulepart=stock&file=SPECIMEN.pdf");
126			return;
127		} else {
128			setEventMessages($module->error, null, 'errors');
129			dol_syslog($module->error, LOG_ERR);
130		}
131	} else {
132		setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
133		dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
134	}
135} elseif ($action == 'set') {
136	// Activate a model
137	$ret = addDocumentModel($value, $type, $label, $scandir);
138} elseif ($action == 'del') {
139	$ret = delDocumentModel($value, $type);
140	if ($ret > 0) {
141		if ($conf->global->STOCK_ADDON_PDF == "$value") {
142			dolibarr_del_const($db, 'STOCK_ADDON_PDF', $conf->entity);
143		}
144	}
145} elseif ($action == 'setdoc') {
146	// Set default model
147	if (dolibarr_set_const($db, "STOCK_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
148		// The constant that was read before the new set
149		// We therefore requires a variable to have a coherent view
150		$conf->global->STOCK_ADDON_PDF = $value;
151	}
152
153	// On active le modele
154	$ret = delDocumentModel($value, $type);
155	if ($ret > 0) {
156		$ret = addDocumentModel($value, $type, $label, $scandir);
157	}
158}
159
160
161/*
162 * View
163 */
164
165$form = new Form($db);
166$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
167
168llxHeader('', $langs->trans("StockSetup"));
169
170$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
171print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup');
172
173$head = stock_admin_prepare_head();
174
175print dol_get_fiche_head($head, 'general', $langs->trans("StockSetup"), -1, 'stock');
176
177$form = new Form($db);
178$formproduct = new FormProduct($db);
179
180
181
182$disabled = '';
183if (!empty($conf->productbatch->enabled)) {
184	$langs->load("productbatch");
185	$disabled = ' disabled';
186	print info_admin($langs->trans("WhenProductBatchModuleOnOptionAreForced"));
187}
188
189//if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
190//{
191print info_admin($langs->trans("IfYouUsePointOfSaleCheckModule"));
192print '<br>';
193//}
194
195
196print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
197print '<input type="hidden" name="token" value="'.newToken().'">';
198print '<input type="hidden" name="action" value="warehouse">';
199
200// Title rule for stock decrease
201print '<table class="noborder centpercent">';
202print '<tr class="liste_titre">';
203print "<td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
204print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
205print '</tr>'."\n";
206
207$found = 0;
208
209print '<tr class="oddeven">';
210print '<td>'.$langs->trans("DeStockOnBill").'</td>';
211print '<td class="right">';
212if (!empty($conf->facture->enabled)) {
213	if ($conf->use_javascript_ajax) {
214		print ajax_constantonoff('STOCK_CALCULATE_ON_BILL', array(), null, 0, 0, 0, 2, 1);
215	} else {
216		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
217		print $form->selectarray("STOCK_CALCULATE_ON_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_BILL);
218	}
219} else {
220	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
221}
222print "</td>\n</tr>\n";
223$found++;
224
225
226print '<tr class="oddeven">';
227print '<td>'.$langs->trans("DeStockOnValidateOrder").'</td>';
228print '<td class="right">';
229if (!empty($conf->commande->enabled)) {
230	if ($conf->use_javascript_ajax) {
231		print ajax_constantonoff('STOCK_CALCULATE_ON_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
232	} else {
233		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
234		print $form->selectarray("STOCK_CALCULATE_ON_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER);
235	}
236} else {
237	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name"));
238}
239print "</td>\n</tr>\n";
240$found++;
241
242//if (! empty($conf->expedition->enabled))
243//{
244
245print '<tr class="oddeven">';
246print '<td>'.$langs->trans("DeStockOnShipment").'</td>';
247print '<td class="right">';
248if (!empty($conf->expedition->enabled)) {
249	if ($conf->use_javascript_ajax) {
250		print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1);
251	} else {
252		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
253		print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT);
254	}
255} else {
256	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
257}
258print "</td>\n</tr>\n";
259$found++;
260
261
262print '<tr class="oddeven">';
263print '<td>'.$langs->trans("DeStockOnShipmentOnClosing").'</td>';
264print '<td class="right">';
265if (!empty($conf->expedition->enabled)) {
266	if ($conf->use_javascript_ajax) {
267		print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1);
268	} else {
269		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
270		print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE);
271	}
272} else {
273	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
274}
275print "</td>\n</tr>\n";
276$found++;
277
278print '</table>';
279
280
281print '<br>';
282
283
284// Title rule for stock increase
285print '<table class="noborder centpercent">';
286print '<tr class="liste_titre">';
287print "<td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
288print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
289print '</tr>'."\n";
290
291$found = 0;
292
293print '<tr class="oddeven">';
294print '<td>'.$langs->trans("ReStockOnBill").'</td>';
295print '<td class="right">';
296if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
297	if ($conf->use_javascript_ajax) {
298		print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_BILL', array(), null, 0, 0, 0, 2, 1);
299	} else {
300		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
301		print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL);
302	}
303} else {
304	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
305}
306print "</td>\n</tr>\n";
307$found++;
308
309
310
311print '<tr class="oddeven">';
312print '<td>'.$langs->trans("ReStockOnValidateOrder").'</td>';
313print '<td class="right">';
314if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
315	if ($conf->use_javascript_ajax) {
316		print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
317	} else {
318		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
319		print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER);
320	}
321} else {
322	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
323}
324print "</td>\n</tr>\n";
325$found++;
326
327if (!empty($conf->reception->enabled)) {
328	print '<tr class="oddeven">';
329	print '<td>'.$langs->trans("StockOnReception").'</td>';
330	print '<td class="right">';
331
332	if ($conf->use_javascript_ajax) {
333		print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1);
334	} else {
335		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
336		print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION);
337	}
338
339	print "</td>\n</tr>\n";
340	$found++;
341
342
343	print '<tr class="oddeven">';
344	print '<td>'.$langs->trans("StockOnReceptionOnClosing").'</td>';
345	print '<td class="right">';
346
347	if ($conf->use_javascript_ajax) {
348		print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1);
349	} else {
350		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
351		print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE);
352	}
353	print "</td>\n</tr>\n";
354	$found++;
355} else {
356	print '<tr class="oddeven">';
357	print '<td>'.$langs->trans("ReStockOnDispatchOrder").'</td>';
358	print '<td class="right">';
359	if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
360		if ($conf->use_javascript_ajax) {
361			print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1);
362		} else {
363			$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
364			print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER);
365		}
366	} else {
367		print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
368	}
369	print "</td>\n</tr>\n";
370	$found++;
371}
372
373print '</table>';
374
375print '<br>';
376
377print '<table class="noborder centpercent">';
378print '<tr class="liste_titre">';
379print "<td>".$langs->trans("RuleForStockAvailability")."</td>\n";
380print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
381print '</tr>'."\n";
382
383
384print '<tr class="oddeven">';
385print '<td>'.$langs->trans("WarehouseAllowNegativeTransfer").'</td>';
386print '<td class="right">';
387if ($conf->use_javascript_ajax) {
388	print ajax_constantonoff('STOCK_ALLOW_NEGATIVE_TRANSFER');
389} else {
390	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
391	print $form->selectarray("STOCK_ALLOW_NEGATIVE_TRANSFER", $arrval, $conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER);
392}
393print "</td>\n";
394print "</tr>\n";
395
396// Option to force stock to be enough before adding a line into document
397if ($conf->invoice->enabled) {
398	print '<tr class="oddeven">';
399	print '<td>'.$langs->trans("StockMustBeEnoughForInvoice").'</td>';
400	print '<td class="right">';
401	if ($conf->use_javascript_ajax) {
402		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_INVOICE');
403	} else {
404		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
405		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_INVOICE", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE);
406	}
407	print "</td>\n";
408	print "</tr>\n";
409}
410
411if ($conf->order->enabled) {
412	print '<tr class="oddeven">';
413	print '<td>'.$langs->trans("StockMustBeEnoughForOrder").'</td>';
414	print '<td class="right">';
415	if ($conf->use_javascript_ajax) {
416		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_ORDER');
417	} else {
418		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
419		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_ORDER", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER);
420	}
421	print "</td>\n";
422	print "</tr>\n";
423}
424
425if ($conf->expedition->enabled) {
426	print '<tr class="oddeven">';
427	print '<td>'.$langs->trans("StockMustBeEnoughForShipment").'</td>';
428	print '<td class="right">';
429	if ($conf->use_javascript_ajax) {
430		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT');
431	} else {
432		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
433		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT);
434	}
435	print "</td>\n";
436	print "</tr>\n";
437}
438print '</table>';
439
440print '<br>';
441
442$virtualdiffersfromphysical = 0;
443if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
444	|| !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
445	|| !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
446	|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
447	|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
448	|| !empty($conf->mrp->enabled)) {
449	$virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
450}
451
452if ($virtualdiffersfromphysical) {
453	print '<table class="noborder centpercent">';
454	print '<tr class="liste_titre">';
455	print "<td>".$langs->trans("RuleForStockReplenishment")." ".img_help('help', $langs->trans("VirtualDiffersFromPhysical"))."</td>\n";
456	print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
457	print '</tr>'."\n";
458
459	print '<tr class="oddeven">';
460	print '<td>';
461	print $form->textwithpicto($langs->trans("UseRealStockByDefault"), $langs->trans("ReplenishmentCalculation"));
462	print '</td>';
463	print '<td class="right">';
464	if ($conf->use_javascript_ajax) {
465		print ajax_constantonoff('STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT');
466	} else {
467		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
468		print $form->selectarray("STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT", $arrval, $conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT);
469	}
470	print "</td>\n";
471	print "</tr>\n";
472	print '</table>';
473
474	print '<br>';
475}
476
477print '<form>';
478
479
480print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
481print '<input type="hidden" name="token" value="'.newToken().'">';
482print '<input type="hidden" name="action" value="warehouse">';
483
484
485/*
486 * Document templates generators
487 */
488
489print load_fiche_titre($langs->trans("WarehouseModelModules"), '', '');
490
491// Load array def with activated templates
492$def = array();
493$sql = "SELECT nom";
494$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
495$sql .= " WHERE type = '".$db->escape($type)."'";
496$sql .= " AND entity = ".$conf->entity;
497$resql = $db->query($sql);
498if ($resql) {
499	$i = 0;
500	$num_rows = $db->num_rows($resql);
501	while ($i < $num_rows) {
502		$array = $db->fetch_array($resql);
503		array_push($def, $array[0]);
504		$i++;
505	}
506} else {
507	dol_print_error($db);
508}
509
510
511print "<table class=\"noborder\" width=\"100%\">\n";
512print "<tr class=\"liste_titre\">\n";
513print '<td>'.$langs->trans("Name").'</td>';
514print '<td>'.$langs->trans("Description").'</td>';
515print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
516print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
517print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
518print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
519print "</tr>\n";
520
521clearstatcache();
522
523foreach ($dirmodels as $reldir) {
524	foreach (array('', '/doc') as $valdir) {
525		$realpath = $reldir."core/modules/stock".$valdir;
526		$dir = dol_buildpath($realpath);
527
528		if (is_dir($dir)) {
529			$handle = opendir($dir);
530			if (is_resource($handle)) {
531				while (($file = readdir($handle)) !== false) {
532					$filelist[] = $file;
533				}
534				closedir($handle);
535				arsort($filelist);
536
537				foreach ($filelist as $file) {
538					if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
539						if (file_exists($dir.'/'.$file)) {
540							$name = substr($file, 4, dol_strlen($file) - 16);
541							$classname = substr($file, 0, dol_strlen($file) - 12);
542
543							require_once $dir.'/'.$file;
544							$module = new $classname($db);
545
546							$modulequalified = 1;
547							if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
548								$modulequalified = 0;
549							}
550							if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
551								$modulequalified = 0;
552							}
553
554							if ($modulequalified) {
555								print '<tr class="oddeven"><td width="100">';
556								print (empty($module->name) ? $name : $module->name);
557								print "</td><td>\n";
558								if (method_exists($module, 'info')) {
559									print $module->info($langs);
560								} else {
561									print $module->description;
562								}
563								print '</td>';
564
565								// Active
566								if (in_array($name, $def)) {
567									print '<td class="center">'."\n";
568									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
569									print img_picto($langs->trans("Enabled"), 'switch_on');
570									print '</a>';
571									print '</td>';
572								} else {
573									print '<td class="center">'."\n";
574									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
575									print "</td>";
576								}
577
578								// Default
579								print '<td class="center">';
580								if ($conf->global->STOCK_ADDON_PDF == $name) {
581									print img_picto($langs->trans("Default"), 'on');
582								} else {
583									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
584								}
585								print '</td>';
586
587								// Info
588								$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
589								$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
590								if ($module->type == 'pdf') {
591									$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
592								}
593								$htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
594
595								$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
596								$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
597								$htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
598
599
600								print '<td class="center">';
601								print $form->textwithpicto('', $htmltooltip, 1, 0);
602								print '</td>';
603
604								// Preview
605								print '<td class="center">';
606								if ($module->type == 'pdf') {
607									print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
608								} else {
609									print img_object($langs->trans("PreviewNotAvailable"), 'generic');
610								}
611								print '</td>';
612
613								print "</tr>\n";
614							}
615						}
616					}
617				}
618			}
619		}
620	}
621}
622
623print '</table>';
624
625print '</form>';
626
627
628// Other
629
630print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
631print '<input type="hidden" name="token" value="'.newToken().'">';
632print '<input type="hidden" name="action" value="warehouse">';
633
634print load_fiche_titre($langs->trans("Other"), '', '');
635
636print '<table class="noborder centpercent">';
637
638print '<tr class="liste_titre">';
639print "<td>".$langs->trans("Parameter")."</td>\n";
640print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
641print '</tr>'."\n";
642
643print '<tr class="oddeven">';
644print '<td>'.$langs->trans("MainDefaultWarehouse").'</td>';
645print '<td class="right">';
646print $formproduct->selectWarehouses($conf->global->MAIN_DEFAULT_WAREHOUSE, 'default_warehouse', '', 1, 0, 0, '', 0, 0, array(), 'left reposition');
647print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
648print "</td>";
649print "</tr>\n";
650
651print '<tr class="oddeven">';
652print '<td>'.$langs->trans("UserDefaultWarehouse").'</td>';
653print '<td class="right">';
654if ($conf->use_javascript_ajax) {
655	print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER', array(), null, 0, 0, 1);
656} else {
657	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
658	print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER);
659}
660print "</td>\n";
661print "</tr>\n";
662
663if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
664	print '<tr class="oddeven">';
665	print '<td>'.$langs->trans("UserWarehouseAutoCreate").'</td>';
666	print '<td class="right">';
667	if ($conf->use_javascript_ajax) {
668		print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE');
669	} else {
670		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
671		print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE);
672	}
673	print "</td>\n";
674	print "</tr>\n";
675}
676
677print '<tr class="oddeven">';
678print '<td>'.$langs->trans("WarehouseAskWarehouseOnThirparty").'</td>';
679print '<td class="right">';
680if ($conf->use_javascript_ajax) {
681	print ajax_constantonoff('SOCIETE_ASK_FOR_WAREHOUSE');
682} else {
683	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
684	print $form->selectarray("SOCIETE_ASK_FOR_WAREHOUSE", $arrval, $conf->global->SOCIETE_ASK_FOR_WAREHOUSE);
685}
686
687print '<tr class="oddeven">';
688print '<td>'.$langs->trans("WarehouseAskWarehouseDuringPropal").'</td>';
689print '<td class="right">';
690if ($conf->use_javascript_ajax) {
691	print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL');
692} else {
693	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
694	print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL);
695}
696print '<tr class="oddeven">';
697print '<td>'.$langs->trans("WarehouseAskWarehouseDuringOrder").'</td>';
698print '<td class="right">';
699if ($conf->use_javascript_ajax) {
700	print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER');
701} else {
702	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
703	print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER);
704}
705print "</td>";
706print '</td>';
707print "</tr>\n";
708
709print '<tr class="oddeven">';
710print '<td>';
711print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc"));
712print '</td>';
713print '<td class="right">';
714if ($conf->use_javascript_ajax) {
715	print ajax_constantonoff('STOCK_SUPPORTS_SERVICES');
716} else {
717	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
718	print $form->selectarray("STOCK_SUPPORTS_SERVICES", $arrval, $conf->global->STOCK_SUPPORTS_SERVICES);
719}
720print "</td>\n";
721print "</tr>\n";
722
723print '<tr class="oddeven">';
724print '<td>'.$langs->trans("AllowAddLimitStockByWarehouse").'</td>';
725print '<td class="right">';
726if ($conf->use_javascript_ajax) {
727	print ajax_constantonoff('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE');
728} else {
729	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
730	print $form->selectarray("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE", $arrval, $conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE);
731}
732print "</td>\n";
733print "</tr>\n";
734
735print '<tr class="oddeven">';
736print '<td>'.$langs->trans("AlwaysShowFullArbo").'</td>';
737print '<td class="right">';
738if ($conf->use_javascript_ajax) {
739	print ajax_constantonoff('STOCK_ALWAYS_SHOW_FULL_ARBO');
740} else {
741	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
742	print $form->selectarray("STOCK_ALWAYS_SHOW_FULL_ARBO", $arrval, $conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO);
743}
744print "</td>\n";
745print "</tr>\n";
746
747/* Disabled. Would be better to be managed with a user cookie
748if (!empty($conf->productbatch->enabled)) {
749	print '<tr class="oddeven">';
750	print '<td>' . $langs->trans("ShowAllBatchByDefault") . '</td>';
751	print '<td class="right">';
752	if ($conf->use_javascript_ajax) {
753		print ajax_constantonoff('STOCK_SHOW_ALL_BATCH_BY_DEFAULT');
754	} else {
755		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
756		print $form->selectarray("STOCK_SHOW_ALL_BATCH_BY_DEFAULT", $arrval, $conf->global->STOCK_SHOW_ALL_BATCH_BY_DEFAULT);
757	}
758	print "</td>\n";
759	print "</tr>\n";
760}
761*/
762
763print '</table>';
764
765print '</form>';
766
767// End of page
768llxFooter();
769$db->close();
770