From 1ce9e4b884c152e62721a126dc4d63daf22f5864 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Jul 2009 19:02:04 +0000 Subject: [PATCH] Qual: Factorize some code. Look: Add picto for warehouse on stock tabs. --- htdocs/lib/stock.lib.php | 75 +++++++++++++++++++++++++ htdocs/product/stock/entrepot.class.php | 36 ++++++------ htdocs/product/stock/fiche-valo.php | 35 ++---------- htdocs/product/stock/fiche.php | 35 +----------- htdocs/product/stock/info.php | 32 +---------- htdocs/product/stock/mouvement.php | 32 ++--------- htdocs/product/stock/user.php | 37 +++--------- 7 files changed, 115 insertions(+), 167 deletions(-) create mode 100644 htdocs/lib/stock.lib.php diff --git a/htdocs/lib/stock.lib.php b/htdocs/lib/stock.lib.php new file mode 100644 index 00000000000..2b7c76f37ae --- /dev/null +++ b/htdocs/lib/stock.lib.php @@ -0,0 +1,75 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/lib/stock.lib.php + * \brief Library file with function for stock module + * \version $Id$ + */ + +/** + * Enter description here... + * + * @param unknown_type $contrat + * @return unknown + */ +function stock_prepare_head($entrepot) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("WarehouseCard"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("StockMovements"); + $head[$h][2] = 'movements'; + $h++; + + /* + $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("EnhancedValue"); + $head[$h][2] = 'value'; + $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"); + $head[$h][2] = 'user'; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + return $head; +} + +?> \ No newline at end of file diff --git a/htdocs/product/stock/entrepot.class.php b/htdocs/product/stock/entrepot.class.php index 324bfe7f8e5..c1dc2061fb3 100644 --- a/htdocs/product/stock/entrepot.class.php +++ b/htdocs/product/stock/entrepot.class.php @@ -228,30 +228,30 @@ class Entrepot extends CommonObject $result=$this->db->query($sql); if ($result) { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; + $this->id = $obj->rowid; - if ($obj->fk_user_author) { - $cuser = new User($this->db, $obj->fk_user_author); - $cuser->fetch(); - $this->user_creation = $cuser; - } + if ($obj->fk_user_author) { + $cuser = new User($this->db, $obj->fk_user_author); + $cuser->fetch(); + $this->user_creation = $cuser; + } - if ($obj->fk_user_valid) { - $vuser = new User($this->db, $obj->fk_user_valid); - $vuser->fetch(); - $this->user_validation = $vuser; - } + if ($obj->fk_user_valid) { + $vuser = new User($this->db, $obj->fk_user_valid); + $vuser->fetch(); + $this->user_validation = $vuser; + } - $this->date_creation = $obj->datec; - $this->date_modification = $obj->datem; + $this->date_creation = $obj->datec; + $this->date_modification = $obj->datem; - } + } - $this->db->free($result); + $this->db->free($result); } else diff --git a/htdocs/product/stock/fiche-valo.php b/htdocs/product/stock/fiche-valo.php index deb59397d33..1817e6a42ed 100644 --- a/htdocs/product/stock/fiche-valo.php +++ b/htdocs/product/stock/fiche-valo.php @@ -25,6 +25,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/stock.lib.php"); $langs->load("products"); $langs->load("stocks"); @@ -52,39 +53,11 @@ if ($_GET["id"]) dol_print_error($db); } - /* - * Affichage onglets - */ - $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("WarehouseCard"); - $h++; + $head = stock_prepare_head($entrepot); - $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("StockMovements"); - $h++; + dol_fiche_head($head, 'value', $langs->trans("Warehouse"), 0, 'stock'); - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("EnhancedValue"); - $hselected=$h; - $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++; - - dol_fiche_head($head, $hselected, $langs->trans("Warehouse")); print ''; @@ -137,7 +110,7 @@ if ($_GET["id"]) print "
\n"; $year = strftime("%Y",time()); - $file=DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year).'.png'; + $file=$conf->stock->dir_temp.'/entrepot-'.$entrepot->id.'-'.($year).'.png'; // TODO Build graph in $file from a table called llx_stock_log diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index 0bae3a88237..3c51d940688 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -27,6 +27,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/stock.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); @@ -208,40 +209,10 @@ else */ if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { + $head = stock_prepare_head($entrepot); - /* - * Affichage onglets - */ - $h = 0; + dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); - $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++; - - 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++; - - dol_fiche_head($head, $hselected, $langs->trans("Warehouse")); print '
'; diff --git a/htdocs/product/stock/info.php b/htdocs/product/stock/info.php index 262deec7b96..2f5d70a4d1f 100644 --- a/htdocs/product/stock/info.php +++ b/htdocs/product/stock/info.php @@ -25,6 +25,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/stock.lib.php"); $langs->load("stocks"); @@ -38,36 +39,9 @@ $entrepot = new Entrepot($db); $entrepot->fetch($_GET["id"]); $entrepot->info($_GET["id"]); -$h = 0; +$head = stock_prepare_head($entrepot); -$head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; -$head[$h][1] = $langs->trans("WarehouseCard"); -$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++; -} - -$head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; -$head[$h][1] = $langs->trans("Info"); -$hselected=$h; -$h++; - -dol_fiche_head($head, $hselected, $langs->trans("Warehouse")); +dol_fiche_head($head, 'info', $langs->trans("Warehouse"), 0, 'stock'); print '
'; diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index ce2c29bbbe4..5bc526c7ca8 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -27,10 +27,12 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/stock.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); $langs->load("products"); +$langs->load("stocks"); if (!$user->rights->produit->lire) accessforbidden(); @@ -126,36 +128,10 @@ if ($resql) */ if ($_GET["id"]) { - $h = 0; + $head = stock_prepare_head($entrepot); - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("WarehouseCard"); - $h++; + dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), 0, 'stock'); - $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("StockMovements"); - $hselected=$h; - $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++; - } - - $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dol_fiche_head($head, $hselected, $langs->trans("Warehouse")); print ''; diff --git a/htdocs/product/stock/user.php b/htdocs/product/stock/user.php index 3a9a91355d3..d160e5bedc7 100644 --- a/htdocs/product/stock/user.php +++ b/htdocs/product/stock/user.php @@ -20,13 +20,15 @@ */ /** - \file htdocs/product/stock/user.php - \ingroup stock - \brief Page to link dolibarr users with warehouses - \version $Id$ + * \file htdocs/product/stock/user.php + * \ingroup stock + * \brief Page to link dolibarr users with warehouses + * \version $Id$ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/stock.lib.php"); + $langs->load("products"); $langs->load("stocks"); @@ -74,33 +76,10 @@ if ($_GET["id"]) if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { - /* - * Affichage onglets - */ - $h = 0; + $head = stock_prepare_head($entrepot); - $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("WarehouseCard"); - $h++; + dol_fiche_head($head, 'user', $langs->trans("Warehouse"), 0, 'stock'); - $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/user.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("Users"); - $hselected=$h; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dol_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle); print '
';