Mutualisation de l'onglet catgorie

Fix: un fournisseur avait la liste droulante des catgories clients
This commit is contained in:
Regis Houssin 2007-11-12 02:06:36 +00:00
parent 03ee736de9
commit ee19ca2821
7 changed files with 202 additions and 310 deletions

View File

@ -832,12 +832,14 @@ class Categorie
/**
* Retourne les catégories contenant le produit $id
*/
function containing ($id,$type)
function containing ($id,$type,$typeid)
{
$cats = array ();
$sql = "SELECT fk_categorie FROM ".MAIN_DB_PREFIX."categorie_".$type." ";
$sql .= "WHERE fk_".$type." = ".$id;
$sql = "SELECT ct.fk_categorie";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid";
$sql.= " WHERE ct.fk_".$type." = ".$id." AND c.type = ".$typeid;
$res = $this->db->query ($sql);
@ -887,7 +889,29 @@ class Categorie
}
/**
* \brief Vérifie le type de la catégorie
*
*/
function verify_type($id)
{
$sql = "SELECT type FROM ".MAIN_DB_PREFIX."categorie ";
$sql .= "WHERE rowid = ".$id." ";
$result = $this->db->query ($sql);
if ($result)
{
$obj = $this->db->fetch_object($result);
return $obj->type;
}
else
{
$this->error=$this->db->error().' sql='.$sql;
dolibarr_print_error('',$this->error);
return -1;
}
}

View File

@ -1,9 +1,9 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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
@ -26,22 +26,31 @@
/**
\file htdocs/categories/categorie.php
\ingroup category
\brief Page de l'onglet categories de produits
\brief Page de l'onglet categories
\version $Revision$
*/
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
$langs->load("categories");
$langs->load("companies");
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($_REQUEST["socid"])
{
$type = 'societe';
$objectid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:'';
}
else if ($_REQUEST["id"] || $_REQUEST["ref"])
{
$type = 'produit';
}
else
{
accessforbidden();
}
// Sécurité d'accès client et commerciaux
$socid = restrictedArea($user, 'societe', $socid);
$objectid = restrictedArea($user, $type, $objectid);
$mesg = '';
@ -50,27 +59,46 @@ $mesg = '';
* Actions
*/
//on veut supprimer une catégorie
if ($_REQUEST["removecat"] && $user->rights->societe->creer)
//Suppression d'un objet d'une catégorie
if ($_REQUEST["removecat"])
{
$soc = new Societe($db);
if ($_REQUEST["socid"]) $result = $soc->fetch($_REQUEST["socid"]);
if ($_REQUEST["socid"] && $user->rights->societe->creer)
{
$object = new Societe($db);
$result = $object->fetch($_REQUEST["socid"]);
}
else if (($_REQUEST["id"] || $_REQUEST["ref"]) && $user->rights->produit->creer)
{
$object = new Product($db);
if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]);
$type = 'product';
}
$cat = new Categorie($db,$_REQUEST["removecat"]);
$result=$cat->del_type($soc,"societe");
$result=$cat->del_type($object,$type);
}
//on veut ajouter une catégorie
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->societe->creer)
//Ajoute d'un objet dans une catégorie
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0)
{
$soc = new Societe($db);
if ($_REQUEST["socid"]) $result = $soc->fetch($_REQUEST["socid"]);
if ($_REQUEST["socid"] && $user->rights->societe->creer)
{
$object = new Societe($db);
$result = $object->fetch($_REQUEST["socid"]);
}
else if (($_REQUEST["id"] || $_REQUEST["ref"]) && $user->rights->produit->creer)
{
$object = new Product($db);
if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]);
$type = 'product';
}
$cat = new Categorie($db,$_REQUEST["catMere"]);
$result=$cat->add_type($soc,"societe");
$result=$cat->add_type($object,$type);
if ($result >= 0)
{
$mesg='<div class="ok">'.$langs->trans("Added").'</div>';
$mesg='<div class="ok">'.$langs->trans("WasAddedSuccessfully").'</div>';
}
else
{
@ -79,29 +107,26 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->so
}
/*
* Creation de l'objet fournisseur correspondant à l'id
*/
if ($_GET["socid"] || $_GET["ref"])
{
$soc = new Societe($db);
if ($_GET["socid"]) $result = $soc->fetch($_GET["socid"]);
llxHeader("","",$langs->trans("CardCompany".$soc->type));
}
$html = new Form($db);
/*
* Fiche produit
* Fiche objet client/fournisseur
*/
if ($_GET["socid"] || $_GET["ref"])
if ($_GET["socid"])
{
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
$langs->load("companies");
/*
* Creation de l'objet client/fournisseur correspondant au socid
*/
$soc = new Societe($db);
$result = $soc->fetch($_GET["socid"]);
llxHeader("","",$langs->trans("CardCompany".$soc->type));
/*
* Affichage onglets
*/
@ -109,9 +134,8 @@ if ($_GET["socid"] || $_GET["ref"])
dolibarr_fiche_head($head, 'category', $soc->nom);
print '<table class="border" width="100%">';
print '<tr><td width="30%">'.$langs->trans("Name").'</td><td width="70%" colspan="3">';
print $soc->nom;
print '</td></tr>';
@ -126,6 +150,15 @@ if ($_GET["socid"] || $_GET["ref"])
if ($soc->check_codeclient() <> 0) print ' '.$langs->trans("WrongCustomerCode");
print '</td></tr>';
}
if ($soc->fournisseur)
{
print '<tr><td>';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $soc->code_fournisseur;
if ($soc->check_codefournisseur() <> 0) print ' '.$langs->trans("WrongSupplierCode");
print '</td></tr>';
}
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($soc->adresse)."</td></tr>";
@ -151,45 +184,120 @@ if ($_GET["socid"] || $_GET["ref"])
print '</div>';
if ($mesg) print($mesg);
if ($soc->client) formCategory($db,$soc,$type,2);
print '<br><br>';
if ($soc->fournisseur) formCategory($db,$soc,$type,1);
}
else if ($_GET["id"] || $_GET["ref"])
{
/*
* Fiche produit
*/
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
/*
* Creation de l'objet produit correspondant à l'id
*/
$product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
llxHeader("","",$langs->trans("CardProduct".$product->type));
$head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'category', $titre);
print '<table class="border" width="100%">';
print "<tr>";
// Reference
print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($product,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>';
// Prix
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">';
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 '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
print $product->getLibStatut(2);
print '</td></tr>';
print '</table>';
print '</div>';
if ($mesg) print($mesg);
formCategory($db,$product,'product',0);
}
/*
* Barre d'actions
* Fonction Barre d'actions
*
*/
print '<div class="tabsAction">';
if ($user->rights->categorie->creer)
function formCategory($db,$object,$type,$typeid)
{
global $user,$langs,$html;
if ($type == 'societe')
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/fiche.php?action=create&amp;origin='.$soc->id.'&type=2">'.$langs->trans("NewCat").'</a>';
$nameId = 'socid';
if ($typeid == 2) $title = $langs->trans("CustomersCategoriesShort");
if ($typeid == 1) $title = $langs->trans("SuppliersCategoriesShort");
}
print '</div>';
else
{
$nameId = 'id';
}
// Formulaire ajout dans une categorie
if ($user->rights->societe->creer)
{
print '<br>';
print '<form method="post" action="'.DOL_URL_ROOT.'/categories/categorie.php?socid='.$soc->id.'">';
print_fiche_titre($title);
print '<form method="post" action="'.DOL_URL_ROOT.'/categories/categorie.php?'.$nameId.'='.$object->id.'">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>';
print $langs->trans("ClassifyInCategory").' ';
print $html->select_all_categories(2,$categorie->id_mere).' <input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
print $html->select_all_categories($typeid).' <input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
if ($user->rights->categorie->creer)
{
print '<td align="right">';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/fiche.php?action=create&amp;origin='.$object->id.'&type='.$typeid.'">'.$langs->trans("NewCat").'</a>';
print '</td>';
}
print '</tr>';
print '</table>';
print '</form>';
print '<br/>';
}
$c = new Categorie($db);
if ($_GET["socid"])
{
$cats = $c->containing($_REQUEST["socid"],"societe");
}
$cats = $c->containing($object->id,$type,$typeid);
if (sizeof($cats) > 0)
{
@ -211,9 +319,9 @@ if ($_GET["socid"] || $_GET["ref"])
// Lien supprimer
print '<td align="right">';
if ($user->rights->societe->creer)
if ($user->rights->$type->creer)
{
print "<a href= '".DOL_URL_ROOT."/categories/categorie.php?socid=".$soc->id."&amp;removecat=".$cat->id."'>";
print "<a href= '".DOL_URL_ROOT."/categories/categorie.php?".$nameId."=".$object->id."&amp;removecat=".$cat->id."'>";
print img_delete($langs->trans("DeleteFromCat")).' ';
print $langs->trans("DeleteFromCat")."</a>";
}
@ -225,7 +333,6 @@ if ($_GET["socid"] || $_GET["ref"])
print "</tr>\n";
}
}
print "</table><br/>\n";
}
@ -233,16 +340,13 @@ if ($_GET["socid"] || $_GET["ref"])
{
print $langs->trans("ErrorUnknown");
}
else
{
print $langs->trans("CompanyHasNoCategory")."<br/>";
}
}
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@ -105,7 +105,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
if ($idProdOrigin)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/categorie.php?id='.$idProdOrigin.'">'.$langs->trans("ReturnInProduct").'</a>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'">'.$langs->trans("ReturnInProduct").'</a>';
}
if ($idSupplierOrigin || $idCompanyOrigin)
{

View File

@ -19,7 +19,7 @@ CatList=List of cat
AllCats=All categories
ViewCat=View category
NewCat=Add category
NewCategory=New product/services category
NewCategory=New category
ModifCat=Modify category
CatCreated=Category added
CreateCat=Create category

View File

@ -19,7 +19,7 @@ CatList=Liste des cat
AllCats=Toutes les catégories
ViewCat=Visualisation de la catégorie
NewCat=Nouvelle catégorie
NewCategory=Nouvelle catégorie de produits/services
NewCategory=Nouvelle catégorie
ModifCat=Modifier une catégorie
CatCreated=Catégorie ajoutée
CreateCat=Ajouter une catégorie

View File

@ -51,7 +51,7 @@ function product_prepare_head($product, $user)
//affichage onglet catégorie
if ($conf->categorie->enabled)
{
$head[$h][0] = DOL_URL_ROOT."/product/categorie.php?id=".$product->id;
$head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$product->id;
$head[$h][1] = $langs->trans('Categories');
$head[$h][2] = 'category';
$h++;

View File

@ -1,236 +0,0 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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/categorie.php
\ingroup product
\brief Page de l'onglet categories de produits
\version $Revision$
*/
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
$langs->load("categories");
if (!$user->rights->produit->lire) accessforbidden();
$mesg = '';
/*
* Actions
*/
//on veut supprimer une catégorie
if ($_REQUEST["removecat"] && $user->rights->produit->creer)
{
$product = new Product($db);
if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]);
$cat = new Categorie($db,$_REQUEST["removecat"]);
$result=$cat->del_type($product,"product");
}
//on veut ajouter une catégorie
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->produit->creer)
{
$product = new Product($db);
if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]);
$cat = new Categorie($db,$_REQUEST["catMere"]);
$result=$cat->add_type($product,"product");
if ($result >= 0)
{
$mesg='<div class="ok">'.$langs->trans("Added").'</div>';
}
else
{
$mesg='<div class="error">'.$langs->trans("Error").' '.$cat->error.'</div>';
}
}
/*
* Creation de l'objet produit correspondant à l'id
*/
if ($_GET["id"] || $_GET["ref"])
{
$product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
llxHeader("","",$langs->trans("CardProduct".$product->type));
}
$html = new Form($db);
/*
* Fiche produit
*/
if ($_GET["id"] || $_GET["ref"])
{
$head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'category', $titre);
print '<table class="border" width="100%">';
print "<tr>";
// Reference
print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($product,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>';
// Prix
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">';
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 '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
print $product->getLibStatut(2);
print '</td></tr>';
print '</table>';
print '</div>';
if ($mesg) print($mesg);
/*
* Barre d'actions
*
*/
print '<div class="tabsAction">';
if ($user->rights->categorie->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/fiche.php?action=create&amp;origin='.$product->id.'&type=0">'.$langs->trans("NewCat").'</a>';
}
print '</div>';
// Formulaire ajout dans une categorie
if ($user->rights->produit->creer)
{
print '<br/>';
print '<form method="post" action="'.DOL_URL_ROOT.'/product/categorie.php?id='.$product->id.'">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>';
print $langs->trans("ClassifyInCategory").' ';
print $html->select_all_categories(0,$categorie->id_mere).' <input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
print '</tr>';
print '</table>';
print '</form>';
print '<br/>';
}
$c = new Categorie($db);
if ($_GET["id"])
{
$cats = $c->containing($_REQUEST["id"],"product");
}
if ($_GET["ref"])
{
$cats = $c->containing_ref($_REQUEST["ref"],"product");
}
if (sizeof($cats) > 0)
{
print_fiche_titre($langs->trans("ProductIsInCategories"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Categories").'</td></tr>';
$var = true;
foreach ($cats as $cat)
{
$ways = $cat->print_all_ways ();
foreach ($ways as $way)
{
$var = ! $var;
print "<tr ".$bc[$var].">";
// Categorie
print "<td>".$way."</td>";
// Lien supprimer
print '<td align="right">';
if ($user->rights->produit->creer)
{
print "<a href= '".DOL_URL_ROOT."/product/categorie.php?id=".$product->id."&amp;removecat=".$cat->id."'>";
print img_delete($langs->trans("DeleteFromCat")).' ';
print $langs->trans("DeleteFromCat")."</a>";
}
else
{
print '&nbsp;';
}
print "</td>";
print "</tr>\n";
}
}
print "</table><br/>\n";
}
else if($cats < 0)
{
print $langs->trans("ErrorUnknown");
}
else
{
print $langs->trans("ProductHasNoCategory")."<br/>";
}
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>