New: Can correct stock of a warehouse from warehouse card.

This commit is contained in:
Laurent Destailleur 2012-06-15 02:16:35 +02:00
parent bfee1630a0
commit 6f8ad124a1
3 changed files with 358 additions and 212 deletions

View File

@ -21,6 +21,7 @@ For users:
- New: Add link to third party into sells and purchase journal. - New: Add link to third party into sells and purchase journal.
- New: Suggest a method to generate a backup file for user with no access - New: Suggest a method to generate a backup file for user with no access
to mysqldump binary. to mysqldump binary.
- New: Can correct stock of a warehouse from warehouse card.
- Fix: No images into product description lines as PDF generation does - Fix: No images into product description lines as PDF generation does
not work with this. not work with this.

View File

@ -27,6 +27,7 @@ require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/stock.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/stock.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
@ -37,6 +38,9 @@ $langs->load("stocks");
if (!$user->rights->produit->lire) accessforbidden(); if (!$user->rights->produit->lire) accessforbidden();
$id=GETPOST('id','int'); $id=GETPOST('id','int');
$product_id=GETPOST("product_id");
$action=GETPOST('action');
$cancel=GETPOST('cancel');
$idproduct = isset($_GET["idproduct"])?$_GET["idproduct"]:$_PRODUCT["idproduct"]; $idproduct = isset($_GET["idproduct"])?$_GET["idproduct"]:$_PRODUCT["idproduct"];
$year = isset($_GET["year"])?$_GET["year"]:$_POST["year"]; $year = isset($_GET["year"])?$_GET["year"]:$_POST["year"];
$month = isset($_GET["month"])?$_GET["month"]:$_POST["month"]; $month = isset($_GET["month"])?$_GET["month"]:$_POST["month"];
@ -65,6 +69,39 @@ if (GETPOST("button_removefilter"))
} }
/*
* Actions
*/
if ($cancel) $action='';
// Correct stock
if ($action == "correct_stock" && ! $_POST["cancel"])
{
if (is_numeric($_POST["nbpiece"]) && $product_id)
{
$product = new Product($db);
$result=$product->fetch($product_id);
$result=$product->correct_stock(
$user,
$id,
$_POST["nbpiece"],
$_POST["mouvement"],
$_POST["label"],
0
); // We do not change value of stock for a correction
if ($result > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
}
}
else $action='';
}
/* /*
* View * View
*/ */
@ -74,6 +111,7 @@ $warehousestatic=new Entrepot($db);
$userstatic=new User($db); $userstatic=new User($db);
$form=new Form($db); $form=new Form($db);
$formother=new FormOther($db); $formother=new FormOther($db);
$formproduct=new FormProduct($db);
$sql = "SELECT p.rowid, p.label as produit, p.fk_product_type as type,"; $sql = "SELECT p.rowid, p.label as produit, p.fk_product_type as type,";
$sql.= " e.label as stock, e.rowid as entrepot_id,"; $sql.= " e.label as stock, e.rowid as entrepot_id,";
@ -89,38 +127,38 @@ $sql.= " AND e.entity = ".$conf->entity;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0"; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0";
if ($id) if ($id)
{ {
$sql.= " AND e.rowid ='".$id."'"; $sql.= " AND e.rowid ='".$id."'";
} }
if ($month > 0) if ($month > 0)
{ {
if ($year > 0) if ($year > 0)
$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
else else
$sql.= " AND date_format(m.datem, '%m') = '$month'"; $sql.= " AND date_format(m.datem, '%m') = '$month'";
} }
else if ($year > 0) else if ($year > 0)
{ {
$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
} }
if (! empty($search_movement)) if (! empty($search_movement))
{ {
$sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'"; $sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
} }
if (! empty($search_product)) if (! empty($search_product))
{ {
$sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'"; $sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'";
} }
if (! empty($search_warehouse)) if (! empty($search_warehouse))
{ {
$sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'"; $sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'";
} }
if (! empty($search_user)) if (! empty($search_user))
{ {
$sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'"; $sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'";
} }
if (! empty($_GET['idproduct'])) if (! empty($_GET['idproduct']))
{ {
$sql.= " AND p.rowid = '".$idproduct."'"; $sql.= " AND p.rowid = '".$idproduct."'";
} }
$sql.= $db->order($sortfield,$sortorder); $sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($conf->liste_limit+1, $offset); $sql.= $db->plimit($conf->liste_limit+1, $offset);
@ -129,217 +167,321 @@ $sql.= $db->plimit($conf->liste_limit+1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($idproduct) if ($idproduct)
{ {
$product = new Product($db); $product = new Product($db);
$product->fetch($idproduct); $product->fetch($idproduct);
} }
if ($_GET["id"]) if ($_GET["id"])
{ {
$entrepot = new Entrepot($db); $entrepot = new Entrepot($db);
$result = $entrepot->fetch($id); $result = $entrepot->fetch($id);
if ($result < 0) if ($result < 0)
{ {
dol_print_error($db); dol_print_error($db);
} }
} }
$i = 0; $i = 0;
$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks'; $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
$texte = $langs->trans("ListOfStockMovements"); $texte = $langs->trans("ListOfStockMovements");
llxHeader("",$texte,$help_url); llxHeader("",$texte,$help_url);
/* /*
* Show tab only if we ask a particular warehouse * Show tab only if we ask a particular warehouse
*/ */
if ($id) if ($id)
{ {
$head = stock_prepare_head($entrepot); $head = stock_prepare_head($entrepot);
dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), 0, 'stock'); dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), 0, 'stock');
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'; print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($entrepot,'id','',1,'rowid','libelle'); print $form->showrefnav($entrepot,'id','',1,'rowid','libelle');
print '</td>'; print '</td>';
print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>'; print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
// Description // Description
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.dol_htmlentitiesbr($entrepot->description).'</td></tr>'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.dol_htmlentitiesbr($entrepot->description).'</td></tr>';
// Address // Address
print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
print $entrepot->address; print $entrepot->address;
print '</td></tr>'; print '</td></tr>';
// Town // Town
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->zip.'</td>'; print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->zip.'</td>';
print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->town.'</td></tr>'; print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->town.'</td></tr>';
// Country // Country
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
$img=picto_from_langcode($entrepot->country_code); $img=picto_from_langcode($entrepot->country_code);
print ($img?$img.' ':''); print ($img?$img.' ':'');
print $entrepot->country; print $entrepot->country;
print '</td></tr>'; print '</td></tr>';
// Status // Status
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
$calcproducts=$entrepot->nb_products(); $calcproducts=$entrepot->nb_products();
// Nb of products // Nb of products
print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
print empty($calcproducts['nb'])?'0':$calcproducts['nb']; print empty($calcproducts['nb'])?'0':$calcproducts['nb'];
print "</td></tr>"; print "</td></tr>";
// Value // Value
print '<tr><td valign="top">'.$langs->trans("EstimatedStockValueShort").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("EstimatedStockValueShort").'</td><td colspan="3">';
print empty($calcproducts['value'])?'0':$calcproducts['value']; print empty($calcproducts['value'])?'0':$calcproducts['value'];
print "</td></tr>"; print "</td></tr>";
// Last movement // Last movement
$sql = "SELECT MAX(m.datem) as datem"; $sql = "SELECT MAX(m.datem) as datem";
$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
$sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'"; $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'";
$resqlbis = $db->query($sql); $resqlbis = $db->query($sql);
if ($resqlbis) if ($resqlbis)
{ {
$obj = $db->fetch_object($resqlbis); $obj = $db->fetch_object($resqlbis);
$lastmovementdate=$db->jdate($obj->datem); $lastmovementdate=$db->jdate($obj->datem);
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
print '<tr><td valign="top">'.$langs->trans("LastMovement").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("LastMovement").'</td><td colspan="3">';
if ($lastmovementdate) if ($lastmovementdate)
{ {
print dol_print_date($lastmovementdate,'dayhour'); print dol_print_date($lastmovementdate,'dayhour');
} }
else else
{ {
print $langs->trans("None"); print $langs->trans("None");
} }
print "</td></tr>"; print "</td></tr>";
print "</table>"; print "</table>";
print '</div>'; print '</div>';
} }
$param='';
if ($id) $param.='&id='.$id;
if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
if ($search_product) $param.='&search_product='.urlencode($search_product);
if ($search_warehouse) $param.='&search_warehouse='.urlencode($search_warehouse);
if ($sref) $param.='&sref='.urlencode($sref);
if ($snom) $param.='&snom='.urlencode($snom);
if ($search_user) $param.='&search_user='.urlencode($search_user);
if ($idproduct > 0) $param.='&idproduct='.$idproduct;
if ($id) print_barre_liste($texte, $page, "mouvement.php", $param, $sortfield, $sortorder,'',$num,0,'');
else print_barre_liste($texte, $page, "mouvement.php", $param, $sortfield, $sortorder,'',$num);
print '<table class="noborder" width="100%">'; /*
print "<tr class=\"liste_titre\">"; * Correct stock
//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); if ($action == "correction")
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder); {
print_liste_field_titre($langs->trans("Product"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder); print_titre($langs->trans("StockCorrection"));
print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "e.label","",$param,"",$sortfield,$sortorder); print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder); print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print_liste_field_titre($langs->trans("Units"),$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder); print '<input type="hidden" name="action" value="correct_stock">';
print "</tr>\n"; print '<table class="border" width="100%">';
// Lignes des champs de filtre // Warehouse
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'; print '<tr>';
if ($id) print '<input type="hidden" name="id" value="'.$id.'">'; print '<td width="20%">'.$langs->trans("Product").'</td>';
print '<td width="20%">';
print $form->select_produits(GETPOST('productid'),'product_id',(empty($conf->global->STOCK_SUPPORTS_SERVICES)?'0':''));
print '</td>';
print '<td width="20%">';
print '<select name="mouvement" class="flat">';
print '<option value="0">'.$langs->trans("Add").'</option>';
print '<option value="1">'.$langs->trans("Delete").'</option>';
print '</select></td>';
print '<td width="20%">'.$langs->trans("NumberOfUnit").'</td><td width="20%"><input class="flat" name="nbpiece" size="10" value=""></td>';
print '</tr>';
print '<tr class="liste_titre">'; // Label
print '<td class="liste_titre" valign="right">'; print '<tr>';
print $langs->trans('Month').': <input class="flat" type="text" size="2" maxlength="2" name="month" value="'.$month.'">'; print '<td width="20%">'.$langs->trans("Label").'</td>';
print '&nbsp;'.$langs->trans('Year').': '; print '<td colspan="4">';
$syear = GETPOST('year')?GETPOST('year'):-1; print '<input type="text" name="label" size="40" value="">';
$formother->select_year($syear,'year',1, 20, 5); print '</td>';
print '</td>'; print '</tr>';
// Label of movement
print '<td class="liste_titre" align="left">'; print '</table>';
print '<input class="flat" type="text" size="12" name="search_movement" value="'.$search_movement.'">';
print '</td>'; print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'">&nbsp;';
// Product print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '<td class="liste_titre" align="left">'; print '</form>';
print '<input class="flat" type="text" size="12" name="search_product" value="'.($idproduct?$product->libelle:$search_product).'">'; }
print '</td>';
print '<td class="liste_titre" align="left">'; /*
print '<input class="flat" type="text" size="10" name="search_warehouse" value="'.($search_warehouse).'">'; * Transfer of units
print '</td>'; */
print '<td class="liste_titre" align="left">'; /*
print '<input class="flat" type="text" size="6" name="search_user" value="'.($search_user).'">'; if ($action == "transfert")
print '</td>'; {
print '<td class="liste_titre" align="right">'; print_titre($langs->trans("Transfer"));
print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">'; 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 '<table class="border" width="100%">';
print '<tr>';
print '<td width="20%">'.$langs->trans("Product").'</td>';
print '<td width="20%">';
print $form->select_produits(GETPOST('productid'),'product_id');
print '</td>';
print '<td width="20%">'.$langs->trans("WarehouseTarget").'</td><td width="20%">';
print $formproduct->selectWarehouses('','id_entrepot_destination','',1);
print '</td>';
print '<td width="20%">'.$langs->trans("NumberOfUnit").'</td><td width="20%"><input name="nbpiece" size="10" value=""></td>';
print '</tr>';
// Label
print '<tr>';
print '<td width="20%">'.$langs->trans("Label").'</td>';
print '<td colspan="5">';
print '<input type="text" name="label" size="40" value="">';
print '</td>';
print '</tr>';
print '</table>';
print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '</form>';
}
*/
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
if (empty($action) && $id)
{
print "<div class=\"tabsAction\">\n";
if ($user->rights->stock->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("StockCorrection").'</a>';
}
/*if ($user->rights->stock->mouvement->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("StockMovement").'</a>';
}*/
print '</div><br>';
}
$param='';
if ($id) $param.='&id='.$id;
if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
if ($search_product) $param.='&search_product='.urlencode($search_product);
if ($search_warehouse) $param.='&search_warehouse='.urlencode($search_warehouse);
if ($sref) $param.='&sref='.urlencode($sref);
if ($snom) $param.='&snom='.urlencode($snom);
if ($search_user) $param.='&search_user='.urlencode($search_user);
if ($idproduct > 0) $param.='&idproduct='.$idproduct;
if ($id) print_barre_liste($texte, $page, "mouvement.php", $param, $sortfield, $sortorder,'',$num,0,'');
else print_barre_liste($texte, $page, "mouvement.php", $param, $sortfield, $sortorder,'',$num);
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">";
//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("Product"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "e.label","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Units"),$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder);
print "</tr>\n";
// Lignes des champs de filtre
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
if ($id) print '<input type="hidden" name="id" value="'.$id.'">';
print '<tr class="liste_titre">';
print '<td class="liste_titre" valign="right">';
print $langs->trans('Month').': <input class="flat" type="text" size="2" maxlength="2" name="month" value="'.$month.'">';
print '&nbsp;'.$langs->trans('Year').': ';
$syear = GETPOST('year')?GETPOST('year'):-1;
$formother->select_year($syear,'year',1, 20, 5);
print '</td>';
// Label of movement
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="12" name="search_movement" value="'.$search_movement.'">';
print '</td>';
// Product
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="12" name="search_product" value="'.($idproduct?$product->libelle:$search_product).'">';
print '</td>';
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_warehouse" value="'.($search_warehouse).'">';
print '</td>';
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="6" name="search_user" value="'.($search_user).'">';
print '</td>';
print '<td class="liste_titre" align="right">';
print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '&nbsp; '; print '&nbsp; ';
print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">'; print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
print '</form>'; print '</form>';
$var=True; $var=True;
while ($i < min($num,$conf->liste_limit)) while ($i < min($num,$conf->liste_limit))
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
// Id movement // Id movement
//print '<td>'.$objp->mid.'</td>'; // This is primary not movement id //print '<td>'.$objp->mid.'</td>'; // This is primary not movement id
// Date // Date
print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>'; print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
// Label of movement // Label of movement
print '<td>'.$objp->label.'</td>'; print '<td>'.$objp->label.'</td>';
// Product // Product
print '<td>'; print '<td>';
$productstatic->id=$objp->rowid; $productstatic->id=$objp->rowid;
$productstatic->ref=$objp->produit; $productstatic->ref=$objp->produit;
$productstatic->type=$objp->type; $productstatic->type=$objp->type;
print $productstatic->getNomUrl(1,'',16); print $productstatic->getNomUrl(1,'',16);
print "</td>\n"; print "</td>\n";
// Warehouse // Warehouse
print '<td>'; print '<td>';
$warehousestatic->id=$objp->entrepot_id; $warehousestatic->id=$objp->entrepot_id;
$warehousestatic->libelle=$objp->stock; $warehousestatic->libelle=$objp->stock;
print $warehousestatic->getNomUrl(1); print $warehousestatic->getNomUrl(1);
print "</td>\n"; print "</td>\n";
// Author // Author
print '<td>'; print '<td>';
$userstatic->id=$objp->fk_user_author; $userstatic->id=$objp->fk_user_author;
$userstatic->lastname=$objp->login; $userstatic->lastname=$objp->login;
print $userstatic->getNomUrl(1); print $userstatic->getNomUrl(1);
print "</td>\n"; print "</td>\n";
// Value // Value
print '<td align="right">'; print '<td align="right">';
if ($objp->value > 0) print '+'; if ($objp->value > 0) print '+';
print $objp->value.'</td>'; print $objp->value.'</td>';
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
$db->free($resql); $db->free($resql);
print "</table>"; print "</table>";
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
llxFooter(); llxFooter();

View File

@ -36,11 +36,12 @@ $langs->load("orders");
$langs->load("bills"); $langs->load("bills");
$langs->load("stocks"); $langs->load("stocks");
$action=GETPOST("action");
$cancel=GETPOST('cancel');
// Security check // Security check
if (isset($_GET["id"]) || isset($_GET["ref"])) $id = GETPOST('id')?GETPOST('id'):GETPOST('ref');
{ $ref = GETPOST('ref');
$id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:'');
}
$fieldid = isset($_GET["ref"])?'ref':'rowid'; $fieldid = isset($_GET["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit&stock',$id,'product','','',$fieldid); $result=restrictedArea($user,'produit&stock',$id,'product','','',$fieldid);
@ -52,8 +53,10 @@ $mesg = '';
* Actions * Actions
*/ */
if ($cancel) $action='';
// Set stock limit // Set stock limit
if ($_POST['action'] == 'setstocklimit') if ($action == 'setstocklimit')
{ {
$product = new Product($db); $product = new Product($db);
$result=$product->fetch($_POST['id']); $result=$product->fetch($_POST['id']);
@ -69,12 +72,12 @@ if ($_POST['action'] == 'setstocklimit')
} }
// Correct stock // Correct stock
if ($_POST["action"] == "correct_stock" && ! $_POST["cancel"]) if ($action == "correct_stock" && ! $_POST["cancel"])
{ {
if (is_numeric($_POST["nbpiece"])) if (is_numeric($_POST["nbpiece"]) && $id)
{ {
$product = new Product($db); $product = new Product($db);
$result=$product->fetch($_GET["id"]); $result=$product->fetch($id);
$result=$product->correct_stock( $result=$product->correct_stock(
$user, $user,
@ -87,21 +90,21 @@ if ($_POST["action"] == "correct_stock" && ! $_POST["cancel"])
if ($result > 0) if ($result > 0)
{ {
header("Location: product.php?id=".$product->id); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id);
exit; exit;
} }
} }
} }
// Transfer stock from a warehouse to another warehouse // Transfer stock from a warehouse to another warehouse
if ($_POST["action"] == "transfert_stock" && ! $_POST["cancel"]) if ($action == "transfert_stock" && ! $_POST["cancel"])
{ {
if ($_POST["id_entrepot_source"] <> $_POST["id_entrepot_destination"]) if ($_POST["id_entrepot_source"] <> $_POST["id_entrepot_destination"])
{ {
if (is_numeric($_POST["nbpiece"])) if (is_numeric($_POST["nbpiece"]) && $id)
{ {
$product = new Product($db); $product = new Product($db);
$result=$product->fetch($_GET["id"]); $result=$product->fetch($id);
$db->begin(); $db->begin();
@ -321,10 +324,10 @@ if ($_GET["id"] || $_GET["ref"])
/* /*
* Correct stock * Correct stock
*/ */
if ($_GET["action"] == "correction") if ($action == "correction")
{ {
print_titre($langs->trans("StockCorrection")); print_titre($langs->trans("StockCorrection"));
print "<form action=\"product.php?id=$product->id\" method=\"post\">\n"; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'" method="post">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="correct_stock">'; print '<input type="hidden" name="action" value="correct_stock">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -356,16 +359,15 @@ if ($_GET["id"] || $_GET["ref"])
print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'">&nbsp;'; print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '</form>'; print '</form>';
} }
/* /*
* Transfer of units * Transfer of units
*/ */
if ($_GET["action"] == "transfert") if ($action == "transfert")
{ {
print_titre($langs->trans("Transfer")); print_titre($langs->trans("Transfer"));
print "<form action=\"product.php?id=$product->id\" method=\"post\">\n"; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'" method="post">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="transfert_stock">'; print '<input type="hidden" name="action" value="transfert_stock">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -394,7 +396,6 @@ if ($_GET["id"] || $_GET["ref"])
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '</form>'; print '</form>';
} }
/* /*
@ -430,21 +431,23 @@ else
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
print "<div class=\"tabsAction\">\n";
//if (empty($_GET["action"])) if (empty($action) && $product->id)
//{ {
print "<div class=\"tabsAction\">\n";
if ($user->rights->stock->creer) if ($user->rights->stock->creer)
{ {
print '<a class="butAction" href="product.php?id='.$product->id.'&amp;action=correction">'.$langs->trans("StockCorrection").'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'&amp;action=correction">'.$langs->trans("StockCorrection").'</a>';
} }
if ($user->rights->stock->mouvement->creer) if ($user->rights->stock->mouvement->creer)
{ {
print '<a class="butAction" href="product.php?id='.$product->id.'&amp;action=transfert">'.$langs->trans("StockMovement").'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'&amp;action=transfert">'.$langs->trans("StockMovement").'</a>';
} }
//}
print '</div>'; print '</div>';
}