Skip to content

Commit

Permalink
feat(bhCurrencySelect): allow linking of cashboxes
Browse files Browse the repository at this point in the history
This commit adds in an error message if the currency accounts have never
been set for a cashbox.  It provides a link back to the cashbox's edit
form to allow a user to easily update the cashbox's currency account
from the input directly.  This isn't displayed if the cashboxId is not
passed in.

It makes the code for opening the cashbox select modal a little more
clearer and improves the user interface slightly.  In particular, the
"do not see your cashbox?" prompt has been moved into the modal.

TODOs
 1. Update the cashboxes page with ui-router to allow deep linking from
 the cash page.  The links should be:
   a. From the bhCurrencySelect to the cashboxes/id/update page
   b. From the cashboxSelectModal to the cashboxes/create/new page.
  • Loading branch information
jniles committed May 23, 2016
1 parent a421129 commit 7f2cf6a
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 257 deletions.
12 changes: 5 additions & 7 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{



"ACCOUNT": {
"ACCOUNT_CHART" : "Chart of Accounts",
"ACCOUNT_COST" : "Costs Accounts",
Expand Down Expand Up @@ -57,7 +54,7 @@
"SELECTION": {
"GO_TO_CASHBOX_PAGE" : "Go to Cashbox Page",
"MISSING_CASH" : "Missing Cash",
"TITLE" : "Selection Cashbox"
"TITLE" : "Select a Cashbox"
},
"TITLE" : "Cash Window",
"TRANSFER": {
Expand All @@ -70,8 +67,7 @@
"CURRENT_CASHBOX" : "Current Cashbox",
"LINK" : "Click here to add it.",
"MISSING" : "Don't see your cashbox?",
"TRANSFER" : "Transfer Funds",
"UNCONFIGURED" : "You have not configured a cashbox yet. Please choose a cashbox by clicking the button (Change Cashbox)"
"TRANSFER" : "Transfer Funds"
},
"DEBTOR_INVOICES" : "Debtor Invoices",
"RECEIPTS_TITLE" : "Cash Payment Receipt",
Expand All @@ -85,7 +81,9 @@
"CONFIG_ACCOUNTS" : "Configuration of Account",
"DANGER_ZONE" : "Danger Zone",
"DESCRIPTION" : "This module is responsible for cashbox management",
"TITLE" : "Cashbox Management"
"TITLE" : "Cashbox Management",
"NO_SUPPORTED_CURRENCIES" : "This cashbox does not have any supported currencies.",
"SET_CURRENCY_ACCOUNTS" : "Set currency accounts for this cashbox."
},
"COUNTRY": {
"CONFIGURATION" : "Country Manager Configuration ",
Expand Down
3 changes: 1 addition & 2 deletions client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"CURRENT_CASHBOX" : "Caisse auxilliare courant",
"LINK" : "Cliquez ici pour l'ajouter.",
"MISSING" : "Vous ne trouvez pas votre caisse?",
"TRANSFER" : "Transférer Fonds",
"UNCONFIGURED" : "Vous n'avez pas encore configuré une caisse. S'il vous plaît choisir une caisse en cliquant sur le bouton (Changer de Caisse)"
"TRANSFER" : "Transférer Fonds"
},
"DEBTOR_INVOICES" : "Factures des débiteurs",
"RECEIPTS_TITLE" : "Reçu de paiement des factures",
Expand Down
55 changes: 29 additions & 26 deletions client/src/js/components/bhCurrencySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,41 @@ angular.module('bhima.components')
controller : bhCurrencySelect,
templateUrl : 'partials/templates/bhCurrencySelect.tmpl.html',
bindings : {
validationTrigger : '<',
currencyId : '=',
disableIds : '<',
onChange : '&'
validationTrigger: '<',
currencyId: '=',
disableIds: '<?',
onChange: '&?',
cashboxId: '<?'
}
});

bhCurrencySelect.$inject = [ '$scope', 'CurrencyService' ];

/**
* Currency Selection Component
* @module components/bhCurrencySelect
*
* @description
* This is a radio button currency selection component for choosing currencies
* in a form. If a list of currencies are passed in, these are used instead of
* the application's currencies.
*
* @module components/bhCurrencySelect
* BINDINGS
* - [currency-id]
* The model value for the underlying `<input>`s. This
* is two-way bound to the parent controller.
*
* - [validation-trigger]
* a boolean that can be passed in
* to show validation messages will only show if this boolean is true. It
* is useful to bind `ParentForm.$submitted` value to this attribute.
*
* - [on-change]
* a callback bound the `ng-change` event on the `<input>`s.
*
* - [disable-ids]
* an array of currency ids to be disabled as required.
* - [cashbox-id]
* the cashbox id of the bound cashbox
*
* @example
* <!-- simple usage -->
Expand All @@ -39,22 +57,6 @@ bhCurrencySelect.$inject = [ '$scope', 'CurrencyService' ];
* validation-trigger="ParentForm.$submitted"
* >
* </bh-currency-select>
*
* BINDINGS
* - [currency-id]
* The model value for the underlying `<input>`s. This
* is two-way bound to the parent controller.
*
* - [validation-trigger]
* a boolean that can be passed in
* to show validation messages will only show if this boolean is true. It
* is useful to bind `ParentForm.$submitted` value to this attribute.
*
* - [on-change]
* a callback bound the `ng-change` event on the `<input>`s.
*
* - [disable-ids]
* an array of currency ids to be disabled as required.
*/
function bhCurrencySelect($scope, Currencies) {
var $ctrl = this;
Expand Down Expand Up @@ -82,17 +84,18 @@ function bhCurrencySelect($scope, Currencies) {

// watch the disabledIds array for changes, and disable the ids in the the
// view based on which ids are present in it
$scope.$watch(function () {
$scope.$watchCollection(function () {
return $ctrl.disableIds;
}, function (array) {

// ensure the array exists and has values
if (!array || !array.length) { return; }
array = array || [];

// loop through the currencies, disabling the currencies with ids in the
// disabledIds array.
$ctrl.currencies.forEach(function (currency) {
currency.disabled = array.indexOf(currency.id) > -1;
});

// if the two array lengths are equal, it means every currency is disabled
$ctrl.allDisabled = ($ctrl.currencies.length === array.length);
});
}
47 changes: 3 additions & 44 deletions client/src/partials/cash/cash.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="flex-header">
<div class="bhima-title">
<ol class="headercrumb">
<li class="static">{{ "TREE.FINANCE" | translate }}</li>
<li class="static">{{ "CASH.TITLE" | translate }}</li>
<li class="title">{{ CashCtrl.cashbox.label }}</li>
</ol>
Expand All @@ -22,29 +21,14 @@
<button class="btn btn-primary btn-block" ng-click="CashCtrl.openTransferModal()" data-perform-transfer>
<span class="glyphicon glyphicon-export"></span> {{ "CASH.VOUCHER.CASHBOXES.TRANSFER" | translate }}
</button>

<div class="alert alert-info btn-block">
<p style="margin-bottom: 10px;" ng-if="!CashCtrl.cashbox.id">
<span class="glyphicon glyphicon-info-sign"></span> {{ "CASH.VOUCHER.CASHBOXES.UNCONFIGURED" | translate }}
<span class="glyphicon glyphicon-inbox"></span>
</p>

<p>
<span class="glyphicon glyphicon-question-sign"></span> {{ "CASH.VOUCHER.CASHBOXES.MISSING" | translate }}
<a href="#/cashboxes">
<span class="glyphicon glyphicon-link"></span> {{ "CASH.VOUCHER.CASHBOXES.LINK" | translate }}
</a>
</p>
</div>

</div>

<!-- Cash Voucher Form -->
<div class="col-md-8">
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-barcode"></span>
{{ "CASH.VOUCHER.SLIP" | translate }} <strong> :: {{ CashCtrl.cashbox.label }} ::</strong>
{{ "CASH.VOUCHER.SLIP" | translate }} <span class="pull-right">{{ CashCtrl.cashbox.label }}</span>
</div>
<div class="panel-body">

Expand All @@ -64,32 +48,12 @@
</bh-date-editor>

<!-- currency selection -->
<!--
<div class="radio" ng-class="{ 'has-error' : CashVoucherForm.$submitted && CashVoucherForm.currency.$invalid }">
<p><strong class="control-label">{{ "FORM.LABELS.CURRENCY" | translate }}</strong></p>
<label ng-repeat="currency in CashCtrl.cashbox.currencies track by currency.currency_id" class="radio-inline">
<input
name="currency"
type="radio"
ng-model="CashCtrl.payment.currency_id"
ng-value="currency.currency_id"
ng-change="CashCtrl.digestExchangeRate()"
data-currency-option="{{ currency.currency_id }}"
required>
{{ CashCtrl.currencies.format(currency.currency_id); }}
</label>
<div class="help-block" ng-messages="CashVoucherForm.currency.$error" ng-show="CashVoucherForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
-->
<bh-currency-select
currency-id="CashCtrl.payment.currency_id"
validation-trigger="CashVoucherForm.$submitted"
on-change="CashCtrl.digestExchangeRate()"
disable-ids="CashCtrl.disabledCurrencyIds"
cashbox-id="CashCtrl.cashbox.id"
>
</bh-currency-select>

Expand Down Expand Up @@ -189,16 +153,11 @@
>
</bh-currency-input>

<div class="form-group">
<div class="form-group text-right">
<bh-loading-button loading-state="CashVoucherForm.$loading">
{{ "FORM.BUTTONS.SUBMIT" | translate }}
</bh-loading-button>
</div>

<!-- show any HTTP errors that are logged from the server -->
<p ng-show="CashCtrl.HttpError" class="text-danger">
<span class="glyphicon glyphicon-alert"></span> {{ CashCtrl.HttpError | translate }}
</p>
</fieldset>
</form>
</div>
Expand Down
Loading

0 comments on commit 7f2cf6a

Please sign in to comment.