Skip to content

Commit

Permalink
fix(accounts): unify account types
Browse files Browse the repository at this point in the history
This commit removes all the `is_` account prefixes to replace them with
account_type checks instead.  The only one actually used was `is_title`
which has been replaced with an account type check.

Closes Third-Culture-Software#2436.
  • Loading branch information
jniles committed Jan 9, 2018
1 parent 9b3d24f commit 483b3f3
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 289 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"angular-messages": "1.6.6",
"angular-bootstrap": "2.5.0",
"angular-ui-router": "1.0.0-rc.1",
"angular-ui-grid": "4.0.4",
"angular-ui-grid": "4.1.3",
"angular-translate": "2.17.0",
"angular-translate-loader-static-files": "2.17.0",
"angular-translate-loader-url": "2.17.0",
Expand Down
8 changes: 6 additions & 2 deletions client/src/modules/accounts/AccountStoreService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* - store to use
*/
angular.module('bhima.services')
.service('AccountStoreService', AccountStoreService);
.service('AccountStoreService', AccountStoreService);

AccountStoreService.$inject = ['$q', 'AccountService', 'AccountTypeService', 'Store'];
AccountStoreService.$inject = [
'$q', 'AccountService', 'AccountTypeService', 'Store',
];

// Temporary service until caching API services is well designed
function AccountStoreService($q, Accounts, AccountTypes, Store) {
Expand Down Expand Up @@ -40,6 +42,7 @@ function AccountStoreService($q, Accounts, AccountTypes, Store) {
return accounts;
});
}

return $q.resolve(accounts);
}

Expand All @@ -49,6 +52,7 @@ function AccountStoreService($q, Accounts, AccountTypes, Store) {
return accountTypes;
});
}

return $q.resolve(accountTypes);
}
}
1 change: 1 addition & 0 deletions client/src/modules/accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function AccountsController($rootScope, $timeout, AccountGrid, Notify, Constants

function bindGridData() {
vm.gridOptions.data = vm.Accounts.data;
console.log('vm.Accounts.data', vm.gridOptions.data);
}

function toggleLoadingIndicator() {
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/finance/accounts/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function detail(req, res, next) {
*/
function list(req, res, next) {
const sql = `
SELECT id, category, translation_key
SELECT id, category, translation_key
FROM account_category;
`;

Expand Down Expand Up @@ -96,7 +96,7 @@ function create(req, res, next) {
*/
function update(req, res, next) {
const data = req.body;
const id = req.params.id;
const { id } = req.params;
const sql = 'UPDATE account_category SET ? WHERE id = ?';

delete data.id;
Expand All @@ -120,7 +120,7 @@ function update(req, res, next) {
* DELETE /accounts/categories/:id
*/
function remove(req, res, next) {
const id = req.params.id;
const { id } = req.params;
const sql = 'DELETE FROM account_category WHERE id = ?';

lookupAccountCategory(id)
Expand Down
11 changes: 5 additions & 6 deletions server/controllers/finance/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ function list(req, res, next) {
if (req.query.detailed === '1') {
sql = `
SELECT a.id, a.enterprise_id, a.locked, a.cc_id, a.pc_id, a.created,
a.classe, a.is_asset, a.reference_id, a.is_brut_link, a.is_charge,
a.number, a.label, a.parent, a.type_id, a.is_title, at.type,
at.translation_key, cc.text AS cost_center_text, pc.text AS profit_center_text
a.classe, a.reference_id, a.number, a.label, a.parent,
a.type_id, at.type, at.translation_key, cc.text AS cost_center_text,
pc.text AS profit_center_text
FROM account AS a JOIN account_type AS at ON a.type_id = at.id
LEFT JOIN cost_center AS cc ON a.cc_id = cc.id
LEFT JOIN profit_center AS pc ON a.pc_id = pc.id
Expand Down Expand Up @@ -304,8 +304,7 @@ function getOpeningBalanceForPeriod(req, res, next) {
function lookupAccount(id) {
let sql = `
SELECT a.id, a.enterprise_id, a.locked, a.cc_id, a.pc_id, a.created,
a.classe, a.is_asset, a.reference_id, a.is_brut_link, a.is_charge,
a.number, a.label, a.parent, a.type_id, a.is_title, at.type,
a.classe, a.reference_id, a.number, a.label, a.parent, a.type_id, at.type,
at.translation_key, cc.text AS cost_center_text, pc.text AS profit_center_text
FROM account AS a JOIN account_type AS at ON a.type_id = at.id
LEFT JOIN cost_center AS cc ON a.cc_id = cc.id
Expand Down Expand Up @@ -358,7 +357,7 @@ function getChildren(accounts, parentId) {

const children = accounts.filter(account => account.parent === parentId);

children.forEach((account) => {
children.forEach(account => {
account.children = getChildren(accounts, account.id);
});

Expand Down
4 changes: 2 additions & 2 deletions server/controllers/finance/reports/accounts/chart.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<tbody>
{{#each accounts}}
{{#if this.is_title}}
{{#equal this.type_id ../TITLE_ID}}
<tr>
<td class="text-right"><strong>{{ this.number }}</strong></td>
<td class="text-left">
Expand All @@ -49,7 +49,7 @@
</td>
<td>{{translate this.translation_key }}</td>
</tr>
{{/if}}
{{/equal}}
{{/each}}
</tbody>
</table>
Expand Down
11 changes: 3 additions & 8 deletions server/controllers/finance/reports/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ function chart(req, res, next) {
const params = req.query;

// @TODO Define server constants library
const TITLE_ID = 4;
const TITLE_ID = 6;

params.user = req.session.user;
params.TITLE_ID = TITLE_ID;

const options = _.extend(req.query, {
csvKey : 'accounts',
Expand All @@ -36,13 +37,7 @@ function chart(req, res, next) {

Accounts.lookupAccount()
.then(Accounts.processAccountDepth)
.then(accounts => {
accounts.forEach(account => {
account.is_title_account = account.type_id === TITLE_ID;
});

return report.render({ accounts });
})
.then(accounts => report.render({ accounts }))
.then(result => {
if (result.headers.type === 'xlsx') {
res.xls(result.headers.filename, result.report.accounts);
Expand Down
4 changes: 0 additions & 4 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ CREATE TABLE `account` (
`pc_id` SMALLINT(6) DEFAULT NULL,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`classe` INT(11) DEFAULT NULL,
`is_asset` TINYINT(1) DEFAULT NULL,
`reference_id` TINYINT(3) UNSIGNED DEFAULT NULL,
`is_brut_link` TINYINT(1) DEFAULT NULL,
`is_title` BOOLEAN DEFAULT FALSE,
`is_charge` TINYINT(1) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `account_1` (`number`),
KEY `type_id` (`type_id`),
Expand Down
20 changes: 0 additions & 20 deletions server/models/updates/account_type.sql

This file was deleted.

2 changes: 0 additions & 2 deletions server/models/updates/service_uuid.sql

This file was deleted.

3 changes: 0 additions & 3 deletions sh/build-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ mysql -u $DB_USER -p$DB_PASS $DB_NAME < server/models/bhima.sql &> /dev/null
echo "[build] test data"
mysql -u $DB_USER -p$DB_PASS $DB_NAME < test/data.sql &> /dev/null

echo "[update] service uuid identifiers"
mysql -u $DB_USER -p$DB_PASS $DB_NAME < server/models/updates/service_uuid.sql &> /dev/null

echo "[build] compute account class"
mysql -u $DB_USER -p$DB_PASS $DB_NAME -e "Call ComputeAccountClass();" &> /dev/null

Expand Down
Loading

0 comments on commit 483b3f3

Please sign in to comment.