mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Convert currencies
This commit is contained in:
parent
d8be149db1
commit
4683f66fc6
@ -159,7 +159,7 @@
|
||||
{!! Former::select('invoice_currency_id')->addOption('','')
|
||||
->label(trans('texts.invoice_currency'))
|
||||
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
|
||||
->data_bind('combobox: invoiceCurrencyId, disable: true')
|
||||
->data_bind('combobox: invoice_currency_id, disable: true')
|
||||
->fromQuery($currencies, 'name', 'id') !!}
|
||||
</span>
|
||||
<span style="display:none;" data-bind="visible: client_id">
|
||||
@ -354,6 +354,12 @@
|
||||
onClientChange();
|
||||
});
|
||||
|
||||
$('#invoice_currency_id, #expense_currency_id').on('change', function() {
|
||||
setTimeout(function() {
|
||||
model.updateExchangeRate();
|
||||
}, 1);
|
||||
})
|
||||
|
||||
@if ($data)
|
||||
// this means we failed so we'll reload the previous state
|
||||
window.model = new ViewModel({!! $data !!});
|
||||
@ -478,13 +484,7 @@
|
||||
}
|
||||
}, self);
|
||||
|
||||
|
||||
self.invoiceCurrencyId = ko.computed({
|
||||
read: function () {
|
||||
return self.invoice_currency_id();
|
||||
},
|
||||
write: function(invoiceCurrencyId) {
|
||||
self.invoice_currency_id(invoiceCurrencyId);
|
||||
self.updateExchangeRate = function() {
|
||||
var fromCode = self.expenseCurrencyCode();
|
||||
var toCode = self.invoiceCurrencyCode();
|
||||
if (currencyMap[fromCode].exchange_rate && currencyMap[toCode].exchange_rate) {
|
||||
@ -492,12 +492,11 @@
|
||||
from: fromCode,
|
||||
to: toCode,
|
||||
});
|
||||
self.exchange_rate(roundToFour(rate));
|
||||
self.exchange_rate(roundToFour(rate, true));
|
||||
} else {
|
||||
self.exchange_rate(1);
|
||||
}
|
||||
}
|
||||
}, self);
|
||||
|
||||
self.getCurrency = function(currencyId) {
|
||||
return currencyMap[currencyId || self.account_currency_id()];
|
||||
|
@ -201,6 +201,12 @@
|
||||
toggleDatePicker('payment_date');
|
||||
});
|
||||
|
||||
$('#exchange_currency_id').on('change', function() {
|
||||
setTimeout(function() {
|
||||
model.updateExchangeRate();
|
||||
}, 1);
|
||||
})
|
||||
|
||||
if (isStorageSupported()) {
|
||||
if (localStorage.getItem('last:send_email_receipt')) {
|
||||
$('#email_receipt').prop('checked', true);
|
||||
@ -262,6 +268,21 @@
|
||||
}
|
||||
}, self);
|
||||
|
||||
|
||||
self.updateExchangeRate = function() {
|
||||
var fromCode = self.paymentCurrencyCode();
|
||||
var toCode = self.exchangeCurrencyCode();
|
||||
if (currencyMap[fromCode].exchange_rate && currencyMap[toCode].exchange_rate) {
|
||||
var rate = fx.convert(1, {
|
||||
from: fromCode,
|
||||
to: toCode,
|
||||
});
|
||||
self.exchange_rate(roundToFour(rate, true));
|
||||
} else {
|
||||
self.exchange_rate(1);
|
||||
}
|
||||
}
|
||||
|
||||
self.getCurrency = function(currencyId) {
|
||||
return currencyMap[currencyId || self.account_currency_id()];
|
||||
};
|
||||
@ -336,6 +357,9 @@
|
||||
|
||||
if (window.model) {
|
||||
model.client_id(clientId);
|
||||
setTimeout(function() {
|
||||
model.updateExchangeRate();
|
||||
}, 1);
|
||||
}
|
||||
});
|
||||
|
||||
@ -358,6 +382,9 @@
|
||||
}
|
||||
}
|
||||
model.client_id(client ? client.public_id : 0);
|
||||
setTimeout(function() {
|
||||
model.updateExchangeRate();
|
||||
}, 1);
|
||||
});
|
||||
|
||||
$invoiceSelect.combobox({highlighter: comboboxHighlighter});
|
||||
|
Loading…
x
Reference in New Issue
Block a user