dolibarr 22.0.5
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-2024 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', 'san_alpha');
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 = GETPOST('seuil_stock_alerte');
197 $desiredstock = GETPOST('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 = GETPOST('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 = 'transfert';
374 }
375 if (!GETPOST("nbpiece")) {
376 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
377 $error++;
378 $action = 'transfert';
379 }
380 if (GETPOSTINT("id_entrepot") == GETPOSTINT("id_entrepot_destination")) {
381 setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
382 $error++;
383 $action = 'transfert';
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 = 'transfert';
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 = 'transfert';
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
546$variants = false;
547if ($id > 0 || $ref) {
548 $object = new Product($db);
549 $result = $object->fetch($id, $ref);
550
551 $variants = $object->hasVariants();
552
553 $object->load_stock(); // This include the load_virtual_stock()
554
555 $title = $langs->trans('ProductServiceCard');
556 $helpurl = '';
557 $shortlabel = dol_trunc($object->label, 16);
558 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
559 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock');
560 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
561 }
562 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
563 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock');
564 $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
565 }
566
567 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-card_stock_product');
568
569 if (!empty($conf->use_javascript_ajax)) {
570 ?>
571 <script type="text/javascript">
572 $(document).ready(function() {
573 $(".collapse_batch").click(function() {
574 console.log("We click on collapse_batch");
575 var id_entrepot = $(this).attr('id').replace('ent', '');
576
577 if($(this).text().indexOf('+') > 0) {
578 $(".batch_warehouse" + id_entrepot).show();
579 $(this).html('(-)');
580 jQuery("#show_all").hide();
581 jQuery("#hide_all").show();
582 }
583 else {
584 $(".batch_warehouse" + id_entrepot).hide();
585 $(this).html('(+)');
586 }
587
588 return false;
589 });
590
591 $("#show_all").click(function() {
592 console.log("We click on show_all");
593 $("[class^=batch_warehouse]").show();
594 $("[class^=collapse_batch]").html('(-)');
595 jQuery("#show_all").hide();
596 jQuery("#hide_all").show();
597 return false;
598 });
599
600 $("#hide_all").click(function() {
601 console.log("We click on hide_all");
602 $("[class^=batch_warehouse]").hide();
603 $("[class^=collapse_batch]").html('(+)');
604 jQuery("#hide_all").hide();
605 jQuery("#show_all").show();
606 return false;
607 });
608
609 });
610 </script>
611 <?php
612 }
613
614 if ($result > 0) {
616 $titre = $langs->trans("CardProduct".$object->type);
617 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
618
619 print dol_get_fiche_head($head, 'stock', $titre, -1, $picto);
620
622
623 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
624 $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")";
625
626 $shownav = 1;
627 if ($user->socid && !in_array('stock', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
628 $shownav = 0;
629 }
630
631 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
632
633 if (!$variants) {
634 print '<div class="fichecenter">';
635
636 print '<div class="fichehalfleft">';
637 print '<div class="underbanner clearboth"></div>';
638
639 print '<table class="border tableforfield centpercent">';
640
641 // Type
642 if (isModEnabled("product") && isModEnabled("service")) {
643 $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
644 print '<tr><td class="">';
645 print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', (string) $object->type, $object, 0, $typeformat) : $langs->trans('Type');
646 print '</td><td>';
647 print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
648 print '</td></tr>';
649 }
650
651 if (isModEnabled('productbatch')) {
652 print '<tr><td class="">'.$langs->trans("ManageLotSerial").'</td><td>';
653 print $object->getLibStatut(0, 2);
654 print '</td></tr>';
655 }
656
657 // Cost price. Can be used for margin module for option "calculate margin on explicit cost price
658 print '<tr><td>';
659 $textdesc = $langs->trans("CostPriceDescription");
660 $textdesc .= "<br>".$langs->trans("CostPriceUsage");
661 $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', '');
662 if (!$usercancreadsupplierprice) {
663 print $form->editfieldkey($text, 'cost_price', '', $object, 0, 'amount:6');
664 print '</td><td>';
665 print $form->editfieldval($text, 'cost_price', '', $object, 0, 'amount:6');
666 } else {
667 print $form->editfieldkey($text, 'cost_price', (string) $object->cost_price, $object, (int) $usercancreate, 'amount:6');
668 print '</td><td>';
669 print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
670 }
671 print '</td></tr>';
672
673
674
675 // AWP
676 print '<tr><td class="titlefieldmiddle">';
677 print $form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc"));
678 print '</td>';
679 print '<td>';
680 if ($object->pmp > 0 && $usercancreadsupplierprice) {
681 print price($object->pmp).' '.$langs->trans("HT");
682 }
683 print '</td>';
684 print '</tr>';
685
686 // Minimum Price
687 print '<tr><td>'.$langs->trans("BuyingPriceMin").'</td>';
688 print '<td>';
689 $product_fourn = new ProductFournisseur($db);
690 if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) {
691 if ($product_fourn->product_fourn_price_id > 0 && $usercancreadsupplierprice) {
692 print $product_fourn->display_price_product_fournisseur();
693 } else {
694 print $langs->trans("NotDefined");
695 }
696 }
697 print '</td></tr>';
698
699 if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
700 // Price
701 print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
702 if ($usercancreadprice) {
703 if ($object->price_base_type == 'TTC') {
704 print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
705 } else {
706 print price($object->price).' '.$langs->trans($object->price_base_type);
707 }
708 }
709 print '</td></tr>';
710
711 // Price minimum
712 print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
713 if ($usercancreadprice) {
714 if ($object->price_base_type == 'TTC') {
715 print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
716 } else {
717 print price($object->price_min).' '.$langs->trans($object->price_base_type);
718 }
719 }
720 print '</td></tr>';
721 } else {
722 // Price
723 print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
724 print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
725 print '</td></tr>';
726
727 // Price minimum
728 print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
729 print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
730 print '</td></tr>';
731 }
732
733 // Hook formObject
734 $parameters = array();
735 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
736 print $hookmanager->resPrint;
737
738 print '</table>';
739
740 print '</div>';
741 print '<div class="fichehalfright"><div class="underbanner clearboth"></div>';
742
743 print '<table class="border tableforfield centpercent">';
744
745 // Stock alert threshold
746 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>';
747 print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->hasRight('produit', 'creer'), 'string');
748 print '</td></tr>';
749
750 // Desired stock
751 print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', (string) $object->desiredstock, $object, $user->hasRight('produit', 'creer'));
752 print '</td><td>';
753 print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->hasRight('produit', 'creer'), 'string');
754 print '</td></tr>';
755
756 // Real stock
757 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
758 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
759 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
760 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
761 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
762 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
763 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
764 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
765 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
766 $parameters = array();
767 $reshook = $hookmanager->executeHooks('physicalStockTextStockOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
768 if ($reshook > 0) {
769 $text_stock_options = $hookmanager->resPrint;
770 } elseif ($reshook == 0) {
771 $text_stock_options .= $hookmanager->resPrint;
772 } else {
773 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
774 }
775
776 print '<tr><td>';
777 print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1);
778 print '</td>';
779 print '<td>'.price2num($object->stock_reel, 'MS');
780 if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) {
781 print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
782 }
783
784 print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?productid='.$object->id.'">'.$langs->trans("StockAtDate").'</a>';
785 print '</td>';
786 print '</tr>';
787
788 $stocktheo = price2num($object->stock_theorique, 'MS');
789
790 $found = 0;
791 $helpondiff = '<strong>'.$langs->trans("StockDiffPhysicTeoric").':</strong><br>';
792 // Number of sales orders running
793 if (isModEnabled('order')) {
794 if ($found) {
795 $helpondiff .= '<br>';
796 } else {
797 $found = 1;
798 }
799 $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty'];
800 $result = $object->load_stats_commande(0, '0', 1);
801 if ($result < 0) {
802 dol_print_error($db, $object->error);
803 }
804 $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')</span>';
805 }
806
807 // Number of product from sales order already sent (partial shipping)
808 if (isModEnabled("shipping")) {
809 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
810 $filterShipmentStatus = '';
811 if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
813 } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
814 $filterShipmentStatus = Expedition::STATUS_CLOSED;
815 }
816 if ($found) {
817 $helpondiff .= '<br>';
818 } else {
819 $found = 1;
820 }
821 $result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus);
822 $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty'];
823 }
824
825 // Number of supplier order running
826 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
827 if ($found) {
828 $helpondiff .= '<br>';
829 } else {
830 $found = 1;
831 }
832 $result = $object->load_stats_commande_fournisseur(0, '3,4', 1);
833 $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty'];
834 $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1);
835 if ($result < 0) {
836 dol_print_error($db, $object->error);
837 }
838 $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')</span>';
839 }
840
841 // Number of product from supplier order already received (partial receipt)
842 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
843 if ($found) {
844 $helpondiff .= '<br>';
845 } else {
846 $found = 1;
847 }
848 $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty'];
849 }
850
851 // Number of product in production
852 if (isModEnabled('mrp')) {
853 if ($found) {
854 $helpondiff .= '<br>';
855 } else {
856 $found = 1;
857 }
858 $helpondiff .= $langs->trans("ProductQtyToConsumeByMO").': '.$object->stats_mrptoconsume['qty'].'<br>';
859 $helpondiff .= $langs->trans("ProductQtyToProduceByMO").': '.$object->stats_mrptoproduce['qty'];
860 }
861 $parameters = array('found' => &$found, 'id' => $object->id, 'includedraftpoforvirtual' => null);
862 $reshook = $hookmanager->executeHooks('virtualStockHelpOnDiff', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
863 if ($reshook > 0) {
864 $helpondiff = $hookmanager->resPrint;
865 } elseif ($reshook == 0) {
866 $helpondiff .= $hookmanager->resPrint;
867 } else {
868 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
869 }
870
871
872 // Calculating a theoretical value
873 print '<tr><td>';
874 print $form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc"));
875 print '</td>';
876 print "<td>";
877 //print (empty($stocktheo)?0:$stocktheo);
878 print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff);
879 if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) {
880 print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
881 }
882 print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?mode=future&productid='.$object->id.'">'.$langs->trans("VirtualStockAtDate").'</a>';
883 print '</td>';
884 print '</tr>';
885
886 // Last movement
887 if ($user->hasRight('stock', 'mouvement', 'lire')) {
888 $sql = "SELECT max(m.datem) as datem";
889 $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
890 $sql .= " WHERE m.fk_product = ".((int) $object->id);
891 $lastmovementdate = 0;
892 $resqlbis = $db->query($sql);
893 if ($resqlbis) {
894 $obj = $db->fetch_object($resqlbis);
895 $lastmovementdate = $db->jdate($obj->datem);
896 } else {
897 dol_print_error($db);
898 }
899 print '<tr><td class="tdtop">'.$langs->trans("LastMovement").'</td><td>';
900 if ($lastmovementdate) {
901 print dol_print_date($lastmovementdate, 'dayhour').' ';
902 print ' &nbsp; &nbsp; ';
903 print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
904 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("FullList").'</a>';
905 } else {
906 print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
907 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("None").'</a>';
908 }
909 print "</td></tr>";
910 }
911
912 print "</table>";
913
914 print '</div>';
915 print '</div>';
916
917 print '<div class="clearboth"></div>';
918 }
919
920 print dol_get_fiche_end();
921 }
922
923 // Correct stock
924 if ($action == "correction") {
925 include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
926 print '<br><br>';
927 }
928
929 // Transfer of units
930 if ($action == "transfert") {
931 include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
932 print '<br><br>';
933 }
934} else {
936}
937
938
939// Actions buttons
940
941$parameters = array();
942
943$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
944if (empty($reshook)) {
945 if (empty($action) && $object->id) {
946 print "<div class=\"tabsAction\">\n";
947
948 if ($user->hasRight('stock', 'mouvement', 'creer')) {
949 if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
950 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=transfert&token='.newToken().'">'.$langs->trans("TransferStock").'</a>';
951 } else {
952 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("TransferStock").'</a>';
953 }
954 } else {
955 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("TransferStock").'</a>';
956 }
957
958 if ($user->hasRight('stock', 'mouvement', 'creer')) {
959 if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
960 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=correction&token='.newToken().'">'.$langs->trans("CorrectStock").'</a>';
961 } else {
962 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("CorrectStock").'</a>';
963 }
964 } else {
965 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
966 }
967
968 print '</div>';
969 }
970}
971
972
973if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) {
974 /*
975 * Stock detail (by warehouse). May go down into batch details.
976 */
977
978 print '<div class="div-table-responsive">';
979 print '<table class="noborder centpercent">';
980
981 print '<tr class="liste_titre">';
982 print '<td colspan="4">'.$langs->trans("Warehouse").'</td>';
983 print '<td class="right">'.$langs->trans("NumberOfUnit").'</td>';
984 print '<td class="right">'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).'</td>';
985 print '<td class="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
986 print '<td class="right">'.$langs->trans("SellPriceMin").'</td>';
987 print '<td class="right">'.$langs->trans("EstimatedStockValueSellShort").'</td>';
988 print '<td></td>';
989 print '<td></td>';
990 print '</tr>';
991
992 if ((isModEnabled('productbatch')) && $object->hasbatch()) {
993 $colspan = 3;
994 print '<tr class="liste_titre"><td class="minwidth200">';
995 if (!empty($conf->use_javascript_ajax)) {
996 print '<a id="show_all" href="#" class="hideobject">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ShowAllLots").'</a>';
997 //print ' &nbsp; ';
998 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("HideLots").'</a>';
999 //print '&nbsp;'.$form->textwithpicto('', $langs->trans('CollapseBatchDetailHelp'), 1, 'help', '');
1000 }
1001 print '</td>';
1002 print '<td class="right">'.$langs->trans("batch_number").'</td>';
1003 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1004 $colspan--;
1005 print '<td class="center width100">'.$langs->trans("SellByDate").'</td>';
1006 }
1007 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1008 $colspan--;
1009 print '<td class="center width100">'.$langs->trans("EatByDate").'</td>';
1010 }
1011 print '<td colspan="'.$colspan.'"></td>';
1012 print '<td></td>';
1013 print '<td></td>';
1014 print '<td></td>';
1015 print '<td></td>';
1016 print '<td></td>';
1017 print '<td></td>';
1018 print '</tr>';
1019 }
1020
1021 $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";
1022 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
1023 $sql .= " ".MAIN_DB_PREFIX."product_stock as ps";
1024 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product";
1025 $sql .= " WHERE ps.reel != 0";
1026 $sql .= " AND ps.fk_entrepot = e.rowid";
1027 $sql .= " AND e.entity IN (".getEntity('stock').")";
1028 $sql .= " AND ps.fk_product = ".((int) $object->id);
1029 $sql .= " ORDER BY e.ref";
1030
1031 $entrepotstatic = new Entrepot($db);
1032 $product_lot_static = new Productlot($db);
1033
1034 $num = 0;
1035 $total = 0;
1036 $totalvalue = $totalvaluesell = 0;
1037 $totalwithpmp = 0;
1038
1039 $resql = $db->query($sql);
1040 if ($resql) {
1041 $num = $db->num_rows($resql);
1042 $total = $totalwithpmp;
1043 $i = 0;
1044 $var = false;
1045 while ($i < $num) {
1046 $obj = $db->fetch_object($resql);
1047
1048 $entrepotstatic->id = $obj->rowid;
1049 $entrepotstatic->ref = $obj->ref;
1050 $entrepotstatic->label = $obj->ref;
1051 $entrepotstatic->lieu = $obj->lieu;
1052 $entrepotstatic->fk_parent = $obj->fk_parent;
1053 $entrepotstatic->statut = $obj->status;
1054 $entrepotstatic->status = $obj->status;
1055
1056 $stock_real = price2num($obj->reel, 'MS');
1057 print '<tr class="oddeven">';
1058
1059 // Warehouse
1060 print '<td colspan="4">';
1061 print $entrepotstatic->getNomUrl(1);
1062 if (!empty($conf->use_javascript_ajax) && isModEnabled('productbatch') && $object->hasbatch()) {
1063 print '<a class="collapse_batch marginleftonly" id="ent' . $entrepotstatic->id . '" href="#">';
1064 print(!getDolGlobalString('STOCK_SHOW_ALL_BATCH_BY_DEFAULT') ? '(+)' : '(-)');
1065 print '</a>';
1066 }
1067 print '</td>';
1068
1069 print '<td class="right">'.$stock_real.($stock_real < 0 ? ' '.img_warning() : '').'</td>';
1070
1071 // PMP
1072 print '<td class="right nowraponall">'.(price2num($object->pmp) ? price2num($object->pmp, 'MU') : '').'</td>';
1073
1074 // Value purchase
1075 if ($usercancreadsupplierprice) {
1076 print '<td class="right amount nowraponall">'.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').'</td>';
1077 } else {
1078 print '<td class="right amount nowraponall"></td>';
1079 }
1080
1081 // Sell price
1082 $minsellprice = null;
1083 $maxsellprice = null;
1084 print '<td class="right nowraponall">';
1085 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1086 foreach ($object->multiprices as $priceforlevel) {
1087 if (is_numeric($priceforlevel)) {
1088 if (is_null($maxsellprice) || $priceforlevel > $maxsellprice) {
1089 $maxsellprice = $priceforlevel;
1090 }
1091 if (is_null($minsellprice) || $priceforlevel < $minsellprice) {
1092 $minsellprice = $priceforlevel;
1093 }
1094 }
1095 }
1096 print '<span class="valignmiddle">';
1097 if ($usercancreadprice) {
1098 if ($minsellprice != $maxsellprice) {
1099 print price(price2num($minsellprice, 'MU'), 1).' - '.price(price2num($maxsellprice, 'MU'), 1);
1100 } else {
1101 print price(price2num($minsellprice, 'MU'), 1);
1102 }
1103 }
1104 print '</span>';
1105 print $form->textwithpicto('', $langs->trans("Variable"));
1106 } elseif ($usercancreadprice) {
1107 print price(price2num($object->price, 'MU'), 1);
1108 }
1109 print '</td>';
1110
1111 // Value sell
1112 print '<td class="right amount nowraponall">';
1113 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1114 print '<span class="valignmiddle">';
1115 if ($usercancreadprice) {
1116 if ($minsellprice != $maxsellprice) {
1117 print price(price2num($minsellprice * $obj->reel, 'MT'), 1).' - '.price(price2num($maxsellprice * $obj->reel, 'MT'), 1);
1118 } else {
1119 print price(price2num($minsellprice * $obj->reel, 'MT'), 1);
1120 }
1121 }
1122 print '</span>';
1123 print $form->textwithpicto('', $langs->trans("Variable"));
1124 } else {
1125 if ($usercancreadprice) {
1126 print price(price2num($object->price * $obj->reel, 'MT'), 1);
1127 }
1128 }
1129 print '</td>';
1130 print '<td></td>';
1131 print '<td></td>';
1132 print '</tr>';
1133 $total += $obj->reel;
1134 if (price2num($object->pmp)) {
1135 $totalwithpmp += $obj->reel;
1136 }
1137 $totalvalue += ($object->pmp * $obj->reel);
1138 $totalvaluesell += ($object->price * $obj->reel);
1139 // Batch Detail
1140 if ((isModEnabled('productbatch')) && $object->hasbatch()) {
1141 $details = Productbatch::findAll($db, $obj->product_stock_id, 0, $object->id);
1142 if ($details < 0) {
1143 dol_print_error($db);
1144 }
1145 foreach ($details as $pdluo) {
1146 $product_lot_static->id = $pdluo->lotid;
1147 $product_lot_static->batch = $pdluo->batch;
1148 $product_lot_static->eatby = $pdluo->eatby;
1149 $product_lot_static->sellby = $pdluo->sellby;
1150
1151 if ($action == 'editline' && GETPOSTINT('lineid') == $pdluo->id) { //Current line edit
1152 print "\n".'<tr>';
1153 print '<td colspan="9">';
1154 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1155 print '<input type="hidden" name="token" value="'.newToken().'">';
1156 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>';
1157 print '<td class="right" width="10%"><input type="text" name="batch_number" value="'.$pdluo->batch.'"></td>';
1158 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1159 print '<td class="center" width="10%">';
1160 print $form->selectDate($pdluo->sellby, 'sellby', 0, 0, 1, '', 1, 0);
1161 print '</td>';
1162 }
1163 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1164 print '<td class="center" width="10%">';
1165 print $form->selectDate($pdluo->eatby, 'eatby', 0, 0, 1, '', 1, 0);
1166 print '</td>';
1167 }
1168 print '<td class="right" colspan="3">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
1169 print '<td colspan="4"><input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'">';
1170 print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="Cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
1171 print '</table>';
1172 print '</form>';
1173 print '</td>';
1174 print '<td></td>';
1175 print '<td></td>';
1176 print '</tr>';
1177 } else {
1178 print "\n".'<tr style="display:'.(!getDolGlobalString('STOCK_SHOW_ALL_BATCH_BY_DEFAULT') ? 'none' : 'visible').';" class="batch_warehouse'.$entrepotstatic->id.'"><td class="left">';
1179 print '</td>';
1180 print '<td class="right nowraponall">';
1181 if ($product_lot_static->id > 0) {
1182 print $product_lot_static->getNomUrl(1);
1183 } else {
1184 print $product_lot_static->getNomUrl(1, 'nolink');
1185 }
1186 print '</td>';
1187 $colspan = 3;
1188 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1189 $colspan--;
1190 print '<td class="center">'.dol_print_date($pdluo->sellby, 'day').'</td>';
1191 }
1192 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1193 $colspan--;
1194 print '<td class="center">'.dol_print_date($pdluo->eatby, 'day').'</td>';
1195 }
1196 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>';
1197 print '<td colspan="4"></td>';
1198 print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("TransferStock")).'">';
1199 if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
1200 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&id_entrepot='.$entrepotstatic->id.'&action=transfert&pdluoid='.$pdluo->id.'&token='.newToken().'">';
1201 print img_picto($langs->trans("TransferStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
1202 print $langs->trans("TransferStock");
1203 print '</a>';
1204 // Disabled, because edition of stock content must use the "Correct stock menu".
1205 // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
1206 //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
1207 //print img_edit().'</a>';
1208 }
1209 print '</td>';
1210 print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("CorrectStock")).'">';
1211 if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
1212 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&id_entrepot='.$entrepotstatic->id.'&action=correction&pdluoid='.$pdluo->id.'&token='.newToken().'">';
1213 print img_picto($langs->trans("CorrectStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
1214 print $langs->trans("CorrectStock");
1215 print '</a>';
1216 // Disabled, because edition of stock content must use the "Correct stock menu".
1217 // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
1218 //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
1219 //print img_edit().'</a>';
1220 }
1221 print '</td>';
1222 print '</tr>';
1223 }
1224 }
1225 }
1226 $i++;
1227 }
1228 } else {
1229 dol_print_error($db);
1230 }
1231
1232 // Total line
1233 print '<tr class="liste_total"><td class="right liste_total" colspan="4">'.$langs->trans("Total").':</td>';
1234 print '<td class="liste_total right">'.price2num($total, 'MS').'</td>';
1235 print '<td class="liste_total right">';
1236 if ($usercancreadsupplierprice) {
1237 print($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : '&nbsp;'); // This value may have rounding errors
1238 }
1239 print '</td>';
1240 // Value purchase
1241 print '<td class="liste_total right">';
1242 if ($usercancreadsupplierprice) {
1243 print $totalvalue ? price(price2num($totalvalue, 'MT'), 1) : '&nbsp;';
1244 }
1245 print '</td>';
1246 print '<td class="liste_total right">';
1247 if ($num) {
1248 if ($total) {
1249 print '<span class="valignmiddle">';
1250 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1251 print $form->textwithpicto('', $langs->trans("Variable"));
1252 } elseif ($usercancreadprice) {
1253 print price($totalvaluesell / $total, 1);
1254 }
1255 print '</span>';
1256 }
1257 }
1258 print '</td>';
1259 // Value to sell
1260 print '<td class="liste_total right amount">';
1261 if ($num) {
1262 print '<span class="valignmiddle">';
1263 if (!getDolGlobalString('PRODUIT_MULTIPRICES') && $usercancreadprice) {
1264 print price(price2num($totalvaluesell, 'MT'), 1);
1265 } else {
1266 print $form->textwithpicto('', $langs->trans("Variable"));
1267 }
1268 print '</span>';
1269 }
1270 print '</td>';
1271 print '<td></td>';
1272 print '<td></td>';
1273 print "</tr>";
1274
1275 print "</table>";
1276 print '</div>';
1277
1278 if (getDolGlobalString('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE')) {
1279 print '<br><br>';
1280 print load_fiche_titre($langs->trans('AddNewProductStockWarehouse'));
1281
1282 if ($user->hasRight('produit', 'creer')) {
1283 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1284 print '<input type="hidden" name="token" value="'.newToken().'">';
1285 print '<input type="hidden" name="action" value="addlimitstockwarehouse">';
1286 print '<input type="hidden" name="id" value="'.$id.'">';
1287 }
1288 print '<table class="noborder centpercent">';
1289 if ($user->hasRight('produit', 'creer')) {
1290 print '<tr class="liste_titre"><td>'.$formproduct->selectWarehouses('', 'fk_entrepot').'</td>';
1291 print '<td class="right"><input name="seuil_stock_alerte" type="text" placeholder="'.$langs->trans("StockLimit").'" /></td>';
1292 print '<td class="right"><input name="desiredstock" type="text" placeholder="'.$langs->trans("DesiredStock").'" /></td>';
1293 print '<td class="right"><input type="submit" value="'.$langs->trans("Save").'" class="button button-save" /></td>';
1294 print '</tr>';
1295 } else {
1296 print '<tr class="liste_titre"><td>'.$langs->trans("Warehouse").'</td>';
1297 print '<td class="right">'.$langs->trans("StockLimit").'</td>';
1298 print '<td class="right">'.$langs->trans("DesiredStock").'</td>';
1299 print '</tr>';
1300 }
1301
1302 $pse = new ProductStockEntrepot($db);
1303 $lines = $pse->fetchAll($id);
1304
1305 $visibleWarehouseEntities = explode(',', getEntity('stock')); // For MultiCompany compatibility
1306
1307 if (!empty($lines)) {
1308 $var = false;
1309 foreach ($lines as $line) {
1310 $ent = new Entrepot($db);
1311 $ent->fetch($line['fk_entrepot']);
1312
1313 if (!isModEnabled("multicompany") || in_array($ent->entity, $visibleWarehouseEntities)) {
1314 // Display only warehouses from our entity and entities sharing stock with actual entity
1315 print '<tr class="oddeven"><td>'.$ent->getNomUrl(3).'</td>';
1316 print '<td class="right">'.$line['seuil_stock_alerte'].'</td>';
1317 print '<td class="right">'.$line['desiredstock'].'</td>';
1318 if ($user->hasRight('produit', 'creer')) {
1319 print '<td class="right"><a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&fk_productstockwarehouse='.$line['id'].'&action=delete_productstockwarehouse&token='.newToken().'">'.img_delete().'</a></td>';
1320 }
1321 print '</tr>';
1322 }
1323 }
1324 }
1325
1326 print "</table>";
1327
1328 if ($user->hasRight('produit', 'creer')) {
1329 print '</form>';
1330 }
1331 }
1332} else {
1333 // List of variants
1334 include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
1335 include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
1336 $prodstatic = new Product($db);
1337 $prodcomb = new ProductCombination($db);
1338 $comb2val = new ProductCombination2ValuePair($db);
1339 $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id);
1340
1341 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1342 print '<input type="hidden" name="token" value="'.newToken().'">';
1343 print '<input type="hidden" name="action" value="massaction">';
1344 print '<input type="hidden" name="id" value="'.$id.'">';
1345 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1346
1347 // load variants
1348 $title = $langs->trans("ProductCombinations");
1349
1350 print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0);
1351
1352 print '<div class="div-table-responsive">'; ?>
1353 <table class="liste">
1354 <tr class="liste_titre">
1355 <td class="liste_titre"><?php echo $langs->trans('Product') ?></td>
1356 <td class="liste_titre"><?php echo $langs->trans('Combination') ?></td>
1357 <td class="liste_titre center"><?php echo $langs->trans('OnSell') ?></td>
1358 <td class="liste_titre center"><?php echo $langs->trans('OnBuy') ?></td>
1359 <td class="liste_titre right"><?php echo $langs->trans('Stock') ?></td>
1360 <td class="liste_titre"></td>
1361 </tr>
1362 <?php
1363
1364 if (count($productCombinations)) {
1365 $stock_total = 0;
1366 foreach ($productCombinations as $currcomb) {
1367 $prodstatic->fetch($currcomb->fk_product_child);
1368 $prodstatic->load_stock();
1369 $stock_total += $prodstatic->stock_reel; ?>
1370 <tr class="oddeven">
1371 <td><?php echo $prodstatic->getNomUrl(1) ?></td>
1372 <td>
1373 <?php
1374
1375 $productCombination2ValuePairs = $comb2val->fetchByFkCombination($currcomb->id);
1376 $iMax = count($productCombination2ValuePairs);
1377
1378 for ($i = 0; $i < $iMax; $i++) {
1379 echo dol_htmlentities($productCombination2ValuePairs[$i]);
1380
1381 if ($i !== ($iMax - 1)) {
1382 echo ', ';
1383 }
1384 } ?>
1385 </td>
1386 <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 0) ?></td>
1387 <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 1) ?></td>
1388 <td class="right"><?php echo $prodstatic->stock_reel ?></td>
1389 <td class="right">
1390 <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>
1391 </td>
1392 <?php
1393 ?>
1394 </tr>
1395 <?php
1396 }
1397
1398 print '<tr class="liste_total">';
1399 print '<td colspan="4" class="left">'.$langs->trans("Total").'</td>';
1400 print '<td class="right">'.$stock_total.'</td>';
1401 print '<td></td>';
1402 print '</tr>';
1403 } else {
1404 print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1405 } ?>
1406 </table>
1407
1408 <?php
1409 print '</div>';
1410
1411 print '</form>';
1412}
1413
1414// End of page
1415llxFooter();
1416$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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
Definition repair.php:158
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.