diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c07e60e709f..c9309bfa883 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7897,7 +7897,7 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' 'show-body-only' => true, "indent-attributes" => false, "vertical-space" => false, - 'ident' => false, + //'ident' => false, // Not always supported "wrap" => 0 // HTML5 tags //'new-blocklevel-tags' => 'article aside audio bdi canvas details dialog figcaption figure footer header hgroup main menu menuitem nav section source summary template track video', diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 644c2b58391..7740eb8d647 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -332,5 +332,5 @@ ConfirmDeleteBatch=Are you sure you want to delete lot/serial ? WarehouseUsage=Warehouse usage InternalWarehouse=Internal warehouse ExternalWarehouse=External warehouse -QtyCurrentlyKnownInStock=The quantity the system think you have in stock. This is a realtime value. It may change if you continue to make stock movement during the inventory. +QtyCurrentlyKnownInStock=The quantity the system think you have in stock. As long as the inventory is not closed, this is a realtime value and it may change if you continue to make stock movement during the inventory (not recommended). QtyInStockWhenInventoryWasValidated=The quantity the system think you had in stock when the inventory was validated (before the stock correction) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 13e793e2920..e793d442313 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -264,7 +264,6 @@ class Inventory extends CommonObject */ public function validate(User $user, $notrigger = 0, $include_sub_warehouse = 0) { - global $conf; $this->db->begin(); $result = 0; @@ -281,10 +280,17 @@ class Inventory extends CommonObject // Scan existing stock to prefill the inventory $sql = "SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,"; - $sql .= " pb.batch, pb.qty"; + if (isModEnabled('productbatch')) { + $sql .= " pb.batch as batch, pb.qty as qty,"; + } else { + $sql .= " '' as batch, 0 as qty,"; + } + $sql .= " p.ref, p.tobatch"; $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; - $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid,"; - $sql .= " ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e"; + if (isModEnabled('productbatch')) { + $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid"; + } + $sql .= ", ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e"; $sql .= " WHERE p.entity IN (".getEntity('product').")"; $sql .= " AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid"; if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { @@ -317,6 +323,7 @@ class Inventory extends CommonObject $sql .= " WHERE pa.fk_product_pere = ps.fk_product"; $sql .= ")"; } + $sql .= " ORDER BY p.rowid"; $inventoryline = new InventoryLine($this->db); @@ -335,10 +342,18 @@ class Inventory extends CommonObject $inventoryline->datec = dol_now(); if (isModEnabled('productbatch')) { + if ($obj->batch && empty($obj->tobatch)) { + // Bad consistency of data. The product is not a product with lot/serial but we found a stock for some lot/serial. + $result = -2; + $this->error = 'The product ID='.$obj->ref." has stock with lot/serial but is configured to not manage lot/serial. You must first fix this, this way: Set the product to have 'Management of Lot/Serial' to Yes, then set it back to 'Management of Lot/Serial to No"; + break; + } + $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel); // If there is batch detail, we take qty for batch, else global qty } else { $inventoryline->qty_stock = $obj->reel; } + //var_dump($obj->batch.' '.$obj->qty.' '.$obj->reel.' '.$this->error);exit; $resultline = $inventoryline->create($user); if ($resultline <= 0) { diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index a3bd728a62d..0aab3be055c 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -150,6 +150,7 @@ if (empty($reshook)) { $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.pmp_real'; $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; $sql .= ' WHERE id.fk_inventory = '.((int) $object->id); + $sql .= ' ORDER BY id.rowid'; $resql = $db->query($sql); if ($resql) { @@ -185,9 +186,10 @@ if (empty($reshook)) { $realqtynow = $product_static->stock_warehouse[$line->fk_warehouse]->detail_batch[$line->batch]->qty; } - if (!is_null($qty_view)) { $stock_movement_qty = price2num($qty_view - $realqtynow, 'MS'); + //print "Process inventory line ".$line->rowid." product=".$product_static->id." realqty=".$realqtynow." qty_stock=".$qty_stock." qty_view=".$qty_view." warehouse=".$line->fk_warehouse." qty to move=".$stock_movement_qty."
\n"; + if ($stock_movement_qty != 0) { if ($stock_movement_qty < 0) { $movement_type = 1;