diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 8e949661c49..a7205207cf9 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -242,4 +242,5 @@ InventoryRealQtyHelp=Set value to 0 to reset qty
Keep field empty, or remove
UpdateByScaning=Update by scaning
UpdateByScaningProductBarcode=Update by scan (product barcode)
UpdateByScaningLot=Update by scan (lot|serial barcode)
-DisableStockChangeOfSubProduct=Deactivate the stock change for all the subproducts of this Kit during this movement.
\ No newline at end of file
+DisableStockChangeOfSubProduct=Deactivate the stock change for all the subproducts of this Kit during this movement.
+LabelOfInventoryMovemement=Inventory %s
\ No newline at end of file
diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php
index ce585c51a10..dc1b46331fc 100644
--- a/htdocs/product/inventory/class/inventory.class.php
+++ b/htdocs/product/inventory/class/inventory.class.php
@@ -359,6 +359,27 @@ class Inventory extends CommonObject
}
}
+ /**
+ * Set to Recorded
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function setRecorded(User $user, $notrigger = false)
+ {
+ $this->db->begin();
+
+ $result = $this->setStatut($this::STATUS_RECORDED, null, '', 'INVENTORY_RECORDED');
+
+ if ($result > 0) {
+ $this->db->commit();
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
/**
* Clone and object into another one
*
diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php
index 6c8f6ab5256..d8e76489ffc 100644
--- a/htdocs/product/inventory/inventory.php
+++ b/htdocs/product/inventory/inventory.php
@@ -27,6 +27,7 @@ include_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
+include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
// Load translation files required by the page
$langs->loadLangs(array("stocks", "other", "productbatch"));
@@ -98,6 +99,67 @@ $now = dol_now();
* Actions
*/
+if ($action == 'update' && $user->rights->stock->mouvement->creer) {
+ $stockmovment = new MouvementStock($db);
+ $stockmovment->origin = $object;
+
+ $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
+ $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
+ $sql .= ' WHERE id.fk_inventory = '.$object->id;
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $totalarray = array();
+ while ($i < $num) {
+ $line = $db->fetch_object($resql);
+ $qty_view = $line->qty_view;
+ $qty_stock = $line->qty_stock;
+ $stock_movement_qty = $qty_view - $qty_stock;
+ if ($stock_movement_qty != 0) {
+ if ($stock_movement_qty < 0) {
+ $movement_type = 1;
+ } else {
+ $movement_type = 0;
+ }
+ $idstockmove = $stockmovment->_create($user, $line->fk_product, $line->fk_warehouse, $stock_movement_qty, $movement_type, 0, $langs->trans('LabelOfInventoryMovemement', $object->id), 'INV'.$object->id);
+ if ($idstockmove < 0) {
+ $error++;
+ setEventMessages($stockmovment->error, $stockmovment->errors, 'errors');
+ }
+ }
+ $i++;
+ }
+ if (!$error) {
+ $object->setRecorded($user);
+ }
+ }
+}
+
+if ($action =='updateinventorylines' && $permissiontoadd) {
+ $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
+ $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
+ $sql .= ' WHERE id.fk_inventory = '.$object->id;
+
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $totalarray = array();
+ while ($i < $num) {
+ $line = $db->fetch_object($resql);
+ $lineid = $line->rowid;
+ $inventoryline = new InventoryLine($db);
+ $inventoryline->fetch($lineid);
+ $inventoryline->qty_view = GETPOST("id_".$inventoryline->id);
+ $inventoryline->update($user);
+ $i++;
+ }
+ }
+}
+
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
@@ -419,10 +481,12 @@ if ($object->id > 0) {
print '