diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index a4df7a95829..088dccf6861 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -42,6 +42,7 @@ class Productbatch extends CommonObject var $batch=''; var $qty; var $import_key; + public $warehouseid; @@ -155,10 +156,11 @@ class Productbatch extends CommonObject $sql.= " t.eatby,"; $sql.= " t.batch,"; $sql.= " t.qty,"; - $sql.= " t.import_key"; - + $sql.= " t.import_key,"; + $sql.= " w.fk_entrepot"; $sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as t"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_stock w on t.fk_product_stock=w.rowid"; $sql.= " WHERE t.rowid = ".$id; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -177,6 +179,7 @@ class Productbatch extends CommonObject $this->batch = $obj->batch; $this->qty = $obj->qty; $this->import_key = $obj->import_key; + $this->warehouseid= $obj->fk_entrepot; } $this->db->free($resql); diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index eaa12794688..13a798548d5 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -170,13 +170,13 @@ if ($action == "correct_stock" && ! $cancel) // Transfer stock from a warehouse to another warehouse if ($action == "transfert_stock" && ! $cancel) { - if (! (GETPOST("id_entrepot_source") > 0) || ! (GETPOST("id_entrepot_destination") > 0)) + if (! (GETPOST("id_entrepot_source",'int') > 0) || ! (GETPOST("id_entrepot_destination",'int') > 0)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Warehouse")), 'errors'); $error++; $action='transfert'; } - if (! GETPOST("nbpiece")) + if (! GETPOST("nbpiece",'int')) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors'); $error++; @@ -185,9 +185,9 @@ if ($action == "transfert_stock" && ! $cancel) if (! $error) { - if (GETPOST("id_entrepot_source") <> GETPOST("id_entrepot_destination")) + if (GETPOST("id_entrepot_source",'int') <> GETPOST("id_entrepot_destination",'int')) { - if (is_numeric(GETPOST("nbpiece")) && $id) + if (GETPOST("nbpiece",'int') && $id) { $product = new Product($db); $result=$product->fetch($id); @@ -201,28 +201,59 @@ if ($action == "transfert_stock" && ! $cancel) if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) $pricesrc=$product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp; $pricedest=$pricesrc; - //print 'price src='.$pricesrc.', price dest='.$pricedest;exit; + $pdluoid=GETPOST('pdluoid','int'); - // Remove stock - $result1=$product->correct_stock( - $user, - GETPOST("id_entrepot_source"), - GETPOST("nbpiece"), - 1, - GETPOST("label"), - $pricesrc - ); + if ($pdluoid>0) + { + $pdluo = new Productbatch($db); + $result=$pdluo->fetch($pdluoid); - // Add stock - $result2=$product->correct_stock( - $user, - GETPOST("id_entrepot_destination"), - GETPOST("nbpiece"), - 0, - GETPOST("label"), - $pricedest - ); + if ($result>0 && $pdluo->id) + { + // Remove stock + $result1=$product->correct_stock_batch( + $user, + $pdluo->warehouseid, + GETPOST("nbpiece",'int'), + 1, + GETPOST("label",'san_alpha'), + $pricesrc, + $pdluo->eatby,$pdluo->sellby,$pdluo->batch + ); + // Add stock + $result2=$product->correct_stock_batch( + $user, + GETPOST("id_entrepot_destination",'int'), + GETPOST("nbpiece",'int'), + 0, + GETPOST("label",'san_alpha'), + $pricedest, + $pdluo->eatby,$pdluo->sellby,$pdluo->batch + ); + } + } + else + { + // Remove stock + $result1=$product->correct_stock( + $user, + GETPOST("id_entrepot_source"), + GETPOST("nbpiece"), + 1, + GETPOST("label"), + $pricesrc + ); + // Add stock + $result2=$product->correct_stock( + $user, + GETPOST("id_entrepot_destination"), + GETPOST("nbpiece"), + 0, + GETPOST("label"), + $pricedest + ); + } if ($result1 >= 0 && $result2 >= 0) { $db->commit(); @@ -239,6 +270,7 @@ if ($action == "transfert_stock" && ! $cancel) } } +// Update batch information if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save')) { @@ -540,15 +572,43 @@ if ($id > 0 || $ref) */ if ($action == "transfert") { + $pdluoid=GETPOST('pdluoid','int'); + + if ($pdluoid > 0) + { + $pdluo = new Productbatch($db); + $result=$pdluo->fetch($pdluoid); + + if ($result > 0) + { + $pdluoid=$pdluo->id; + } + else + { + dol_print_error($db); + } + } + print_titre($langs->trans("StockTransfer")); print '