mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 22:14:33 -04:00
Convert currencies
This commit is contained in:
parent
d6590455f1
commit
c8579660df
@ -877,6 +877,7 @@ class AccountController extends BaseController
|
|||||||
|
|
||||||
$account->fill_products = Input::get('fill_products') ? true : false;
|
$account->fill_products = Input::get('fill_products') ? true : false;
|
||||||
$account->update_products = Input::get('update_products') ? true : false;
|
$account->update_products = Input::get('update_products') ? true : false;
|
||||||
|
$account->convert_products = Input::get('convert_products') ? true : false;
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
Session::flash('message', trans('texts.updated_settings'));
|
Session::flash('message', trans('texts.updated_settings'));
|
||||||
|
@ -47,6 +47,10 @@ class AddRemember2faToken extends Migration
|
|||||||
Schema::table('currencies', function ($table) {
|
Schema::table('currencies', function ($table) {
|
||||||
$table->decimal('exchange_rate', 13, 4)->nullable();
|
$table->decimal('exchange_rate', 13, 4)->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('accounts', function ($table) {
|
||||||
|
$table->boolean('convert_products')->default(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,5 +78,9 @@ class AddRemember2faToken extends Migration
|
|||||||
Schema::table('currencies', function ($table) {
|
Schema::table('currencies', function ($table) {
|
||||||
$table->dropColumn('exchange_rate');
|
$table->dropColumn('exchange_rate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('accounts', function ($table) {
|
||||||
|
$table->dropColumn('convert_products');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2620,6 +2620,8 @@ $LANG = array(
|
|||||||
'add_status' => 'Add status',
|
'add_status' => 'Add status',
|
||||||
'archive_status' => 'Archive Status',
|
'archive_status' => 'Archive Status',
|
||||||
'new_status' => 'New Status',
|
'new_status' => 'New Status',
|
||||||
|
'convert_products' => 'Convert Products',
|
||||||
|
'convert_products_help' => 'Automatically convert product prices to the client\'s currency',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
@include('accounts.nav', ['selected' => ACCOUNT_PRODUCTS])
|
@include('accounts.nav', ['selected' => ACCOUNT_PRODUCTS])
|
||||||
|
|
||||||
{!! Former::open()->addClass('warn-on-exit') !!}
|
{!! Former::open()->addClass('warn-on-exit') !!}
|
||||||
|
|
||||||
{{ Former::populateField('fill_products', intval($account->fill_products)) }}
|
{{ Former::populateField('fill_products', intval($account->fill_products)) }}
|
||||||
{{ Former::populateField('update_products', intval($account->update_products)) }}
|
{{ Former::populateField('update_products', intval($account->update_products)) }}
|
||||||
|
{{ Former::populateField('convert_products', intval($account->convert_products)) }}
|
||||||
|
|
||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
@ -19,6 +21,8 @@
|
|||||||
{!! Former::checkbox('fill_products')->text(trans('texts.fill_products_help'))->value(1) !!}
|
{!! Former::checkbox('fill_products')->text(trans('texts.fill_products_help'))->value(1) !!}
|
||||||
{!! Former::checkbox('update_products')->text(trans('texts.update_products_help'))->value(1) !!}
|
{!! Former::checkbox('update_products')->text(trans('texts.update_products_help'))->value(1) !!}
|
||||||
|
|
||||||
|
{!! Former::checkbox('convert_products')->text(trans('texts.convert_products_help'))->value(1) !!}
|
||||||
|
|
||||||
{!! Former::actions( Button::success(trans('texts.save'))->submit()->appendIcon(Icon::create('floppy-disk')) ) !!}
|
{!! Former::actions( Button::success(trans('texts.save'))->submit()->appendIcon(Icon::create('floppy-disk')) ) !!}
|
||||||
{!! Former::close() !!}
|
{!! Former::close() !!}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1037,19 +1037,32 @@ ko.bindingHandlers.productTypeahead = {
|
|||||||
}
|
}
|
||||||
if (parseFloat(datum.cost)) {
|
if (parseFloat(datum.cost)) {
|
||||||
if (! model.cost() || ! model.task_public_id()) {
|
if (! model.cost() || ! model.task_public_id()) {
|
||||||
// optionally handle curency conversion
|
|
||||||
var cost = datum.cost;
|
var cost = datum.cost;
|
||||||
|
|
||||||
|
// optionally handle curency conversion
|
||||||
|
@if ($account->convert_products)
|
||||||
var client = window.model.invoice().client();
|
var client = window.model.invoice().client();
|
||||||
if (client) {
|
if (client) {
|
||||||
var clientCurrencyId = client.currency_id();
|
var clientCurrencyId = client.currency_id();
|
||||||
if (clientCurrencyId) {
|
|
||||||
var accountCurrencyId = {{ $account->getCurrencyId() }};
|
var accountCurrencyId = {{ $account->getCurrencyId() }};
|
||||||
|
if (clientCurrencyId && clientCurrencyId != accountCurrencyId) {
|
||||||
cost = fx.convert(cost, {
|
cost = fx.convert(cost, {
|
||||||
from: currencyMap[accountCurrencyId].code,
|
from: currencyMap[accountCurrencyId].code,
|
||||||
to: currencyMap[clientCurrencyId].code,
|
to: currencyMap[clientCurrencyId].code,
|
||||||
});
|
});
|
||||||
|
var rate = fx.convert(1, {
|
||||||
|
from: currencyMap[accountCurrencyId].code,
|
||||||
|
to: currencyMap[clientCurrencyId].code,
|
||||||
|
});
|
||||||
|
if ((account.custom_invoice_text_label1 || '').toLowerCase() == 'exchange rate') {
|
||||||
|
window.model.invoice().custom_text_value1(roundToFour(rate, true));
|
||||||
|
} else if ((account.custom_invoice_text_label2 || '').toLowerCase() == 'exchange rate') {
|
||||||
|
window.model.invoice().custom_text_value2(roundToFour(rate, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@endif
|
||||||
|
|
||||||
model.cost(roundSignificant(cost, true));
|
model.cost(roundSignificant(cost, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user