* Copyright (C) 2004-2020 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2013-2018 Juanjo Menent * Copyright (C) 2014-2015 Cédric Gross * Copyright (C) 2015 Marcos García * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/product/stock/product.php * \ingroup product stock * \brief Page to list detailed stock of a product */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; if (isModEnabled('productbatch')) { require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; } if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } if (isModEnabled('variants')) { require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; } /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadlangs(array('products', 'suppliers', 'orders', 'bills', 'stocks', 'sendings', 'margins')); if (isModEnabled('productbatch')) { $langs->load("productbatch"); } $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); $id = GETPOSTINT('id'); $ref = GETPOST('ref', 'alpha'); $stocklimit = GETPOSTFLOAT('seuil_stock_alerte'); $desiredstock = GETPOSTFLOAT('desiredstock'); $cancel = GETPOST('cancel', 'alpha'); $fieldid = GETPOSTISSET("ref") ? 'ref' : 'rowid'; $d_eatby = dol_mktime(0, 0, 0, GETPOSTINT('eatbymonth'), GETPOSTINT('eatbyday'), GETPOSTINT('eatbyyear')); $d_sellby = dol_mktime(0, 0, 0, GETPOSTINT('sellbymonth'), GETPOSTINT('sellbyday'), GETPOSTINT('sellbyyear')); $pdluoid = GETPOSTINT('pdluoid'); $batchnumber = GETPOST('batch_number', 'san_alpha'); if (!empty($batchnumber)) { $batchnumber = trim($batchnumber); } $cost_price = GETPOST('cost_price', 'alpha'); // Security check if ($user->socid) { $socid = $user->socid; } $object = new Product($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); } if (empty($id) && !empty($object->id)) { $id = $object->id; } $modulepart = 'product'; // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas"); $objcanvas = null; if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('stockproduct', 'card', $canvas); } // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('stockproductcard', 'globalcard')); $error = 0; $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'lire')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'lire'))); $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer'))); $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_prices') : $user->hasRight('product', 'lire'); $usercanupdatestock = $user->hasRight('stock', 'mouvement', 'creer'); if ($object->isService()) { $label = $langs->trans('Service'); $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_prices') : $user->hasRight('service', 'lire'); } if ($object->id > 0) { if ($object->type == $object::TYPE_PRODUCT) { restrictedArea($user, 'produit', $object->id, 'product&product', '', ''); } if ($object->type == $object::TYPE_SERVICE) { restrictedArea($user, 'service', $object->id, 'product&product', '', ''); } } else { restrictedArea($user, 'produit|service', $id, 'product&product', '', '', $fieldid); } /* * Actions */ if ($cancel) { $action = ''; } $parameters = array('id' => $id, 'ref' => $ref, 'objcanvas' => $objcanvas); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if ($action == 'setcost_price' && $usercancreate) { if ($id) { $result = $object->fetch($id); $object->cost_price = (float) price2num($cost_price); $result = $object->update($object->id, $user); if ($result > 0) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $action = ''; } else { $error++; setEventMessages($object->error, $object->errors, 'errors'); } } } if ($action == 'addlimitstockwarehouse' && $usercancreate) { $seuil_stock_alerte = GETPOST('seuil_stock_alerte'); $desiredstock = GETPOST('desiredstock'); $maj_ok = true; if ($seuil_stock_alerte == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors'); $maj_ok = false; } if ($desiredstock == '' || is_array($desiredstock)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors'); $maj_ok = false; } $desiredstock = (float) $desiredstock; if ($maj_ok) { $pse = new ProductStockEntrepot($db); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition if ($pse->fetch(0, $id, GETPOSTINT('fk_entrepot')) > 0) { // Update $pse->seuil_stock_alerte = $seuil_stock_alerte; $pse->desiredstock = $desiredstock; if ($pse->update($user) > 0) { setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs'); } } else { // Create $pse->fk_entrepot = GETPOSTINT('fk_entrepot'); $pse->fk_product = $id; $pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); $pse->desiredstock = GETPOSTFLOAT('desiredstock'); if ($pse->create($user) > 0) { setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs'); } } } header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } if ($action == 'delete_productstockwarehouse' && $usercancreate) { $pse = new ProductStockEntrepot($db); $pse->fetch(GETPOSTINT('fk_productstockwarehouse')); if ($pse->delete($user) > 0) { setEventMessages($langs->trans('ProductStockWarehouseDeleted'), null, 'mesgs'); } $action = ''; } // Set stock limit if ($action == 'setseuil_stock_alerte' && $usercancreate) { $object = new Product($db); $result = $object->fetch($id); $object->seuil_stock_alerte = $stocklimit; $result = $object->update($object->id, $user, 0, 'update'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } //else // setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs'); $action = ''; } // Set desired stock if ($action == 'setdesiredstock' && $usercancreate) { $object = new Product($db); $result = $object->fetch($id); $object->desiredstock = $desiredstock; $result = $object->update($object->id, $user, 0, 'update'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; } // Correct stock if ($action == "correct_stock" && !$cancel && $usercanupdatestock) { if (!(GETPOSTINT("id_entrepot") > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'correction'; } if (!GETPOST("nbpiece")) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'correction'; } if (isModEnabled('productbatch')) { $object = new Product($db); $result = $object->fetch($id); if ($object->hasbatch() && !$batchnumber) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'correction'; } } if (!$error) { $priceunit = price2num(GETPOST("unitprice")); $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml')); if (is_numeric($nbpiece) && $nbpiece != 0 && $id) { $origin_element = ''; $origin_id = null; if (GETPOSTINT('projectid')) { $origin_element = 'project'; $origin_id = GETPOSTINT('projectid'); } if (empty($object)) { $object = new Product($db); $result = $object->fetch($id); } $disablestockchangeforsubproduct = 0; if (GETPOST('disablesubproductstockchange')) { $disablestockchangeforsubproduct = 1; } if ($object->hasbatch()) { $result = $object->correct_stock_batch( $user, GETPOSTINT("id_entrepot"), $nbpiece, GETPOSTINT("mouvement"), GETPOST("label", 'alphanohtml'), // label movement $priceunit, $d_eatby, $d_sellby, $batchnumber, GETPOST('inventorycode', 'alphanohtml'), $origin_element, $origin_id, $disablestockchangeforsubproduct ); // We do not change value of stock for a correction } else { $result = $object->correct_stock( $user, GETPOSTINT("id_entrepot"), $nbpiece, GETPOSTINT("mouvement"), GETPOST("label", 'alphanohtml'), $priceunit, GETPOST('inventorycode', 'alphanohtml'), $origin_element, $origin_id, $disablestockchangeforsubproduct ); // We do not change value of stock for a correction } if ($result > 0) { if ($backtopage) { header("Location: ".$backtopage); exit; } else { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } } else { setEventMessages($object->error, $object->errors, 'errors'); $action = 'correction'; } } } } // Transfer stock from a warehouse to another warehouse if ($action == "transfert_stock" && !$cancel && $usercanupdatestock) { if (!(GETPOSTINT("id_entrepot") > 0) || !(GETPOSTINT("id_entrepot_destination") > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'transfert'; } if (!GETPOSTINT("nbpiece")) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'transfert'; } if (GETPOSTINT("id_entrepot") == GETPOSTINT("id_entrepot_destination")) { setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); $error++; $action = 'transfert'; } if (isModEnabled('productbatch')) { $object = new Product($db); $result = $object->fetch($id); if ($object->hasbatch() && !$batchnumber) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'transfert'; } } if (!$error) { if ($id) { $object = new Product($db); $result = $object->fetch($id); $db->begin(); $object->load_stock('novirtual'); // Load array product->stock_warehouse // Define value of products moved $pricesrc = 0; if (isset($object->pmp)) { $pricesrc = $object->pmp; } $pricedest = $pricesrc; $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml')); if ($object->hasbatch()) { $pdluo = new Productbatch($db); if ($pdluoid > 0) { $result = $pdluo->fetch($pdluoid); if ($result) { $srcwarehouseid = $pdluo->warehouseid; $batch = $pdluo->batch; $eatby = $pdluo->eatby; $sellby = $pdluo->sellby; } else { setEventMessages($pdluo->error, $pdluo->errors, 'errors'); $error++; } } else { $srcwarehouseid = GETPOSTINT('id_entrepot'); $batch = $batchnumber; $eatby = $d_eatby; $sellby = $d_sellby; } $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml')); if (!$error) { // Remove stock $result1 = $object->correct_stock_batch( $user, $srcwarehouseid, $nbpiece, 1, GETPOST("label", 'alphanohtml'), $pricesrc, $eatby, $sellby, $batch, GETPOST('inventorycode', 'alphanohtml') ); if ($result1 < 0) { $error++; } } if (!$error) { // Add stock $result2 = $object->correct_stock_batch( $user, GETPOSTINT("id_entrepot_destination"), $nbpiece, 0, GETPOST("label", 'alphanohtml'), $pricedest, $eatby, $sellby, $batch, GETPOST('inventorycode', 'alphanohtml') ); if ($result2 < 0) { $error++; } } } else { if (!$error) { // Remove stock $result1 = $object->correct_stock( $user, GETPOSTINT("id_entrepot"), $nbpiece, 1, GETPOST("label", 'alphanohtml'), $pricesrc, GETPOST('inventorycode', 'alphanohtml') ); if ($result1 < 0) { $error++; } } if (!$error) { // Add stock $result2 = $object->correct_stock( $user, GETPOSTINT("id_entrepot_destination"), $nbpiece, 0, GETPOST("label", 'alphanohtml'), $pricedest, GETPOST('inventorycode', 'alphanohtml') ); if ($result2 < 0) { $error++; } } } if (!$error && $result1 >= 0 && $result2 >= 0) { $db->commit(); if ($backtopage) { header("Location: ".$backtopage); exit; } else { header("Location: product.php?id=".$object->id); exit; } } else { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); $action = 'transfert'; } } } } // Update batch information if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save") && $usercancreate) { $pdluo = new Productbatch($db); $result = $pdluo->fetch(GETPOSTINT('pdluoid')); if ($result > 0) { if ($pdluo->id) { if ((!GETPOST("sellby")) && (!GETPOST("eatby")) && (!$batchnumber)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), null, 'errors'); } else { $d_eatby = dol_mktime(0, 0, 0, GETPOSTINT('eatbymonth'), GETPOSTINT('eatbyday'), GETPOSTINT('eatbyyear')); $d_sellby = dol_mktime(0, 0, 0, GETPOSTINT('sellbymonth'), GETPOSTINT('sellbyday'), GETPOSTINT('sellbyyear')); $pdluo->batch = $batchnumber; $pdluo->eatby = $d_eatby; $pdluo->sellby = $d_sellby; $result = $pdluo->update($user); if ($result < 0) { setEventMessages($pdluo->error, $pdluo->errors, 'errors'); } } } else { setEventMessages($langs->trans('BatchInformationNotfound'), null, 'errors'); } } else { setEventMessages($pdluo->error, null, 'errors'); } header("Location: product.php?id=".$id); exit; } /* * View */ $form = new Form($db); $formproduct = new FormProduct($db); if (isModEnabled('project')) { $formproject = new FormProjets($db); } if ($id > 0 || $ref) { $object = new Product($db); $result = $object->fetch($id, $ref); $variants = $object->hasVariants(); $object->load_stock(); // This include the load_virtual_stock() $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-card_stock_product'); if (!empty($conf->use_javascript_ajax)) { ?> 0) { $head = product_prepare_head($object); $titre = $langs->trans("CardProduct".$object->type); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); print dol_get_fiche_head($head, 'stock', $titre, -1, $picto); dol_htmloutput_events(); $linkback = ''.$langs->trans("BackToList").''; $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")"; $shownav = 1; if ($user->socid && !in_array('stock', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) { $shownav = 0; } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); if (!$variants) { print '
'; print '
'; print '
'; print ''; // Type if (isModEnabled("product") && isModEnabled("service")) { $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); print ''; } if (isModEnabled('productbatch')) { print ''; } // Cost price. Can be used for margin module for option "calculate margin on explicit cost price print ''; // AWP print ''; print ''; print ''; // Minimum Price print ''; print ''; if (!getDolGlobalString('PRODUIT_MULTIPRICES')) { // Price print ''; // Price minimum print ''; } else { // Price print ''; // Price minimum print ''; } // Hook formObject $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'; print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type'); print ''; print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat); print '
'.$langs->trans("ManageLotSerial").''; print $object->getLibStatut(0, 2); print '
'; $textdesc = $langs->trans("CostPriceDescription"); $textdesc .= "
".$langs->trans("CostPriceUsage"); $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', ''); if (!$usercancreadprice) { print $form->editfieldkey($text, 'cost_price', '', $object, 0, 'amount:6'); print '
'; print $form->editfieldval($text, 'cost_price', '', $object, 0, 'amount:6'); } else { print $form->editfieldkey($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6'); print ''; print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6'); } print '
'; print $form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")); print ''; if ($object->pmp > 0 && $usercancreadprice) { print price($object->pmp).' '.$langs->trans("HT"); } print '
'.$langs->trans("BuyingPriceMin").''; $product_fourn = new ProductFournisseur($db); if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) { if ($product_fourn->product_fourn_price_id > 0 && $usercancreadprice) { print $product_fourn->display_price_product_fournisseur(); } else { print $langs->trans("NotDefined"); } } print '
'.$langs->trans("SellingPrice").''; if ($usercancreadprice) { if ($object->price_base_type == 'TTC') { print price($object->price_ttc).' '.$langs->trans($object->price_base_type); } else { print price($object->price).' '.$langs->trans($object->price_base_type); } } print '
'.$langs->trans("MinPrice").''; if ($usercancreadprice) { if ($object->price_base_type == 'TTC') { print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type); } else { print price($object->price_min).' '.$langs->trans($object->price_base_type); } } print '
'.$langs->trans("SellingPrice").''; print ''.$langs->trans("Variable").''; print '
'.$langs->trans("MinPrice").''; print ''.$langs->trans("Variable").''; print '
'; print '
'; print '
'; print ''; // Stock alert threshold print ''; // Desired stock print ''; // Real stock $text_stock_options = $langs->trans("RealStockDesc").'
'; $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'
'; $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'
' : ''); $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'
' : ''); $parameters = array(); $reshook = $hookmanager->executeHooks('physicalStockTextStockOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook > 0) { $text_stock_options = $hookmanager->resPrint; } elseif ($reshook == 0) { $text_stock_options .= $hookmanager->resPrint; } else { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } print ''; print ''; print ''; $stocktheo = price2num($object->stock_theorique, 'MS'); $found = 0; $helpondiff = ''.$langs->trans("StockDiffPhysicTeoric").':
'; // Number of sales orders running if (isModEnabled('order')) { if ($found) { $helpondiff .= '
'; } else { $found = 1; } $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty']; $result = $object->load_stats_commande(0, '0', 1); if ($result < 0) { dol_print_error($db, $object->error); } $helpondiff .= ' ('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')'; } // Number of product from sales order already sent (partial shipping) if (isModEnabled("shipping")) { require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; $filterShipmentStatus = ''; if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { $filterShipmentStatus = Expedition::STATUS_VALIDATED.','.Expedition::STATUS_CLOSED; } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { $filterShipmentStatus = Expedition::STATUS_CLOSED; } if ($found) { $helpondiff .= '
'; } else { $found = 1; } $result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus); $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty']; } // Number of supplier order running if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) { if ($found) { $helpondiff .= '
'; } else { $found = 1; } $result = $object->load_stats_commande_fournisseur(0, '3,4', 1); $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty']; $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1); if ($result < 0) { dol_print_error($db, $object->error); } $helpondiff .= ' ('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')'; } // Number of product from supplier order already received (partial receipt) if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) { if ($found) { $helpondiff .= '
'; } else { $found = 1; } $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty']; } // Number of product in production if (isModEnabled('mrp')) { if ($found) { $helpondiff .= '
'; } else { $found = 1; } $helpondiff .= $langs->trans("ProductQtyToConsumeByMO").': '.$object->stats_mrptoconsume['qty'].'
'; $helpondiff .= $langs->trans("ProductQtyToProduceByMO").': '.$object->stats_mrptoproduce['qty']; } $parameters = array('found' => &$found, 'id' => $object->id, 'includedraftpoforvirtual' => null); $reshook = $hookmanager->executeHooks('virtualStockHelpOnDiff', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook > 0) { $helpondiff = $hookmanager->resPrint; } elseif ($reshook == 0) { $helpondiff .= $hookmanager->resPrint; } else { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } // Calculating a theoretical value print ''; print "'; print ''; // Last movement if ($user->hasRight('stock', 'mouvement', 'lire')) { $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " WHERE m.fk_product = ".((int) $object->id); $resqlbis = $db->query($sql); if ($resqlbis) { $obj = $db->fetch_object($resqlbis); $lastmovementdate = $db->jdate($obj->datem); } else { dol_print_error($db); } print '"; } print "
'.$form->editfieldkey($form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1), 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->hasRight('produit', 'creer')).''; print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->hasRight('produit', 'creer'), 'string'); print '
'.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', $object->desiredstock, $object, $user->hasRight('produit', 'creer')); print ''; print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->hasRight('produit', 'creer'), 'string'); print '
'; print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1); print ''.price2num($object->stock_reel, 'MS'); if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) { print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); } print '    '.$langs->trans("StockAtDate").''; print '
'; print $form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")); print '"; //print (empty($stocktheo)?0:$stocktheo); print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff); if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) { print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); } print '    '.$langs->trans("VirtualStockAtDate").''; print '
'.$langs->trans("LastMovement").''; if ($lastmovementdate) { print dol_print_date($lastmovementdate, 'dayhour').' '; print '     '; print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"'); print ''.$langs->trans("FullList").''; } else { print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"'); print ''.$langs->trans("None").''; } print "
"; print '
'; print '
'; print '
'; } print dol_get_fiche_end(); } // Correct stock if ($action == "correction") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; print '

'; } // Transfer of units if ($action == "transfert") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; print '

'; } } else { dol_print_error(); } // Actions buttons $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { if (empty($action) && $object->id) { print "
\n"; if ($user->hasRight('stock', 'mouvement', 'creer')) { if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) { print ''.$langs->trans("TransferStock").''; } else { print ''.$langs->trans("TransferStock").''; } } else { print ''.$langs->trans("TransferStock").''; } if ($user->hasRight('stock', 'mouvement', 'creer')) { if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) { print ''.$langs->trans("CorrectStock").''; } else { print ''.$langs->trans("CorrectStock").''; } } else { print ''.$langs->trans("CorrectStock").''; } print '
'; } } if (!$variants || getDolGlobalString('VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT')) { /* * Stock detail (by warehouse). May go down into batch details. */ print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ((isModEnabled('productbatch')) && $object->hasbatch()) { $colspan = 3; print ''; print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { $colspan--; print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { $colspan--; print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } $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"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; $sql .= " ".MAIN_DB_PREFIX."product_stock as ps"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product"; $sql .= " WHERE ps.reel != 0"; $sql .= " AND ps.fk_entrepot = e.rowid"; $sql .= " AND e.entity IN (".getEntity('stock').")"; $sql .= " AND ps.fk_product = ".((int) $object->id); $sql .= " ORDER BY e.ref"; $entrepotstatic = new Entrepot($db); $product_lot_static = new Productlot($db); $num = 0; $total = 0; $totalvalue = $totalvaluesell = 0; $totalwithpmp = 0; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $total = $totalwithpmp; $i = 0; $var = false; while ($i < $num) { $obj = $db->fetch_object($resql); $entrepotstatic->id = $obj->rowid; $entrepotstatic->ref = $obj->ref; $entrepotstatic->label = $obj->ref; $entrepotstatic->lieu = $obj->lieu; $entrepotstatic->fk_parent = $obj->fk_parent; $entrepotstatic->statut = $obj->status; $entrepotstatic->status = $obj->status; $stock_real = price2num($obj->reel, 'MS'); print ''; // Warehouse print ''; print ''; // PMP print ''; // Value purchase if ($usercancreadprice) { print ''; } else { print ''; } // Sell price $minsellprice = null; $maxsellprice = null; print ''; // Value sell print ''; print ''; print ''; print ''; $total += $obj->reel; if (price2num($object->pmp)) { $totalwithpmp += $obj->reel; } $totalvalue += ($object->pmp * $obj->reel); $totalvaluesell += ($object->price * $obj->reel); // Batch Detail if ((isModEnabled('productbatch')) && $object->hasbatch()) { $details = Productbatch::findAll($db, $obj->product_stock_id, 0, $object->id); if ($details < 0) { dol_print_error($db); } foreach ($details as $pdluo) { $product_lot_static->id = $pdluo->lotid; $product_lot_static->batch = $pdluo->batch; $product_lot_static->eatby = $pdluo->eatby; $product_lot_static->sellby = $pdluo->sellby; if ($action == 'editline' && GETPOSTINT('lineid') == $pdluo->id) { //Current line edit print "\n".''; print ''; print ''; print ''; print ''; } else { print "\n".''; print ''; $colspan = 3; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { $colspan--; print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { $colspan--; print ''; } print ''; print ''; print ''; print ''; print ''; } } } $i++; } } else { dol_print_error($db); } // Total line print ''; print ''; print ''; // Value purchase print ''; print ''; // Value to sell print ''; print ''; print ''; print ""; print "
'.$langs->trans("Warehouse").''.$langs->trans("NumberOfUnit").''.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).''.$langs->trans("EstimatedStockValueShort").''.$langs->trans("SellPriceMin").''.$langs->trans("EstimatedStockValueSellShort").'
'; if (!empty($conf->use_javascript_ajax)) { print ''.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ShowAllLots").''; //print '   '; print ''.img_picto('', 'folder', 'class="paddingright"').$langs->trans("HideLots").''; //print ' '.$form->textwithpicto('', $langs->trans('CollapseBatchDetailHelp'), 1, 'help', ''); } print ''.$langs->trans("batch_number").''.$langs->trans("SellByDate").''.$langs->trans("EatByDate").'
'; print $entrepotstatic->getNomUrl(1); if (!empty($conf->use_javascript_ajax) && isModEnabled('productbatch') && $object->hasbatch()) { print ''; print(!getDolGlobalString('STOCK_SHOW_ALL_BATCH_BY_DEFAULT') ? '(+)' : '(-)'); print ''; } print ''.$stock_real.($stock_real < 0 ? ' '.img_warning() : '').''.(price2num($object->pmp) ? price2num($object->pmp, 'MU') : '').''.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').''; if (getDolGlobalString('PRODUIT_MULTIPRICES')) { foreach ($object->multiprices as $priceforlevel) { if (is_numeric($priceforlevel)) { if (is_null($maxsellprice) || $priceforlevel > $maxsellprice) { $maxsellprice = $priceforlevel; } if (is_null($minsellprice) || $priceforlevel < $minsellprice) { $minsellprice = $priceforlevel; } } } print ''; if ($usercancreadprice) { if ($minsellprice != $maxsellprice) { print price(price2num($minsellprice, 'MU'), 1).' - '.price(price2num($maxsellprice, 'MU'), 1); } else { print price(price2num($minsellprice, 'MU'), 1); } } print ''; print $form->textwithpicto('', $langs->trans("Variable")); } elseif ($usercancreadprice) { print price(price2num($object->price, 'MU'), 1); } print ''; if (getDolGlobalString('PRODUIT_MULTIPRICES')) { print ''; if ($usercancreadprice) { if ($minsellprice != $maxsellprice) { print price(price2num($minsellprice * $obj->reel, 'MT'), 1).' - '.price(price2num($maxsellprice * $obj->reel, 'MT'), 1); } else { print price(price2num($minsellprice * $obj->reel, 'MT'), 1); } } print ''; print $form->textwithpicto('', $langs->trans("Variable")); } else { if ($usercancreadprice) { print price(price2num($object->price * $obj->reel, 'MT'), 1); } } print '
'; print '
'; print ''; print ''; print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } print ''; print ''; print '
'; print $form->selectDate($pdluo->sellby, 'sellby', 0, 0, 1, '', 1, 0); print ''; print $form->selectDate($pdluo->eatby, 'eatby', 0, 0, 1, '', 1, 0); print ''.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').''; print '
'; print '
'; print '
'; print ''; if ($product_lot_static->id > 0) { print $product_lot_static->getNomUrl(1); } else { print $product_lot_static->getNomUrl(1, 'nolink'); } print ''.dol_print_date($pdluo->sellby, 'day').''.dol_print_date($pdluo->eatby, 'day').''.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : (($pdluo->qty > 1 && $object->status_batch == 2) ? ' '.img_warning($langs->trans('IlligalQtyForSerialNumbers')) : '')).''; if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) { print 'id.'&token='.newToken().'">'; print img_picto($langs->trans("TransferStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"'); print $langs->trans("TransferStock"); print ''; // Disabled, because edition of stock content must use the "Correct stock menu". // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ... //print 'id.'#'.$pdluo->id.'">'; //print img_edit().''; } print ''; if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) { print 'id.'&token='.newToken().'">'; print img_picto($langs->trans("CorrectStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"'); print $langs->trans("CorrectStock"); print ''; // Disabled, because edition of stock content must use the "Correct stock menu". // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ... //print 'id.'#'.$pdluo->id.'">'; //print img_edit().''; } print '
'.$langs->trans("Total").':'.price2num($total, 'MS').''; if ($usercancreadprice) { print($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : ' '); // This value may have rounding errors } print ''; if ($usercancreadprice) { print $totalvalue ? price(price2num($totalvalue, 'MT'), 1) : ' '; } print ''; if ($num) { if ($total) { print ''; if (getDolGlobalString('PRODUIT_MULTIPRICES')) { print $form->textwithpicto('', $langs->trans("Variable")); } elseif ($usercancreadprice) { print price($totalvaluesell / $total, 1); } print ''; } } print ''; if ($num) { print ''; if (!getDolGlobalString('PRODUIT_MULTIPRICES') && $usercancreadprice) { print price(price2num($totalvaluesell, 'MT'), 1); } else { print $form->textwithpicto('', $langs->trans("Variable")); } print ''; } print '
"; print '
'; if (getDolGlobalString('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE')) { print '

'; print load_fiche_titre($langs->trans('AddNewProductStockWarehouse')); if ($user->hasRight('produit', 'creer')) { print '
'; print ''; print ''; print ''; } print ''; if ($user->hasRight('produit', 'creer')) { print ''; print ''; print ''; print ''; print ''; } else { print ''; print ''; print ''; print ''; } $pse = new ProductStockEntrepot($db); $lines = $pse->fetchAll($id); $visibleWarehouseEntities = explode(',', getEntity('stock')); // For MultiCompany compatibility if (!empty($lines)) { $var = false; foreach ($lines as $line) { $ent = new Entrepot($db); $ent->fetch($line['fk_entrepot']); if (!isModEnabled("multicompany") || in_array($ent->entity, $visibleWarehouseEntities)) { // Display only warehouses from our entity and entities sharing stock with actual entity print ''; print ''; print ''; if ($user->hasRight('produit', 'creer')) { print ''; } print ''; } } } print "
'.$formproduct->selectWarehouses('', 'fk_entrepot').'
'.$langs->trans("Warehouse").''.$langs->trans("StockLimit").''.$langs->trans("DesiredStock").'
'.$ent->getNomUrl(3).''.$line['seuil_stock_alerte'].''.$line['desiredstock'].''.img_delete().'
"; if ($user->hasRight('produit', 'creer')) { print '
'; } } } else { // List of variants include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; $prodstatic = new Product($db); $prodcomb = new ProductCombination($db); $comb2val = new ProductCombination2ValuePair($db); $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id); print '
'; print ''; print ''; print ''; print ''; // load variants $title = $langs->trans("ProductCombinations"); print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0); print '
'; ?> fetch($currcomb->fk_product_child); $prodstatic->load_stock(); $stock_total += $prodstatic->stock_reel; ?> '; print ''; print ''; print ''; print ''; } else { print ''; } ?>
trans('Product') ?> trans('Combination') ?> trans('OnSell') ?> trans('OnBuy') ?> trans('Stock') ?>
getNomUrl(1) ?> fetchByFkCombination($currcomb->id); $iMax = count($productCombination2ValuePairs); for ($i = 0; $i < $iMax; $i++) { echo dol_htmlentities($productCombination2ValuePairs[$i]); if ($i !== ($iMax - 1)) { echo ', '; } } ?> getLibStatut(2, 0) ?> getLibStatut(2, 1) ?> stock_reel ?>
'.$langs->trans("Total").''.$stock_total.'
'.$langs->trans("None").'
'; print ''; } // End of page llxFooter(); $db->close();