From 7ec17f17d555b93c0715ee9a3ebeb61a72d59dee Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Thu, 23 Jan 2020 09:41:22 +0100 Subject: [PATCH] FIX - API - DLC/DLUO date for stock movement Instead of giving a string to the creation of a stock movement, we have to give an integer. This PR fixes that. [see: X] --- .../product/stock/class/api_stockmovements.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 9951c05d323..c4f6ee56b5a 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -186,10 +186,15 @@ class StockMovements extends DolibarrApi } // Type increase or decrease - if ($qty >= 0) $type = 3; - else $type = 2; + $type = 2; + if ($qty >= 0){ + $type = 3; + } - if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $dlc, $dluo, $lot) <= 0) { + $eatBy = empty($dluo) ? '' : (new DateTime($dluo))->getTimestamp(); + $sellBy = empty($dlc) ? '' : (new DateTime($dlc))->getTimestamp();; + + if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error); }