dolibarr 23.0.4
product.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
6 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2013 Cédric Salvador <csalvador.gpcsolutions.fr>
8 * Copyright (C) 2013-2018 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2014-2015 Cédric Gross <c.gross@kreiz-it.fr>
10 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
11 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
13 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
38require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
40require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
43require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php';
44if (isModEnabled('productbatch')) {
45 require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
46}
47if (isModEnabled('project')) {
48 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
50}
51
52if (isModEnabled('variants')) {
53 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
56 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
57}
58
67// Load translation files required by the page
68$langs->loadlangs(array('products', 'suppliers', 'orders', 'bills', 'stocks', 'sendings', 'margins'));
69if (isModEnabled('productbatch')) {
70 $langs->load("productbatch");
71}
72
73$backtopage = GETPOST('backtopage', 'alpha');
74$action = GETPOST('action', 'aZ09');
75$cancel = GETPOST('cancel', 'alpha');
76
77$id = GETPOSTINT('id');
78$ref = GETPOST('ref', 'alpha');
79$stocklimit = (GETPOST('seuil_stock_alerte') !== '') ? GETPOSTFLOAT('seuil_stock_alerte') : null;
80$desiredstock = (GETPOST('desiredstock') !== '') ? GETPOSTFLOAT('desiredstock') : null;
81$cancel = GETPOST('cancel', 'alpha');
82$fieldid = GETPOSTISSET("ref") ? 'ref' : 'rowid';
83$d_eatby = dol_mktime(0, 0, 0, GETPOSTINT('eatbymonth'), GETPOSTINT('eatbyday'), GETPOSTINT('eatbyyear'));
84$d_sellby = dol_mktime(0, 0, 0, GETPOSTINT('sellbymonth'), GETPOSTINT('sellbyday'), GETPOSTINT('sellbyyear'));
85$pdluoid = GETPOSTINT('pdluoid');
86$batchnumber = GETPOST('batch_number', 'alphanohtml'); // Lot/serial number may contain chars like '/' so we must not use aZ09 sanitizing here. Value is escaped before SQL use.
87if (!empty($batchnumber)) {
88 $batchnumber = trim($batchnumber);
89}
90$cost_price = GETPOST('cost_price', 'alpha');
91
92
93// Load variable for pagination
94$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
95$sortfield = GETPOST('sortfield', 'aZ09comma');
96$sortorder = GETPOST('sortorder', 'aZ09comma');
97$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
98if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
99 // If $page is not defined, or '' or -1 or if we click on clear filters
100 $page = 0;
101}
102$offset = $limit * $page;
103$pageprev = $page - 1;
104$pagenext = $page + 1;
105
106
107// Security check
108if ($user->socid) {
109 $socid = $user->socid;
110}
111
112$object = new Product($db);
113$extrafields = new ExtraFields($db);
114
115// fetch optionals attributes and labels
116$extrafields->fetch_name_optionals_label($object->table_element);
117
118if ($id > 0 || !empty($ref)) {
119 $result = $object->fetch($id, $ref);
120}
121
122if (empty($id) && !empty($object->id)) {
123 $id = $object->id;
124}
125
126$modulepart = 'product';
127
128// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
129$canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
130$objcanvas = null;
131if (!empty($canvas)) {
132 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
133 $objcanvas = new Canvas($db, $action);
134 $objcanvas->getCanvas('stockproduct', 'card', $canvas);
135}
136
137// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
138$hookmanager->initHooks(array('stockproductcard', 'globalcard'));
139
140$error = 0;
141
142$usercanread = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'lire')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'lire')));
143$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer')));
144$usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_prices') : $user->hasRight('product', 'lire');
145$usercancreadsupplierprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_supplier_prices') : $user->hasRight('product', 'lire');
146$usercanupdatestock = $user->hasRight('stock', 'mouvement', 'creer');
147
148if ($object->isService()) {
149 $label = $langs->trans('Service');
150 $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_prices') : $user->hasRight('service', 'lire');
151 $usercancreadsupplierprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_supplier_prices') : $user->hasRight('service', 'lire');
152}
153
154if ($object->id > 0) {
155 if ($object->type == $object::TYPE_PRODUCT) {
156 restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
157 }
158 if ($object->type == $object::TYPE_SERVICE) {
159 restrictedArea($user, 'service', $object->id, 'product&product', '', '');
160 }
161} else {
162 restrictedArea($user, 'produit|service', $id, 'product&product', '', '', $fieldid);
163}
164
165
166/*
167 * Actions
168 */
169
170if ($cancel) {
171 $action = '';
172}
173
174$parameters = array('id' => $id, 'ref' => $ref, 'objcanvas' => $objcanvas);
175$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
176if ($reshook < 0) {
177 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
178}
179
180if ($action == 'setcost_price' && $usercancreate) {
181 if ($id) {
182 $result = $object->fetch($id);
183 $object->cost_price = (float) price2num($cost_price);
184 $result = $object->update($object->id, $user);
185 if ($result > 0) {
186 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
187 $action = '';
188 } else {
189 $error++;
190 setEventMessages($object->error, $object->errors, 'errors');
191 }
192 }
193}
194
195if ($action == 'addlimitstockwarehouse' && $usercancreate) {
196 $seuil_stock_alerte = GETPOSTFLOAT('seuil_stock_alerte');
197 $desiredstock = GETPOSTFLOAT('desiredstock');
198
199 $maj_ok = true;
200 if ($seuil_stock_alerte == '') {
201 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors');
202 $maj_ok = false;
203 }
204 if ($desiredstock == '' || is_array($desiredstock)) {
205 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors');
206 $maj_ok = false;
207 }
208
209 $desiredstock = (float) $desiredstock;
210
211 if ($maj_ok) {
212 $pse = new ProductStockEntrepot($db);
213 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
214 if ($pse->fetch(0, $id, GETPOSTINT('fk_entrepot')) > 0) {
215 // Update
216 $pse->seuil_stock_alerte = $seuil_stock_alerte;
217 $pse->desiredstock = $desiredstock;
218 if ($pse->update($user) > 0) {
219 setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs');
220 }
221 } else {
222 // Create
223 $pse->fk_entrepot = GETPOSTINT('fk_entrepot');
224 $pse->fk_product = $id;
225 $pse->seuil_stock_alerte = GETPOSTFLOAT('seuil_stock_alerte');
226 $pse->desiredstock = GETPOSTFLOAT('desiredstock');
227 if ($pse->create($user) > 0) {
228 setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs');
229 }
230 }
231 }
232
233 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
234 exit;
235}
236
237if ($action == 'delete_productstockwarehouse' && $usercancreate) {
238 $pse = new ProductStockEntrepot($db);
239
240 $pse->fetch(GETPOSTINT('fk_productstockwarehouse'));
241 if ($pse->delete($user) > 0) {
242 setEventMessages($langs->trans('ProductStockWarehouseDeleted'), null, 'mesgs');
243 }
244
245 $action = '';
246}
247
248// Set stock limit
249if ($action == 'setseuil_stock_alerte' && $usercancreate) {
250 $object = new Product($db);
251 $result = $object->fetch($id);
252 $object->seuil_stock_alerte = $stocklimit;
253 $result = $object->update($object->id, $user, 0, 'update');
254 if ($result < 0) {
255 setEventMessages($object->error, $object->errors, 'errors');
256 }
257 //else
258 // setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs');
259 $action = '';
260}
261
262// Set desired stock
263if ($action == 'setdesiredstock' && $usercancreate) {
264 $object = new Product($db);
265 $result = $object->fetch($id);
266 $object->desiredstock = $desiredstock;
267 $result = $object->update($object->id, $user, 0, 'update');
268 if ($result < 0) {
269 setEventMessages($object->error, $object->errors, 'errors');
270 }
271 $action = '';
272}
273
274
275// Correct stock
276if ($action == "correct_stock" && !$cancel && $usercanupdatestock) {
277 if (!(GETPOSTINT("id_entrepot") > 0)) {
278 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
279 $error++;
280 $action = 'correction';
281 }
282 if (!GETPOST("nbpiece")) {
283 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
284 $error++;
285 $action = 'correction';
286 }
287
288 if (isModEnabled('productbatch')) {
289 $object = new Product($db);
290 $result = $object->fetch($id);
291
292 if ($object->hasbatch() && !$batchnumber) {
293 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
294 $error++;
295 $action = 'correction';
296 }
297 }
298
299 if (!$error) {
300 $priceunit = price2num(GETPOST("unitprice"));
301 $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
302 if (is_numeric($nbpiece) && $nbpiece != 0 && $id) {
303 $origin_element = '';
304 $origin_id = null;
305
306 if (GETPOSTINT('projectid')) {
307 $origin_element = 'project';
308 $origin_id = GETPOSTINT('projectid');
309 }
310
311 if (empty($object)) {
312 $object = new Product($db);
313 $result = $object->fetch($id);
314 }
315
316 $disablestockchangeforsubproduct = 0;
317 if (GETPOST('disablesubproductstockchange')) {
318 $disablestockchangeforsubproduct = 1;
319 }
320
321 if ($object->hasbatch()) {
322 $result = $object->correct_stock_batch(
323 $user,
324 GETPOSTINT("id_entrepot"),
325 (float) $nbpiece,
326 GETPOSTINT("mouvement"),
327 GETPOST("label", 'alphanohtml'), // label movement
328 (float) $priceunit,
329 $d_eatby,
330 $d_sellby,
331 $batchnumber,
332 GETPOST('inventorycode', 'alphanohtml'),
333 $origin_element,
334 $origin_id,
335 $disablestockchangeforsubproduct
336 ); // We do not change value of stock for a correction
337 } else {
338 $result = $object->correct_stock(
339 $user,
340 GETPOSTINT("id_entrepot"),
341 (float) $nbpiece,
342 GETPOSTINT("mouvement"),
343 GETPOST("label", 'alphanohtml'),
344 (float) $priceunit,
345 GETPOST('inventorycode', 'alphanohtml'),
346 $origin_element,
347 $origin_id,
348 $disablestockchangeforsubproduct
349 ); // We do not change value of stock for a correction
350 }
351
352 if ($result > 0) {
353 if ($backtopage) {
354 header("Location: ".$backtopage);
355 exit;
356 } else {
357 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
358 exit;
359 }
360 } else {
361 setEventMessages($object->error, $object->errors, 'errors');
362 $action = 'correction';
363 }
364 }
365 }
366}
367
368// Transfer stock from a warehouse to another warehouse
369if ($action == "transfert_stock" && !$cancel && $usercanupdatestock) {
370 if (!(GETPOSTINT("id_entrepot") > 0) || !(GETPOSTINT("id_entrepot_destination") > 0)) {
371 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
372 $error++;
373 $action = 'transfer';
374 }
375 if (!GETPOST("nbpiece")) {
376 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
377 $error++;
378 $action = 'transfer';
379 }
380 if (GETPOSTINT("id_entrepot") == GETPOSTINT("id_entrepot_destination")) {
381 setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
382 $error++;
383 $action = 'transfer';
384 }
385 if (isModEnabled('productbatch')) {
386 $object = new Product($db);
387 $result = $object->fetch($id);
388
389 if ($object->hasbatch() && !$batchnumber) {
390 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
391 $error++;
392 $action = 'transfer';
393 }
394 }
395 $batch = '';
396 $sellby = 0;
397 $eatby = 0;
398
399 if (!$error) {
400 if ($id) {
401 $object = new Product($db);
402 $result = $object->fetch($id);
403 $result1 = -1;
404 $result2 = -1;
405
406 $db->begin();
407
408 $object->load_stock('novirtual'); // Load array product->stock_warehouse
409
410 // Define value of products moved
411 $pricesrc = 0;
412 if (isset($object->pmp)) {
413 $pricesrc = $object->pmp;
414 }
415 $pricedest = $pricesrc;
416
417 $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
418
419 if ($object->hasbatch()) {
420 $pdluo = new Productbatch($db);
421
422 $srcwarehouseid = 0;
423
424 if ($pdluoid > 0) {
425 $result = $pdluo->fetch($pdluoid);
426 if ($result > 0 && $pdluo->id > 0 && $pdluo->fk_product == $object->id) {
427 // The lot row gives the lot and its dates, the source warehouse is the one selected in the form (checked against the target above)
428 $srcwarehouseid = GETPOSTINT('id_entrepot');
429 $batch = $pdluo->batch;
430 $eatby = $pdluo->eatby;
431 $sellby = $pdluo->sellby;
432 } else {
433 setEventMessages($pdluo->error ? $pdluo->error : $langs->trans('ErrorRecordNotFound'), $pdluo->errors, 'errors');
434 $error++;
435 }
436 } else {
437 $srcwarehouseid = GETPOSTINT('id_entrepot');
438 $batch = $batchnumber;
439 $eatby = $d_eatby;
440 $sellby = $d_sellby;
441 }
442
443 $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
444
445 if (!$error) {
446 // Remove stock
447 $result1 = $object->correct_stock_batch(
448 $user,
449 $srcwarehouseid,
450 (float) $nbpiece,
451 1,
452 GETPOST("label", 'alphanohtml'),
453 (float) $pricesrc,
454 $eatby,
455 $sellby,
456 $batch,
457 GETPOST('inventorycode', 'alphanohtml')
458 );
459 if ($result1 < 0) {
460 $error++;
461 }
462 }
463 if (!$error) {
464 // Add stock
465 $result2 = $object->correct_stock_batch(
466 $user,
467 GETPOSTINT("id_entrepot_destination"),
468 (float) $nbpiece,
469 0,
470 GETPOST("label", 'alphanohtml'),
471 (float) $pricedest,
472 $eatby,
473 $sellby,
474 (string) $batch,
475 GETPOST('inventorycode', 'alphanohtml')
476 );
477 if ($result2 < 0) {
478 $error++;
479 }
480 }
481 } else {
482 if (!$error) {
483 // Remove stock
484 $result1 = $object->correct_stock(
485 $user,
486 GETPOSTINT("id_entrepot"),
487 (float) $nbpiece,
488 1,
489 GETPOST("label", 'alphanohtml'),
490 (float) $pricesrc,
491 GETPOST('inventorycode', 'alphanohtml')
492 );
493 if ($result1 < 0) {
494 $error++;
495 }
496 }
497 if (!$error) {
498 // Add stock
499 $result2 = $object->correct_stock(
500 $user,
501 GETPOSTINT("id_entrepot_destination"),
502 (float) $nbpiece,
503 0,
504 GETPOST("label", 'alphanohtml'),
505 (float) $pricedest,
506 GETPOST('inventorycode', 'alphanohtml')
507 );
508 if ($result2 < 0) {
509 $error++;
510 }
511 }
512 }
513
514
515 if (!$error && $result1 >= 0 && $result2 >= 0) {
516 $db->commit();
517
518 if ($backtopage) {
519 header("Location: ".$backtopage);
520 exit;
521 } else {
522 header("Location: product.php?id=".$object->id);
523 exit;
524 }
525 } else {
526 setEventMessages($object->error, $object->errors, 'errors');
527 $db->rollback();
528 $action = 'transfer';
529 }
530 }
531 }
532}
533
534/*
535 * View
536 */
537
538$form = new Form($db);
539$formproduct = new FormProduct($db);
540$formproject = null;
541if (isModEnabled('project')) {
542 $formproject = new FormProjets($db);
543}
544
545$variants = false;
546$iskit = 0;
547
548if ($id > 0 || $ref) {
549 $object = new Product($db);
550 $result = $object->fetch($id, $ref);
551
552 $iskit = $object->hasFatherOrChild(1);
553
554 $variants = $object->hasVariants();
555
556 $object->load_stock(); // This include the load_virtual_stock()
557
558 $title = $langs->trans('ProductServiceCard');
559 $helpurl = '';
560 $shortlabel = dol_trunc($object->label, 16);
561 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
562 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock');
563 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
564 }
565 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
566 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock');
567 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
568 }
569
570 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-card_stock_product');
571
572 if (!empty($conf->use_javascript_ajax)) {
573 ?>
574 <script type="text/javascript">
575 $(document).ready(function() {
576 $(".collapse_batch").click(function() {
577 console.log("We click on collapse_batch");
578 var id_entrepot = $(this).attr('id').replace('ent', '');
579
580 if($(this).text().indexOf('+') > 0) {
581 $(".batch_warehouse" + id_entrepot).show();
582 $(this).html('(-)');
583 jQuery("#show_all").hide();
584 jQuery("#hide_all").show();
585 }
586 else {
587 $(".batch_warehouse" + id_entrepot).hide();
588 $(this).html('(+)');
589 }
590
591 return false;
592 });
593
594 $("#show_all").click(function() {
595 console.log("We click on show_all");
596 $("[class^=batch_warehouse]").show();
597 $("[class^=collapse_batch]").html('(-)');
598 jQuery("#show_all").hide();
599 jQuery("#hide_all").show();
600 return false;
601 });
602
603 $("#hide_all").click(function() {
604 console.log("We click on hide_all");
605 $("[class^=batch_warehouse]").hide();
606 $("[class^=collapse_batch]").html('(+)');
607 jQuery("#hide_all").hide();
608 jQuery("#show_all").show();
609 return false;
610 });
611
612 });
613 </script>
614 <?php
615 }
616
617 if ($result > 0) {
619 $titre = $langs->trans("CardProduct".$object->type);
620 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
621
622 print dol_get_fiche_head($head, 'stock', $titre, -1, $picto);
623
625
626 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
627 $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")";
628
629 $shownav = 1;
630 if ($user->socid && !in_array('stock', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
631 $shownav = 0;
632 }
633
634 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
635
636 if (!$variants) {
637 print '<div class="fichecenter">';
638
639 print '<div class="fichehalfleft">';
640 print '<div class="underbanner clearboth"></div>';
641
642 print '<table class="border tableforfield centpercent">';
643
644 // Type
645 if (isModEnabled("product") && isModEnabled("service")) {
646 $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
647 print '<tr><td class="titlefieldmiddle">';
648 print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', (string) $object->type, $object, 0, $typeformat) : $langs->trans('Type');
649 print '</td><td>';
650 print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
651 print '</td></tr>';
652 }
653
654 // Stockable product / default warehouse
655 if (($object->isProduct() || getDolGlobalInt('STOCK_SUPPORTS_SERVICES')) && isModEnabled('stock')) { // Do not use isStockManaged here.We must sow info even if stock not managed
656 print '<tr><td>' . $form->textwithpicto($langs->trans("StockableProduct"), $langs->trans('StockableProductDescription')) . '</td>';
657 print '<td>';
658 if ($iskit) {
659 print '<input type="checkbox" readonly disabled> <span class="opacitymedium">' . $langs->trans("NotSupportedOnKits").'</span>';
660 } else {
661 print '<input type="checkbox" readonly disabled '.($object->stockable_product == 1 ? 'checked' : '').'>';
662 }
663 print '</td></tr>';
664
665 if ($object->isStockManaged() && !$iskit) {
666 $warehouse = new Entrepot($db);
667 $warehouse->fetch($object->fk_default_warehouse);
668
669 print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
670 print(!empty($warehouse->id) ? $warehouse->getNomUrl(1) : '');
671 print '</td>';
672 }
673 }
674
675 if (isModEnabled('productbatch')) {
676 print '<tr><td class="titlefieldmiddle">'.$langs->trans("ManageLotSerial").'</td><td>';
677 print $object->getLibStatut(0, 2);
678 print '</td></tr>';
679 }
680
681 // Cost price. Can be used for margin module for option "calculate margin on explicit cost price
682 print '<tr><td>';
683 $textdesc = $langs->trans("CostPriceDescription");
684 $textdesc .= "<br>".$langs->trans("CostPriceUsage");
685 $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', '');
686 if (!$usercancreadsupplierprice) {
687 print $form->editfieldkey($text, 'cost_price', '', $object, 0, 'amount:6');
688 print '</td><td>';
689 print $form->editfieldval($text, 'cost_price', '', $object, 0, 'amount:6');
690 } else {
691 print $form->editfieldkey($text, 'cost_price', (string) $object->cost_price, $object, (int) $usercancreate, 'amount:6');
692 print '</td><td>';
693 print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
694 }
695 print '</td></tr>';
696
697
698
699 // AWP
700 print '<tr><td class="titlefieldmiddle">';
701 print $form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc"));
702 print '</td>';
703 print '<td>';
704 if ($object->pmp > 0 && $usercancreadsupplierprice) {
705 print price($object->pmp).' '.$langs->trans("HT");
706 }
707 print '</td>';
708 print '</tr>';
709
710 // Minimum Price
711 print '<tr><td>'.$langs->trans("BuyingPriceMin").'</td>';
712 print '<td>';
713 $product_fourn = new ProductFournisseur($db);
714 if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) {
715 if ($product_fourn->product_fourn_price_id > 0 && $usercancreadsupplierprice) {
716 print $product_fourn->display_price_product_fournisseur();
717 } else {
718 print $langs->trans("NotDefined");
719 }
720 }
721 print '</td></tr>';
722
723 if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
724 // Price
725 print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
726 if ($usercancreadprice) {
727 if ($object->price_base_type == 'TTC') {
728 print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
729 } else {
730 print price($object->price).' '.$langs->trans($object->price_base_type);
731 }
732 }
733 print '</td></tr>';
734
735 // Price minimum
736 print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
737 if ($usercancreadprice) {
738 if ($object->price_base_type == 'TTC') {
739 print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
740 } else {
741 print price($object->price_min).' '.$langs->trans($object->price_base_type);
742 }
743 }
744 print '</td></tr>';
745 } else {
746 // Price
747 print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
748 print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
749 print '</td></tr>';
750
751 // Price minimum
752 print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
753 print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
754 print '</td></tr>';
755 }
756
757 // Hook formObject
758 $parameters = array();
759 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
760 print $hookmanager->resPrint;
761
762 print '</table>';
763
764 print '</div>';
765 print '<div class="fichehalfright"><div class="underbanner clearboth"></div>';
766
767 if (!$iskit || getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) {
768 print '<table class="border tableforfield centpercent">';
769
770 // Stock alert threshold
771 print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1), 'seuil_stock_alerte', (string) $object->seuil_stock_alerte, $object, $user->hasRight('produit', 'creer')).'</td><td>';
772 print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->hasRight('produit', 'creer'), 'string');
773 print '</td></tr>';
774
775 // Desired stock
776 print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', (string) $object->desiredstock, $object, $user->hasRight('produit', 'creer'));
777 print '</td><td>';
778 print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->hasRight('produit', 'creer'), 'string');
779 print '</td></tr>';
780
781 // Real stock
782 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
783 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
784 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
785 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
786 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
787 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
788 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
789 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
790 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
791 $parameters = array();
792 $reshook = $hookmanager->executeHooks('physicalStockTextStockOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
793 if ($reshook > 0) {
794 $text_stock_options = $hookmanager->resPrint;
795 } elseif ($reshook == 0) {
796 $text_stock_options .= $hookmanager->resPrint;
797 } else {
798 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
799 }
800
801 print '<tr><td>';
802 print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1);
803 print '</td>';
804 print '<td>'.price2num($object->stock_reel, 'MS');
805 if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) {
806 print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
807 }
808
809 print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?productid='.$object->id.'">'.$langs->trans("StockAtDate").'</a>';
810 print '</td>';
811 print '</tr>';
812
813 $stocktheo = price2num($object->stock_theorique, 'MS');
814
815 $found = 0;
816 $helpondiff = '<strong>'.$langs->trans("StockDiffPhysicTeoric").':</strong><br>';
817 // Number of sales orders running
818 if (isModEnabled('order')) {
819 if ($found) {
820 $helpondiff .= '<br>';
821 } else {
822 $found = 1;
823 }
824 $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty'];
825 $result = $object->load_stats_commande(0, '0', 1);
826 if ($result < 0) {
827 dol_print_error($db, $object->error);
828 }
829 $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')</span>';
830 }
831
832 // Number of product from sales order already sent (partial shipping)
833 if (isModEnabled("shipping")) {
834 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
835 $filterShipmentStatus = '';
836 if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
838 } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
839 $filterShipmentStatus = Expedition::STATUS_CLOSED;
840 }
841 if ($found) {
842 $helpondiff .= '<br>';
843 } else {
844 $found = 1;
845 }
846 $result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus);
847 $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty'];
848 }
849
850 // Number of supplier order running
851 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
852 if ($found) {
853 $helpondiff .= '<br>';
854 } else {
855 $found = 1;
856 }
857 $result = $object->load_stats_commande_fournisseur(0, '3,4', 1);
858 $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty'];
859 $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1);
860 if ($result < 0) {
861 dol_print_error($db, $object->error);
862 }
863 $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')</span>';
864 }
865
866 // Number of product from supplier order already received (partial receipt)
867 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
868 if ($found) {
869 $helpondiff .= '<br>';
870 } else {
871 $found = 1;
872 }
873 $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty'];
874 }
875
876 // Number of product in production
877 if (isModEnabled('mrp')) {
878 if ($found) {
879 $helpondiff .= '<br>';
880 } else {
881 $found = 1;
882 }
883 $helpondiff .= $langs->trans("ProductQtyToConsumeByMO").': '.$object->stats_mrptoconsume['qty'].'<br>';
884 $helpondiff .= $langs->trans("ProductQtyToProduceByMO").': '.$object->stats_mrptoproduce['qty'];
885 }
886 $parameters = array('found' => &$found, 'id' => $object->id, 'includedraftpoforvirtual' => null);
887 $reshook = $hookmanager->executeHooks('virtualStockHelpOnDiff', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
888 if ($reshook > 0) {
889 $helpondiff = $hookmanager->resPrint;
890 } elseif ($reshook == 0) {
891 $helpondiff .= $hookmanager->resPrint;
892 } else {
893 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
894 }
895
896
897 // Calculating a theoretical value
898 print '<tr><td>';
899 print $form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc"));
900 print '</td>';
901 print "<td>";
902 //print (empty($stocktheo)?0:$stocktheo);
903 print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff);
904 if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) {
905 print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
906 }
907 print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?mode=future&productid='.$object->id.'">'.$langs->trans("VirtualStockAtDate").'</a>';
908 print '</td>';
909 print '</tr>';
910
911 // Last movement
912 if ($user->hasRight('stock', 'mouvement', 'lire')) {
913 $sql = "SELECT max(m.datem) as datem";
914 $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
915 $sql .= " WHERE m.fk_product = ".((int) $object->id);
916 $lastmovementdate = 0;
917 $resqlbis = $db->query($sql);
918 if ($resqlbis) {
919 $obj = $db->fetch_object($resqlbis);
920 $lastmovementdate = $db->jdate($obj->datem);
921 } else {
922 dol_print_error($db);
923 }
924 print '<tr><td class="tdtop">'.$langs->trans("LastMovement").'</td><td>';
925 if ($lastmovementdate) {
926 print dol_print_date($lastmovementdate, 'dayhour').' ';
927 print ' &nbsp; &nbsp; ';
928 print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
929 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("FullList").'</a>';
930 } else {
931 print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
932 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("None").'</a>';
933 }
934 print "</td></tr>";
935 }
936
937 print "</table>";
938 }
939
940 print '</div>';
941 print '</div>';
942
943 print '<div class="clearboth"></div>';
944 }
945
946 print dol_get_fiche_end();
947 }
948
949 // Correct stock
950 if ($action == "correction") {
951 include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
952 print '<br><br>';
953 }
954
955 // Transfer of units
956 if ($action == "transfer") {
957 include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
958 print '<br><br>';
959 }
960} else {
962}
963
964
965$showstockdetails = 1;
966if ($variants && !getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
967 $showstockdetails = 0;
968}
969if ($iskit && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) {
970 $showstockdetails = 0;
971}
972
973
974
975// Actions buttons
976
977$parameters = array();
978
979$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
980if (empty($reshook)) {
981 if (empty($action) && $object->id) {
982 if ($showstockdetails) {
983 print '<div class="tabsAction">'."\n";
984
985 if ($user->hasRight('stock', 'mouvement', 'creer')) {
986 if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
987 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=transfer&token='.newToken().'">'.$langs->trans("TransferStock").'</a>';
988 } else {
989 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("TransferStock").'</a>';
990 }
991 } else {
992 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("TransferStock").'</a>';
993 }
994
995 if ($user->hasRight('stock', 'mouvement', 'creer')) {
996 if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
997 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=correction&token='.newToken().'">'.$langs->trans("CorrectStock").'</a>';
998 } else {
999 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("CorrectStock").'</a>';
1000 }
1001 } else {
1002 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
1003 }
1004
1005 print '</div>';
1006 }
1007 }
1008}
1009
1010
1011if ($showstockdetails) {
1012 /*
1013 * Stock detail (by warehouse). May go down into batch details.
1014 */
1015
1016 print '<div class="div-table-responsive">';
1017 print '<table class="noborder centpercent">';
1018
1019 print '<tr class="liste_titre">';
1020 print '<td colspan="4">'.$langs->trans("Warehouse").'</td>';
1021 print '<td class="right">'.$langs->trans("NumberOfUnit").'</td>';
1022 print '<td class="right">'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).'</td>';
1023 print '<td class="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
1024 print '<td class="right">'.$langs->trans("SellPriceMin").'</td>';
1025 print '<td class="right">'.$langs->trans("EstimatedStockValueSellShort").'</td>';
1026 print '<td></td>';
1027 print '<td></td>';
1028 print '</tr>';
1029
1030 if ((isModEnabled('productbatch')) && $object->hasbatch()) {
1031 $colspan = 3;
1032 print '<tr class="liste_titre"><td class="minwidth200">';
1033 if (!empty($conf->use_javascript_ajax)) {
1034 print '<a id="show_all" href="#" class="hideobject">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ShowAllLots").'</a>';
1035 //print ' &nbsp; ';
1036 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("HideLots").'</a>';
1037 //print '&nbsp;'.$form->textwithpicto('', $langs->trans('CollapseBatchDetailHelp'), 1, 'help', '');
1038 }
1039 print '</td>';
1040 print '<td class="right">'.$langs->trans("batch_number").'</td>';
1041 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1042 $colspan--;
1043 print '<td class="center width100">'.$langs->trans("SellByDate").'</td>';
1044 }
1045 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1046 $colspan--;
1047 print '<td class="center width100">'.$langs->trans("EatByDate").'</td>';
1048 }
1049 print '<td colspan="'.$colspan.'"></td>';
1050 print '<td></td>';
1051 print '<td></td>';
1052 print '<td></td>';
1053 print '<td></td>';
1054 print '<td></td>';
1055 print '<td></td>';
1056 print '</tr>';
1057 }
1058
1059 $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut as status, ps.reel, ps.rowid as product_stock_id, p.pmp";
1060 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
1061 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps";
1062 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product";
1063 $sql .= " WHERE ps.reel != 0";
1064 $sql .= " AND ps.fk_entrepot = e.rowid";
1065 $sql .= " AND e.entity IN (".getEntity('stock').")";
1066 $sql .= " AND ps.fk_product = ".((int) $object->id);
1067 $sql .= " ORDER BY e.ref";
1068
1069 $entrepotstatic = new Entrepot($db);
1070 $product_lot_static = new Productlot($db);
1071
1072 $num = 0;
1073 $total = 0;
1074 $totalvalue = $totalvaluesell = 0;
1075 $totalwithpmp = 0;
1076
1077 $resql = $db->query($sql);
1078 if ($resql) {
1079 $num = $db->num_rows($resql);
1080 $total = $totalwithpmp;
1081 $i = 0;
1082 $var = false;
1083 while ($i < $num) {
1084 $obj = $db->fetch_object($resql);
1085
1086 $entrepotstatic->id = $obj->rowid;
1087 $entrepotstatic->ref = $obj->ref;
1088 $entrepotstatic->label = $obj->ref;
1089 $entrepotstatic->lieu = $obj->lieu;
1090 $entrepotstatic->fk_parent = $obj->fk_parent;
1091 $entrepotstatic->statut = $obj->status;
1092 $entrepotstatic->status = $obj->status;
1093
1094 $stock_real = price2num($obj->reel, 'MS');
1095 print '<tr class="oddeven">';
1096
1097 // Warehouse
1098 print '<td colspan="4">';
1099 print $entrepotstatic->getNomUrl(1);
1100 if (!empty($conf->use_javascript_ajax) && isModEnabled('productbatch') && $object->hasbatch()) {
1101 print '<a class="collapse_batch marginleftonly" id="ent' . $entrepotstatic->id . '" href="#">';
1102 print(!getDolGlobalString('STOCK_SHOW_ALL_BATCH_BY_DEFAULT') ? '(+)' : '(-)');
1103 print '</a>';
1104 }
1105 print '</td>';
1106
1107 print '<td class="right">'.$stock_real.($stock_real < 0 ? ' '.img_warning() : '').'</td>';
1108
1109 // PMP
1110 print '<td class="right nowraponall">'.($usercancreadsupplierprice ? (price2num($object->pmp) ? price2num($object->pmp, 'MU') : '') : '').'</td>';
1111
1112 // Value purchase
1113 if ($usercancreadsupplierprice) {
1114 print '<td class="right amount nowraponall">'.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').'</td>';
1115 } else {
1116 print '<td class="right amount nowraponall"></td>';
1117 }
1118
1119 // Sell price
1120 $minsellprice = null;
1121 $maxsellprice = null;
1122 print '<td class="right nowraponall">';
1123 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1124 foreach ($object->multiprices as $priceforlevel) {
1125 if (is_numeric($priceforlevel)) {
1126 if (is_null($maxsellprice) || $priceforlevel > $maxsellprice) {
1127 $maxsellprice = $priceforlevel;
1128 }
1129 if (is_null($minsellprice) || $priceforlevel < $minsellprice) {
1130 $minsellprice = $priceforlevel;
1131 }
1132 }
1133 }
1134 print '<span class="valignmiddle">';
1135 if ($usercancreadprice) {
1136 if ($minsellprice != $maxsellprice) {
1137 print price(price2num($minsellprice, 'MU'), 1).' - '.price(price2num($maxsellprice, 'MU'), 1);
1138 } else {
1139 print price(price2num($minsellprice, 'MU'), 1);
1140 }
1141 }
1142 print '</span>';
1143 print $form->textwithpicto('', $langs->trans("Variable"));
1144 } elseif ($usercancreadprice) {
1145 print price(price2num($object->price, 'MU'), 1);
1146 }
1147 print '</td>';
1148
1149 // Value sell
1150 print '<td class="right amount nowraponall">';
1151 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1152 print '<span class="valignmiddle">';
1153 if ($usercancreadprice) {
1154 if ($minsellprice != $maxsellprice) {
1155 print price(price2num($minsellprice * $obj->reel, 'MT'), 1).' - '.price(price2num($maxsellprice * $obj->reel, 'MT'), 1);
1156 } else {
1157 print price(price2num($minsellprice * $obj->reel, 'MT'), 1);
1158 }
1159 }
1160 print '</span>';
1161 print $form->textwithpicto('', $langs->trans("Variable"));
1162 } else {
1163 if ($usercancreadprice) {
1164 print price(price2num($object->price * $obj->reel, 'MT'), 1);
1165 }
1166 }
1167 print '</td>';
1168 print '<td></td>';
1169 print '<td></td>';
1170 print '</tr>';
1171 $total += $obj->reel;
1172 if (price2num($object->pmp)) {
1173 $totalwithpmp += $obj->reel;
1174 }
1175 $totalvalue += ($object->pmp * $obj->reel);
1176 $totalvaluesell += ($object->price * $obj->reel);
1177 // Batch Detail
1178 if ((isModEnabled('productbatch')) && $object->hasbatch()) {
1179 $details = Productbatch::findAll($db, $obj->product_stock_id, 0, $object->id);
1180 if ($details < 0) {
1181 dol_print_error($db);
1182 }
1183 foreach ($details as $pdluo) {
1184 $product_lot_static->id = $pdluo->lotid;
1185 $product_lot_static->batch = $pdluo->batch;
1186 $product_lot_static->eatby = $pdluo->eatby;
1187 $product_lot_static->sellby = $pdluo->sellby;
1188
1189 if ($action == 'editline' && GETPOSTINT('lineid') == $pdluo->id) { //Current line edit
1190 print "\n".'<tr>';
1191 print '<td colspan="9">';
1192 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1193 print '<input type="hidden" name="token" value="'.newToken().'">';
1194 print '<input type="hidden" name="pdluoid" value="'.$pdluo->id.'"><input type="hidden" name="action" value="updateline"><input type="hidden" name="id" value="'.$id.'"><table class="noborder centpercent"><tr><td width="10%"></td>';
1195 print '<td class="right" width="10%"><input type="text" name="batch_number" value="'.$pdluo->batch.'"></td>';
1196 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1197 print '<td class="center" width="10%">';
1198 print $form->selectDate($pdluo->sellby, 'sellby', 0, 0, 1, '', 1, 0);
1199 print '</td>';
1200 }
1201 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1202 print '<td class="center" width="10%">';
1203 print $form->selectDate($pdluo->eatby, 'eatby', 0, 0, 1, '', 1, 0);
1204 print '</td>';
1205 }
1206 print '<td class="right" colspan="3">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
1207 print '<td colspan="4"><input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'">';
1208 print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="Cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
1209 print '</table>';
1210 print '</form>';
1211 print '</td>';
1212 print '<td></td>';
1213 print '<td></td>';
1214 print '</tr>';
1215 } else {
1216 print "\n".'<tr style="display:'.(!getDolGlobalString('STOCK_SHOW_ALL_BATCH_BY_DEFAULT') ? 'none' : 'visible').';" class="batch_warehouse'.$entrepotstatic->id.'"><td class="left">';
1217 print '</td>';
1218 print '<td class="right nowraponall">';
1219 if ($product_lot_static->id > 0) {
1220 print $product_lot_static->getNomUrl(1);
1221 } else {
1222 print $product_lot_static->getNomUrl(1, 'nolink');
1223 }
1224 print '</td>';
1225 $colspan = 3;
1226 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1227 $colspan--;
1228 print '<td class="center">'.dol_print_date($pdluo->sellby, 'day').'</td>';
1229 }
1230 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1231 $colspan--;
1232 print '<td class="center">'.dol_print_date($pdluo->eatby, 'day').'</td>';
1233 }
1234 print '<td class="right" colspan="'.$colspan.'">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : (($pdluo->qty > 1 && $object->status_batch == 2) ? ' '.img_warning($langs->trans('IlligalQtyForSerialNumbers')) : '')).'</td>';
1235 print '<td colspan="4"></td>';
1236 print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("TransferStock")).'">';
1237 if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
1238 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&id_entrepot='.$entrepotstatic->id.'&action=transfer&pdluoid='.$pdluo->id.'&token='.newToken().'">';
1239 print img_picto($langs->trans("TransferStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
1240 print $langs->trans("TransferStock");
1241 print '</a>';
1242 // Disabled, because edition of stock content must use the "Correct stock menu".
1243 // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
1244 //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
1245 //print img_edit().'</a>';
1246 }
1247 print '</td>';
1248 print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("CorrectStock")).'">';
1249 if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
1250 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&id_entrepot='.$entrepotstatic->id.'&action=correction&pdluoid='.$pdluo->id.'&token='.newToken().'">';
1251 print img_picto($langs->trans("CorrectStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
1252 print $langs->trans("CorrectStock");
1253 print '</a>';
1254 // Disabled, because edition of stock content must use the "Correct stock menu".
1255 // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
1256 //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
1257 //print img_edit().'</a>';
1258 }
1259 print '</td>';
1260 print '</tr>';
1261 }
1262 }
1263 }
1264 $i++;
1265 }
1266 } else {
1267 dol_print_error($db);
1268 }
1269
1270 // Total line
1271 print '<tr class="liste_total"><td class="right liste_total" colspan="4">'.$langs->trans("Total").':</td>';
1272 print '<td class="liste_total right">'.price2num($total, 'MS').'</td>';
1273 print '<td class="liste_total right">';
1274 if ($usercancreadsupplierprice) {
1275 print($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : '&nbsp;'); // This value may have rounding errors
1276 }
1277 print '</td>';
1278 // Value purchase
1279 print '<td class="liste_total right">';
1280 if ($usercancreadsupplierprice) {
1281 print $totalvalue ? price(price2num($totalvalue, 'MT'), 1) : '&nbsp;';
1282 }
1283 print '</td>';
1284 print '<td class="liste_total right">';
1285 if ($num) {
1286 if ($total) {
1287 print '<span class="valignmiddle">';
1288 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1289 print $form->textwithpicto('', $langs->trans("Variable"));
1290 } elseif ($usercancreadprice) {
1291 print price($totalvaluesell / $total, 1);
1292 }
1293 print '</span>';
1294 }
1295 }
1296 print '</td>';
1297 // Value to sell
1298 print '<td class="liste_total right amount">';
1299 if ($num) {
1300 print '<span class="valignmiddle">';
1301 if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && $usercancreadprice) {
1302 print price(price2num($totalvaluesell, 'MT'), 1);
1303 } else {
1304 print $form->textwithpicto('', $langs->trans("Variable"));
1305 }
1306 print '</span>';
1307 }
1308 print '</td>';
1309 print '<td></td>';
1310 print '<td></td>';
1311 print "</tr>";
1312
1313 print "</table>";
1314 print '</div>';
1315
1316
1317 if (getDolGlobalString('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE')) {
1318 print '<br><br>';
1319 print load_fiche_titre($langs->trans('AddNewProductStockWarehouse'));
1320
1321 if ($user->hasRight('produit', 'creer')) {
1322 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1323 print '<input type="hidden" name="token" value="'.newToken().'">';
1324 print '<input type="hidden" name="action" value="addlimitstockwarehouse">';
1325 print '<input type="hidden" name="id" value="'.$id.'">';
1326 }
1327 print '<table class="noborder centpercent">';
1328 if ($user->hasRight('produit', 'creer')) {
1329 print '<tr class="liste_titre"><td>'.$formproduct->selectWarehouses('', 'fk_entrepot').'</td>';
1330 print '<td class="right"><input name="seuil_stock_alerte" type="text" placeholder="'.$langs->trans("StockLimit").'" /></td>';
1331 print '<td class="right"><input name="desiredstock" type="text" placeholder="'.$langs->trans("DesiredStock").'" /></td>';
1332 print '<td class="right"><input type="submit" value="'.$langs->trans("Save").'" class="button button-save" /></td>';
1333 print '</tr>';
1334 } else {
1335 print '<tr class="liste_titre"><td>'.$langs->trans("Warehouse").'</td>';
1336 print '<td class="right">'.$langs->trans("StockLimit").'</td>';
1337 print '<td class="right">'.$langs->trans("DesiredStock").'</td>';
1338 print '</tr>';
1339 }
1340
1341 $pse = new ProductStockEntrepot($db);
1342 $lines = $pse->fetchAll($id);
1343
1344 $visibleWarehouseEntities = explode(',', getEntity('stock')); // For MultiCompany compatibility
1345
1346 if (!empty($lines)) {
1347 $var = false;
1348 foreach ($lines as $line) {
1349 $ent = new Entrepot($db);
1350 $ent->fetch($line['fk_entrepot']);
1351
1352 if (!isModEnabled("multicompany") || in_array($ent->entity, $visibleWarehouseEntities)) {
1353 // Display only warehouses from our entity and entities sharing stock with actual entity
1354 print '<tr class="oddeven"><td>'.$ent->getNomUrl(3).'</td>';
1355 print '<td class="right">'.$line['seuil_stock_alerte'].'</td>';
1356 print '<td class="right">'.$line['desiredstock'].'</td>';
1357 if ($user->hasRight('produit', 'creer')) {
1358 print '<td class="right"><a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&fk_productstockwarehouse='.$line['id'].'&action=delete_productstockwarehouse&token='.newToken().'">'.img_delete().'</a></td>';
1359 }
1360 print '</tr>';
1361 }
1362 }
1363 }
1364
1365 print "</table>";
1366
1367 if ($user->hasRight('produit', 'creer')) {
1368 print '</form>';
1369 }
1370 }
1371}
1372
1373if ($variants) {
1374 // List of variants
1375 include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
1376 include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
1377 $prodstatic = new Product($db);
1378 $prodcomb = new ProductCombination($db);
1379 $comb2val = new ProductCombination2ValuePair($db);
1380 $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id);
1381
1382 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
1383 print '<input type="hidden" name="token" value="'.newToken().'">';
1384 print '<input type="hidden" name="action" value="massaction">';
1385 print '<input type="hidden" name="id" value="'.$id.'">';
1386 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1387
1388 // load variants
1389 $title = $langs->trans("ProductCombinations");
1390
1391 print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0);
1392
1393 print '<div class="div-table-responsive">'; ?>
1394 <table class="liste">
1395 <tr class="liste_titre">
1396 <td class="liste_titre"><?php echo $langs->trans('Product') ?></td>
1397 <td class="liste_titre"><?php echo $langs->trans('Combination') ?></td>
1398 <td class="liste_titre center"><?php echo $langs->trans('OnSell') ?></td>
1399 <td class="liste_titre center"><?php echo $langs->trans('OnBuy') ?></td>
1400 <td class="liste_titre right"><?php echo $langs->trans('Stock') ?></td>
1401 <td class="liste_titre"></td>
1402 </tr>
1403 <?php
1404
1405 if (count($productCombinations)) {
1406 $stock_total = 0;
1407 foreach ($productCombinations as $currcomb) {
1408 $prodstatic->fetch($currcomb->fk_product_child);
1409 $prodstatic->load_stock();
1410 $stock_total += $prodstatic->stock_reel; ?>
1411 <tr class="oddeven">
1412 <td><?php echo $prodstatic->getNomUrl(1) ?></td>
1413 <td>
1414 <?php
1415
1416 $productCombination2ValuePairs = $comb2val->fetchByFkCombination($currcomb->id);
1417 $iMax = count($productCombination2ValuePairs);
1418
1419 for ($i = 0; $i < $iMax; $i++) {
1420 echo dol_htmlentities($productCombination2ValuePairs[$i]);
1421
1422 if ($i !== ($iMax - 1)) {
1423 echo ', ';
1424 }
1425 } ?>
1426 </td>
1427 <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 0) ?></td>
1428 <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 1) ?></td>
1429 <td class="right"><?php echo $prodstatic->stock_reel ?></td>
1430 <td class="right">
1431 <a class="paddingleft paddingright editfielda" href="<?php echo dol_buildpath('/product/stock/product.php?id='.$currcomb->fk_product_child, 2) ?>"><?php echo img_edit() ?></a>
1432 </td>
1433 <?php
1434 ?>
1435 </tr>
1436 <?php
1437 }
1438
1439 print '<tr class="liste_total">';
1440 print '<td colspan="4" class="left">'.$langs->trans("Total").'</td>';
1441 print '<td class="right">'.$stock_total.'</td>';
1442 print '<td></td>';
1443 print '</tr>';
1444 } else {
1445 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1446 } ?>
1447 </table>
1448
1449 <?php
1450 print '</div>';
1451
1452 print '</form>';
1453}
1454
1455// End of page
1456llxFooter();
1457$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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
Class to manage canvas.
Class to manage warehouses.
const STATUS_CLOSED
Closed status -> parcel was received by customer / end of process prev status : validated or shipment...
const STATUS_VALIDATED
Validated status -> parcel is ready to be sent prev status : draft next status : closed or shipment_i...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
Class ProductCombination2ValuePair Used to represent the relation between a variant and its attribute...
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class ProductStockEntrepot.
Manage record for batch number management.
static findAll($dbs, $fk_product_stock, $with_qty=0, $fk_product=0)
Return all batch detail records for a given product and warehouse.
Class with list of lots and properties.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
treeview li table
No Email.
product_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:132
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.