Fix: List of supplier categories

This commit is contained in:
Laurent Destailleur 2008-07-01 19:30:39 +00:00
parent c627492ead
commit 227c389806
2 changed files with 22 additions and 13 deletions

View File

@ -382,21 +382,29 @@ class Categorie
} }
/** /**
* Retourne les produits de la catégorie * \brief Retourne les produits de la catégorie
* \param field Field name for select in table. Full field name will be fk_field.
* \param class PHP Class of object to store entity
* \param table Table name for select in table. Full table name will be PREFIX_categorie_table.
*/ */
function get_type($type,$class) function get_type($field,$class,$table='')
{ {
$sql = "SELECT fk_".$type." FROM ".MAIN_DB_PREFIX."categorie_".$type." "; $objs = array();
$sql .= "WHERE fk_categorie = ".$this->id;
// Clean parameters
if (empty($table)) $table=$field;
$sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table;
$sql .= " WHERE fk_categorie = ".$this->id;
dolibarr_syslog("Categorie::get_type sql=".$sql);
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
{ {
$obj = array();
while ($rec = $this->db->fetch_array ($res)) while ($rec = $this->db->fetch_array ($res))
{ {
$obj = new $class ($this->db, $rec['fk_'.$type]); $obj = new $class ($this->db, $rec['fk_'.$field]);
$obj->fetch ($obj->id); $obj->fetch ($obj->id);
$objs[] = $obj; $objs[] = $obj;
} }
@ -405,6 +413,7 @@ class Categorie
else else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->error().' sql='.$sql;
dolibarr_syslog("Categorie::get_type ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org> /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* *
@ -69,10 +69,10 @@ if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete'
/* /*
* Affichage fiche categorie * View
*/ */
llxHeader ("","",$langs->trans("Categories")); llxHeader ("","",$langs->trans("Categories"));
$html=new Form($db);
if ($mesg) print $mesg.'<br>'; if ($mesg) print $mesg.'<br>';
@ -190,7 +190,7 @@ else
} }
if($c->type == 0) if ($c->type == 0)
{ {
$prods = $c->get_type ("product","Product"); $prods = $c->get_type ("product","Product");
@ -230,9 +230,9 @@ if($c->type == 0)
} }
} }
if($c->type == 1) if ($c->type == 1)
{ {
$socs = $c->get_type ("societe","Fournisseur"); $socs = $c->get_type ("societe","Fournisseur","fournisseur");
if ($socs < 0) if ($socs < 0)
{ {
dolibarr_print_error(); dolibarr_print_error();