Skip to content

Commit

Permalink
fix(vouchers): bhAccountSelect on Simple Vouchers
Browse files Browse the repository at this point in the history
This commit adds the bhAccountSelect to the simple vouchers module.
This comes with all the benefits of the bhAccountSelect, including
excluding title accounts and vastly simplified code.
  • Loading branch information
jniles committed Dec 6, 2017
1 parent 907a0b9 commit 25372d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 69 deletions.
24 changes: 16 additions & 8 deletions client/src/modules/vouchers/simple-voucher.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
angular.module('bhima.controllers')
.controller('SimpleJournalVoucherController', SimpleJournalVoucherController);
.controller('SimpleJournalVoucherController', SimpleJournalVoucherController);

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

/**
Expand All @@ -22,7 +22,7 @@ SimpleJournalVoucherController.$inject = [
* @todo - use VoucherForm
* forms (via AppCache and the breadcrumb component).
*/
function SimpleJournalVoucherController(Vouchers, Accounts, Session, util, Notify, Receipts, bhConstants, RS, VoucherForm, $translate) {
function SimpleJournalVoucherController(Vouchers, util, Notify, Receipts, bhConstants, RS, VoucherForm, $translate) {
var vm = this;

vm.bhConstants = bhConstants;
Expand All @@ -31,16 +31,19 @@ function SimpleJournalVoucherController(Vouchers, Accounts, Session, util, Notif
vm.Voucher = new VoucherForm('SimpleVoucher');

// global variables
vm.timestamp = new Date();
vm.maxLength = util.maxTextLength;

// expose methods to the view
vm.submit = submit;
vm.clear = clear;

vm.onSelectCreditAccount = onSelectCreditAccount;
vm.onSelectDebitAccount = onSelectDebitAccount;

// format voucher types and bind to the view
Vouchers.transactionType()
.then(function (list) {

// make sure that the items are translated
list.data.forEach(function (item) {
item.hrText = $translate.instant(item.text);
Expand All @@ -51,10 +54,15 @@ function SimpleJournalVoucherController(Vouchers, Accounts, Session, util, Notif
})
.catch(Notify.handleError);

vm.timestamp = new Date();
function onSelectCreditAccount(account) {
vm.Voucher.store.data[1].account_id = account.id;
}

function submit(form) {
function onSelectDebitAccount(account) {
vm.Voucher.store.data[0].account_id = account.id;
}

function submit(form) {
// stop submission if the form is invalid
if (form.$invalid) {
Notify.danger('FORM.ERRORS.RECORD_ERROR');
Expand Down Expand Up @@ -94,7 +102,6 @@ function SimpleJournalVoucherController(Vouchers, Accounts, Session, util, Notif
}

function clear() {

// current timestamp to limit date
vm.timestamp = new Date();

Expand All @@ -105,6 +112,7 @@ function SimpleJournalVoucherController(Vouchers, Accounts, Session, util, Notif
delete vm.amount;
}

// used for scanning barcodes
RS.$on('voucher:configure', function (evt, data) {

// configure the basics of the transaction type.
Expand Down
75 changes: 21 additions & 54 deletions client/src/modules/vouchers/simple-voucher.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,60 +103,27 @@
</div>
</div>

<div
class="form-group"
ng-class="{ 'has-error' : SimpleVoucherForm.$submitted && SimpleVoucherForm.fromAccount.$invalid }">
<label class="control-label">
<span translate>FORM.LABELS.DEBIT</span> (D)
</label>

<ui-select
name="fromAccount"
ng-model="SimpleVoucherCtrl.Voucher.store.data[0].account_id"
required>
<ui-select-match placeholder="{{ ::'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<span><strong>{{$select.selected.number}}</strong> {{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === SimpleVoucherCtrl.bhConstants.accounts.TITLE"
repeat="account.id as account in SimpleVoucherCtrl.Voucher.accounts | filter: { 'hrlabel' : $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>
</ui-select>

<div class="help-block" ng-messages="SimpleVoucherForm.fromAccount.$error" ng-show="SimpleVoucherForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div
class="form-group"
ng-class="{ 'has-error' : SimpleVoucherForm.$submitted && SimpleVoucherForm.toAccount.$invalid }">
<label class="control-label">
<span translate>FORM.LABELS.CREDIT</span> (C)
</label>
<ui-select
name="toAccount"
ng-model="SimpleVoucherCtrl.Voucher.store.data[1].account_id"
required>
<ui-select-match placeholder="{{ ::'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<span><strong>{{$select.selected.number}}</strong> {{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === SimpleVoucherCtrl.bhConstants.accounts.TITLE"
repeat="account.id as account in SimpleVoucherCtrl.Voucher.accounts | filter: { 'hrlabel' : $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>
</ui-select>

<div class="help-block" ng-messages="SimpleVoucherForm.toAccount.$error" ng-show="SimpleVoucherForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
<bh-account-select
id="fromAccount"
name="fromAccount"
account-id="SimpleVoucherCtrl.Voucher.store.data[0].account_id"
on-select-callback="SimpleVoucherCtrl.onSelectDebitAccount(account)"
label="FORM.LABELS.DEBIT"
exclude-title-accounts="true"
validation-trigger="SimpleVoucherForm.$submitted">
<span>(D)</span>
</bh-account-select>

<bh-account-select
id="toAccount"
name="toAccount"
account-id="SimpleVoucherCtrl.Voucher.store.data[1].account_id"
on-select-callback="SimpleVoucherCtrl.onSelectCreditAccount(account)"
label="FORM.LABELS.CREDIT"
exclude-title-accounts="true"
validation-trigger="SimpleVoucherForm.$submitted">
<span>(C)</span>
</bh-account-select>

<bh-currency-select
currency-id="SimpleVoucherCtrl.Voucher.details.currency_id"
Expand Down
10 changes: 5 additions & 5 deletions test/end-to-end/vouchers/simple.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global browser, element, by */
/* global by */
const components = require('../shared/components');
const FU = require('../shared/FormUtils');
const helpers = require('../shared/helpers');

describe('Simple Vouchers', function () {
describe('Simple Vouchers', () => {
before(() => helpers.navigate('#/vouchers/simple'));

/*
Expand All @@ -21,16 +21,16 @@ describe('Simple Vouchers', function () {
amount : 100.12,
};

it('can create a simple voucher', function () {
it('can create a simple voucher', () => {
// configure the date to yesterday
components.dateEditor.set(voucher.date);

FU.input('SimpleVoucherCtrl.Voucher.details.description', voucher.description);
FU.uiSelect('SimpleVoucherCtrl.Voucher.details.type_id', voucher.type);

// select the appropriate accounts
FU.uiSelect('SimpleVoucherCtrl.Voucher.store.data[0].account_id', voucher.fromAccount);
FU.uiSelect('SimpleVoucherCtrl.Voucher.store.data[1].account_id', voucher.toAccount);
components.accountSelect.set(voucher.fromAccount, 'fromAccount');
components.accountSelect.set(voucher.toAccount, 'toAccount');

components.currencySelect.set(2);
components.currencyInput.set(voucher.amount);
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/vouchers/vouchers.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = VoucherRegistrySearch;
function VoucherRegistrySearch() {
const gridId = 'voucher-grid';
const NUM_VOUCHERS = 18;
const NUM_USER_RECORDS = 19;
const NUM_USER_RECORDS = 18;
const NUM_DESCRIPTION_RECORDS = 2;
const NUM_TRANSACTION_TYPE_RECORD = 1;
const transactionTypes = ['Autres Depenses'];
Expand Down Expand Up @@ -53,7 +53,7 @@ function VoucherRegistrySearch() {
it(`filters by <select> should return ${NUM_USER_RECORDS} results`, () => {
modal.setUser('Super User');
modal.submit();
expectNumberOfGridRows(NUM_VOUCHERS);
expectNumberOfGridRows(NUM_USER_RECORDS);
});

it(`filters by <select> transaction type should return ${NUM_TRANSACTION_TYPE_RECORD} results`, () => {
Expand Down

0 comments on commit 25372d9

Please sign in to comment.