From f2238b6885253a331c05e3a3715a359108391552 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Oct 2008 12:49:16 +0000 Subject: [PATCH] Enhancements on datawarehouse management --- htdocs/product/price.php | 6 +- htdocs/product/stock/fiche.php | 629 ++++++++++++++++--------------- htdocs/product/stock/product.php | 50 ++- 3 files changed, 361 insertions(+), 324 deletions(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 91a15d02916..6f62bc2ac00 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -105,7 +105,7 @@ if ($_POST["action"] == 'update_price' && ! $_POST["cancel"] && $user->rights->p } } -if ($_GET["action"] == 'delete' && $user->rights->produit->creer) +if ($_GET["action"] == 'delete' && $user->rights->produit->supprimer) { $productstatic = new Product($db); $result=$productstatic->log_price_delete($user,$_GET["lineid"]); @@ -406,7 +406,7 @@ if ($result) print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").''; print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''; print ''.$langs->trans("ChangedBy").''; - if ($user->rights->produit->creer) print ' '; + if ($user->rights->produit->supprimer) print ' '; print ''; $var=True; @@ -436,7 +436,7 @@ if ($result) print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.''; // Action - if ($user->rights->produit->creer) + if ($user->rights->produit->supprimer) { print ''; if ($i > 0) diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index e1f655c3a20..ab257ad6f6f 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -20,11 +20,11 @@ */ /** - \file htdocs/product/stock/fiche.php - \ingroup stock - \brief Page fiche entrepot - \version $Id$ -*/ + \file htdocs/product/stock/fiche.php + \ingroup stock + \brief Page fiche entrepot + \version $Id$ + */ require("./pre.inc.php"); @@ -48,80 +48,80 @@ $mesg = ''; // Ajout entrepot if ($_POST["action"] == 'add') { - $entrepot = new Entrepot($db); + $entrepot = new Entrepot($db); - $entrepot->ref = $_POST["ref"]; - $entrepot->libelle = $_POST["libelle"]; - $entrepot->description = $_POST["desc"]; - $entrepot->statut = $_POST["statut"]; - $entrepot->lieu = $_POST["lieu"]; - $entrepot->address = $_POST["address"]; - $entrepot->cp = $_POST["cp"]; - $entrepot->ville = $_POST["ville"]; - $entrepot->pays_id = $_POST["pays_id"]; + $entrepot->ref = $_POST["ref"]; + $entrepot->libelle = $_POST["libelle"]; + $entrepot->description = $_POST["desc"]; + $entrepot->statut = $_POST["statut"]; + $entrepot->lieu = $_POST["lieu"]; + $entrepot->address = $_POST["address"]; + $entrepot->cp = $_POST["cp"]; + $entrepot->ville = $_POST["ville"]; + $entrepot->pays_id = $_POST["pays_id"]; - if ($entrepot->libelle) { - $id = $entrepot->create($user); - if ($id > 0) { - Header("Location: fiche.php?id=$id"); - } + if ($entrepot->libelle) { + $id = $entrepot->create($user); + if ($id > 0) { + Header("Location: fiche.php?id=$id"); + } - $_GET["action"] = 'create'; - $mesg="
".$entrepot->error."
"; - } - else { - $mesg="
".$langs->trans("ErrorWarehouseRefRequired")."
"; - $_GET["action"]="create"; // Force retour sur page création - } + $_GET["action"] = 'create'; + $mesg="
".$entrepot->error."
"; + } + else { + $mesg="
".$langs->trans("ErrorWarehouseRefRequired")."
"; + $_GET["action"]="create"; // Force retour sur page cr�ation + } } // Modification entrepot if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel")) { - $entrepot = new Entrepot($db); - if ($entrepot->fetch($_POST["id"])) - { - $entrepot->libelle = $_POST["libelle"]; - $entrepot->description = $_POST["desc"]; - $entrepot->statut = $_POST["statut"]; - $entrepot->lieu = $_POST["lieu"]; - $entrepot->address = $_POST["address"]; - $entrepot->cp = $_POST["cp"]; - $entrepot->ville = $_POST["ville"]; - $entrepot->pays_id = $_POST["pays_id"]; + $entrepot = new Entrepot($db); + if ($entrepot->fetch($_POST["id"])) + { + $entrepot->libelle = $_POST["libelle"]; + $entrepot->description = $_POST["desc"]; + $entrepot->statut = $_POST["statut"]; + $entrepot->lieu = $_POST["lieu"]; + $entrepot->address = $_POST["address"]; + $entrepot->cp = $_POST["cp"]; + $entrepot->ville = $_POST["ville"]; + $entrepot->pays_id = $_POST["pays_id"]; - if ( $entrepot->update($_POST["id"], $user) > 0) - { - $_GET["action"] = ''; - $_GET["id"] = $_POST["id"]; - //$mesg = '
Fiche mise à jour
'; - } - else - { - $_GET["action"] = 'edit'; - $_GET["id"] = $_POST["id"]; - $mesg = '
Fiche non mise à jour !' . "
" . $entrepot->error.'
'; - } - } - else - { - $_GET["action"] = 'edit'; - $_GET["id"] = $_POST["id"]; - $mesg = '
Fiche non mise à jour !' . "
" . $entrepot->error.'
'; - } + if ( $entrepot->update($_POST["id"], $user) > 0) + { + $_GET["action"] = ''; + $_GET["id"] = $_POST["id"]; + //$mesg = '
Fiche mise � jour
'; + } + else + { + $_GET["action"] = 'edit'; + $_GET["id"] = $_POST["id"]; + $mesg = '
Fiche non mise � jour !' . "
" . $entrepot->error.'
'; + } + } + else + { + $_GET["action"] = 'edit'; + $_GET["id"] = $_POST["id"]; + $mesg = '
Fiche non mise � jour !' . "
" . $entrepot->error.'
'; + } } if ($_POST["cancel"] == $langs->trans("Cancel")) { - $_GET["action"] = ''; - $_GET["id"] = $_POST["id"]; + $_GET["action"] = ''; + $_GET["id"] = $_POST["id"]; } /* -* View -*/ + * View + */ llxHeader("","",$langs->trans("WarehouseCard")); @@ -129,322 +129,335 @@ $form=new Form($db); if ($_GET["action"] == 'create') { - print "
\n"; - print ''; - print ''."\n"; - print_titre($langs->trans("NewWarehouse")); + print "\n"; + print ''; + print ''."\n"; + print_titre($langs->trans("NewWarehouse")); - if ($mesg) - { - print $mesg; - } + if ($mesg) + { + print $mesg; + } - print ''; + print '
'; // Ref - print ''; + print ''; - print ''; + print ''; // Description - print ''; + } + print ''; - print ''; + print ''; - print ''; - print ''; - - print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print '
'.$langs->trans("Ref").'
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; + print '
'.$langs->trans("Description").''; if ($conf->fckeditor->enabled) - { - // Editeur wysiwyg + { + // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('desc',$entrepot->description,180,'dolibarr_notes','In',false); $doleditor->Create(); - } - else - { + } + else + { print ''; - } - print '
'.$langs->trans('Address').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Country').''; - $form->select_pays($entrepot->pays_id?$entrepot->pays_id:$mysoc->pays_code, 'pays_id'); - print '
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans("Status").''; - print ''; - print '
'.$langs->trans('Country').''; + $form->select_pays($entrepot->pays_id?$entrepot->pays_id:$mysoc->pays_code, 'pays_id'); + print '
'.$langs->trans("Status").''; + print ''; + print '
'; - print '
'; + print ''; + + print ''; + print ''; } else { - if ($_GET["id"]) - { - if ($mesg) print $mesg; + if ($_GET["id"]) + { + if ($mesg) print $mesg; - $entrepot = new Entrepot($db); - $result = $entrepot->fetch($_GET["id"]); - if ($result < 0) - { - dolibarr_print_error($db); - } + $entrepot = new Entrepot($db); + $result = $entrepot->fetch($_GET["id"]); + if ($result < 0) + { + dolibarr_print_error($db); + } - /* - * Affichage fiche - */ - if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') - { + /* + * Affichage fiche + */ + if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') + { - /* - * Affichage onglets - */ - $h = 0; + /* + * Affichage onglets + */ + $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("WarehouseCard"); - $hselected=$h; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("WarehouseCard"); + $hselected=$h; + $h++; - $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("StockMovements"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("EnhancedValue"); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("StockMovements"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("EnhancedValue"); + $h++; - if ($conf->global->STOCK_USE_WAREHOUSE_BY_USER) - { - // Add the constant STOCK_USE_WAREHOUSE_BY_USER in cont table to use this feature. - // Should not be enabled by defaut because does not work yet correctly because - // there is no way to add values in the table llx_user_entrepot - $head[$h][0] = DOL_URL_ROOT.'/product/stock/user.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("Users"); - $h++; - } + if ($conf->global->STOCK_USE_WAREHOUSE_BY_USER) + { + // Add the constant STOCK_USE_WAREHOUSE_BY_USER in cont table to use this feature. + // Should not be enabled by defaut because does not work yet correctly because + // there is no way to add values in the table llx_user_entrepot + $head[$h][0] = DOL_URL_ROOT.'/product/stock/user.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("Users"); + $h++; + } - $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("Info"); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("Info"); + $h++; - dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle); + dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle); - print ''; + print '
'; // Ref - print ''; + print ''; - print ''; + print ''; // Description - print ''; + print ''; - print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; - // Statut - print ''; + // Statut + print ''; - print '"; + print '"; - // Dernier mouvement - $sql = "SELECT max( ".$db->pdate("m.datem").") as datem"; - $sql .= " FROM llx_stock_mouvement as m"; - $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."';"; - $resql = $db->query($sql); - if ($resql) - { - $row = $db->fetch_row($resql); - } - else - { - dolibarr_print_error($db); - } + // Dernier mouvement + $sql = "SELECT max( ".$db->pdate("m.datem").") as datem"; + $sql .= " FROM llx_stock_mouvement as m"; + $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."';"; + $resql = $db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + } + else + { + dolibarr_print_error($db); + } - print '"; + print '"; - print "
'.$langs->trans("Ref").''.$entrepot->libelle.'
'.$langs->trans("Ref").''.$entrepot->libelle.'
'.$langs->trans("LocationSummary").''.$entrepot->lieu.'
'.$langs->trans("LocationSummary").''.$entrepot->lieu.'
'.$langs->trans("Description").''.nl2br($entrepot->description).'
'.$langs->trans("Description").''.nl2br($entrepot->description).'
'.$langs->trans('Address').''; - print $entrepot->address; - print '
'.$langs->trans('Address').''; + print $entrepot->address; + print '
'.$langs->trans('Zip').''.$entrepot->cp.''.$langs->trans('Town').''.$entrepot->ville.'
'.$langs->trans('Zip').''.$entrepot->cp.''.$langs->trans('Town').''.$entrepot->ville.'
'.$langs->trans('Country').''; - print $entrepot->pays; - print '
'.$langs->trans('Country').''; + print $entrepot->pays; + print '
'.$langs->trans("Status").''.$entrepot->getLibStatut(4).'
'.$langs->trans("Status").''.$entrepot->getLibStatut(4).'
'.$langs->trans("NumberOfProducts").''; - print $entrepot->nb_products(); - print "
'.$langs->trans("NumberOfProducts").''; + print $entrepot->nb_products(); + print "
'.$langs->trans("LastMovement").''; - print ''.dolibarr_print_date($row[0]).''; - print "
'.$langs->trans("LastMovement").''; + print ''.dolibarr_print_date($row[0]).''; + print "
"; + print ""; - print ''; - - - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ - - print "
\n"; - - if ($_GET["action"] == '') - { - print "id."\">".$langs->trans("Modify").""; - } - - print "
"; + print ''; - /* ************************************************************************** */ - /* */ - /* Affichage de la liste des produits de l'entrepot */ - /* */ - /* ************************************************************************** */ - print '
'; - - print ''; - print ""; + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ - print_liste_field_titre($langs->trans("Product"),"", "p.ref","&id=".$_GET['id'],"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"", "p.label","&id=".$_GET['id'],"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder); - - print ""; - $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, ps.reel as value "; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p "; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; - } - $sql .= " WHERE ps.fk_product = p.rowid "; - $sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse) - $sql .= " AND ps.fk_entrepot = ".$entrepot->id; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { - $sql.= ' AND IFNULL(c.visible,1)=1'; - } + print "
\n"; + + if ($_GET["action"] == '') + { + print "id."\">".$langs->trans("Modify").""; + } + + print "
"; + + + /* ************************************************************************** */ + /* */ + /* Affichage de la liste des produits de l'entrepot */ + /* */ + /* ************************************************************************** */ + print '
'; + + print '
'; + print ""; + print_liste_field_titre($langs->trans("Product"),"", "p.ref","&id=".$_GET['id'],"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"", "p.label","&id=".$_GET['id'],"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder); + if ($user->rights->stock->mouvement->creer) print ''; + if ($user->rights->stock->creer) print ''; + print ""; + + $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, ps.reel as value "; + $sql .= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p "; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; + } + $sql .= " WHERE ps.fk_product = p.rowid "; + $sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse) + $sql .= " AND ps.fk_entrepot = ".$entrepot->id; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { + $sql.= ' AND IFNULL(c.visible,1)=1'; + } $sql .= " ORDER BY " . $sortfield . " " . $sortorder; - //$sql .= $db->plimit($limit + 1 ,$offset); + //$sql .= $db->plimit($limit + 1 ,$offset); - $resql = $db->query($sql) ; - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - // Multilangs - if ($conf->global->MAIN_MULTILANGS) // si l'option est active - { - $sql = "SELECT label FROM ".MAIN_DB_PREFIX."product_det"; - $sql.= " WHERE fk_product=".$objp->rowid." AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; + $resql = $db->query($sql) ; + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); - $result = $db->query($sql); - if ($result) - { - $objtp = $db->fetch_object($result); - if ($objtp->label != '') $objp->produit = $objtp->label; - } - } - - $var=!$var; - //print ''; - print ""; - print ""; - print ''; - print ''; - //print "\n"; - print ""; - $i++; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - print "
  
'.dolibarr_print_date($objp->datem).'
rowid\">"; - print img_object($langs->trans("ShowProduct"),"product").' '.$objp->ref; - print "'.$objp->produit.''.$objp->value.'entrepot_id\">"; - //print img_object($langs->trans("ShowWarehous"),"stock").' '.$objp->stock; - //print "
\n"; - } + // Multilangs + if ($conf->global->MAIN_MULTILANGS) // si l'option est active + { + $sql = "SELECT label FROM ".MAIN_DB_PREFIX."product_det"; + $sql.= " WHERE fk_product=".$objp->rowid." AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if ($objtp->label != '') $objp->produit = $objtp->label; + } + } + + $var=!$var; + //print ''.dolibarr_print_date($objp->datem).''; + print ""; + print "rowid\">"; + print img_object($langs->trans("ShowProduct"),"product").' '.$objp->ref; + print ""; + print ''.$objp->produit.''; + print ''.$objp->value.''; + + if ($user->rights->stock->mouvement->creer) + { + print ''; + print $langs->trans("StockMovement"); + print ""; + } + + if ($user->rights->stock->creer) + { + print ''; + print $langs->trans("StockCorrection"); + print ""; + } + + print ""; + $i++; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + print "\n"; + } - /* - * Edition fiche - */ - if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && 1) - { - print_fiche_titre($langs->trans("WarehouseEdit"), $mesg); + /* + * Edition fiche + */ + if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && 1) + { + print_fiche_titre($langs->trans("WarehouseEdit"), $mesg); - print '
'; - print ''; - print ''; + print ''; + print ''; + print ''; - print ''; + print '
'; // Ref - print ''; - - print ''; + print ''; - // Description - print ''; + + // Description + print ''; + } + print ''; - print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; - print '
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Ref").'
'.$langs->trans("Description").''; + print '
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; if ($conf->fckeditor->enabled) - { - // Editeur wysiwyg + { + // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('desc',$entrepot->description,180,'dolibarr_notes','In',false); $doleditor->Create(); - } - else - { + } + else + { print ''; - } - print '
'.$langs->trans('Address').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Country').''; - $form->select_pays($entrepot->pays_id, 'pays_id'); - print '
'.$langs->trans('Country').''; + $form->select_pays($entrepot->pays_id, 'pays_id'); + print '
'.$langs->trans("Status").''; - print ''; - print '
'.$langs->trans("Status").''; + print ''; + print '
 '; - print '
'; - print '
'; + print ' '; + print ''; + print ''; + print ''; - } - } + } + } } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 43a8ffcbefe..a9cc1cdc017 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -121,7 +121,7 @@ if ($_GET["id"] || $_GET["ref"]) print ''; print ''; - // Libellé + // Libell� print ''.$langs->trans("Label").''.$product->libelle.''; print ''; @@ -231,7 +231,9 @@ if ($_GET["id"] || $_GET["ref"]) print ''.$langs->trans("Warehouse").''; // Entrepot - print ''; $sql = "SELECT e.rowid, e.label FROM ".MAIN_DB_PREFIX."entrepot as e"; $sql .= " WHERE statut = 1"; $sql .= " ORDER BY lower(e.label)"; @@ -240,15 +242,20 @@ if ($_GET["id"] || $_GET["ref"]) if ($resql) { $num = $db->num_rows($resql); + if ($num > 1) print '