* Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * 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/fournisseurs.php * \ingroup product * \brief Page de l'onglet fournisseur de produits * \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.product.class.php"; $langs->load("products"); $langs->load("suppliers"); $langs->load("bills"); // If socid provided by ajax company selector if (! empty($_REQUEST['id_fourn_id'])) { $_GET['id_fourn'] = $_GET['id_fourn_id']; $_POST['id_fourn'] = $_POST['id_fourn_id']; $_REQUEST['id_fourn'] = $_REQUEST['id_fourn_id']; } // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) { $id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:''); } $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service&fournisseur',$id,'product','','',$fieldid); $mesg = ''; /* * Actions */ if ($_GET["action"] == 'remove_pf') { $product = new ProductFournisseur($db); if ($product->fetch($_GET["id"]) > 0) { if ($_GET["rowid"]) { $result=$product->remove_product_fournisseur_price($_GET["rowid"]); $_GET["action"] = ''; $mesg = '
'.$langs->trans("PriceRemoved").'.
'; } else { // Deprecated. Should not occurs if ($product->remove_fournisseur($_GET["socid"]) > 0) { $_GET["action"] = ''; $mesg = '
'.$langs->trans("SupplierRemoved").'.
'; } else { $_GET["action"] = ''; } } } } if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) { $product = new ProductFournisseur($db); $result=$product->fetch($_REQUEST["id"]); if ($result > 0) { $db->begin(); $error=0; if (! $_POST["ref_fourn"]) { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; } if ($_POST["id_fourn"] <= 0) { //print "eee".$_POST["id_fourn"]; $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")).'
'; } if (! $error) { $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]); if ($ret == -3) { $error++; $product->fetch($product->product_id_already_linked); $productLink = $product->getNomUrl(1,'supplier'); $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink).'
'; } else if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } if (! $error) { if ($_POST["qty"]) { if ($_POST["price"] >= 0) { $supplier=new Fournisseur($db); $result=$supplier->fetch($_POST["id_fourn"]); $ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user, $_POST["price_base_type"], $supplier); if ($ret < 0) { $error++; $mesg='
'.$product->error.'
'; } } else { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'
'; } } else { $error++; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'
'; } } if (! $error) { $db->commit(); $_POST['action']=''; } else { $db->rollback(); } } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; Header("Location: fournisseurs.php?id=".$_GET["id"]); exit; } /* * Affichage fiche */ $html = new Form($db); if ($_GET["id"] || $_GET["ref"]) { if ($_GET["action"] <> 're-edit') { $product = new ProductFournisseur($db); $result = $product->fetch($_GET["id"],$_GET["ref"]); $result = $product->fetch_fourn_data($_REQUEST["id_fourn"]); //print 'eeeee'.$_GET["socid"];exit; llxHeader("","",$langs->trans("CardProduct".$product->type)); } if ( $result ) { if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { /* * En mode visu */ $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); dol_fiche_head($head, 'suppliers', $titre, 0, $picto); print ''; // Reference print ''; print ''; print ''; // Libelle print ''; // Prix print ''; // Statut print ''; print '
'.$langs->trans("Ref").''; print $html->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''; if ($product->price_base_type == 'TTC') { print price($product->price_ttc).' '.$langs->trans($product->price_base_type); } else { print price($product->price).' '.$langs->trans($product->price_base_type); } print '
'.$langs->trans("Status").''; print $product->getLibStatut(2); print '
'; print "\n"; if ($mesg) print($mesg); // Form to add or update a price if (($_GET["action"] == 'add_price' || $_POST["action"] == 'updateprice' ) && ($user->rights->produit->creer || $user->rights->service->creer)) { $langs->load("suppliers"); if ($_GET["rowid"]) { $product->fetch_product_fournisseur_price($_GET["rowid"]); print_fiche_titre($langs->trans("ChangeSupplierPrice")); } else { print_fiche_titre($langs->trans("AddSupplierPrice")); } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Supplier").''; if ($_GET["rowid"]) { $supplier=new Fournisseur($db); $supplier->fetch($_GET["socid"]); print $supplier->getNomUrl(1); print ''; print ''; print ''; } else { $html=new Form($db); $html->select_societes($_POST["id_fourn"],'id_fourn','fournisseur=1',1); } print '
'.$langs->trans("SupplierRef").''; if ($_GET["rowid"]) { print $product->fourn_ref; } else { print 'ref_fourn).'">'; } print '
'.$langs->trans("QtyMin").''; $quantity = $_REQUEST["qty"] ? $_REQUEST["qty"] : "1"; if ($_GET["rowid"]) { print ''; print $product->fourn_qty; } else { print ''; } print ''.$langs->trans("PriceQtyMin").'fourn_price)).'">'; print ' '; print $html->select_PriceBaseType(($_POST["price_base_type"]?$_POST["price_base_type"]:$product->price_base_type), "price_base_type"); print '
'; print '   '; print '
'; } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n"; if ($_GET["action"] != 'add_price') { if ($user->rights->produit->creer || $user->rights->service->creer) { print ''; print $langs->trans("AddSupplierPrice").''; } } print "\n
\n"; print '
'; if ($user->rights->fournisseur->lire) { // Suppliers list title print ''; if ($product->isproduct()) $nblignefour=4; else $nblignefour=4; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Suppliers list $sql = "SELECT s.nom, s.rowid as socid,"; $sql.= " pf.ref_fourn,"; $sql.= " pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " ON pf.rowid = pfp.fk_product_fournisseur"; $sql.= " WHERE pf.fk_soc = s.rowid"; $sql.= " AND s.entity = ".$conf->entity; $sql.= " AND pf.fk_product = ".$product->id; $sql.= " ORDER BY lower(s.nom), pfp.quantity"; $resql=""; $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 ''; // Supplier print ''; // Quantity print ''; // Price quantity print ''; // Unit price print ''; // Modify-Remove print ''; print ''; $i++; } $db->free($resql); } else { dol_print_error($db); } print '
'; print $langs->trans("Suppliers").''.$langs->trans("SupplierRef").''.$langs->trans("QtyMin").''.$langs->trans("PriceQtyMinHT").''.$langs->trans("UnitPriceHT").' 
'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.''.$objp->ref_fourn.''; print $objp->quantity; print ''; print $objp->price?price($objp->price):""; print ''; print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" "); print ''; if ($user->rights->produit->creer || $user->rights->service->creer) { print ''.img_edit().""; print ''.img_picto($langs->trans("Remove"),'disable.png').''; } print '
'; } } } } else { print $langs->trans("ErrorUnknown"); } $db->close(); llxFooter('$Date$ - $Revision$'); ?>