refactor: final discount
This commit is contained in:
parent
263a4fcedc
commit
06c96d1136
1 changed files with 53 additions and 26 deletions
|
|
@ -59,7 +59,9 @@ const summaryPrice = defineModel<{
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalDiscount4show = ref(summaryPrice.value.totalDiscount.toString());
|
const currentBtnOpen = ref<boolean[]>([]);
|
||||||
|
const finalDiscount = ref<number>(0);
|
||||||
|
const finalDiscount4Show = ref<string>(finalDiscount.value.toString());
|
||||||
|
|
||||||
function calcPrice(c: (typeof rows.value)[number]) {
|
function calcPrice(c: (typeof rows.value)[number]) {
|
||||||
return precisionRound(
|
return precisionRound(
|
||||||
|
|
@ -80,7 +82,7 @@ const summary = computed(() =>
|
||||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
a.totalPrice = precisionRound(a.totalPrice + price);
|
||||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
||||||
a.vat = precisionRound(a.vat + vat);
|
a.vat = precisionRound(a.vat + vat);
|
||||||
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
|
a.finalPrice = precisionRound(a.finalPrice + price + vat);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
@ -88,7 +90,7 @@ const summary = computed(() =>
|
||||||
totalPrice: 0,
|
totalPrice: 0,
|
||||||
totalDiscount: 0,
|
totalDiscount: 0,
|
||||||
vat: 0,
|
vat: 0,
|
||||||
finalPrice: 0,
|
finalPrice: -(+finalDiscount.value || 0),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -158,9 +160,23 @@ const columns = [
|
||||||
|
|
||||||
const EngBahtText = (number: number) => {
|
const EngBahtText = (number: number) => {
|
||||||
const [baht, satang] = number.toString().split('.');
|
const [baht, satang] = number.toString().split('.');
|
||||||
return `${toWords(baht)} Baht${satang && ` and ${toWords(satang)} Satang`}`;
|
const bahtText =
|
||||||
|
toWords(baht).charAt(0).toUpperCase() + toWords(baht).slice(1);
|
||||||
|
const satangText =
|
||||||
|
toWords(satang).charAt(0).toUpperCase() + toWords(satang).slice(1);
|
||||||
|
return `${bahtText} Baht${satang ? ` and ${satangText} Satang` : ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function openEmployeeTable(index: number) {
|
||||||
|
currentBtnOpen.value.map((_, i) => {
|
||||||
|
if (i !== index) {
|
||||||
|
currentBtnOpen.value[i] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
currentBtnOpen.value[index] = !currentBtnOpen.value[index];
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => summary.value,
|
() => summary.value,
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -280,7 +296,22 @@ watch(
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #button>
|
<template #button="{ props }">
|
||||||
|
<q-btn
|
||||||
|
@click.stop="openEmployeeTable(props.rowIndex)"
|
||||||
|
dense
|
||||||
|
flat
|
||||||
|
size="sm"
|
||||||
|
class="rounded q-mr-xs"
|
||||||
|
>
|
||||||
|
<div class="row items-center no-wrap">
|
||||||
|
<q-icon name="mdi-account-group-outline" />
|
||||||
|
<q-icon
|
||||||
|
size="xs"
|
||||||
|
:name="`mdi-chevron-${currentBtnOpen[props.rowIndex] ? 'down' : 'up'}`"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
icon="mdi-monitor"
|
icon="mdi-monitor"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|
@ -298,14 +329,14 @@ watch(
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row text-weight-bold text-caption items-start">
|
<div class="row items-start">
|
||||||
<span
|
<span
|
||||||
class="col row items-center justify-between q-px-md q-py-xs q-mr-lg rounded bg-color-orange-light"
|
class="col row items-center justify-between q-px-md q-py-xs q-mr-lg rounded app-text-muted-2 bg-color-orange-light"
|
||||||
>
|
>
|
||||||
<span class="app-text-muted-2">
|
<span class="text-weight-bold text-caption">
|
||||||
{{ $t('general.totalAmount') }}
|
{{ $t('general.totalAmount') }}
|
||||||
</span>
|
</span>
|
||||||
<span v-if="summary.finalPrice">
|
<span v-if="summary.finalPrice + Number(finalDiscount)">
|
||||||
{{
|
{{
|
||||||
$i18n.locale === 'eng'
|
$i18n.locale === 'eng'
|
||||||
? EngBahtText(summary.finalPrice)
|
? EngBahtText(summary.finalPrice)
|
||||||
|
|
@ -325,40 +356,34 @@ watch(
|
||||||
readonly
|
readonly
|
||||||
outlined
|
outlined
|
||||||
input-class="text-right text-bold "
|
input-class="text-right text-bold "
|
||||||
:model-value="formatNumberDecimal(summary.totalPrice, 2)"
|
:model-value="
|
||||||
|
formatNumberDecimal(summary.finalPrice + Number(finalDiscount), 2)
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row q-py-xs q-pr-xs q-pl-md">
|
<div class="row q-py-xs q-pr-xs q-pl-md">
|
||||||
<span class="col-9 app-text-muted-2">
|
<span class="col-9 app-text-muted-2">
|
||||||
{{ $t('quotation.quotationDiscount') }}
|
{{ $t('quotation.quotationDiscount') }}
|
||||||
{{ console.log(totalDiscount4show) }}
|
|
||||||
</span>
|
</span>
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
class="col price-tag"
|
class="col price-tag"
|
||||||
outlined
|
outlined
|
||||||
input-class="text-right text-bold"
|
input-class="text-right text-bold"
|
||||||
v-model="summary.totalDiscount"
|
:model-value="commaInput(finalDiscount.toString())"
|
||||||
/>
|
|
||||||
<!-- <q-input
|
|
||||||
dense
|
|
||||||
class="col price-tag"
|
|
||||||
outlined
|
|
||||||
input-class="text-right text-bold"
|
|
||||||
:model-value="commaInput(summary.totalDiscount.toString())"
|
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(v) => {
|
(v) => {
|
||||||
if (typeof v === 'string') totalDiscount4show = commaInput(v);
|
if (typeof v === 'string') finalDiscount4Show = commaInput(v);
|
||||||
const x = parseInt(
|
const x = parseFloat(
|
||||||
totalDiscount4show && typeof totalDiscount4show === 'string'
|
finalDiscount4Show && typeof finalDiscount4Show === 'string'
|
||||||
? totalDiscount4show.replace(/,/g, '')
|
? finalDiscount4Show.replace(/,/g, '')
|
||||||
: '',
|
: '',
|
||||||
);
|
);
|
||||||
summary.totalDiscount = x;
|
finalDiscount = x;
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/> -->
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
@ -374,7 +399,9 @@ watch(
|
||||||
outlined
|
outlined
|
||||||
readonly
|
readonly
|
||||||
input-class="text-right text-bold "
|
input-class="text-right text-bold "
|
||||||
:model-value="formatNumberDecimal(summary.finalPrice, 2)"
|
:model-value="
|
||||||
|
formatNumberDecimal(Math.max(summary.finalPrice, 0), 2)
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue