Several fixes in stock management (label, and bad action when lot module

is on)
This commit is contained in:
Laurent Destailleur 2016-02-18 23:21:02 +01:00
parent 14fb2c914a
commit bc4c964b89
8 changed files with 235 additions and 45 deletions

View File

@ -110,7 +110,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->stock->enabled', __HANDLER__, 'left', 3102__+MAX_llx_menu__, 'products', '', 3100__+MAX_llx_menu__, '/product/stock/list.php', 'List', 1, 'stocks', '$user->rights->stock->lire', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->stock->enabled', __HANDLER__, 'left', 3104__+MAX_llx_menu__, 'products', '', 3100__+MAX_llx_menu__, '/product/stock/mouvement.php', 'Movements', 1, 'stocks', '$user->rights->stock->mouvement->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->stock->enabled && $conf->fournisseur->enabled', __HANDLER__, 'left', 3105__+MAX_llx_menu__, 'products', '', 3100__+MAX_llx_menu__, '/product/stock/replenish.php', 'Replenishments', 1, 'stocks', '$user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire', '', 2, 4, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->stock->enabled', __HANDLER__, 'left', 3106__+MAX_llx_menu__, 'products', '', 3100__+MAX_llx_menu__, '/product/stock/massstockmove.php', 'StockTransfer', 1, 'stocks', '$user->rights->stock->mouvement->creer', '', 2, 5, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->stock->enabled', __HANDLER__, 'left', 3106__+MAX_llx_menu__, 'products', '', 3100__+MAX_llx_menu__, '/product/stock/massstockmove.php', 'MassStockTransferShort', 1, 'stocks', '$user->rights->stock->mouvement->creer', '', 2, 5, __ENTITY__);
-- Product - Categories
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3200__+MAX_llx_menu__, 'products', 'cat', 3__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&type=0', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__);

View File

@ -1133,7 +1133,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/product/stock/list.php", $langs->trans("List"), 1, $user->rights->stock->lire);
$newmenu->add("/product/stock/mouvement.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
if ($conf->fournisseur->enabled) $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire);
$newmenu->add("/product/stock/massstockmove.php", $langs->trans("StockTransfer"), 1, $user->rights->stock->mouvement->creer);
$newmenu->add("/product/stock/massstockmove.php", $langs->trans("MassStockTransferShort"), 1, $user->rights->stock->mouvement->creer);
}
// Expeditions

View File

@ -34,7 +34,8 @@ LastMovements=Last movements
Units=Units
Unit=Unit
StockCorrection=Correct stock
StockTransfer=Stock movement
StockTransfer=Transfer stock
MassStockTransferShort=Mass stock transfer
StockMovement=Stock movement
StockMovements=Stock movements
LabelMovement=Movement label

View File

@ -325,7 +325,7 @@ $title = $langs->trans('MassMovement');
llxHeader('', $title);
print load_fiche_titre($langs->trans("MassStockMovement"));
print load_fiche_titre($langs->trans("MassStockTransferShort"));
$titletoadd=$langs->trans("Select");
$titletoaddnoent=$langs->transnoentitiesnoconv("Select");

View File

@ -54,16 +54,18 @@ $search_warehouse = trim(GETPOST("search_warehouse"));
$search_inventorycode = trim(GETPOST("search_inventorycode"));
$search_user = trim(GETPOST("search_user"));
$search_batch = trim(GETPOST("search_batch"));
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$page = GETPOST("page",'int');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
if ($page < 0) $page = 0;
$offset = $limit * $page;
if (! $sortfield) $sortfield="m.datem";
if (! $sortorder) $sortorder="DESC";
$pdluoid=GETPOST('pdluoid','int');
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{
$year='';
@ -152,6 +154,171 @@ if ($action == "correct_stock")
if (! $error) $action='';
}
// Transfer stock from a warehouse to another warehouse
if ($action == "transfert_stock" && ! $cancel)
{
$product = new Product($db);
if (! empty($product_id)) $result=$product->fetch($product_id);
if (! (GETPOST("id_entrepot_destination",'int') > 0))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
$error++;
$action='transfert';
}
if (empty($product_id))
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
$action='transfert';
}
if (! GETPOST("nbpiece",'int'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
$error++;
$action='transfert';
}
if ($id == GETPOST("id_entrepot_destination",'int'))
{
setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
$error++;
$action='transfert';
}
if (! empty($conf->productbatch->enabled))
{
$product = new Product($db);
$result=$product->fetch($product_id);
if ($product->hasbatch() && ! GETPOST("batch_number"))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
$error++;
$action='transfert';
}
}
if (! $error)
{
if ($id)
{
$object = new Entrepot($db);
$result=$object->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;
if (isset($product->pmp)) $pricesrc=$product->pmp;
$pricedest=$pricesrc;
if ($product->hasbatch())
{
$pdluo = new Productbatch($db);
if ($pdluoid > 0)
{
$result=$pdluo->fetch($pdluoid);
if ($result)
{
$srcwarehouseid=$pdluo->warehouseid;
$batch=$pdluo->batch;
$eatby=$pdluo->eatby;
$sellby=$pdluo->sellby;
}
else
{
setEventMessages($pdluo->error, $pdluo->errors, 'errors');
$error++;
}
}
else
{
$srcwarehouseid=$id;
$batch=GETPOST('batch_number');
$eatby=$d_eatby;
$sellby=$d_sellby;
}
if (! $error)
{
// Remove stock
$result1=$product->correct_stock_batch(
$user,
$srcwarehouseid,
GETPOST("nbpiece",'int'),
1,
GETPOST("label",'san_alpha'),
$pricesrc,
$eatby,$sellby,$batch,
GETPOST('inventorycode')
);
// Add stock
$result2=$product->correct_stock_batch(
$user,
GETPOST("id_entrepot_destination",'int'),
GETPOST("nbpiece",'int'),
0,
GETPOST("label",'san_alpha'),
$pricedest,
$eatby,$sellby,$batch,
GETPOST('inventorycode')
);
}
}
else
{
// Remove stock
$result1=$product->correct_stock(
$user,
$id,
GETPOST("nbpiece"),
1,
GETPOST("label"),
$pricesrc,
GETPOST('inventorycode')
);
// Add stock
$result2=$product->correct_stock(
$user,
GETPOST("id_entrepot_destination"),
GETPOST("nbpiece"),
0,
GETPOST("label"),
$pricedest,
GETPOST('inventorycode')
);
}
if (! $error && $result1 >= 0 && $result2 >= 0)
{
$db->commit();
if ($backtopage)
{
header("Location: ".$backtopage);
exit;
}
else
{
header("Location: mouvement.php?id=".$object->id);
exit;
}
}
else
{
setEventMessages($product->error, $product->errors, 'errors');
$db->rollback();
$action='transfert';
}
}
}
}
/*
* View
@ -451,7 +618,7 @@ if ($resql)
/* */
/* ************************************************************************** */
if (empty($action) && $id)
if (empty($action) && $id > 0)
{
print "<div class=\"tabsAction\">\n";
@ -460,16 +627,17 @@ if ($resql)
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("StockCorrection").'</a>';
}
/*if ($user->rights->stock->mouvement->creer)
if ($user->rights->stock->mouvement->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("StockMovement").'</a>';
}*/
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("StockTransfer").'</a>';
}
print '</div><br>';
}
$param='';
if ($id) $param.='&id='.$id;
if ($id > 0) $param.='&id='.$id;
if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
if ($search_inventorycode) $param.='&search_inventorycode='.urlencode($search_inventorycode);
if ($search_product_ref) $param.='&search_product_ref='.urlencode($search_product_ref);
@ -479,11 +647,11 @@ if ($resql)
if (!empty($snom)) $param.='&snom='.urlencode($snom); // FIXME $snom is not defined
if ($search_user) $param.='&search_user='.urlencode($search_user);
if ($idproduct > 0) $param.='&idproduct='.$idproduct;
if ($id) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $nbtotalofrecords,'');
if ($id > 0) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $nbtotalofrecords,'');
else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $nbtotalofrecords);
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
if ($id) print '<input type="hidden" name="id" value="'.$id.'">';
if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">";
@ -498,7 +666,7 @@ if ($resql)
print_liste_field_titre($langs->trans("l_eatby"),$_SERVER["PHP_SELF"],'m.eatby','',$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("l_sellby"),$_SERVER["PHP_SELF"],'m.sellby','',$param,'align="center"',$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
if (! $id > 0) 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
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("InventoryCodeShort"),$_SERVER["PHP_SELF"], "m.inventorycode","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("LabelMovement"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder);
@ -532,9 +700,12 @@ if ($resql)
print '<td></td>';
}
// Warehouse
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
print '</td>';
if (! $id > 0)
{
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
print '</td>';
}
// Author
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="6" name="search_user" value="'.($search_user).'">';
@ -598,17 +769,20 @@ if ($resql)
// Batch
if (! empty($conf->productbatch->enabled))
{
print '<td align="center">'.$objp->batch.'</td>';
print '<td align="center">'. dol_print_date($objp->eatby,'day') .'</td>';
print '<td align="center">'. dol_print_date($objp->sellby,'day') .'</td>';
print '<td align="center">'.$objp->batch.'</td>';
print '<td align="center">'. dol_print_date($objp->eatby,'day') .'</td>';
print '<td align="center">'. dol_print_date($objp->sellby,'day') .'</td>';
}
// Warehouse
print '<td>';
$warehousestatic->id=$objp->entrepot_id;
$warehousestatic->libelle=$objp->stock;
$warehousestatic->lieu=$objp->lieu;
print $warehousestatic->getNomUrl(1);
print "</td>\n";
if (! $id > 0)
{
print '<td>';
$warehousestatic->id=$objp->entrepot_id;
$warehousestatic->libelle=$objp->stock;
$warehousestatic->lieu=$objp->lieu;
print $warehousestatic->getNomUrl(1);
print "</td>\n";
}
// Author
print '<td>';
$userstatic->id=$objp->fk_user_author;

View File

@ -648,7 +648,7 @@ if (empty($action) && $object->id)
//if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch())
if ($user->rights->stock->mouvement->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert">'.$langs->trans("StockMovement").'</a>';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert">'.$langs->trans("StockTransfer").'</a>';
}
print '</div>';
@ -753,7 +753,7 @@ if ($resql)
{
print "\n".'<tr><td align="right">';
print img_picto($langs->trans("Tranfer"),'uparrow','class="hideonsmartphone"').' ';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert&amp;pdluoid='.$pdluo->id.'">'.$langs->trans("StockMovement").'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert&amp;pdluoid='.$pdluo->id.'">'.$langs->trans("StockTransfer").'</a>';
// Disabled, because edition of stock content must use the "Correct stock menu".
// Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
//print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=editline&amp;lineid='.$pdluo->id.'#'.$pdluo->id.'">';

View File

@ -15,13 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $object must be defined
* $product can be defined
*/
?>
<!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
<?php
if (! is_object($product)) $product=$object;
$productref = '';
if ($object->element == 'product') $productref = $object->ref;
$langs->load("productbatch");
@ -81,10 +81,13 @@
print '</tr>';
// Serial / Eat-by date
if ((! empty($conf->productbatch->enabled)) && is_object($product) && $product->hasbatch())
if (! empty($conf->productbatch->enabled) &&
(($object->element == 'product' && $object->hasbatch())
|| ($object->element == 'stock'))
)
{
print '<tr>';
print '<td colspan="2" class="fieldrequired">'.$langs->trans("batch_number").'</td><td colspan="4">';
print '<td colspan="2"'.($object->element == 'stock'?'': ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="4">';
print '<input type="text" name="batch_number" size="40" value="'.GETPOST("batch_number").'">';
print '</td>';
print '</tr><tr>';
@ -101,7 +104,7 @@
}
// Label of mouvement of id of inventory
$valformovementlabel=((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock",''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $product->ref));
$valformovementlabel=((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock",''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $productref));
print '<tr>';
print '<td width="20%" colspan="2">'.$langs->trans("MovementLabel").'</td>';
print '<td colspan="2">';

View File

@ -14,17 +14,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $product must be defined
* $object must be defined
* $backtopage
*/
?>
<!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
<?php
if (! is_object($product)) $product=$object;
$productref='';
if ($object->element == 'product') $productref = $object->ref;
$langs->load("productbatch");
if (empty($id)) $id = $object->id;
$pdluoid=GETPOST('pdluoid','int');
$pdluo = new Productbatch($db);
@ -44,7 +47,7 @@
print load_fiche_titre($langs->trans("StockTransfer"),'','title_generic.png');
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'" method="post">'."\n";
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="transfert_stock">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
@ -54,28 +57,37 @@
}
print '<table class="border" width="100%">';
// Source warehouse or product
print '<tr>';
print '<td width="15%" class="fieldrequired">'.$langs->trans("WarehouseSource").'</td><td width="15%">';
if ($pdluoid > 0)
if ($object->element == 'product')
{
print $formproduct->selectWarehouses($pdluo->warehouseid,'id_entrepot_source','',1,1);
print '<td width="15%" class="fieldrequired">'.$langs->trans("WarehouseSource").'</td>';
print '<td width="15%">';
print $formproduct->selectWarehouses((GETPOST("dwid")?GETPOST("dwid",'int'):(GETPOST('id_entrepot')?GETPOST('id_entrepot','int'):'ifone')),'id_entrepot','',1);
print '</td>';
}
else
if ($object->element == 'stock')
{
print $formproduct->selectWarehouses((GETPOST("dwid")?GETPOST("dwid",'int'):(GETPOST('id_entrepot_source')?GETPOST('id_entrepot_source','int'):'ifone')),'id_entrepot_source','',1);
print '<td width="15%" class="fieldrequired">'.$langs->trans("Product").'</td>';
print '<td width="15%">';
print $form->select_produits(GETPOST('product_id'),'product_id',(empty($conf->global->STOCK_SUPPORTS_SERVICES)?'0':''));
print '</td>';
}
print '</td>';
print '<td width="15%" class="fieldrequired">'.$langs->trans("WarehouseTarget").'</td><td width="15%">';
print $formproduct->selectWarehouses(GETPOST('id_entrepot_destination'),'id_entrepot_destination','',1);
print '</td>';
print '<td width="15%" class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td><td width="15%"><input type="text" class="flat" name="nbpiece" size="10" value="'.dol_escape_htmltag(GETPOST("nbpiece")).'"></td>';
print '</tr>';
// Eat-by date
if ((! empty($conf->productbatch->enabled)) && $product->hasbatch())
// Serial / Eat-by date
if (! empty($conf->productbatch->enabled) &&
(($object->element == 'product' && $object->hasbatch())
|| ($object->element == 'stock'))
)
{
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("batch_number").'</td><td colspan="5">';
print '<td'.($object->element == 'stock'?'': ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="5">';
print '<input type="text" name="batch_number" size="40"'.($pdluoid > 0 ? ' disabled':'').' value="'.(GETPOST('batch_number')?GETPOST('batch_number'):$pdluo->batch).'">'; // If form was opened for a specific pdluoid, field is disabled
print '</td>';
print '</tr><tr>';
@ -90,7 +102,7 @@
}
// Label
$valformovementlabel=(GETPOST("label")?GETPOST("label"):$langs->trans("MovementTransferStock", $product->ref));
$valformovementlabel=(GETPOST("label")?GETPOST("label"):$langs->trans("MovementTransferStock", $productref));
print '<tr>';
print '<td width="15%">'.$langs->trans("MovementLabel").'</td>';
print '<td colspan="3">';