diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 1a4c80db28d..4b4dcc518d2 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2688,12 +2688,12 @@ class Adherent extends CommonObject // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'member'); + $c->del_type($this, Categorie::TYPE_MEMBER); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'member'); + $c->add_type($this, Categorie::TYPE_MEMBER); } } diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index edbabd4476d..4bf6a4d73e3 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -53,7 +53,7 @@ class Categorie extends CommonObject const TYPE_PROJECT = 'project'; const TYPE_ACCOUNT = 'bank_account'; const TYPE_BANK_LINE = 'bank_line'; - const TYPE_STOCK = 'stock'; + const TYPE_WAREHOUSE = 'warehouse'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png @@ -76,7 +76,7 @@ class Categorie extends CommonObject 'project' => 6, 'user' => 7, 'bank_line' => 8, - 'stock' => 9, + 'warehouse' => 9, ); /** @@ -92,13 +92,13 @@ class Categorie extends CommonObject 6 => 'project', 7 => 'user', 8 => 'bank_line', - 9 => 'stock', + 9 => 'warehouse', ); /** * @var array Foreign keys mapping from type string * - * @note Move to const array when PHP 5.6 will be our minimum target + * @TODO Move to const array when PHP 5.6 will be our minimum target */ protected $MAP_CAT_FK = array( 'product' => 'product', @@ -107,14 +107,14 @@ class Categorie extends CommonObject 'member' => 'member', 'contact' => 'socpeople', 'user' => 'user', - 'account' => 'account', // old for bank_account + 'account' => 'account', // old key for bank_account 'bank_account' => 'account', 'project' => 'project', - 'stock' => 'entrepot', + 'warehouse'=> 'warehouse', ); /** - * @var array Category tables mapping from type string + * @var array Category tables mapping from type string (llx_categorie_...) * * @note Move to const array when PHP 5.6 will be our minimum target */ @@ -125,10 +125,10 @@ class Categorie extends CommonObject 'member' => 'member', 'contact' => 'contact', 'user' => 'user', - 'account' => 'account', // old for bank_account + 'account' => 'account', // old key for bank_account 'bank_account'=> 'account', 'project' => 'project', - 'stock' => 'entrepot', + 'warehouse'=> 'warehouse', ); /** @@ -146,11 +146,11 @@ class Categorie extends CommonObject 'account' => 'Account', // old for bank account 'bank_account' => 'Account', 'project' => 'Project', - 'stock' => 'Entrepot', + 'warehouse'=> 'Entrepot', ); /** - * @var array Object table mapping from type string + * @var array Object table mapping from type string (table llx_...) * * @note Move to const array when PHP 5.6 will be our minimum target */ @@ -163,7 +163,7 @@ class Categorie extends CommonObject 'user' => 'user', 'account' => 'bank_account', 'project' => 'projet', - 'stock' => 'entrepot', + 'warehouse'=> 'entrepot', ); /** @@ -204,14 +204,16 @@ class Categorie extends CommonObject /** * @var string Category type * + * @see Categorie::TYPE_ACCOUNT * @see Categorie::TYPE_PRODUCT * @see Categorie::TYPE_SUPPLIER * @see Categorie::TYPE_CUSTOMER * @see Categorie::TYPE_MEMBER * @see Categorie::TYPE_CONTACT * @see Categorie::TYPE_USER - * @see Categorie::TYPE_ACCOUNT * @see Categorie::TYPE_PROJECT + * @see Categorie::TYPE_BANK_LINE + * @see Categorie::TYPE_WAREHOUSE */ public $type; diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index ab6c6df5a26..52936f57a78 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -58,7 +58,7 @@ elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCate elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; } elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; } elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; } -elseif ($type == Categorie::TYPE_STOCK) { $title=$langs->trans("StocksCategoriesArea"); $typetext='stock'; } +elseif ($type == Categorie::TYPE_WAREHOUSE) { $title=$langs->trans("StocksCategoriesArea"); $typetext='warehouse'; } else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; } $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 282a296a5f1..02b8e01d3bf 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -989,12 +989,12 @@ class Account extends CommonObject // Process foreach($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'account'); + $c->del_type($this, Categorie::TYPE_ACCOUNT); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'account'); + $c->add_type($this, Categorie::TYPE_ACCOUNT); } } diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index ebfafa698b7..f9ad9ca358d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1406,12 +1406,12 @@ class Contact extends CommonObject // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'contact'); + $c->del_type($this, Categorie::TYPE_CONTACT); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'contact'); + $c->add_type($this, Categorie::TYPE_CONTACT); } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c470231e5de..fe815bd33b0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6481,6 +6481,7 @@ class Form if ($rendermode == 0) { + $arrayselected=array(); $cate_arbo = $this->select_all_categories($type, '', 'parent', 64, 0, 1); foreach($categories as $c) { $arrayselected[] = $c->id; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 32bf5b8e08e..758f12b3f5e 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1522,10 +1522,13 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM $newmenu->add("/product/stock/massstockmove.php", $langs->trans("MassStockTransferShort"), 1, $user->rights->stock->mouvement->creer); if ($conf->supplier_order->enabled) $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire); + + // Categories for warehouses + if (! empty($conf->categorie->enabled)) + { + $newmenu->add("/categories/index.php?leftmenu=stock&type=9", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat'); + } } - //Categories Stock - $newmenu->add("/categories/index.php?leftmenu=stock&type=9", $langs->trans("StockCategoriesShort"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat'); - $newmenu->add("/categories/card.php?leftmenu=stock&action=create&type=9", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer); // Inventory if ($conf->global->MAIN_FEATURES_LEVEL >= 2) diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 45bd666abb0..a55938030c4 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -36,6 +36,21 @@ UPDATE llx_expensereport set paid = 1 WHERE fk_statut = 6 and paid = 0; -- For v11 +create table llx_categorie_warehouse +( + fk_categorie integer NOT NULL, + fk_warehouse integer NOT NULL, + import_key varchar(14) +) ENGINE=innodb; + +ALTER TABLE llx_categorie_warehouse ADD PRIMARY KEY pk_categorie_warehouse (fk_categorie, fk_warehouse); +ALTER TABLE llx_categorie_warehouse ADD INDEX idx_categorie_warehouse_fk_categorie (fk_categorie); +ALTER TABLE llx_categorie_warehouse ADD INDEX idx_categorie_warehouse_fk_warehouse (fk_warehouse); + +ALTER TABLE llx_categorie_warehouse ADD CONSTRAINT fk_categorie_warehouse_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_warehouse ADD CONSTRAINT fk_categorie_warehouse_fk_warehouse_rowid FOREIGN KEY (fk_warehouse) REFERENCES llx_entrepot (rowid); + + create table llx_holiday_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/install/mysql/tables/llx_categorie_stock.key.sql b/htdocs/install/mysql/tables/llx_categorie_warehouse.key.sql similarity index 61% rename from htdocs/install/mysql/tables/llx_categorie_stock.key.sql rename to htdocs/install/mysql/tables/llx_categorie_warehouse.key.sql index e57361ed8bb..0df8bb0e6f5 100644 --- a/htdocs/install/mysql/tables/llx_categorie_stock.key.sql +++ b/htdocs/install/mysql/tables/llx_categorie_warehouse.key.sql @@ -17,9 +17,9 @@ -- -- ============================================================================ -ALTER TABLE llx_categorie_entrepot ADD PRIMARY KEY pk_categorie_entrepot (fk_categorie, fk_entrepot); -ALTER TABLE llx_categorie_entrepot ADD INDEX idx_categorie_entrepot_fk_categorie (fk_categorie); -ALTER TABLE llx_categorie_entrepot ADD INDEX idx_categorie_entrepot_fk_entrepot (fk_entrepot); +ALTER TABLE llx_categorie_warehouse ADD PRIMARY KEY pk_categorie_warehouse (fk_categorie, fk_warehouse); +ALTER TABLE llx_categorie_warehouse ADD INDEX idx_categorie_warehouse_fk_categorie (fk_categorie); +ALTER TABLE llx_categorie_warehouse ADD INDEX idx_categorie_warehouse_fk_warehouse (fk_warehouse); -ALTER TABLE llx_categorie_entrepot ADD CONSTRAINT fk_categorie_entrepot_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); -ALTER TABLE llx_categorie_entrepot ADD CONSTRAINT fk_categorie_entrepot_fk_entrepot_rowid FOREIGN KEY (fk_entrepot) REFERENCES llx_entrepot (rowid); +ALTER TABLE llx_categorie_warehouse ADD CONSTRAINT fk_categorie_warehouse_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_warehouse ADD CONSTRAINT fk_categorie_warehouse_fk_warehouse_rowid FOREIGN KEY (fk_warehouse) REFERENCES llx_entrepot (rowid); diff --git a/htdocs/install/mysql/tables/llx_categorie_stock.sql b/htdocs/install/mysql/tables/llx_categorie_warehouse.sql similarity index 94% rename from htdocs/install/mysql/tables/llx_categorie_stock.sql rename to htdocs/install/mysql/tables/llx_categorie_warehouse.sql index 92173d83a01..692b9be92af 100644 --- a/htdocs/install/mysql/tables/llx_categorie_stock.sql +++ b/htdocs/install/mysql/tables/llx_categorie_warehouse.sql @@ -19,9 +19,9 @@ -- -- ============================================================================ -create table llx_categorie_entrepot +create table llx_categorie_warehouse ( fk_categorie integer NOT NULL, - fk_entrepot integer NOT NULL, + fk_warehouse integer NOT NULL, import_key varchar(14) )ENGINE=innodb; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 647ffda194d..c8e472fb718 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5040,12 +5040,12 @@ class Product extends CommonObject // Process foreach($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'product'); + $c->del_type($this, Categorie::TYPE_PRODUCT); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'product'); + $c->add_type($this, Categorie::TYPE_PRODUCT); } } diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index f8d9cee9634..c085bff8082 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -310,7 +310,7 @@ if ($action == 'create') if ($conf->categorie->enabled) { // Categories print ''.$langs->trans("Categories").''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_STOCK, '', 'parent', 64, 0, 1); + $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1); print $form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, '', 0, '100%'); print ""; } @@ -454,7 +454,7 @@ else // Categories if($conf->categorie->enabled) { print ''.$langs->trans("Categories").''; - print $form->showCategories($object->id, 'stock', 1); + print $form->showCategories($object->id, 'warehouse', 1); print ""; } print ""; @@ -732,9 +732,9 @@ else if ($conf->categorie->enabled) { print ''.$langs->trans("Categories").''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_STOCK, '', 'parent', 64, 0, 1); + $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1); $c = new Categorie($db); - $cats = $c->containing($object->id, Categorie::TYPE_STOCK); + $cats = $c->containing($object->id, Categorie::TYPE_WAREHOUSE); $arrayselected=array(); foreach($cats as $cat) { $arrayselected[] = $cat->id; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 25feb132117..9c19979308b 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -856,7 +856,9 @@ class Entrepot extends CommonObject */ public function setCategories($categories) { - // Handle single category + $type_categ = Categorie::TYPE_WAREHOUSE; + + // Handle single category if (! is_array($categories)) { $categories = array($categories); } @@ -864,7 +866,7 @@ class Entrepot extends CommonObject // Get current categories require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_STOCK, 'id'); + $existing = $c->containing($this->id, $type_categ, 'id'); // Diff if (is_array($existing)) { @@ -878,12 +880,12 @@ class Entrepot extends CommonObject // Process foreach($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'stock'); + $c->del_type($this, $type_categ); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'stock'); + $c->add_type($this, $type_categ); } } diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 3dcc486d266..1764126bbe4 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1979,10 +1979,7 @@ class Project extends CommonObject */ public function setCategories($categories) { - // Decode type - $type_id = Categorie::TYPE_PROJECT; - $type_text = 'project'; - + $type_categ = Categorie::TYPE_PROJECT; // Handle single category if (!is_array($categories)) { @@ -1992,7 +1989,7 @@ class Project extends CommonObject // Get current categories require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $c = new Categorie($this->db); - $existing = $c->containing($this->id, $type_id, 'id'); + $existing = $c->containing($this->id, $type_categ, 'id'); // Diff if (is_array($existing)) { @@ -2006,7 +2003,7 @@ class Project extends CommonObject // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $result=$c->del_type($this, $type_text); + $result=$c->del_type($this, $type_categ); if ($result<0) { $this->errors=$c->errors; $this->error=$c->error; @@ -2016,7 +2013,7 @@ class Project extends CommonObject } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $result=$c->add_type($this, $type_text); + $result=$c->add_type($this, $type_categ); if ($result<0) { $this->errors=$c->errors; $this->error=$c->error; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 0172d67e5c7..bfc6eac906e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4037,22 +4037,16 @@ class Societe extends CommonObject * Existing categories are left untouch. * * @param int[]|int $categories Category ID or array of Categories IDs - * @param string $type Category type ('customer' or 'supplier') + * @param string $type_categ Category type ('customer' or 'supplier') * @return int <0 if KO, >0 if OK */ - public function setCategories($categories, $type) + public function setCategories($categories, $type_categ) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; // Decode type - if ($type == 'customer') { - $type_id = Categorie::TYPE_CUSTOMER; - $type_text = 'customer'; - } elseif ($type == 'supplier') { - $type_id = Categorie::TYPE_SUPPLIER; - $type_text = 'supplier'; - } else { - dol_syslog(__METHOD__ . ': Type ' . $type . 'is an unknown company category type. Done nothing.', LOG_ERR); + if (! in_array($type_categ, array(Categorie::TYPE_CUSTOMER, Categorie::TYPE_SUPPLIER))) { + dol_syslog(__METHOD__ . ': Type ' . $type_categ . 'is an unknown company category type. Done nothing.', LOG_ERR); return -1; } @@ -4063,7 +4057,7 @@ class Societe extends CommonObject // Get current categories $c = new Categorie($this->db); - $existing = $c->containing($this->id, $type_id, 'id'); + $existing = $c->containing($this->id, $type_categ, 'id'); // Diff if (is_array($existing)) { @@ -4079,13 +4073,13 @@ class Societe extends CommonObject // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, $type_text); + $c->del_type($this, $type_categ); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $result = $c->add_type($this, $type_text); + $result = $c->add_type($this, $type_categ); if ($result < 0) { $error++; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index ae1d9afa062..03188fb9e3f 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -997,6 +997,8 @@ class User extends CommonObject */ public function setCategories($categories) { + $type_categ = Categorie::TYPE_USER; + // Handle single category if (!is_array($categories)) { $categories = array($categories); @@ -1005,7 +1007,7 @@ class User extends CommonObject // Get current categories require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_USER, 'id'); + $existing = $c->containing($this->id, $type_categ, 'id'); // Diff if (is_array($existing)) { @@ -1019,12 +1021,12 @@ class User extends CommonObject // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, 'user'); + $c->del_type($this, $type_categ); } } foreach ($to_add as $add) { if ($c->fetch($add) > 0) { - $c->add_type($this, 'user'); + $c->add_type($this, $type_categ); } }