NEW stock categories

This commit is contained in:
atm-quentin 2019-09-19 16:03:40 +02:00
parent 76cc40973d
commit c09f2d8c4e
8 changed files with 141 additions and 3 deletions

View File

@ -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',
);
/**

View File

@ -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');

View File

@ -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)

View File

@ -0,0 +1,25 @@
-- ============================================================================
-- Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
-- Copyright (C) 2019 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ============================================================================
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);

View File

@ -0,0 +1,27 @@
-- ============================================================================
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2019 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_categorie_entrepot
(
fk_categorie integer NOT NULL,
fk_entrepot integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View File

@ -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

View File

@ -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 '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
$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 "</td></tr>";
}
print '</table>';
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 '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->showCategories($object->id,'stock',1);
print "</td></tr>";
}
print "</table>";
print '</div>';
@ -712,7 +728,20 @@ else
{
print $object->showOptionals($extrafields, 'edit');
}
// Tags-Categories
if ($conf->categorie->enabled)
{
print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td colspan="3">';
$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 "</td></tr>";
}
print '</table>';
dol_fiche_end();

View File

@ -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;
}
}