From bd083483b00e19dce794316e4fbc0fbd2a0a948f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 7 Oct 2008 09:36:33 +0000 Subject: [PATCH] Added ability to assign a category of product to a customer --- htdocs/categories/categorie.class.php | 6 ++++-- htdocs/categories/fiche.php | 12 ++++++++++-- mysql/migration/2.4.0-2.5.0.sql | 2 +- mysql/tables/llx_categorie.sql | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 4ed340c86c1..fba8ddcf7b0 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -45,6 +45,7 @@ class Categorie var $id_mere; var $label; var $description; + var $socid; var $statut; var $type; // 0=Produit, 1=Fournisseur, 2=Tiers @@ -124,6 +125,7 @@ class Categorie { global $langs; $langs->load('categories'); + if ($this->already_exists ()) { $this->error=$langs->trans("ImpossibleAddCat"); @@ -131,8 +133,8 @@ class Categorie return -1; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, visible,type) "; - $sql .= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."', '".$this->visible."',".$this->type.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, fk_soc, visible, type) "; + $sql .= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."','".$this->socid."','".$this->visible."',".$this->type.")"; $res = $this->db->query ($sql); diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 4c3e41c1b79..c67856d3a3b 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -48,6 +48,13 @@ if ($_REQUEST['origin']) } +// If socid provided by ajax company selector +if (! empty($_POST['socid_id'])) +{ + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + /* * Actions @@ -87,6 +94,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) $categorie->socid = $_POST["socid"]; $categorie->visible = $_POST["visible"]; $categorie->type = $_POST["type"]; + if($_POST['catMere'] != "-1") $categorie->id_mere = $_POST['catMere']; @@ -193,10 +201,10 @@ if ($user->rights->categorie->creer) if ($_GET['type'] == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { print ''.$langs->trans ("AssignedToCustomer").''; - print $html->select_societes('','socid','s.client = 1 AND s.fournisseur = 0',1); + print $html->select_societes($_REQUEST['socid_id'],'socid','s.client = 1 AND s.fournisseur = 0',1); print ''; print ''; - print ''; + print ''; } else { diff --git a/mysql/migration/2.4.0-2.5.0.sql b/mysql/migration/2.4.0-2.5.0.sql index 5eac7afec6c..d7efd100a15 100644 --- a/mysql/migration/2.4.0-2.5.0.sql +++ b/mysql/migration/2.4.0-2.5.0.sql @@ -34,4 +34,4 @@ alter table llx_rights_def modify column type varchar(1); ALTER TABLE `llx_commandedet` ADD column `date_start` DATETIME DEFAULT NULL, ADD `date_end` DATETIME DEFAULT NULL ; -alter table llx_categorie add column fk_soc integer DEFAULT NULL after description; +alter table llx_categorie add column fk_soc integer DEFAULT 0 after description; diff --git a/mysql/tables/llx_categorie.sql b/mysql/tables/llx_categorie.sql index 31aa8bf6c91..c4a07f3a058 100644 --- a/mysql/tables/llx_categorie.sql +++ b/mysql/tables/llx_categorie.sql @@ -25,7 +25,7 @@ create table llx_categorie rowid integer AUTO_INCREMENT PRIMARY KEY, label VARCHAR(255), -- category name description text, -- description of the category - fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only) + fk_soc integer DEFAULT 0, -- attribution of the category has a company (for product only) visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not type tinyint DEFAULT 1 NOT NULL -- category type (product, supplier, customer) )type=innodb;