* Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005 Simon Tosser * Copyright (C) 2005-2009 Regis Houssin * * 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. */ /** * \file htdocs/product/stock/fiche.php * \ingroup stock * \brief Page fiche entrepot * \version $Id$ */ 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"); $langs->load("products"); $langs->load("stocks"); $langs->load("companies"); $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; if (! $sortfield) $sortfield="p.ref"; if (! $sortorder) $sortorder="DESC"; $mesg = ''; /* * Actions */ // Ajout entrepot if ($_POST["action"] == 'add' && $user->rights->stock->creer) { $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"]; if ($entrepot->libelle) { $id = $entrepot->create($user); if ($id > 0) { header("Location: fiche.php?id=".$id); exit; } $_GET["action"] = 'create'; $mesg="
".$entrepot->error."
"; } else { $mesg="
".$langs->trans("ErrorWarehouseRefRequired")."
"; $_GET["action"]="create"; // Force retour sur page cr�ation } } // Delete warehouse if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->stock->supprimer) { $entrepot = new Entrepot($db); $entrepot->fetch($_REQUEST["id"]); $result=$entrepot->delete($user); if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/product/stock/liste.php'); exit; } else { $mesg='
'.$entrepot->error.'
'; $_REQUEST['action']=''; } } // 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"]; 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"]; } /* * View */ $productstatic=new Product($db); $form=new Form($db); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("",$langs->trans("WarehouseCard"),$help_url); if ($_GET["action"] == 'create') { print_fiche_titre($langs->trans("NewWarehouse")); print "
\n"; print ''; print ''; print ''."\n"; if ($mesg) { print $mesg; } print ''; // Ref print ''; print ''; // Description print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; if ($conf->fckeditor->enabled) { // 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 { print ''; } print '
'.$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("Status").''; print ''; print '
'; print '
'; } else { if ($_GET["id"]) { if ($mesg) print $mesg; $entrepot = new Entrepot($db); $result = $entrepot->fetch($_GET["id"]); if ($result < 0) { dol_print_error($db); } /* * Affichage fiche */ if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { $head = stock_prepare_head($entrepot); dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); // Confirm delete third party if ($_GET["action"] == 'delete') { $html = new Form($db); $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$entrepot->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$entrepot->libelle),"confirm_delete",'',0,2); if ($ret == 'html') print '
'; } print ''; // Ref print ''; print ''; // Description print ''; // Address print ''; // Ville print ''; print ''; // Country print ''; // Statut print ''; $calcproducts=$entrepot->nb_products(); // Nb of products print '"; // Value print '"; // Last movement $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM llx_stock_mouvement as m"; $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'"; $resqlbis = $db->query($sql); if ($resqlbis) { $obj = $db->fetch_object($resqlbis); $lastmovementdate=$db->jdate($obj->datem); } else { dol_print_error($db); } print '"; print "
'.$langs->trans("Ref").''; print $form->showrefnav($entrepot,'id','',1,'rowid','libelle'); print '
'.$langs->trans("LocationSummary").''.$entrepot->lieu.'
'.$langs->trans("Description").''.nl2br($entrepot->description).'
'.$langs->trans('Address').''; print $entrepot->address; print '
'.$langs->trans('Zip').''.$entrepot->cp.''.$langs->trans('Town').''.$entrepot->ville.'
'.$langs->trans('Country').''; print $entrepot->pays; print '
'.$langs->trans("Status").''.$entrepot->getLibStatut(4).'
'.$langs->trans("NumberOfProducts").''; print empty($calcproducts['nb'])?'0':$calcproducts['nb']; print "
'.$langs->trans("EstimatedStockValueShort").''; print empty($calcproducts['value'])?'0':$calcproducts['value']; print "
'.$langs->trans("LastMovement").''; if ($lastmovementdate) print dol_print_date($lastmovementdate,'dayhour').' '; print '('.$langs->trans("FullList").')'; print "
"; print ''; /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "
\n"; if ($_GET["action"] == '') { if ($user->rights->stock->creer) print "id."\">".$langs->trans("Modify").""; else print "".$langs->trans("Modify").""; if ($user->rights->stock->supprimer) print "id."\">".$langs->trans("Delete").""; else print "".$langs->trans("Delete").""; } 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); print_liste_field_titre($langs->trans("AverageUnitPricePMPShort"),"", "ps.pmp","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("EstimatedStockValueShort"),"", "","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder); if ($user->rights->stock->mouvement->creer) print ''; if ($user->rights->stock->creer) print ''; print ""; $totalunit=0; $totalvalue=0; $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.fk_product_type as type,"; $sql.= " ps.pmp, 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 COALESCE(c.visible,1)=1'; } $sql.= " ORDER BY " . $sortfield . " " . $sortorder; //$sql .= $db->plimit($limit + 1 ,$offset); dol_syslog('List products sql='.$sql); $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"; $sql.= " FROM ".MAIN_DB_PREFIX."product_det"; $sql.= " WHERE fk_product=".$objp->rowid; $sql.= " 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 ''; print ""; print "'; print ''; print ''; $totalunit+=$objp->value; print ''; print ''; $totalvalue+=price2num($objp->pmp*$objp->value,'MT'); if ($user->rights->stock->mouvement->creer) { print '"; } if ($user->rights->stock->creer) { print '"; } print ""; $i++; } $db->free($resql); print ''; print ''; print ''; print ''; print ''; print ''; print ''; } else { dol_print_error($db); } print "
  
'.dol_print_date($objp->datem).'
"; $productstatic->id=$objp->rowid; $productstatic->ref=$objp->ref; $productstatic->type=$objp->type; print $productstatic->getNomUrl(1,'',16); print ''.$objp->produit.''.$objp->value.''.price(price2num($objp->pmp,'MU')).''.price(price2num($objp->pmp*$objp->value,'MT')).''; print img_picto($langs->trans("StockMovement"),'uparrow.png').' '.$langs->trans("StockMovement"); print "'; print $langs->trans("StockCorrection"); print "
'.$langs->trans("Total").''.$totalunit.' '.$totalvalue.'  
\n"; } /* * Edition fiche */ if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && 1) { print_fiche_titre($langs->trans("WarehouseEdit"), $mesg); print '
'; print ''; print ''; print ''; print ''; // Ref print ''; print ''; // Description print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; if ($conf->fckeditor->enabled) { // 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 { print ''; } print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Country').''; $form->select_pays($entrepot->pays_id, 'pays_id'); print '
'.$langs->trans("Status").''; print ''; print '
 '; print '
'; print '
'; } } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>