-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(accounts reports) report on transtions for multiple accounts #3159
feat(accounts reports) report on transtions for multiple accounts #3159
Conversation
40787ef
to
7288500
Compare
7288500
to
3a4b583
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good first pass on the multiple accounts report, great work!
My main feedback here is on code that can be shared between this report and the account statement report. It looks like around ~200 lines of code could be removed from this and shared by the reports in a library.
The issue also mentions a 'combined' or 'separated' flag for the reports presentation:
Ideally, it should be available on two presentations: combined and separated. The "combined" presentation will put all the transactions in the same table and add an extra column for the "account" so that we can determine from which account the transaction came from. The "separated" view would basically repeat the "Account Statement Report" multiple times for each account selected, one table after the other
This feature can be discussed in the issue proposal thread if it is not appropriate, otherwise it would be good to implement it to properly close the feature.
} | ||
|
||
/** | ||
* @function getGeneralLedgerSQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this method already exists in reportAccounts
https://github.com/IMA-WorldHealth/bhima-2.X/blob/59a150ec96c18fa053e877e047761d03f34311d1/server/controllers/finance/reports/reportAccounts/index.js#L106
There is a useful CS principle known as Don't repeat yourself (or DRY). Keeping code in one place means that when we update features, text or fix bugs we can just change the core code and not have to search around.
Can this be moved to a shared library so that all accounts that use this logic can share the code? (Something like AccountsExtra
)
|
||
// @TODO define standards for displaying and rounding totals, unless numbers are rounded | ||
// uniformly they may be displayed differently from what is recorded | ||
function getTotalsSQL(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same principle as comment on getGeneralLedgerSQL
)
* @description | ||
* This function returns all the transactions for an account, | ||
*/ | ||
function getAccountTransactions(options, openingBalance = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same principle as comment on getGeneralLedgerSQL
)
/** | ||
* @method document | ||
* | ||
* @description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to update this comment description to explain the difference between this and the accounts report.
@@ -98,7 +98,8 @@ INSERT INTO unit VALUES | |||
(204, 'Exchange Rate','TREE.EXCHANGE','',1,'/modules/exchange/exchange','/exchange'), | |||
(205, 'Account Reference Management','TREE.ACCOUNT_REFERENCE_MANAGEMENT','',1,'/modules/account_reference','/account_reference'), | |||
(206, '[OHADA] Bilan','TREE.OHADA_BALANCE_SHEET','',144,'/modules/reports/ohada_balance_sheet_report','/reports/ohada_balance_sheet_report'), | |||
(207, 'Account Reference Report','TREE.ACCOUNT_REFERENCE_REPORT','',144,'/modules/reports/account_reference','/reports/account_reference'); | |||
(207, 'Account Reference Report','TREE.ACCOUNT_REFERENCE_REPORT','',144,'/modules/reports/account_reference','/reports/account_reference'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jniles How should changes to core BHIMA tables be tracked for upgrading production servers?
Is bhima.sql
run whenever and upgrade is performed? It does include things that may have changed like transaction_type
. Otherwise is there a method of tracking changes that don't require a schema update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Right now we just manually upgrade things. I'm not sure of a better way, or how to make sure people respect the better way when writing new code. As a reviewer, I find it hard to remember to remind people to make upgrade scripts.
3a4b583
to
1aefd1e
Compare
@sfount This PR is ready for a review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of code here, and most looks good. I've made some comments on some confusion that needs to be cleared up.
.env.development
Outdated
@@ -5,7 +5,7 @@ PORT=8080 | |||
DB_HOST='localhost' | |||
DB_USER='bhima' | |||
DB_PASS='HISCongo2013' | |||
DB_NAME='bhima_test' | |||
DB_NAME='imck' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reset to bhima_test
.
client/src/i18n/en/report.json
Outdated
"TITLE": "Accounts Report", | ||
"DESCRIPTION": "This report shows all transactions for a group of accounts given a set time period.", | ||
"WARN_MULTIPLE": "N.B. This report concerns an income/ expense account and spans multiple fiscal years. Income/ expense accounts are cleared to 0 at the beginning of every fiscal year, the cumulative balance displayed is for the transactions within this period of time. It is recommended to use this statement within a single fiscal year.", | ||
"WARN_CURRENCY": "Attention! You are using a currency other than the enterprise currency. Values on this report are subject to change with changes to the exchange rate and should not be considered final. Please save a report in the enterprise currency for long term reference." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these keys are the same as the previous report, you can just re-use them. There is no need to repeat ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
const reportUrl = 'reports/finance/account_report_multiple'; | ||
vm.previewGenerated = false; | ||
vm.accountIds = []; | ||
delete cache.reportDetails; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to delete the cache.reportDetails
? Doesn't that defeat the purpose of a cache?
delete cache.reportDetails; | ||
vm.reportDetails = { | ||
currency_id : Session.enterprise.currency_id, | ||
selectedAccounts : [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already like that
const cache = new AppCache('configure_account_report_multiple'); | ||
const reportUrl = 'reports/finance/account_report_multiple'; | ||
vm.previewGenerated = false; | ||
vm.accountIds = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need both vm.accountIds
and vm.reportDetails.selectedAccounts
? We should keep all the data in one array.
<bh-currency-select | ||
currency-id="ReportConfigCtrl.reportDetails.currency_id" | ||
on-change="ReportConfigCtrl.setCurrency(currency)" | ||
validation-trigger="ConfigForm.$submitted"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like validationTrigger
was removed from bh-currency-select. Please remove it here.
|
||
vm.reportDetails.selectedAccounts = vm.reportDetails.selectedAccounts.filter(ac => { | ||
return vm.accountIds.indexOf(ac.id); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this statement doing? It isn't clear to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can notice that I need in the ui-select both then label and the account number but when the user remove the selected account, the on-remove callback return just the id of the account
const { selectedAccounts } = params; | ||
const accounts = [].concat(selectedAccounts); | ||
return q.all(accounts.map(account => { | ||
const parseAccount = JSON.parse(account); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement tells me that you are not sending account IDs to the server, but JSON objects. You should be sending an array of one or more account IDs to the server. Like this:
GET some/report?account_ids=1,2,3
That way, there won't be any need to call JSON.parse
on each value.
}) | ||
.then(results => { | ||
_.extend(bundle, { Alltransactions : results }, { params }); | ||
return Fiscal.getNumberOfFiscalYears(params.dateFrom, params.dateTo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like you ever use Fiscal.getNumberOfFiscalYears()
. Why did you call it?
@@ -98,7 +98,8 @@ INSERT INTO unit VALUES | |||
(204, 'Exchange Rate','TREE.EXCHANGE','',1,'/modules/exchange/exchange','/exchange'), | |||
(205, 'Account Reference Management','TREE.ACCOUNT_REFERENCE_MANAGEMENT','',1,'/modules/account_reference','/account_reference'), | |||
(206, '[OHADA] Bilan','TREE.OHADA_BALANCE_SHEET','',144,'/modules/reports/ohada_balance_sheet_report','/reports/ohada_balance_sheet_report'), | |||
(207, 'Account Reference Report','TREE.ACCOUNT_REFERENCE_REPORT','',144,'/modules/reports/account_reference','/reports/account_reference'); | |||
(207, 'Account Reference Report','TREE.ACCOUNT_REFERENCE_REPORT','',144,'/modules/reports/account_reference','/reports/account_reference'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Right now we just manually upgrade things. I'm not sure of a better way, or how to make sure people respect the better way when writing new code. As a reviewer, I find it hard to remember to remind people to make upgrade scripts.
d5b2834
to
26509fc
Compare
@jeremielodi, what is the status of this report? |
Ready to be merged |
Could you fix the conflicts first? Also, are you sure you fixed the issues in the last review? It doesn't look like any changes were made. |
26509fc
to
c98220b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list of accounts doesn't display the account number
The translation here could just be "Rapport des comptes"
🔥 There is not opening balance
The "Rapport de compte (simple)" has the opening balance for the selected account but not the "Rapport des comptes (multiple)"
@@ -109,6 +109,10 @@ | |||
"WARN_MULTIPLE": "N.B. This report concerns an income/ expense account and spans multiple fiscal years. Income/ expense accounts are cleared to 0 at the beginning of every fiscal year, the cumulative balance displayed is for the transactions within this period of time. It is recommended to use this statement within a single fiscal year.", | |||
"WARN_CURRENCY": "Attention! You are using a currency other than the enterprise currency. Values on this report are subject to change with changes to the exchange rate and should not be considered final. Please save a report in the enterprise currency for long term reference." | |||
}, | |||
"REPORT_ACCOUNTS_MULTIPLE": { | |||
"TITLE": "Multiple Accounts Report", | |||
"DESCRIPTION": "This report shows all transactions for a group of accounts given a set time period." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about : This report displays all transactions of a group of accounts for a given period
client/src/i18n/fr/tree.json
Outdated
@@ -83,6 +83,7 @@ | |||
"PURCHASE_REGISTRY":"Registre des achats", | |||
"REPORTS":"Rapports", | |||
"REPORT_ACCOUNTS":"Rapport de comptes", | |||
"REPORTS_MULTIPLE_ACCOUNTS" : "Rapport de comptes mutiple", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would say multiples
instead of mutiple
.
Also, i think the correct phrase could just be : "Rapport des comptes"
client/src/i18n/fr/tree.json
Outdated
@@ -83,6 +83,7 @@ | |||
"PURCHASE_REGISTRY":"Registre des achats", | |||
"REPORTS":"Rapports", | |||
"REPORT_ACCOUNTS":"Rapport de comptes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This translation could be updated to "Rapport de compte" in singular
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also seeing that Rapport de compte
and Rapport des comptes
are close in the navigation tree, it can be a bit confusing for users, so we can add a suffixes (simple and multiple) to differentiate them :
- "Rapport de compte" => "Rapport de compte (simple)", in the report page we just keep "Rapport de compte"
- "Rapport des comptes" => "Rapport des comptes (multiple)", in the report page we just keep "Rapport des comptes"
f78574d
to
9c46d1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more things to clean up.
})); | ||
}) | ||
.then(openginBalances => { | ||
openginBalances.forEach((balance, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to read if you change this variable name from openginBalances
to openingBalances
.
})); | ||
}) | ||
.then(_accountTransactions => { | ||
accountTransactions = _accountTransactions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is useless. Do ahead and just call the parameter accountTransactions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's used in several places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see it now. I wasn't expecting it to be used outside of it's context.
openginBalances.forEach((balance, index) => { | ||
accountTransactions[index].header = balance; | ||
}); | ||
_.extend(bundle, { Alltransactions : accountTransactions }, { params }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually only class names start with a capital letter. Could you rename this variable allTransactions
?
let accountTransactions = []; // list of all account containing transactions | ||
const accountIDs = [].concat(params.accountIds); | ||
|
||
const accounts = await q.all(accountIDs.map(id => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of await
. We could apply it to the entire function, but it isn't necessary here.
<th></th> | ||
|
||
<th class="text-right"> | ||
{{debcred header.exchangedBalance ../params.currency_id }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9c46d1c
to
ed85bea
Compare
ed85bea
to
0fda952
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough!
bors r+
3159: feat(accounts reports) report on transtions for multiple accounts r=jniles a=jeremielodi closes #3103 Co-authored-by: jeremielodi <[email protected]>
Build succeeded |
closes #3103