From 5d9f16ca20cf8763acaf79d1eab6122bef1a4f11 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Aug 2012 11:33:11 +0200 Subject: [PATCH] New: More surface control on stock correction page --- ChangeLog | 1 + htdocs/core/lib/functions.lib.php | 1 + htdocs/product/stock/product.php | 218 ++++++++++++++++++------------ 3 files changed, 133 insertions(+), 87 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ea99586972..63952957652 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,7 @@ For users: - New: [ task #454 ]: Add "No category" into filters on category. - New: Update language files (de, tr, pt, ca_ES, es_ES). - New: Auto check box on page to edit interface options of user. +- New: More surface control on stock correction page. - New: Add great britain provinces. - New: Update libs/tools/logo for DoliWamp. - Fix: No images into product description lines as PDF generation does diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c61c16e108f..48e02b5b6fc 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3472,6 +3472,7 @@ function get_date_range($date_start,$date_end,$format = '',$outputlangs='') */ function setEventMessage($mesgstring, $style='mesgs') { + if (! in_array($style,array('mesgs','warnings','errors'))) dol_print_error('','Bad parameter for setEventMessage'); $_SESSION['dol_events'][$style][] = $mesgstring; } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 47aa0792f55..e232a92df65 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -42,6 +42,8 @@ $cancel=GETPOST('cancel'); // Security check $id = GETPOST('id')?GETPOST('id'):GETPOST('ref'); $ref = GETPOST('ref'); +$stocklimit = GETPOST('stocklimit'); +$cancel = GETPOST('cancel'); $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit&stock',$id,'product&product','','',$fieldid); @@ -59,96 +61,125 @@ if ($cancel) $action=''; if ($action == 'setstocklimit') { $product = new Product($db); - $result=$product->fetch($_POST['id']); - $product->seuil_stock_alerte=$_POST["stocklimit"]; + $result=$product->fetch($id); + $product->seuil_stock_alerte=$stocklimit; $result=$product->update($product->id,$user,1,0,1); if ($result < 0) { $mesg=join(',',$product->errors); } - $POST["action"]=""; - $id=$_POST["id"]; - $_GET["id"]=$_POST["id"]; + $action=''; } // Correct stock -if ($action == "correct_stock" && ! $_POST["cancel"]) +if ($action == "correct_stock" && ! $cancel) { - //if ($_POST["price"] == '') $_POST["price"] = 0; - if (isset($_POST["price"])) $priceunit=price2num($_POST["price"]); - if (is_numeric($_POST["nbpiece"]) && $id) + if (! (GETPOST("id_entrepot") > 0)) { - $product = new Product($db); - $result=$product->fetch($id); - - $result=$product->correct_stock( - $user, - $_POST["id_entrepot"], - $_POST["nbpiece"], - $_POST["mouvement"], - $_POST["label"], - $priceunit - ); // We do not change value of stock for a correction - - if ($result > 0) + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Warehouse")), 'errors'); + $error++; + $action='correction'; + } + if (! GETPOST("nbpiece")) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors'); + $error++; + $action='correction'; + } + + if (! $error) + { + $priceunit=price2num(GETPOST("price")); + if (is_numeric(GETPOST("nbpiece")) && $id) { - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id); - exit; + $product = new Product($db); + $result=$product->fetch($id); + + $result=$product->correct_stock( + $user, + GETPOST("id_entrepot"), + GETPOST("nbpiece"), + GETPOST("mouvement"), + GETPOST("label"), + $priceunit + ); // We do not change value of stock for a correction + + if ($result > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id); + exit; + } } } } // Transfer stock from a warehouse to another warehouse -if ($action == "transfert_stock" && ! $_POST["cancel"]) +if ($action == "transfert_stock" && ! $cancel) { - if ($_POST["id_entrepot_source"] <> $_POST["id_entrepot_destination"]) - { - if (is_numeric($_POST["nbpiece"]) && $id) + if (! (GETPOST("id_entrepot_source") > 0) || ! (GETPOST("id_entrepot_destination") > 0)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Warehouse")), 'errors'); + $error++; + $action='transfert'; + } + if (! GETPOST("nbpiece")) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors'); + $error++; + $action='transfert'; + } + + if (! $error) + { + if (GETPOST("id_entrepot_source") <> GETPOST("id_entrepot_destination")) { - $product = new Product($db); - $result=$product->fetch($id); - - $db->begin(); - - $product->load_stock(); // Load array product->stock_warehouse - - // Define value of products moved - $pricesrc=0; - if (isset($product->stock_warehouse[$_POST["id_entrepot_source"]]->pmp)) $pricesrc=$product->stock_warehouse[$_POST["id_entrepot_source"]]->pmp; - $pricedest=$pricesrc; - - //print 'price src='.$pricesrc.', price dest='.$pricedest;exit; - - // Remove stock - $result1=$product->correct_stock( - $user, - $_POST["id_entrepot_source"], - $_POST["nbpiece"], - 1, - $_POST["label"], - $pricesrc - ); - - // Add stock - $result2=$product->correct_stock( - $user, - $_POST["id_entrepot_destination"], - $_POST["nbpiece"], - 0, - $_POST["label"], - $pricedest - ); - - if ($result1 >= 0 && $result2 >= 0) + if (is_numeric(GETPOST("nbpiece")) && $id) { - $db->commit(); - header("Location: product.php?id=".$product->id); - exit; - } - else - { - $mesg=$product->error; - $db->rollback(); + $product = new Product($db); + $result=$product->fetch($id); + + $db->begin(); + + $product->load_stock(); // Load array product->stock_warehouse + + // Define value of products moved + $pricesrc=0; + 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; + + // 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(); + header("Location: product.php?id=".$product->id); + exit; + } + else + { + $mesg=$product->error; + $db->rollback(); + } } } } @@ -162,11 +193,11 @@ if ($action == "transfert_stock" && ! $_POST["cancel"]) $formproduct=new FormProduct($db); -if ($_GET["id"] || $_GET["ref"]) +if ($id > 0 || $ref) { $product = new Product($db); - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); + if ($ref) $result = $product->fetch('',$ref); + if ($id > 0) $result = $product->fetch($id); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("",$langs->trans("CardProduct".$product->type),$help_url); @@ -180,7 +211,8 @@ if ($_GET["id"] || $_GET["ref"]) $form = new Form($db); - print($mesg); + if ($mesg) print($mesg); + dol_htmloutput_events(); print ''; @@ -329,6 +361,20 @@ if ($_GET["id"] || $_GET["ref"]) */ if ($action == "correction") { + print ''; + print_titre($langs->trans("StockCorrection")); print ''."\n"; print ''; @@ -339,23 +385,23 @@ if ($_GET["id"] || $_GET["ref"]) print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; // Label print ''; print ''; print ''; - print ''; + print ''; print ''; print '
'.$langs->trans("Warehouse").''; - print $formproduct->selectWarehouses($_GET["dwid"],'id_entrepot','',1); + print $formproduct->selectWarehouses(($_GET["dwid"]?$_GET["dwid"]:GETPOST('id_entrepot')),'id_entrepot','',1); print ''; - print ''; print ''; print ''; print ''.$langs->trans("NumberOfUnit").''.$langs->trans("NumberOfUnit").'
'.$langs->trans("Label").''; - print ''; + print ''; print ''.$langs->trans("UnitPurchaseValue").''.$langs->trans("UnitPurchaseValue").'
'; @@ -378,19 +424,19 @@ if ($_GET["id"] || $_GET["ref"]) print ''; print ''.$langs->trans("WarehouseSource").''; - print $formproduct->selectWarehouses($_GET["dwid"],'id_entrepot_source','',1); + print $formproduct->selectWarehouses(($_GET["dwid"]?$_GET["dwid"]:GETPOST('id_entrepot_source')),'id_entrepot_source','',1); print ''; print ''.$langs->trans("WarehouseTarget").''; - print $formproduct->selectWarehouses('','id_entrepot_destination','',1); + print $formproduct->selectWarehouses(GETPOST('id_entrepot_destination'),'id_entrepot_destination','',1); print ''; - print ''.$langs->trans("NumberOfUnit").''; + print ''.$langs->trans("NumberOfUnit").''; print ''; // Label print ''; print ''.$langs->trans("Label").''; print ''; - print ''; + print ''; print ''; print ''; @@ -536,9 +582,7 @@ print ""; print ""; +llxFooter(); $db->close(); - - -llxFooter(); ?>