Skip to content

Commit

Permalink
fix(vouchers): disable title accounts
Browse files Browse the repository at this point in the history
This commit disables the title accounts on all voucher pages.  The title
accounts are still shown, but are disabled by checking the TITLE
bhConstant value.

It also does not allow a user to use the same account twice in a simple
voucher, as this would lead to an invalid transaction.

Closes IMA-WorldHealth#884.  Closes IMA-WorldHealth#896.
  • Loading branch information
Jonathan Niles committed Nov 15, 2016
1 parent cabc1fa commit 9441796
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,8 @@
"USE_FINANCIAL_ACCOUNT" : "Use of cashes or banks accounts in this transaction",
"RECEIPT" : {
"SUCCESS" : "Voucher Payment recorded successfully."
}
},
"ERROR_SAME_ACCOUNT" : "You cannot use the same account twice to in this transaction. Please select two different accounts."
},
"SIMPLE": {
"CASH_PAYMENT" : "Client Payment",
Expand Down
7 changes: 5 additions & 2 deletions client/src/partials/vouchers/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ angular.module('bhima.controllers')
ComplexJournalVoucherController.$inject = [
'VoucherService', '$translate', 'AccountService',
'CurrencyService', 'SessionService', 'FindEntityService',
'FindReferenceService', 'NotifyService', 'CashboxService', 'ReceiptModal'
'FindReferenceService', 'NotifyService', 'CashboxService', 'ReceiptModal',
'bhConstants'
];

/**
Expand All @@ -19,9 +20,11 @@ ComplexJournalVoucherController.$inject = [
* @todo - Implement Patient Invoices data and Cash Payment data for modal
* @todo - Implement a mean to categorise transactions for cashflow reports
*/
function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currencies, Session, FindEntity, FindReference, Notify, Cashbox, Receipts) {
function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currencies, Session, FindEntity, FindReference, Notify, Cashbox, Receipts, bhConstants) {
var vm = this;

vm.bhConstants = bhConstants;

// bread crumb paths
vm.paths = [{
label : $translate.instant('VOUCHERS.COMPLEX.TITLE'),
Expand Down
12 changes: 8 additions & 4 deletions client/src/partials/vouchers/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@
<ui-select
name="fromAccount"
ng-model="SimpleVoucherCtrl.voucher.fromAccount"
theme="bootstrap"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in SimpleVoucherCtrl.accounts | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === SimpleVoucherCtrl.bhConstants.accounts.TITLE"
repeat="account in SimpleVoucherCtrl.accounts | filter:$select.search">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand All @@ -105,12 +107,14 @@
<ui-select
name="toAccount"
ng-model="SimpleVoucherCtrl.voucher.toAccount"
theme="bootstrap"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in SimpleVoucherCtrl.accounts | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === SimpleVoucherCtrl.bhConstants.accounts.TITLE"
repeat="account in SimpleVoucherCtrl.accounts | filter:$select.search">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand Down
12 changes: 10 additions & 2 deletions client/src/partials/vouchers/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('bhima.controllers')

SimpleJournalVoucherController.$inject = [
'AppCache', 'VoucherService', 'AccountService', 'SessionService', 'util',
'NotifyService', 'ReceiptModal'
'NotifyService', 'ReceiptModal','bhConstants'
];

/**
Expand All @@ -18,12 +18,14 @@ SimpleJournalVoucherController.$inject = [
* @todo - Implement Voucher Templates to allow users to save pre-selected
* forms (via AppCache and the breadcrumb component).
*/
function SimpleJournalVoucherController(AppCache, Vouchers, Accounts, Session, util, Notify, Receipts) {
function SimpleJournalVoucherController(AppCache, Vouchers, Accounts, Session, util, Notify, Receipts, bhConstants) {
var vm = this;

// cache to save work-in-progress data and pre-fabricated templates
var cache = AppCache('JournalVouchers');

vm.bhConstants = bhConstants;

// global variables
vm.maxLength = util.maxTextLength;
vm.paths = [
Expand Down Expand Up @@ -75,6 +77,12 @@ function SimpleJournalVoucherController(AppCache, Vouchers, Accounts, Session, u
// transfer type
vm.voucher.type_id = vm.selectedType ? JSON.parse(vm.selectedType).id : null;

// make sure we are not using the same accounts for both fields
if (vm.voucher.toAccount.id === vm.voucher.fromAccount.id) {
Notify.danger('VOUCHERS.GLOBAL.ERROR_SAME_ACCOUNT');
return;
}

// submit the voucher
return Vouchers.createSimple(vm.voucher)
.then(function (res) {
Expand Down
6 changes: 4 additions & 2 deletions client/src/partials/vouchers/templates/account.grid.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
ng-model="row.entity.account"
ng-change="grid.appScope.checkRowValidity(row.entity.index)"
name="account"
theme="bootstrap"
style="width:100%;"
append-to-body="true"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account in grid.appScope.accounts | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === grid.appScope.bhConstants.accounts.TITLE"
repeat="account in grid.appScope.accounts | filter:$select.search">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/vouchers/complex.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Complex Vouchers', function () {
{ account : 'Test Debtor Accounts1', debit: 18, credit: 0, entity : { type : 'D', name: 'Patient/2/Patient' }},
{ account : 'Test Capital One', debit: 0, credit: 8, reference : { type : 'voucher', index : 0 }},
{ account : 'Test Capital Two', debit: 0, credit: 5, reference : { type : 'voucher', index : 2 }},
{ account : 'Test Balance Accounts', debit: 0, credit: 5, reference : { type : 'voucher', index : 1 }},
{ account : 'First Test Item Account', debit: 0, credit: 5, reference : { type : 'voucher', index : 1 }},
{ account : 'Test Capital One', debit: 7, credit: 0, entity : { type : 'C', name : 'Fournisseur' }},
{ account : 'Test Capital Two', debit: 0, credit: 7, reference : { type : 'patient-invoice', index : 1 }}
]
Expand Down

0 comments on commit 9441796

Please sign in to comment.