WIP: 7984-addCurrency #1265

Draft
alexm wants to merge 18 commits from 7984-addCurrency into dev
4 changed files with 54 additions and 38 deletions
Showing only changes of commit 05b35f8d29 - Show all commits

View File

@ -1,6 +1,6 @@
<script setup>
import { toCurrency } from 'src/filters';
import { computed, onMounted, ref } from 'vue';
import { watch, ref } from 'vue';
import { useArrayData } from 'src/composables/useArrayData';
import { useState } from 'src/composables/useState';
@ -32,41 +32,51 @@ const $props = defineProps({
const state = useState();
const user = state.getUser();
const foreignFieldComputed = ref();
const arrayData = $props.arrayDataModel && useArrayData($props.arrayDataModel);
const foreignValue = ref();
const localValue = computed(() => $props.model?.[$props.localField]);
const currency = computed(
() => $props.currencyCode ?? arrayData.store.data?.currency?.code,
);
const toCurrencyLabel = ref();
const currencyCodeModel = ref();
const foreignValue = ref();
const localValue = ref();
const currency = ref();
onMounted(() => {
// if ($props.arrayDataModel) {
// currencyCodeModel.value = arrayData.store.data?.currency?.code;
// }
foreignFieldComputed.value =
$props.foreignField ??
'foreign' +
$props.localField.charAt(0).toUpperCase() +
$props.localField.slice(1);
foreignValue.value = $props.model[foreignFieldComputed.value];
getLabel();
});
watch(
() => $props.model,
() => calculate(),
{ immediate: true, deep: true },
);
function calculate() {
if (!$props.model) return;
currency.value = $props.currencyCode;
if ($props.arrayDataModel) {
const arrayData = $props.arrayDataModel && useArrayData($props.arrayDataModel);
currency.value = arrayData.store.data?.currency?.code;
}
foreignValue.value = $props.model[getForeignFieldComputed()];
localValue.value = $props.model?.[$props.localField];
function getLabel() {
toCurrencyLabel.value = toCurrency(
foreignValue.value ?? localValue.value,
currency.value,
);
}
function getForeignFieldComputed() {
return (
$props.foreignField ??
'foreign' + $props.localField.charAt(0).toUpperCase() + $props.localField.slice(1)
);
}
</script>
<template>
<span :title="toCurrencyLabel" v-if="currency && localValue">
<span v-if="foreignValue && user.foreignCurrency">{{ toCurrencyLabel }}</span>
<span v-else>{{ toCurrency(localValue) }}</span>
<span :title="toCurrencyLabel">
<template v-if="currency && (localValue || localValue === 0)">
{{
foreignValue && user.foreignCurrency
? toCurrencyLabel
: toCurrency(localValue)
}}
</template>
<template v-else>-</template>
</span>
<!-- <span v-else>-</span> -->
</template>

View File

@ -1,9 +1,9 @@
import { useI18n } from 'vue-i18n';
// import { useI18n } from 'vue-i18n';
export default function (value, symbol = 'EUR', fractionSize = 2) {
if (value == null || value === '') value = 0;
const { locale } = useI18n();
// const { locale } = useI18n(); // sacar en el boot, cuando se añade al user. Y aqui usarlo
const options = {
style: 'currency',
@ -12,7 +12,7 @@ export default function (value, symbol = 'EUR', fractionSize = 2) {
maximumFractionDigits: fractionSize,
};
const lang = locale.value == 'es' ? 'de' : locale.value;
const lang = 'de';
return new Intl.NumberFormat(lang, options).format(value);
}

View File

@ -250,7 +250,10 @@ onMounted(async () => {
</template>
<template #body-cell-price="{ row }">
<QTd class="number">
<VnCurrency :model="row.component" array-data-model="ticketData" />
<VnCurrency
:model="row.component"
:currency-code="formData.currency.code"
/>
</QTd>
</template>
<template #body-cell-newPrice="{ row }">

View File

@ -631,7 +631,7 @@ watch(
</span>
<VnCurrency
:model="store.data"
:currency-code="store.data.currency.code"
:currency-code="store.data?.currency?.code"
local-field="totalWithoutVat"
foreign-field="foreignTotalWithoutVat"
/>
@ -642,12 +642,12 @@ watch(
</span>
<VnCurrency
:model="{
vat: store.data.totalWithVat - store.data?.totalWithoutVat,
vat: store.data?.totalWithVat - store.data?.totalWithoutVat,
foreignVat:
store.data.foreignTotalWithVat -
store.data?.foreignTotalWithVat -
store.data?.foreignTotalWithoutVat,
}"
:currency-code="store.data.currency.code"
:currency-code="store.data?.currency?.code"
local-field="vat"
foreign-field="foreignVat"
/>
@ -661,7 +661,7 @@ watch(
</span>
<VnCurrency
:model="store.data"
:currency-code="store.data.currency.code"
:currency-code="store.data?.currency?.code"
local-field="totalWithVat"
foreign-field="foreignTotalWithVat"
/>
@ -823,7 +823,10 @@ watch(
<template #column-price="{ row }">
<template v-if="isTicketEditable && row.id">
<QBtn flat class="link" dense @click="onOpenEditPricePopover(row)">
<VnCurrency :model="row" :currency-code="store.data.currency.code" />
<VnCurrency
:model="row"
:currency-code="store.data?.currency?.code"
/>
</QBtn>
<TicketEditManaProxy
ref="editPriceProxyRef"
@ -839,7 +842,7 @@ watch(
</TicketEditManaProxy>
</template>
<span v-else>
<VnCurrency :model="row" :currency-code="store.data.currency.code" />
<VnCurrency :model="row" :currency-code="store.data?.currency?.code" />
</span>
</template>
<template #column-discount="{ row }">
@ -872,7 +875,7 @@ watch(
amount: row.quantity * row.price,
foreignAmount: row.quantity * row.foreignPrice,
}"
:currency-code="store.data.currency.code"
:currency-code="store.data?.currency?.code"
local-field="amount"
foreign-field="foreignAmount"
/>