* Copyright (C) 2004-2005 Laurent Destailleur * * 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. * * $Id$ * $Source$ */ /** \file htdocs/fourn/product/fiche.php \ingroup product \brief Page de la fiche produit \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); $langs->load("products"); $user->getrights('produit'); $user->getrights('propale'); $user->getrights('facture'); $mesg = ''; if (!$user->rights->produit->lire) accessforbidden(); $types[0] = $langs->trans("Product"); $types[1] = $langs->trans("Service"); /* * */ if ($_GET["action"] == 'fastappro') { $product = new Product($db); $product->fetch($_GET["id"]); $result = $product->fastappro($user); Header("Location: fiche.php?id=".$_GET["id"]); } // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->produit->creer) { $product = new Product($db); $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->catid = $_POST["catid"]; $product->tva_tx = $_POST["tva_tx"]; $product->type = $_POST["type"]; $product->envente = $_POST["statut"]; $product->description = $_POST["desc"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $e_product = $product; $id = $product->create($user); if ($id > 0) { Header("Location: fiche.php?id=$id"); } else { if ($id == -3) { $mesg='
'.$product->error.'
'; $_error = 1; $_GET["action"] = "create"; $_GET["type"] = $_POST["type"]; } } } // Action mise a jour d'un produit ou service if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer) { $product = new Product($db); if ($product->fetch($_POST["id"])) { $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->description = $_POST["desc"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; if ($product->check()) { if ($product->update($product->id, $user) > 0) { $_GET["action"] = ''; $_GET["id"] = $_POST["id"]; Header("Location: fiche.php?id=".$_POST["id"]); } else { $_GET["action"] = 're-edit'; $_GET["id"] = $_POST["id"]; $mesg = $product->mesg_error; } } else { $_GET["action"] = 're-edit'; $_GET["id"] = $_POST["id"]; $mesg = $langs->trans("ErrorProductBadRefOrLabel"); } } } if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel")) { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0) { $action = ''; } else { $action = ''; } } } if ($_GET["action"] == 'remove_fourn') { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0) { $_GET["action"] = ''; $mesg = $langs->trans("SupplierRemoved"); } else { $_GET["action"] = ''; } } } if ($_POST["action"] == 'update_price' && $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer) { $product = new Product($db); $result = $product->fetch($_GET["id"]); $product->price = ereg_replace(" ","",$_POST["price"]); if ( $product->update_price($product->id, $user) > 0 ) { $_GET["action"] = ''; $mesg = 'Fiche mise à jour'; } else { $_GET["action"] = 'edit_price'; $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error; } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; Header("Location: fiche.php?id=".$_POST["id"]); } // Le produit n'est pas encore chargé a ce stade llxHeader("","",$langs->trans("CardProduct0")); /* * Création du produit * */ if ($_GET["action"] == 'create' && $user->rights->produit->creer) { $html = new Form($db); $nbligne=0; $product = new Product($db); if ($_error == 1) { $product = $e_product; } print '
'; print ''; print ''."\n"; print ''."\n"; if ($_GET["type"]==0) { $title=$langs->trans("NewProduct"); } if ($_GET["type"]==1) { $title=$langs->trans("NewService"); } print_fiche_titre($title); print ''; if ($mesg) print $mesg; if ($conf->categorie->enabled) { print ''; } print ''; print ''; if ($_GET["type"] == 0 && $conf->stock->enabled) { print "".''; } else { print ''; } print '"; if ($_GET["type"] == 1) { print ''; } print ''; print '
'.$langs->trans("Categorie"); print ''; if (isset($_REQUEST["catid"])) { $c = new Categorie ($db, $_REQUEST["catid"]); $ways = $c->print_all_ways(' > ','fourn/product/liste.php'); print $ways[0]."
\n"; } print '
'.$langs->trans("Ref").''; if ($_error == 1) { print $langs->trans("RefAlreadyExists"); } print '
'.$langs->trans("Label").'
Seuil stock'; print ''; print '
'.$langs->trans("Description").''; print '
'.$langs->trans("Duration").'  '; print ''.$langs->trans("Day").' '; print ''.$langs->trans("Week").' '; print ''.$langs->trans("Month").' '; print ''.$langs->trans("Year").' '; print '
 
'; print '
'; } else { /* * Fiche produit */ if ($_GET["id"]) { if ($_GET["action"] <> 're-edit') { $product = new Product($db); $result = $product->fetch($_GET["id"]); } if ( $product->id > 0 ) { if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { /* * En mode visu */ $h=0; $head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans("Card"); $hselected = $h; $h++; if($product->type == 0) { if ($conf->stock->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; $head[$h][1] = $langs->trans("Stock"); $h++; } } $head[$h][0] = DOL_URL_ROOT."/fourn/product/photos.php?id=".$product->id; $head[$h][1] = $langs->trans("Photos"); $h++; //Affichage onglet Catégories if ($conf->categorie->enabled){ $head[$h][0] = DOL_URL_ROOT."/fourn/product/categorie.php?id=".$product->id; $head[$h][1] = $langs->trans('Categories'); $h++; } $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans("CommercialCard"); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); if ($mesg) print($mesg); print ''; if ($conf->categorie->enabled) { print ''; print ''; print ''; } print ""; print ''; print ''; print ''; print ''; $nblignefour=2; if ($product->type == 0 && $conf->stock->enabled) $nblignefour++; if ($product->type == 1) $nblignefour++; print ''; // Description print ''; // Stock if ($product->type == 0 && $conf->stock->enabled) { print ''; if ($product->no_stock) { print "'; } // Duration if ($product->type == 1) { print ''; } print "
'; $cat = new Categorie ($db); $way = $cat->print_primary_way($product->id," > ",'fourn/product/liste.php'); if ($way == "") { print "Ce produit n'appartient à aucune catégorie"; } else { print $langs->trans("Categorie")." : "; print $way; } print '
'.$langs->trans("Ref").''.$product->ref.''; if ($product->envente) { print $langs->trans("OnSell"); } else { print $langs->trans("NotOnSell"); } print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''.price($product->price).''; $product->show_photo($conf->produit->dir_output,1); print '
'.$langs->trans("Description").''.nl2br($product->description).'
'.$langs->trans("Stock").'Pas de définition de stock pour ce produit"; } else { if ($product->stock_reel <= $product->seuil_stock_alerte) { print ''.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte; } else { print "".$product->stock_reel; } } print '
'.$langs->trans("Duration").''.$product->duration_value.' '; if ($product->duration_value > 1) { $dur=array("d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years")); } else { $dur=array("d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year")); } print $langs->trans($dur[$product->duration_unit])." "; print '

\n"; // Liste des fournisseurs print ''; print ''; print ''; print ''; print ''; print ''; $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON s.idp = pfp.fk_soc"; $sql .= " AND pfp.fk_product =".$product->id; $sql .= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; $sql .= " ORDER BY pfp.price ASC, lower(s.nom)"; if ( $db->query($sql) ) { $num_fournisseur = $db->num_rows($resql); $i = 0; $var=True; while ($i < $num_fournisseur) { $objp = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ''; print ''; print ''; $i++; } $db->free(); } print '
'; print $langs->trans("Suppliers").''.$langs->trans("Ref").''.$langs->trans("BuiingPrice").''.$langs->trans("Quantity").'
'.$objp->nom.''; print ''; print img_edit($langs->trans("Edit")); print ' '; print $objp->ref_fourn.''; print price($objp->price); print ''.$objp->quantity.'
'; print "\n"; /* * Ajouter un fournisseur * */ if ($_GET["action"] == 'ajout_fourn' && $user->rights->produit->creer) { $langs->load("suppliers"); print_titre($langs->trans("AddSupplier")); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Suppliers").'
'.$langs->trans("SupplierRef").'
'; print ' '; print '
'; print '
'; } } /* * Fiche en mode edition */ if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) { print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, ""); if ($mesg) { print '
'.$mesg.'

'; } print "
\n"; print ''; print ''; print ''; print "".''; print ''; if ($product->type == 0 && $conf->stock->enabled) { print "".''; } else { print ''; } print '"; if ($product->type == 1) { print ''; } print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
Seuil stock'; print ''; print '
'.$langs->trans("Description").''; print '
'.$langs->trans("Duration").''; print '  '; print 'duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); print '  '; print 'duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); print '  '; print 'duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); print '  '; print 'duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); print '
 '; print '
'; print '
'; } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($_GET["action"] == '') { print ''.$langs->trans("AddSupplier").''; if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1) { print ''; print $langs->trans("Order").''; } if ( $user->rights->produit->creer) { print ''.$langs->trans("Edit").''; } if ($product->type == 0 && $conf->stock->enabled) { print ''.$langs->trans("CorrectStock").''; } } print "\n
\n"; } else { print $langs->trans("BadId"); } } else { print $langs->trans("BadId"); } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>