Currency conversion component edited
This commit is contained in:
parent
85fd9ffcae
commit
0786753d48
@ -1,14 +1,27 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="d-flex align-items-center justify-content-end mt-3">
|
||||||
{{ conversion }}
|
<span>{{ texts[0] }}</span>
|
||||||
|
<money v-bind="{
|
||||||
|
decimal: this.currencySymbol.decimal_mark,
|
||||||
|
thousands: this.currencySymbol.thousands_separator,
|
||||||
|
prefix: (this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
|
suffix: (!this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
|
precision: parseInt(this.currencySymbol.precision),
|
||||||
|
masked: true
|
||||||
|
}" :value="price" name="rate" disabled size="5" masked class="disabled-money text-right mr-2 js-conversion-input"></money>
|
||||||
|
<span class="mr-2">{{ currecyCode }}</span>
|
||||||
|
<input v-model="currencyRate" @input="onChange" class="disabled-money text-right js-conversion-input" size="4" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue';
|
import {Money} from 'v-money';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'akaunting-currency-conversion',
|
name: 'akaunting-currency-conversion',
|
||||||
|
components: {
|
||||||
|
Money
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
currencyConversionText: {
|
currencyConversionText: {
|
||||||
@ -26,16 +39,47 @@ export default {
|
|||||||
currencyRate: {
|
currencyRate: {
|
||||||
default: 1.000,
|
default: 1.000,
|
||||||
},
|
},
|
||||||
|
currencySymbol: {
|
||||||
|
default: {}
|
||||||
|
},
|
||||||
|
currency: {
|
||||||
|
type: Object,
|
||||||
|
default: function () {
|
||||||
|
return {
|
||||||
|
|
||||||
|
};
|
||||||
|
},
|
||||||
|
description: "Default currency"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
conversion: '',
|
conversion: '',
|
||||||
|
rate: this.currencyRate,
|
||||||
|
texts: [],
|
||||||
|
money: {
|
||||||
|
decimal: this.currencySymbol.decimal_mark,
|
||||||
|
thousands: this.currencySymbol.thousands_separator,
|
||||||
|
prefix: (this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
|
suffix: (!this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
|
precision: parseInt(this.currencySymbol.precision),
|
||||||
|
masked: true
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', this.currencyRate);
|
let conver = this.currencyConversionText.split(':price');
|
||||||
|
|
||||||
|
this.texts.push(conver[0]);
|
||||||
|
this.texts.push(conver[1].replace(':currency_code', this.currecyCode).replace(':currency_rate', this.currencyRate));
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onChange() {
|
||||||
|
this.$emit('change', this.rate);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
@ -44,15 +88,18 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
price: function (price) {
|
price: function (price) {
|
||||||
this.conversion = this.currencyConversionText.replace(':price', price).replace(':currency_code', this.currecyCode).replace(':currency_rate', this.currencyRate);
|
this.conversion = this.currencyConversionText.replace(':price', price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
},
|
},
|
||||||
|
|
||||||
currecyCode: function (currecyCode) {
|
currecyCode: function (currecyCode) {
|
||||||
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', currecyCode).replace(':currency_rate', this.currencyRate);
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
},
|
},
|
||||||
|
|
||||||
currencyRate: function (currencyRate) {
|
currencyRate: function (currencyRate) {
|
||||||
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', currencyRate);
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
|
},
|
||||||
|
currencySymbol: function (currencySymbol) {
|
||||||
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
24
resources/assets/js/views/common/documents.js
vendored
24
resources/assets/js/views/common/documents.js
vendored
@ -55,6 +55,16 @@
|
|||||||
page_loaded: false,
|
page_loaded: false,
|
||||||
currencies: [],
|
currencies: [],
|
||||||
min_due_date: false,
|
min_due_date: false,
|
||||||
|
currency_symbol: {
|
||||||
|
"name":"US Dollar",
|
||||||
|
"code":"USD",
|
||||||
|
"rate":1,
|
||||||
|
"precision":2,
|
||||||
|
"symbol":"$",
|
||||||
|
"symbol_first":1,
|
||||||
|
"decimal_mark":".",
|
||||||
|
"thousands_separator":","
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -542,6 +552,9 @@
|
|||||||
|
|
||||||
this.form.currency_code = currency.code;
|
this.form.currency_code = currency.code;
|
||||||
this.form.currency_rate = currency.rate;
|
this.form.currency_rate = currency.rate;
|
||||||
|
this.currency_symbol = currency;
|
||||||
|
|
||||||
|
this.currencyConversion();
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
@ -549,6 +562,17 @@
|
|||||||
setDueMinDate(date) {
|
setDueMinDate(date) {
|
||||||
this.min_due_date = date;
|
this.min_due_date = date;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
currencyConversion() {
|
||||||
|
setTimeout(() => {
|
||||||
|
if(document.querySelectorAll('.js-conversion-input')) {
|
||||||
|
let currency_input = document.querySelectorAll('.js-conversion-input');
|
||||||
|
for(let input of currency_input) {
|
||||||
|
input.setAttribute('size', input.value.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 250)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
@ -1,151 +1,89 @@
|
|||||||
<div class="row document-item-body">
|
<template>
|
||||||
<div class="col-sm-12 mb-4 p-0">
|
<div class="d-flex align-items-center justify-content-end mt-3">
|
||||||
<div class="table-responsive overflow-x-scroll overflow-y-hidden">
|
<span>{{ texts[0] }}</span>
|
||||||
<table class="table" id="totals">
|
<money v-bind="{
|
||||||
<colgroup>
|
decimal: this.currencySymbol.decimal_mark,
|
||||||
<col class="document-total-50">
|
thousands: this.currencySymbol.thousands_separator,
|
||||||
<col class="document-total-30">
|
prefix: (this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
<col class="document-total-25">
|
suffix: (!this.currencySymbol.symbol_first) ? this.currencySymbol.symbol : '',
|
||||||
<col class="document-total-50-px">
|
precision: parseInt(this.currencySymbol.precision),
|
||||||
</colgroup>
|
masked: true
|
||||||
<tbody id="invoice-total-rows" class="table-padding-05">
|
}" :value="price" name="rate" disabled size="5" masked class="disabled-money text-right mr-2 js-conversion-input"></money>
|
||||||
@stack('sub_total_td_start')
|
<span class="mr-2">{{ currecyCode }}</span>
|
||||||
<tr id="tr-subtotal">
|
<input v-model="currencyRate" @input="onChange" class="disabled-money text-right js-conversion-input" size="4" />
|
||||||
<td class="border-bottom-0 pb-0"></td>
|
|
||||||
<td class="text-right border-right-0 border-bottom-0 align-middle pb-0 pr-0">
|
|
||||||
<strong>{{ trans('invoices.sub_total') }}</strong>
|
|
||||||
</td>
|
|
||||||
<td class="text-right border-bottom-0 long-texts pb-0 pr-3">
|
|
||||||
<div>
|
|
||||||
{{ Form::moneyGroup('sub_total', '', '', ['disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'totals.sub', 'currency' => $currency, 'dynamic-currency' => 'currency', 'money-class' => 'text-right disabled-money'], 0.00, 'text-right disabled-money') }}
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</template>
|
||||||
<td class="border-bottom-0 pb-0" style="max-width: 50px"></td>
|
|
||||||
</tr>
|
|
||||||
@stack('sub_total_td_end')
|
|
||||||
|
|
||||||
@if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
|
<script>
|
||||||
@stack('item_discount_td_start')
|
import {Money} from 'v-money';
|
||||||
<tr id="tr-line-discount" v-if="totals.item_discount">
|
|
||||||
<td class="border-top-0 pt-0 pb-0"></td>
|
|
||||||
<td class="text-right border-top-0 border-right-0 border-bottom-0 align-middle pt-0 pb-0 pr-0">
|
|
||||||
<strong>{{ trans('invoices.item_discount') }}</strong>
|
|
||||||
</td>
|
|
||||||
<td class="text-right border-top-0 border-bottom-0 long-texts pt-0 pb-0 pr-3">
|
|
||||||
<div>
|
|
||||||
{{ Form::moneyGroup('item_discount', '', '', ['disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'dynamic-currency' => 'currency', 'money-class' => 'text-right disabled-money'], 0.00, 'text-right disabled-money') }}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="border-top-0 pt-0 pb-0" style="max-width: 50px"></td>
|
|
||||||
</tr>
|
|
||||||
@stack('item_discount_td_end')
|
|
||||||
@endif
|
|
||||||
|
|
||||||
@if (in_array(setting('localisation.discount_location', 'total'), ['total', 'both']))
|
export default {
|
||||||
@stack('add_discount_td_start')
|
name: 'akaunting-currency-conversion',
|
||||||
<tr id="tr-discount">
|
components: {
|
||||||
<td class="border-top-0 pt-0 pb-0"></td>
|
Money
|
||||||
<td class="text-right border-top-0 border-right-0 border-bottom-0 align-middle pt-0 pb-0 pr-0">
|
},
|
||||||
<el-popover
|
|
||||||
popper-class="p-0 h-0"
|
|
||||||
placement="bottom"
|
|
||||||
width="300"
|
|
||||||
v-model="discount">
|
|
||||||
<div class="card d-none" :class="[{'show' : discount}]">
|
|
||||||
<div class="discount card-body">
|
|
||||||
<div class="row align-items-center">
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<div class="input-group input-group-merge">
|
|
||||||
<div class="input-group-prepend">
|
|
||||||
<span class="input-group-text" id="input-discount">
|
|
||||||
<i class="fa fa-percent"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<div class="discount-description">
|
|
||||||
<strong>{{ trans('invoices.discount_desc') }}</strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="discount card-footer">
|
|
||||||
<div class="row float-right">
|
|
||||||
<div class="col-xs-12 col-sm-12">
|
|
||||||
<a href="javascript:void(0)" @click="discount = false" class="btn btn-outline-secondary" @click="closePayment">
|
|
||||||
{{ trans('general.cancel') }}
|
|
||||||
</a>
|
|
||||||
{!! Form::button(trans('general.save'), ['type' => 'button', 'id' => 'save-discount', '@click' => 'onAddTotalDiscount', 'class' => 'btn btn-success']) !!}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<el-link class="cursor-pointer text-info" slot="reference" type="primary" v-if="!totals.discount_text">{{ trans('invoices.add_discount') }}</el-link>
|
|
||||||
<el-link slot="reference" type="primary" v-if="totals.discount_text" v-html="totals.discount_text"></el-link>
|
|
||||||
</el-popover>
|
|
||||||
</td>
|
|
||||||
<td class="text-right border-top-0 border-bottom-0 pt-0 pb-0 pr-3">
|
|
||||||
<div>
|
|
||||||
{{ Form::moneyGroup('discount_total', '', '', ['disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'totals.discount', 'currency' => $currency, 'dynamic-currency' => 'currency', 'money-class' => 'text-right disabled-money'], 0.00, 'text-right disabled-money') }}
|
|
||||||
</div>
|
|
||||||
{!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!}
|
|
||||||
</td>
|
|
||||||
<td class="border-top-0 pt-0 pb-0" style="max-width: 50px"></td>
|
|
||||||
</tr>
|
|
||||||
@stack('add_discount_td_end')
|
|
||||||
@endif
|
|
||||||
|
|
||||||
@stack('tax_total_td_start')
|
props: {
|
||||||
<tr v-for="(tax, tax_index) in totals.taxes"
|
currencyConversionText: {
|
||||||
:index="tax_index">
|
type: String,
|
||||||
<td class="border-top-0 pt-0 pb-0"></td>
|
default: 'Currency conversion'
|
||||||
<td class="text-right border-top-0 border-right-0 border-bottom-0 align-middle pt-0 pb-0 pr-0">
|
},
|
||||||
<strong v-html="tax.name"></strong>
|
price: {
|
||||||
</td>
|
type: String,
|
||||||
<td class="text-right border-top-0 border-bottom-0 long-texts pb-0 pr-3">
|
default: 'sale'
|
||||||
<div>
|
},
|
||||||
{{ Form::moneyGroup('tax_total', '', '', ['disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'tax.total', 'currency' => $currency, 'dynamic-currency' => 'currency', 'money-class' => 'text-right disabled-money'], 0.00, 'text-right disabled-money') }}
|
currecyCode: {
|
||||||
</div>
|
type: String,
|
||||||
</td>
|
default: 'USD'
|
||||||
<td class="border-top-0 pt-0 pb-0" style="max-width: 50px"></td>
|
},
|
||||||
</tr>
|
currencyRate: {
|
||||||
@stack('tax_total_td_end')
|
default: 1.000,
|
||||||
|
},
|
||||||
|
currencySymbol: {
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
@stack('grand_total_td_start')
|
data() {
|
||||||
<tr id="tr-total">
|
return {
|
||||||
<td class="border-top-0 pt-0 pb-0"></td>
|
conversion: '',
|
||||||
<td class="text-right border-top-0 border-right-0 align-middle pt-0 pb-0 pr-0">
|
rate: this.currencyRate,
|
||||||
<strong class="document-total-span">{{ trans('invoices.total') }}</strong>
|
texts: []
|
||||||
{{ Form::selectGroup('currency_code', '', 'exchange-alt', $currencies, $currency->code, ['required' => 'required', 'model' => 'form.currency_code', 'change' => 'onChangeCurrency'], 'document-total-currency') }}
|
};
|
||||||
{!! Form::hidden('currency_rate', (!empty($document)) ? $document->currency_rate : $currency->rate, ['id' => 'currency_rate', 'class' => 'form-control', 'required' => 'required']) !!}
|
},
|
||||||
</td>
|
|
||||||
<td class="text-right border-top-0 long-texts pt-0 pb-0 pr-3">
|
|
||||||
<div>
|
|
||||||
{{ Form::moneyGroup('grand_total', '', '', ['disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'totals.total', 'currency' => $currency, 'dynamic-currency' => 'currency', 'money-class' => 'text-right disabled-money'], 0.00, 'text-right disabled-money') }}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="border-top-0 pt-0 pb-0" style="max-width: 50px"></td>
|
|
||||||
</tr>
|
|
||||||
@stack('grand_total_td_end')
|
|
||||||
|
|
||||||
@stack('currency_conversion_td_start')
|
created() {
|
||||||
<tr id="tr-currency-conversion" class="d-none" :class="[{'d-table-row': (('{{ $currency->code }}' != form.currency_code) && totals.total)}]">
|
let conver = this.currencyConversionText.split(':price');
|
||||||
<td class="border-top-0 pb-0"></td>
|
|
||||||
<td class="text-right border-top-0 border-right-0 align-middle pb-0 pr-3 pr-0" colspan="2">
|
this.texts.push(conver[0]);
|
||||||
<akaunting-currency-conversion
|
this.texts.push(conver[1].replace(':currency_code', this.currecyCode).replace(':currency_rate', this.currencyRate));
|
||||||
currency-conversion-text="{{ trans('currencies.conversion') }}"
|
},
|
||||||
:price="(totals.total / form.currency_rate).toFixed(2)"
|
|
||||||
currecy-code="{{ $currency->code }}"
|
methods: {
|
||||||
:currency-rate="form.currency_rate"
|
onChange() {
|
||||||
></akaunting-currency-conversion>
|
this.$emit('change', this.rate);
|
||||||
</td>
|
}
|
||||||
<td class="border-top-0 pt-0 pb-0" style="max-width: 50px"></td>
|
},
|
||||||
</tr>
|
|
||||||
@stack('currency_conversion_td_end')
|
watch: {
|
||||||
</tbody>
|
currencyConversionText: function (text) {
|
||||||
</table>
|
this.conversion = text.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace('', this.currencyRate);
|
||||||
</div>
|
},
|
||||||
</div>
|
|
||||||
</div>
|
price: function (price) {
|
||||||
|
this.conversion = this.currencyConversionText.replace(':price', price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
|
},
|
||||||
|
|
||||||
|
currecyCode: function (currecyCode) {
|
||||||
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
|
},
|
||||||
|
|
||||||
|
currencyRate: function (currencyRate) {
|
||||||
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
|
},
|
||||||
|
currencySymbol: function (currencySymbol) {
|
||||||
|
this.conversion = this.currencyConversionText.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace(':currency_rate', '');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user