diff --git a/client/src/i18n/en/form.json b/client/src/i18n/en/form.json index 7883c1c243..0725c318a2 100644 --- a/client/src/i18n/en/form.json +++ b/client/src/i18n/en/form.json @@ -15,6 +15,7 @@ "CANCEL": "Cancel", "CANCEL_EDIT": "Cancel Edit", "CASHBOX_MANAGEMENT": "Cashbox Management", + "CASHBOXES": "Cashboxes", "CLEAR": "Clear", "CLOSE": "Close", "CONFIGURE": "Configure", diff --git a/client/src/i18n/fr/form.json b/client/src/i18n/fr/form.json index 4c81843556..a25279c2d6 100644 --- a/client/src/i18n/fr/form.json +++ b/client/src/i18n/fr/form.json @@ -15,6 +15,7 @@ "CANCEL": "Annuler", "CANCEL_EDIT": "Annuler Modifier", "CASHBOX_MANAGEMENT": "Gestion des Caisses", + "CASHBOXES": "Caisses", "CLEAR": "Effacer", "CLOSE": "Fermer", "CONFIGURE": "Configurer", diff --git a/client/src/modules/payroll/rubrics/modals/rubric.modal.html b/client/src/modules/payroll/rubrics/modals/rubric.modal.html index 01bc69ddc7..fc5ca30c26 100644 --- a/client/src/modules/payroll/rubrics/modals/rubric.modal.html +++ b/client/src/modules/payroll/rubrics/modals/rubric.modal.html @@ -43,7 +43,7 @@ value="RubricModalCtrl.rubric.is_monetary_value" on-change-callback="RubricModalCtrl.isMonetaryValueSetting(value)"> - + - + - \ No newline at end of file + diff --git a/client/src/modules/templates/bhRubricSelect.tmpl.html b/client/src/modules/templates/bhRubricSelect.tmpl.html index 8cdde8fb6d..1880e2843b 100644 --- a/client/src/modules/templates/bhRubricSelect.tmpl.html +++ b/client/src/modules/templates/bhRubricSelect.tmpl.html @@ -2,12 +2,12 @@
- + - - + + - +
- \ No newline at end of file diff --git a/client/src/modules/users/users.js b/client/src/modules/users/users.js index 8ae6ba6a81..80d5bde98a 100644 --- a/client/src/modules/users/users.js +++ b/client/src/modules/users/users.js @@ -58,6 +58,13 @@ function UsersController($state, $uibModal, Users, Notify, Modal, uiGridConstant enableFiltering : true, cellClass : muteDisabledCells, }, + { + field : 'cashboxes', + displayName : 'FORM.LABELS.CASHBOXES', + headerCellFilter : 'translate', + enableFiltering : true, + cellClass : muteDisabledCells, + }, { field : 'action', displayName : '', diff --git a/client/src/modules/users/users.service.js b/client/src/modules/users/users.service.js index 33bd6840c2..9babda28ab 100644 --- a/client/src/modules/users/users.service.js +++ b/client/src/modules/users/users.service.js @@ -31,6 +31,9 @@ function UserService(Api) { delete user.lastLogin; delete user.id; delete user.active; + delete user.roles; + delete user.cashboxes; + delete user.depots; return service.$http.put(`/users/${id}`, user) .then(service.util.unwrapHttpResponse); diff --git a/client/src/modules/vouchers/complex-voucher.ctrl.js b/client/src/modules/vouchers/complex-voucher.ctrl.js index 3fe2c53058..98a78d74c9 100644 --- a/client/src/modules/vouchers/complex-voucher.ctrl.js +++ b/client/src/modules/vouchers/complex-voucher.ctrl.js @@ -17,12 +17,11 @@ ComplexJournalVoucherController.$inject = [ * * @constructor * - * TODO - Implement caching mechanism for incomplete forms (via AppCache) * TODO/FIXME - this error notification system needs serious refactor. */ function ComplexJournalVoucherController( Vouchers, Currencies, Session, FindEntity, FindReference, Notify, Toolkit, - Receipts, bhConstants, uiGridConstants, VoucherForm, $timeout, Rates + Receipts, bhConstants, uiGridConstants, VoucherForm, $timeout, Rates, ) { const vm = this; @@ -136,7 +135,6 @@ function ComplexJournalVoucherController( * @param {object} result */ function updateView(result) { - $timeout(() => { // transaction type vm.Voucher.details.type_id = result.type_id || vm.Voucher.details.type_id; diff --git a/client/src/modules/vouchers/voucher-form.service.js b/client/src/modules/vouchers/voucher-form.service.js index 94396b79c3..218b077436 100644 --- a/client/src/modules/vouchers/voucher-form.service.js +++ b/client/src/modules/vouchers/voucher-form.service.js @@ -19,7 +19,7 @@ VoucherFormService.$inject = [ */ function VoucherFormService( Vouchers, Constants, Session, VoucherItem, AppCache, Store, Accounts, - $timeout, $translate, Exchange, FormatTreeData + $timeout, $translate, Exchange, FormatTreeData, ) { // Error Flags // must have transaction_type for certain cases diff --git a/server/controllers/admin/users/index.js b/server/controllers/admin/users/index.js index 7cf655e476..fc02de47bd 100644 --- a/server/controllers/admin/users/index.js +++ b/server/controllers/admin/users/index.js @@ -47,9 +47,20 @@ async function lookupUser(id) { let sql = ` SELECT user.id, user.username, user.email, user.display_name, - user.active, user.last_login AS lastLogin, user.deactivated - FROM user WHERE user.id = ?; - `; + user.active, user.last_login AS lastLogin, user.deactivated, + GROUP_CONCAT(DISTINCT role.label ORDER BY role.label DESC SEPARATOR ', ') AS roles, + GROUP_CONCAT(DISTINCT depot.text ORDER BY depot.text DESC SEPARATOR ', ') AS depots, + GROUP_CONCAT(DISTINCT cb.label ORDER BY cb.label DESC SEPARATOR ', ') AS cashboxes + FROM user + LEFT JOIN user_role ur ON user.id = ur.user_id + LEFT JOIN role ON role.uuid = ur.role_uuid + LEFT JOIN depot_permission dp ON dp.user_id = user.id + LEFT JOIN depot ON dp.depot_uuid = depot.uuid + LEFT JOIN cashbox_permission ON user.id = cashbox_permission.user_id + LEFT JOIN cash_box cb ON cashbox_permission.cashbox_id = cb.id + WHERE user.id = ? + GROUP BY user.id; + `.trim(); const user = await db.one(sql, [id]); @@ -73,69 +84,35 @@ async function lookupUser(id) { * * @description * If the client queries to /users endpoint, the API will respond with an array - * of zero or more JSON objects, with id, and username keys. + * of zero or more JSON objects, with id, username, display_name, activation state, + * roles and depots keys. * * GET /users */ async function list(req, res, next) { try { - const sql = 'SELECT user.id, display_name, user.username, user.deactivated FROM user;'; - let users = await db.exec(sql); - users = await setDepots(users); - users = await setRoles(users); + const sql = ` + SELECT user.id, user.display_name, user.username, user.deactivated, + GROUP_CONCAT(DISTINCT role.label ORDER BY role.label DESC SEPARATOR ', ') AS roles, + GROUP_CONCAT(DISTINCT depot.text ORDER BY depot.text DESC SEPARATOR ', ') AS depots, + GROUP_CONCAT(DISTINCT cb.label ORDER BY cb.label DESC SEPARATOR ', ') AS cashboxes + FROM user + LEFT JOIN user_role ur ON user.id = ur.user_id + LEFT JOIN role ON role.uuid = ur.role_uuid + LEFT JOIN depot_permission dp ON dp.user_id = user.id + LEFT JOIN depot ON dp.depot_uuid = depot.uuid + LEFT JOIN cashbox_permission ON user.id = cashbox_permission.user_id + LEFT JOIN cash_box cb ON cashbox_permission.cashbox_id = cb.id + GROUP BY user.id; + `.trim(); + + const users = await db.exec(sql); res.status(200).json(users); } catch (error) { next(error); } } -async function setRoles(users) { - const sql = ` - SELECT ur.user_id, r.label - FROM user_role ur - JOIN role r ON r.uuid = ur.role_uuid`; - - const userMap = {}; - users.forEach(user => { - user.roles = ''; - userMap[user.id] = user; - }); - - const roles = await db.exec(sql); - - users.forEach(user => { - user.roles = roles - .filter(role => role.user_id === user.id) - .map(role => role.label) - .join(', '); - }); - return users; -} - -async function setDepots(users) { - const sql = ` - SELECT d.text, dpp.user_id - FROM depot_permission dpp - JOIN depot d ON d.uuid = dpp.depot_uuid`; - - const depotMap = {}; - users.forEach(user => { - user.roles = ''; - depotMap[user.id] = user; - }); - - const depots = await db.exec(sql); - - users.forEach(user => { - user.depots = depots - .filter(depot => depot.user_id === user.id) - .map(depot => depot.text) - .join(', '); - }); - - return users; -} - /** * @function detail * diff --git a/server/controllers/payroll/rubricConfig/index.js b/server/controllers/payroll/rubricConfig/index.js index 762cff3cfc..fd17f2d2b8 100644 --- a/server/controllers/payroll/rubricConfig/index.js +++ b/server/controllers/payroll/rubricConfig/index.js @@ -18,7 +18,7 @@ function lookupRubricConfig(id) { // Lists the Payroll RubricConfigs function list(req, res, next) { const sql = ` - SELECT c.id, c.label FROM config_rubric AS c + SELECT c.id, c.label FROM config_rubric AS c ;`; db.exec(sql) @@ -98,7 +98,7 @@ function del(req, res, next) { */ function listConfig(req, res, next) { const sql = ` - SELECT config_rubric_item.id, config_rubric_item.config_rubric_id, config_rubric_item.rubric_payroll_id + SELECT config_rubric_item.id, config_rubric_item.config_rubric_id, config_rubric_item.rubric_payroll_id FROM config_rubric_item WHERE config_rubric_item.config_rubric_id = ?; `;