-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exchange): add exchange rate modal
This commit adds the exchange rate modal to the enterprise configuration page. This allows a user to set a new exchange rate for a given currency on a given date.
- Loading branch information
Showing
7 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<form name="ModalForm" bh-submit="ModalCtrl.submit(ModalForm)" bh-form-defaults novalidate> | ||
<div class="modal-header"> | ||
<ol class="headercrumb"> | ||
<li class="static">{{ "EXCHANGE.TITLE" | translate }}</li> | ||
<li class="title">{{ "EXCHANGE.ADDING_RATE" | translate }}</li> | ||
</ol> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
|
||
<bh-date-editor | ||
date-value="ModalCtrl.rate.date" | ||
validation-trigger="ModalForm.$submitted" | ||
max-date="ModalCtrl.timestamp"> | ||
</bh-date-editor> | ||
|
||
<div | ||
class="form-group" | ||
ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.currency_id.$invalid }"> | ||
<label class="control-label"> | ||
{{ "FORM.LABELS.CURRENCY" | translate }} | ||
</label> | ||
|
||
<ui-select | ||
name="currency_id" | ||
ng-model="ModalCtrl.rate.currency_id" | ||
ng-disabled="ModalCtrl.currencies.length === 1" | ||
required> | ||
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.CURRENCY' | translate }}"> | ||
<span>{{ ModalCtrl.format($select.selected.id) }}</span> | ||
</ui-select-match> | ||
<ui-select-choices | ||
ui-select-focus-patch | ||
repeat="currency.id as currency in ModalCtrl.currencies | filter:$select.search"> | ||
<span ng-bind-html="ModalCtrl.format(currency.id) | highlight:$select.search"></span> | ||
</ui-select-choices> | ||
</ui-select> | ||
|
||
<div class="help-block" ng-messages="ModalForm.currency_id.$error" ng-show="ModalForm.$submitted"> | ||
<div ng-messages-include="partials/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group" | ||
ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.rate.$invalid }" | ||
> | ||
<label class="control-label">{{ "FORM.LABELS.EXCHANGE_RATE" | translate }}</label> | ||
<input class="form-control" type="number" name="rate" ng-model="ModalCtrl.rate.rate" required> | ||
<div class="help-block" ng-messages="ModalForm.rate.$error" ng-show="ModalForm.$submitted"> | ||
<div ng-messages-include="partials/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" ng-click="ModalCtrl.cancel()" data-method="cancel"> | ||
{{ "FORM.BUTTONS.CANCEL" | translate }} | ||
</button> | ||
|
||
<bh-loading-button loading-state="ModalForm.$loading"> | ||
{{ "FORM.BUTTONS.SUBMIT" | translate }} | ||
</bh-loading-button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
angular.module('bhima.controllers') | ||
.controller('ExchangeRateModalController', ExchangeRateModalController); | ||
|
||
ExchangeRateModalController.$inject = [ | ||
'$uibModalInstance', 'ExchangeRateService', 'CurrencyService', 'SessionService', 'NotifyService' | ||
]; | ||
|
||
/** | ||
* This modal is a generic exchange rate modal that allows a user to | ||
* set the exchange rate from virtually anywhere in the application. | ||
* | ||
*/ | ||
function ExchangeRateModalController(ModalInstance, Exchange, Currencies, Session, Notify) { | ||
var vm = this; | ||
|
||
// bind defaults | ||
vm.timestamp = new Date(); | ||
vm.date = new Date(); | ||
vm.enterprise = Session.enterprise; | ||
|
||
vm.rate = { | ||
date : new Date(), | ||
}; | ||
|
||
vm.submit = submit; | ||
vm.format = Currencies.format; | ||
vm.cancel = function () { ModalInstance.dismiss(); }; | ||
|
||
Currencies.read() | ||
.then(function (currencies) { | ||
vm.currencies = currencies | ||
.filter(function (currency) { | ||
return currency.id !== Session.enterprise.currency_id; | ||
}); | ||
|
||
// use the first currency in the list | ||
vm.rate.currency_id = vm.currencies[0]; | ||
}) | ||
.catch(Notify.handleError); | ||
|
||
function submit(form) { | ||
if (form.$invalid) { return; } | ||
|
||
vm.rate.enterprise_id = Session.enterprise.id; | ||
|
||
// TODO clean this up with proper Ui-select syntax when internet available | ||
var currency = vm.rate.currency_id; | ||
vm.rate.currency_id = currency.id; | ||
|
||
return Exchange.create(vm.rate) | ||
.then(function () { | ||
ModalInstance.close(); | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters