Convert currencies

This commit is contained in:
Hillel Coren 2017-12-21 10:28:44 +02:00
parent d6590455f1
commit c8579660df
5 changed files with 38 additions and 10 deletions

View File

@ -877,6 +877,7 @@ class AccountController extends BaseController
$account->fill_products = Input::get('fill_products') ? true : false;
$account->update_products = Input::get('update_products') ? true : false;
$account->convert_products = Input::get('convert_products') ? true : false;
$account->save();
Session::flash('message', trans('texts.updated_settings'));

View File

@ -47,6 +47,10 @@ class AddRemember2faToken extends Migration
Schema::table('currencies', function ($table) {
$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) {
$table->dropColumn('exchange_rate');
});
Schema::table('accounts', function ($table) {
$table->dropColumn('convert_products');
});
}
}

View File

@ -2620,6 +2620,8 @@ $LANG = array(
'add_status' => 'Add status',
'archive_status' => 'Archive Status',
'new_status' => 'New Status',
'convert_products' => 'Convert Products',
'convert_products_help' => 'Automatically convert product prices to the client\'s currency',
);

View File

@ -6,8 +6,10 @@
@include('accounts.nav', ['selected' => ACCOUNT_PRODUCTS])
{!! Former::open()->addClass('warn-on-exit') !!}
{{ Former::populateField('fill_products', intval($account->fill_products)) }}
{{ Former::populateField('update_products', intval($account->update_products)) }}
{{ Former::populateField('convert_products', intval($account->convert_products)) }}
<div class="panel panel-default">
@ -19,6 +21,8 @@
{!! Former::checkbox('fill_products')->text(trans('texts.fill_products_help'))->value(1) !!}
{!! Former::checkbox('update_products')->text(trans('texts.update_products_help'))->value(1) !!}
&nbsp;
{!! Former::checkbox('convert_products')->text(trans('texts.convert_products_help'))->value(1) !!}
&nbsp;
{!! Former::actions( Button::success(trans('texts.save'))->submit()->appendIcon(Icon::create('floppy-disk')) ) !!}
{!! Former::close() !!}
</div>

View File

@ -1037,19 +1037,32 @@ ko.bindingHandlers.productTypeahead = {
}
if (parseFloat(datum.cost)) {
if (! model.cost() || ! model.task_public_id()) {
// optionally handle curency conversion
var cost = datum.cost;
// optionally handle curency conversion
@if ($account->convert_products)
var client = window.model.invoice().client();
if (client) {
var clientCurrencyId = client.currency_id();
if (clientCurrencyId) {
var accountCurrencyId = {{ $account->getCurrencyId() }};
if (clientCurrencyId && clientCurrencyId != accountCurrencyId) {
cost = fx.convert(cost, {
from: currencyMap[accountCurrencyId].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));
}
}