From 9dda41611673be6932aea9d19db7d67b56d57799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cserveny=2C=20Tam=C3=A1s?= Date: Wed, 26 Jan 2022 23:41:31 +0100 Subject: [PATCH 1/4] add datem and type parameters --- .../stock/class/api_stockmovements.class.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 8291e910917..acce9d6ac51 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -156,14 +156,16 @@ class StockMovements extends DolibarrApi * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. - * + * * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} + * @param string $type Optionally specify the type of movement. 1=input (stock increase by a stock transfer), 2=output (stock decrease by a stock transfer),3=output (stock decrease), 4=input (stock increase). {@from body} {@type int} * @param string $lot Lot {@from body} * @param string $movementcode Movement code {@example INV123} {@from body} * @param string $movementlabel Movement label {@example Inventory number 123} {@from body} * @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). {@from body} + * @param string $datem Date of movement {@from body} {@type date} * @param string $dlc Eat-by date. {@from body} {@type date} * @param string $dluo Sell-by date. {@from body} {@type date} * @param string $origin_type Origin type (Element of source object, like 'project', 'inventory', ...) @@ -172,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type='', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -183,17 +185,22 @@ class StockMovements extends DolibarrApi } // Type increase or decrease - $type = 2; - if ($qty >= 0) { - $type = 3; - } + if ($type == '') { + $type = 2; + if ($qty >= 0) { + $type = 3; + } + } else { + $type = $type - 1; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); $sellBy = empty($dlc) ? '' : dol_stringtotime($dlc); + $dateMvt = empty($datem) ? '' : dol_stringtotime($datem); $this->stockmovement->setOrigin($origin_type, $origin_id); - if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { + if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, $dateMvt, $eatBy, $sellBy, $lot) <= 0) { $errormessage = $this->stockmovement->error; if (empty($errormessage)) { $errormessage = join(',', $this->stockmovement->errors); From a6bd35c7d82e7e48ca63c8c693735d72a792e217 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 26 Jan 2022 22:52:07 +0000 Subject: [PATCH 2/4] Fixing style errors. --- .../stock/class/api_stockmovements.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index acce9d6ac51..fc745ef614d 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -156,7 +156,7 @@ class StockMovements extends DolibarrApi * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. - * + * * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} @@ -174,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $type='', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type = '', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -186,13 +186,13 @@ class StockMovements extends DolibarrApi // Type increase or decrease if ($type == '') { - $type = 2; - if ($qty >= 0) { - $type = 3; - } - } else { - $type = $type - 1; - } + $type = 2; + if ($qty >= 0) { + $type = 3; + } + } else { + $type = $type - 1; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); From a20594c2a5dee067753c17568eeaf7771926d190 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Jan 2022 17:18:28 +0100 Subject: [PATCH 3/4] Restore similar values for type than internal methods --- .../stock/class/api_stockmovements.class.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index fc745ef614d..7e9f2f7a22b 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -160,7 +160,7 @@ class StockMovements extends DolibarrApi * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} - * @param string $type Optionally specify the type of movement. 1=input (stock increase by a stock transfer), 2=output (stock decrease by a stock transfer),3=output (stock decrease), 4=input (stock increase). {@from body} {@type int} + * @param int $type Optionally specify the type of movement. 0=input (stock increase by a stock transfer), 1=output (stock decrease by a stock transfer), 2=output (stock decrease), 3=input (stock increase). {@from body} {@type int} * @param string $lot Lot {@from body} * @param string $movementcode Movement code {@example INV123} {@from body} * @param string $movementlabel Movement label {@example Inventory number 123} {@from body} @@ -174,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $type = '', $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type = 3, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -185,13 +185,11 @@ class StockMovements extends DolibarrApi } // Type increase or decrease - if ($type == '') { - $type = 2; - if ($qty >= 0) { - $type = 3; - } - } else { - $type = $type - 1; + if ($type == 1 && $qty >= 0) { + $type = 0; + } + if ($type == 2 && $qty >= 0) { + $type = 3; } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; From 2b39e381ad87b51b17e41054a26a96ae4e1ff416 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Jan 2022 18:14:11 +0100 Subject: [PATCH 4/4] Update api_stockmovements.class.php --- htdocs/product/stock/class/api_stockmovements.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 7e9f2f7a22b..b8705a20198 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -174,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $type = 3, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type = 2, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401);