Currency conversion component edited
This commit is contained in:
		@@ -1,14 +1,27 @@
 | 
			
		||||
<template>
 | 
			
		||||
    <div>
 | 
			
		||||
        {{ conversion }}
 | 
			
		||||
    <div class="d-flex align-items-center justify-content-end mt-3">
 | 
			
		||||
        <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>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import Vue from 'vue';
 | 
			
		||||
import {Money} from 'v-money';
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    name: 'akaunting-currency-conversion',
 | 
			
		||||
    components: {
 | 
			
		||||
        Money
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    props: {
 | 
			
		||||
        currencyConversionText: {
 | 
			
		||||
@@ -26,33 +39,67 @@ export default {
 | 
			
		||||
        currencyRate: {
 | 
			
		||||
            default: 1.000,
 | 
			
		||||
        },
 | 
			
		||||
        currencySymbol: {
 | 
			
		||||
           default: {}
 | 
			
		||||
        },
 | 
			
		||||
        currency: {
 | 
			
		||||
            type: Object,
 | 
			
		||||
            default: function () {
 | 
			
		||||
                return {
 | 
			
		||||
                   
 | 
			
		||||
                };
 | 
			
		||||
            },
 | 
			
		||||
            description: "Default currency"
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    data() {
 | 
			
		||||
        return {
 | 
			
		||||
            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() {
 | 
			
		||||
        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: {
 | 
			
		||||
        currencyConversionText: function (text) {
 | 
			
		||||
            this.conversion = text.replace(':price', this.price).replace(':currency_code', this.currecyCode).replace('', this.currencyRate);
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
            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) {
 | 
			
		||||
            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', '');
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								resources/assets/js/views/common/documents.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								resources/assets/js/views/common/documents.js
									
									
									
									
										vendored
									
									
								
							@@ -55,6 +55,16 @@
 | 
			
		||||
             page_loaded: false,
 | 
			
		||||
             currencies: [],
 | 
			
		||||
             min_due_date: false,
 | 
			
		||||
             currency_symbol: {
 | 
			
		||||
                "name":"US Dollar",
 | 
			
		||||
                "code":"USD",
 | 
			
		||||
                "rate":1,
 | 
			
		||||
                "precision":2,
 | 
			
		||||
                "symbol":"$",
 | 
			
		||||
                "symbol_first":1,
 | 
			
		||||
                "decimal_mark":".",
 | 
			
		||||
                "thousands_separator":","
 | 
			
		||||
             }
 | 
			
		||||
         }
 | 
			
		||||
     },
 | 
			
		||||
 
 | 
			
		||||
@@ -535,13 +545,16 @@
 | 
			
		||||
                     this.onChangeCurrency(currency_code);
 | 
			
		||||
                 });
 | 
			
		||||
             }
 | 
			
		||||
 
 | 
			
		||||
            
 | 
			
		||||
             this.currencies.forEach(function (currency, index) {
 | 
			
		||||
                 if (currency_code == currency.code) {
 | 
			
		||||
                     this.currency = currency;
 | 
			
		||||
 
 | 
			
		||||
                     this.form.currency_code = currency.code;
 | 
			
		||||
                     this.form.currency_rate = currency.rate;
 | 
			
		||||
                     this.currency_symbol = currency;
 | 
			
		||||
 | 
			
		||||
                     this.currencyConversion();
 | 
			
		||||
                 }
 | 
			
		||||
             }, this);
 | 
			
		||||
         },
 | 
			
		||||
@@ -549,6 +562,17 @@
 | 
			
		||||
         setDueMinDate(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() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user