* Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 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. * * $Id$ * $Source$ */ /** \file htdocs/product/fournisseurs.php \ingroup product \brief Page de la fiche produit \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); $langs->load("products"); $langs->load("suppliers"); $langs->load("bills"); $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"); /* * Actions */ if ($_GET["action"] == 'remove_fourn') { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($_GET["qty"]) { // On supprime une quantité if ($product->remove_price($user, $_GET["id_fourn"], $_GET["qty"]) > 0) { $_GET["action"] = ''; $mesg = '
'.$langs->trans("PriceRemoved").'.
'; } else { $_GET["action"] = ''; } } else { // On supprime un fournisseur if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0) { $_GET["action"] = ''; $mesg = '
'.$langs->trans("SupplierRemoved").'.
'; } else { $_GET["action"] = ''; } } } } if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { $db->begin(); $error=0; if ($_POST["ref_fourn"]) { $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]); if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } else { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Ref")).'
'; } if ($_POST["qty"] && $_POST["price"] > 0) { $ret=$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user); if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } if (! $error) { $db->commit(); } else { $db->rollback(); } } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; Header("Location: fournisseurs.php?id=".$_GET["id"]); exit; } llxHeader("","",$langs->trans("CardProduct".$product->type)); /* * Fiche produit */ if ($_GET["id"]) { if ($_GET["action"] <> 're-edit') { $product = new Product($db); $result = $product->fetch($_GET["id"]); } if ( $result ) { if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { /* * En mode visu */ // Zone recherche /* Deja présent dans menu gauche print '
'; print '
'; print ''; print $langs->trans("Ref").':    '; print $langs->trans("Label").':  '; print '
'; */ $h=0; $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans("Card"); $h++; $head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id; $head[$h][1] = $langs->trans("Price"); $h++; if($product->type == 0) { if ($user->rights->barcode->lire) { if ($conf->barcode->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$product->id; $head[$h][1] = $langs->trans("BarCode"); $h++; } } } $head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id; $head[$h][1] = $langs->trans("Photos"); $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] = 'Stock'; $h++; } } if ($conf->fournisseur->enabled) { $head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$product->id; $head[$h][1] = $langs->trans("Suppliers"); $hselected = $h; $h++; } $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][1] = $langs->trans('Statistics'); $h++; //erics: pour créer des produits composés de x 'sous' produits $head[$h][0] = DOL_URL_ROOT."/product/pack.php?id=".$product->id; $head[$h][1] = $langs->trans('Packs'); $h++; $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id; $head[$h][1] = $langs->trans('Referers'); $h++; $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id; $head[$h][1] = $langs->trans('Documents'); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); print ''; print ''; print ''; print ''; // Statut print ''; print '
'.$langs->trans("Ref").''.$product->ref.'
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''.price($product->price).'
'.$langs->trans("Status").''; if ($product->envente) print $langs->trans("OnSell"); else print $langs->trans("NotOnSell"); print '
'; print "\n"; if ($mesg) print($mesg); // Formulaire ajout prix if ($_GET["action"] == 'add_price' && $user->rights->produit->creer) { $langs->load("suppliers"); if ($_GET["id_fourn"]) { print_fiche_titre($langs->trans("ChangeSupplierPrice")); } else { print_fiche_titre($langs->trans("AddSupplierPrice")); } print ''; print ''; print ''; if ($_GET["id_fourn"]) { print ''; $product->fetch_fourn_data($_GET["id_fourn"]); print ''; } else { print ''; print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Supplier").''; $html=new Form($db); $html->select_societes('','id_fourn','fournisseur=1'); print '
'.$langs->trans("Ref").''; print ''; print '
'.$langs->trans("Qty").''.$langs->trans("Price").'
 '; print '
'; } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($_GET["action"] != 'add_price') { print ''; print $langs->trans("AddSupplier").''; } print "\n
\n"; print '
'; // Titre liste des fournisseurs print ''; if ($product->type == 0) $nblignefour=4; else $nblignefour=4; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Liste des fournisseurs $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"; $sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product"; $sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; $sql.= " ORDER BY lower(s.nom), pfp.quantity"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print ""; print ''; // Fournisseur print ''; // Quantité print ''; // Prix quantité print ''; // Prix unitaire print ''; // Modifier-Supprimer print ''; print ''; $i++; } $db->free($resql); } else { dolibarr_print_error($db); } print '
'; print $langs->trans("Suppliers").''.$langs->trans("Ref").''.$langs->trans("Qty").''.$langs->trans("BuyingPrice").''.$langs->trans("UnitPrice").' 
'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.''.$objp->ref_fourn.''; print $objp->quantity; print ''; print $objp->price?price($objp->price):""; print ''; print $objp->quantity?price($objp->price / $objp->quantity):" "; print ''; if ($user->rights->produit->creer) { print ''.img_edit().""; print ''; } print img_disable($langs->trans("Remove")).''; print '
'; } } } else { print $langs->trans("ErrorUnknown"); } $db->close(); llxFooter('$Date$ - $Revision$'); ?>