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

Voucher cash transfer, generic income and expense tools #1586

Merged
merged 4 commits into from
May 9, 2017

Conversation

mbayopanda
Copy link
Contributor

This PR add tools for journal voucher :

  • Generic income
  • Generic Expense
  • Cash Transfer

issue #1550

@mbayopanda
Copy link
Contributor Author

@jniles could you review this PR

@jniles
Copy link
Collaborator

jniles commented May 4, 2017

@mbayopanda this is ~900 lines of code to review + functionality .. it's a lot for me to review here at Vanga. You can either ask @sfount to do it, or I'll review it when I get back...

@sfount
Copy link
Contributor

sfount commented May 5, 2017

@mbayopanda @jniles I will look at this pull request this morning.

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.

I will be reviewing the functionality of this pull request soon, I have made some comments on how the code here can be significantly reduced - this would help make it much easier to read!

lastRow.configure(rows[n]);
}

setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use the Angular js library $timeout which ensures that methods are called within $apply etc.

It would also be useful to leave a comment here explaining why this timeout of 0 seconds is needed!

@@ -105,6 +111,134 @@ function ComplexJournalVoucherController(Vouchers, $translate, Currencies, Sessi
});
}

// open generic income function
function openGenericIncomeTool() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that all of these tool chains do exactly the same thing which is to configure the rows - we could greatly reduce the code here by making all of these one function.

For example:

Toolkit.open(voucherTool)
  .then(processVoucherToolRows);

function processVoucherToolRows(result) { 
  // ... 
}

We also then may not even need the opening methods - I'm not sure exactly how this would work:

genericIncomeTool.action = openVoucherTool(genericIncomeTool);

function openVoucherTool(voucherTool) { 
  return function() { 
    Toolkit.open(voucherTool) //...
  }
}

There are a lot of patterns here that could be reduced into helper methods with clear comments!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:+1

// initial clear
vm.Voucher.clear();

while (n--) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be written as a helper method on the VoucherFormService? It seems like it may be used a lot.

For example:

// voucher-form.service.js
VoucherForm.prototype.replaceFormRows = function replaceFormRows(rows) { 
  this.clear();
  
  rows.forEach(function (row) { 
    //...
  });
}

I would also encourage using methods on arrays like forEach and map, while loops are useful for creating utilities that do not create an additional scope however methods like forEach and map are much easier to read and understand for other developers.

@ghost
Copy link

ghost commented May 8, 2017

☔ The latest upstream changes (presumably 2ff9b91) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -0,0 +1,4 @@
<a href>
Copy link
Collaborator

Choose a reason for hiding this comment

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

What typeahead dropdown does Complex Vouchers use? Can this code be removed and your PR use the same one?

* @param {object} result
*/
function updateView(result) {
$timeout(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you use:

vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ROW);

does this eliminate the need to $timeout()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, it's doesn't fill the need.

*
* @description remove null rows
*/
function removeNullRows() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a well-named function. 👍

@@ -41,7 +56,8 @@ function VoucherToolkitService($http, Modal, util) {
controller : option.controller,
controllerAs : 'ToolCtrl',
size : 'md',
resolve : { data : function () { return option; } }
backdrop : 'static',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👍

};
}

// on select cashbox
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are these functions for and why are they empty?

account : vm.account,
});

var msgTransfer = $translate.instant('VOUCHERS.GLOBAL.CASH_TRANSFER');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be much easier to maintain if you use one translate key and then do parameter substition as proposed in #408.

Like this:

var ms = $translate.instant('VOUCHER.TOOLS.SOME_DESCRIPTION', {
  cashbox: vm.cashbox.label,
  account: vm.account.label,
  amount: vm.amount,
  symbol : vm.cashbox.symbol 
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

VoucherForm.prototype.replaceFormRows = function replaceFormRows(rows) {
this.clear();

var form = this;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice alias 👍

var lastRowIdx = form.store.data.length - 1;
var lastRow = form.store.data[lastRowIdx];

lastRow.configure(rows[--n]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is creative!

The reason I originally used while (n--) was to make sure we were adding the rows on to the end of the complex voucher. Since you are directly accessing the store, there is no need for this anymore.

Can you just do lastRow.configure(row)?

@@ -54,8 +54,8 @@
<tr>
<td>{{number}}</td>
<td>{{label}}</td>
<td class="text-right">{{currency debit currency_id}}</td>
<td class="text-right">{{currency credit currency_id}}</td>
<td class="text-right">{{currency debit ../details.currency_id}}</td>
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -54,8 +54,8 @@
<tr>
<td>{{number}}</td>
<td>{{label}}</td>
<td class="text-right">{{currency debit currency_id}}</td>
<td class="text-right">{{currency credit currency_id}}</td>
<td class="text-right">{{currency debit ../details.currency_id}}</td>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Closes #1595

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.

Code looks good to me!

Instance.close({
rows : bundle,
description : msg,
type_id : bhConstants.transactionType.TRANSFER, // Cash transfer
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

account : vm.account,
});

var msg = $translate.instant('VOUCHERS.GLOBAL.TRANSFER_DESCRIPTION', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

(<label class="control-label" translate>FORM.LABELS.CREDIT</label>)

<!-- input typeahead -->
<input
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point, we should formalize when to use an account typeahead versus an account ui-select. We could eliminate a lot of code from this PR if we used a component!

@mbayopanda
Copy link
Contributor Author

@jniles could you review this PR please

@jniles
Copy link
Collaborator

jniles commented May 9, 2017

LGTM!

@jniles jniles merged commit 1a8d00f into IMA-WorldHealth:master May 9, 2017
Fix grid rows updating

Test e2e for generic income and expense

Cash transfer tool and test

update test values

Fix and enhancements

Fix test e2e

Fix and enhancements

voucher tools

Fix and enhancements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants