From ef6f7a619a802f2637e1980c4b03b71dd107ba4b Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Fri, 8 Oct 2021 13:33:19 +0200 Subject: [PATCH] FIX : object linked to stock movement + travis --- .../class/stocktransfer.class.php | 7 +++---- .../class/stocktransferline.class.php | 18 ++++++++++-------- .../stock/stocktransfer/stocktransfer_card.php | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 76300c1596e..3cff895c215 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -505,7 +505,6 @@ class StockTransfer extends CommonObject */ public function deleteLine(User $user, $idline, $notrigger = false) { - global $db; if ($this->status < 0) { $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; return -2; @@ -564,8 +563,8 @@ class StockTransfer extends CommonObject $sql .= " SET ref = '".$this->db->escape($num)."',"; $sql .= " status = ".self::STATUS_VALIDATED; if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; - if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; - $sql .= " WHERE rowid = ".$this->id; + if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".((int) $user->id); + $sql .= " WHERE rowid = ".((int) $this->id); dol_syslog(get_class($this)."::validate()", LOG_DEBUG); $resql = $this->db->query($sql); @@ -590,7 +589,7 @@ class StockTransfer extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } diff --git a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php index 2db20cca0d1..f2378469e29 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php @@ -447,19 +447,21 @@ class StockTransferLine extends CommonObjectLine public function doStockMovement($label, $code_inv, $fk_entrepot, $direction = 1) { - global $db, $conf, $user, $langs; + global $conf, $user, $langs; require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; + include_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransfer.class.php'; - $p = new Product($db); + $p = new Product($this->db); $p->fetch($this->fk_product); $op[0] = "+".trim($this->qty); $op[1] = "-".trim($this->qty); - $movementstock = new MouvementStock($db); - $movementstock->origin = new StockTransfer($db); - $movementstock->origin->id = $this->fk_stocktransfer; + $movementstock = new MouvementStock($this->db); + $st = new StockTransfer($this->db); + $movementstock->origin_type = $st->origin_type; + $movementstock->origin_id = $this->fk_stocktransfer; if (empty($this->batch)) { // no batch for line /*$result = $p->correct_stock( @@ -586,8 +588,8 @@ class StockTransferLine extends CommonObjectLine $sql .= " SET ref = '".$this->db->escape($num)."',"; $sql .= " status = ".self::STATUS_VALIDATED; if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; - if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; - $sql .= " WHERE rowid = ".$this->id; + if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".((int) $user->id); + $sql .= " WHERE rowid = ".((int) $this->id); dol_syslog(get_class($this)."::validate()", LOG_DEBUG); $resql = $this->db->query($sql); @@ -612,7 +614,7 @@ class StockTransferLine extends CommonObjectLine if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransferline/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index b001904b6de..0c1d46bcd3e 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -215,7 +215,7 @@ if (empty($reshook)) { if (empty($error)) { $line = new StockTransferLine($db); - $records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.$id.' AND fk_product = '.$fk_product.' AND fk_warehouse_source = '.$fk_warehouse_source.' AND fk_warehouse_destination = '.$fk_warehouse_destination.' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : 'batch = "'.$batch.'"' ).')')); + $records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.((int) $id).' AND fk_product = '.((int) $fk_product).' AND fk_warehouse_source = '.((int) $fk_warehouse_source).' AND fk_warehouse_destination = '.((int) $fk_warehouse_destination).' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : "batch = '".$db->escape($batch)."'" ).')')); if (!empty($records[key($records)])) $line = $records[key($records)]; $line->fk_stocktransfer = $id; $line->qty += $qty;