From 1d85529eda86b03f206ea627ca917551041a6c18 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Wed, 1 Jul 2015 23:24:54 +0200 Subject: [PATCH 1/4] Fix delete not used empty stock record When removing all stock from warehouse are move all stock to other warehouse, there is still an 0 stock record in in the stock table for the source warehouse, not visible in Dolibarr. --- .../stock/class/mouvementstock.class.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index b37384932cf..9c1e555ba3b 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2013 Laurent Destailleur * Copyright (C) 2011 Jean Heimburger * Copyright (C) 2014 Cedric GROSS + * Copyright (C) 2015 Francis Appels * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -232,7 +233,37 @@ class MouvementStock extends CommonObject { $fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock"); } - + + // delete empty stock record + $sql = "SELECT reel FROM ".MAIN_DB_PREFIX."product_stock"; + $sql.= " WHERE rowid = ".$fk_product_stock; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj) + { + if ($obj->reel == 0) + { + dol_syslog(get_class($this)."::_create delete 0 stock record", LOG_DEBUG); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock"; + $sql.= " WHERE rowid = ".$fk_product_stock; + $delsql=$this->db->query($sql); + if (! $delsql) + { + $this->errors[]=$this->db->lasterror(); + $error = -8; + } + } + } + $this->db->free($resql); + } + else + { + $this->errors[]=$this->db->lasterror(); + $error = -7; + } } // Update detail stock for sell-by date From a294700cef7e253e63723e83f68199e9c88571c7 Mon Sep 17 00:00:00 2001 From: fappels Date: Thu, 10 Sep 2015 22:16:03 +0200 Subject: [PATCH 2/4] fix dispatch rounding version 1 --- htdocs/fourn/commande/dispatch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index e62402feabb..76d09d8f3d3 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -266,7 +266,7 @@ if ($id > 0 || ! empty($ref)) { while ( $row = $db->fetch_row($resql) ) { - $products_dispatched[$row[0]] = $row[2]; + $products_dispatched[$row[0]] = price2num($row[2], 5); } $db->free($resql); } @@ -322,7 +322,7 @@ if ($id > 0 || ! empty($ref)) } else { - $remaintodispatch=($objp->qty - $products_dispatched[$objp->rowid]); // Calculation of dispatched + $remaintodispatch=(price2num($objp->qty, 5) - $products_dispatched[$objp->rowid]); // Calculation of dispatched if ($remaintodispatch < 0) $remaintodispatch=0; if ($remaintodispatch) { From 75a14e02d8e1429c5545d8785fa80792f568b153 Mon Sep 17 00:00:00 2001 From: fappels Date: Thu, 10 Sep 2015 23:29:13 +0200 Subject: [PATCH 3/4] Fix #3471 3.7 Rounding issue when dispatching non-integer --- htdocs/fourn/commande/dispatch.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 76d09d8f3d3..f4adaf1ba0d 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -264,9 +264,17 @@ if ($id > 0 || ! empty($ref)) $resql = $db->query($sql); if ($resql) { - while ( $row = $db->fetch_row($resql) ) + $num = $db->num_rows($resql); + $i = 0; + + if ($num) { - $products_dispatched[$row[0]] = price2num($row[2], 5); + while ($i < $num) + { + $objd = $db->fetch_object($resql); + $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); + $i++; + } } $db->free($resql); } From c290840513b9cc6bf3ab50e5beace5e3a5aaedb0 Mon Sep 17 00:00:00 2001 From: fappels Date: Thu, 10 Sep 2015 23:31:23 +0200 Subject: [PATCH 4/4] Revert "Fix delete not used empty stock record" This reverts commit 1d85529eda86b03f206ea627ca917551041a6c18. --- .../stock/class/mouvementstock.class.php | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 9c1e555ba3b..b37384932cf 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -3,7 +3,6 @@ * Copyright (C) 2005-2013 Laurent Destailleur * Copyright (C) 2011 Jean Heimburger * Copyright (C) 2014 Cedric GROSS - * Copyright (C) 2015 Francis Appels * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -233,37 +232,7 @@ class MouvementStock extends CommonObject { $fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock"); } - - // delete empty stock record - $sql = "SELECT reel FROM ".MAIN_DB_PREFIX."product_stock"; - $sql.= " WHERE rowid = ".$fk_product_stock; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - if ($obj) - { - if ($obj->reel == 0) - { - dol_syslog(get_class($this)."::_create delete 0 stock record", LOG_DEBUG); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock"; - $sql.= " WHERE rowid = ".$fk_product_stock; - $delsql=$this->db->query($sql); - if (! $delsql) - { - $this->errors[]=$this->db->lasterror(); - $error = -8; - } - } - } - $this->db->free($resql); - } - else - { - $this->errors[]=$this->db->lasterror(); - $error = -7; - } + } // Update detail stock for sell-by date