Skip to content
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

Merged

Conversation

jeremielodi
Copy link
Collaborator

closes #3103

Copy link
Contributor

@sfount sfount left a 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
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @description
* This function returns all the transactions for an account,
*/
function getAccountTransactions(options, openingBalance = 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @method document
*
* @description
Copy link
Contributor

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'),
Copy link
Contributor

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?

Copy link
Collaborator

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.

@jeremielodi
Copy link
Collaborator Author

jeremielodi commented Sep 10, 2018

@sfount This PR is ready for a review

Copy link
Collaborator

@jniles jniles left a 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'
Copy link
Collaborator

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.

"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."
Copy link
Collaborator

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.

Copy link
Collaborator Author

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;
Copy link
Collaborator

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 : [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we save the accounts so that when a user comes back to this screen, they find the same accounts? It's how the other account report works. See below.

2018-09-10_13-23-51

Copy link
Collaborator Author

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 = [];
Copy link
Collaborator

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">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


vm.reportDetails.selectedAccounts = vm.reportDetails.selectedAccounts.filter(ac => {
return vm.accountIds.indexOf(ac.id);
});
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are using a select multiple; when a selected account is removed , this snipet of code will filter vm.reportDetails.selectedAccounts then it will be reduced.
You can see at the screen shot bellow how accounts are displayed

selected accounsts

Copy link
Collaborator Author

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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'),
Copy link
Collaborator

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.

@jeremielodi jeremielodi force-pushed the multiple_account_statement branch 3 times, most recently from d5b2834 to 26509fc Compare September 14, 2018 08:59
@jniles
Copy link
Collaborator

jniles commented Sep 14, 2018

Looks like this isn't quite done:

The account dropdown should have the account numbers on it. This is how all other account dropdowns work.
fixmultipleaccountreport
Fig 1: Account Dropdown Needs Numbers

The currency symbol should be rendered in the account header:
needscurrencyaccount

The opening balance needs to be in the same currency as what the user chose.
openingbalanceshouldbeincorrectcurrency

@jniles
Copy link
Collaborator

jniles commented Sep 18, 2018

@jeremielodi, what is the status of this report?

@jeremielodi
Copy link
Collaborator Author

Ready to be merged

@jniles
Copy link
Collaborator

jniles commented Sep 19, 2018

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.

Copy link
Collaborator

@mbayopanda mbayopanda left a 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

image

The translation here could just be "Rapport des comptes"

image

🔥 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)"

  • "Rapport de compte (simple)" : for 57110011
    image

  • "Rapport de compte (multiple)" : for 57110011
    image

@@ -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."
Copy link
Collaborator

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

@@ -83,6 +83,7 @@
"PURCHASE_REGISTRY":"Registre des achats",
"REPORTS":"Rapports",
"REPORT_ACCOUNTS":"Rapport de comptes",
"REPORTS_MULTIPLE_ACCOUNTS" : "Rapport de comptes mutiple",
Copy link
Collaborator

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"

@@ -83,6 +83,7 @@
"PURCHASE_REGISTRY":"Registre des achats",
"REPORTS":"Rapports",
"REPORT_ACCOUNTS":"Rapport de comptes",
Copy link
Collaborator

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

Copy link
Collaborator

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"

@jeremielodi jeremielodi force-pushed the multiple_account_statement branch 3 times, most recently from f78574d to 9c46d1c Compare September 24, 2018 08:51
Copy link
Collaborator

@jniles jniles left a 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) => {
Copy link
Collaborator

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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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 });
Copy link
Collaborator

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 => {
Copy link
Collaborator

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 }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this doesn't reflect the same as the normal account statement in the "balance" column. Can you check what is going on?

simpleaccountstatement
This version works

multipleaccountsbalance
This version isn't correct

Copy link
Collaborator

@jniles jniles left a 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+

bors bot added a commit that referenced this pull request Sep 27, 2018
3159: feat(accounts reports) report on transtions for multiple accounts r=jniles a=jeremielodi

closes #3103 

Co-authored-by: jeremielodi <[email protected]>
@jniles jniles added the Report label Sep 27, 2018
@bors
Copy link
Contributor

bors bot commented Sep 27, 2018

Build succeeded

@bors bors bot merged commit 0fda952 into Third-Culture-Software:master Sep 27, 2018
@jeremielodi jeremielodi deleted the multiple_account_statement branch October 1, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report on Transactions in Multiple Accounts
4 participants