diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 60fb76293ea..edbabd4476d 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -53,6 +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'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png @@ -75,6 +76,7 @@ class Categorie extends CommonObject 'project' => 6, 'user' => 7, 'bank_line' => 8, + 'stock' => 9, ); /** @@ -90,6 +92,7 @@ class Categorie extends CommonObject 6 => 'project', 7 => 'user', 8 => 'bank_line', + 9 => 'stock', ); /** @@ -107,6 +110,7 @@ class Categorie extends CommonObject 'account' => 'account', // old for bank_account 'bank_account' => 'account', 'project' => 'project', + 'stock' => 'entrepot', ); /** @@ -124,6 +128,7 @@ class Categorie extends CommonObject 'account' => 'account', // old for bank_account 'bank_account'=> 'account', 'project' => 'project', + 'stock' => 'entrepot', ); /** @@ -141,6 +146,7 @@ class Categorie extends CommonObject 'account' => 'Account', // old for bank account 'bank_account' => 'Account', 'project' => 'Project', + 'stock' => 'Entrepot', ); /** @@ -157,6 +163,7 @@ class Categorie extends CommonObject 'user' => 'user', 'account' => 'bank_account', 'project' => 'projet', + 'stock' => 'entrepot', ); /** diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 16cba59ca4a..ab6c6df5a26 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -58,6 +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'; } 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/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 2eead6da81d..498c3fe9798 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1522,6 +1522,9 @@ 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 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/tables/llx_categorie_stock.key.sql b/htdocs/install/mysql/tables/llx_categorie_stock.key.sql new file mode 100644 index 00000000000..e57361ed8bb --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_stock.key.sql @@ -0,0 +1,25 @@ +-- ============================================================================ +-- Copyright (C) 2007 Patrick Raguin +-- Copyright (C) 2019 Quentin Vial-Gouteyron +-- +-- 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 3 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, see . +-- +-- ============================================================================ + +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_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); diff --git a/htdocs/install/mysql/tables/llx_categorie_stock.sql b/htdocs/install/mysql/tables/llx_categorie_stock.sql new file mode 100644 index 00000000000..92173d83a01 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_stock.sql @@ -0,0 +1,27 @@ +-- ============================================================================ +-- Copyright (C) 2005 Brice Davoleau +-- Copyright (C) 2005 Matthieu Valleton +-- Copyright (C) 2012 Juanjo Menent +-- Copyright (C) 2019 Quentin Vial-Gouteyron +-- +-- 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 3 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, see . +-- +-- ============================================================================ + +create table llx_categorie_entrepot +( + fk_categorie integer NOT NULL, + fk_entrepot integer NOT NULL, + import_key varchar(14) +)ENGINE=innodb; diff --git a/htdocs/langs/fr_FR/categories.lang b/htdocs/langs/fr_FR/categories.lang index f42057eeb53..34cd3014270 100644 --- a/htdocs/langs/fr_FR/categories.lang +++ b/htdocs/langs/fr_FR/categories.lang @@ -88,3 +88,4 @@ AddProductServiceIntoCategory=Ajouter le produit/service suivant ShowCategory=Afficher tag/catégorie ByDefaultInList=Par défaut dans la liste ChooseCategory=Choisissez une catégorie +StocksCategoriesArea=Espace Tags/Catégories d'entrepôts diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 958f03dff2f..2d6d5698d61 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -34,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; - +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; // Load translation files required by the page $langs->loadLangs(array('products', 'stocks', 'companies', 'categories')); @@ -115,6 +115,8 @@ if ($action == 'add' && $user->rights->stock->creer) if ($id > 0) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); if (!empty($backtopage)) { header("Location: " . $backtopage); exit; @@ -181,6 +183,8 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel")) $action = 'edit'; setEventMessages($object->error, $object->errors, 'errors'); } else { + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); $action = ''; } } @@ -303,6 +307,13 @@ if ($action == 'create') // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; + if ($conf->categorie->enabled) { + // Categories + print ''.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_STOCK, '', 'parent', 64, 0, 1); + print $form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, '', 0, '100%'); + print ""; + } print ''; dol_fiche_end(); @@ -440,7 +451,12 @@ else // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + // Categories + if($conf->categorie->enabled) { + print ''.$langs->trans("Categories").''; + print $form->showCategories($object->id,'stock',1); + print ""; + } print ""; print ''; @@ -712,7 +728,20 @@ else { print $object->showOptionals($extrafields, 'edit'); } - + // Tags-Categories + if ($conf->categorie->enabled) + { + print ''.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_STOCK, '', 'parent', 64, 0, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id,Categorie::TYPE_STOCK); + $arrayselected=array(); + foreach($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%'); + print ""; + } print ''; dol_fiche_end(); diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 18d17f9acf0..716c34f6077 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -843,4 +843,49 @@ class Entrepot extends CommonObject return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } + + /** + * Sets object to supplied categories. + * + * Deletes object from existing categories not supplied. + * Adds it to non existing supplied categories. + * Existing categories are left untouch. + * + * @param int[]|int $categories Category or categories IDs + */ + public function setCategories($categories) { + // Handle single category + if (! is_array($categories)) { + $categories = array($categories); + } + + // 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'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, 'stock'); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, 'stock'); + } + } + + return; + } + }