diff --git a/ChangeLog b/ChangeLog index 15b50425f45..00a99cef973 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,7 @@ For users: - Fix: [bug #1022] correct margin calculation for credit notes. - New: Can choose contact on event (action com) creation, and filtred by thirdparty. - New: Add hidden option MAIN_FORCE_DEFAULT_STATE_ID. +- New: Add page to make mass stock movement. For translators: - Qual: Normalized sort order of all languages files with english reference files. diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index 1ad1807d459..4e9abfcbaeb 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -122,12 +122,95 @@ if ($action == 'delline' && $idline != '') else unset($_SESSION['massstockmove']); } -if ($action == 'createmovement' && isset($_POST['valid'])) +if ($action == 'createmovements') { + $error=0; + + if (! GETPOST("label")) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired"),$langs->transnoentitiesnoconv("LabelMovement")); + } + + $db->begin(); + + if (! $error) + { + $product = new Product($db); + foreach($listofdata as $key => $val) // Loop on each movement to do + { + $id=$val['id']; + $id_product=$val['id_product']; + $id_sw=$val['id_sw']; + $id_tw=$val['id_tw']; + $qty=price2num($val['qty']); + + if (! $error && $id_sw <> $id_tw && is_numeric($qty) && $id_product) + { + $result=$product->fetch($id_product); + $product->load_stock(); // Load array product->stock_warehouse + // Define value of products moved + $pricesrc=0; + if (isset($product->stock_warehouse[$id_sw]->pmp)) $pricesrc=$product->stock_warehouse[$id_sw]->pmp; + $pricedest=$pricesrc; + //print 'price src='.$pricesrc.', price dest='.$pricedest;exit; + + // Remove stock + $result1=$product->correct_stock( + $user, + $id_sw, + $qty, + 1, + GETPOST("label"), + $pricesrc + ); + if ($result1 < 0) + { + $error++; + setEventMessage($product->errors,'errors'); + } + + // Add stock + $result2=$product->correct_stock( + $user, + $id_tw, + $qty, + 0, + GETPOST("label"), + $pricedest + ); + if ($result2 < 0) + { + $error++; + setEventMessage($product->errors,'errors'); + } + } + else + { + dol_print_error('',"Bad value saved into sessions"); + $error++; + } + } + } + + if (! $error) + { + unset($_SESSION['massstockmove']); + + $db->commit(); + setEventMessage($langs->trans("StockMovementRecorded"),'mesgs'); + header("Location: ".DOL_URL_ROOT.'/product/stock/index.php'); // Redirect to avoid pb when using back + exit; + } + else + { + $db->rollback(); + setEventMessage($langs->trans("Error"),'errors'); + } } @@ -230,8 +313,16 @@ foreach($listofdata as $key => $val) print ''; +print ''; + + print '
'; + +print '
'; +print ''; +print ''; + // Button to record mass movement $labelmovement=GETPOST("label")?GETPOST('label'):$langs->trans("MassStockMovement").' '.dol_print_date($now,'%Y-%m-%d %H:%M'); @@ -246,7 +337,6 @@ print ''; print '
'; - print '
'; diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 074d684b10e..eb9391c8698 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -414,7 +414,7 @@ if ($resql) print ""; //print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"], "m.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"], "m.datem","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("LabelMovement"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("ProductRef"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("ProductLabel"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible