refactor: agent price & format number
This commit is contained in:
parent
55cf996ffe
commit
e5b95e5cc0
1 changed files with 67 additions and 42 deletions
|
|
@ -1,10 +1,15 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
import { computed, watch } from 'vue';
|
||||
import { precisionRound } from 'src/utils/arithmetic';
|
||||
|
||||
import { QTableProps } from 'quasar';
|
||||
import TableComponents from 'src/components/TableComponents.vue';
|
||||
import { QuotationPayload } from 'src/stores/quotations/types';
|
||||
import { formatNumberDecimal } from 'stores/utils';
|
||||
|
||||
defineProps<{
|
||||
agentPrice: boolean;
|
||||
}>();
|
||||
|
||||
defineEmits<{
|
||||
(e: 'delete', index: number): void;
|
||||
|
|
@ -14,6 +19,21 @@ const rows = defineModel<
|
|||
Required<QuotationPayload['productServiceList'][number]>[]
|
||||
>('rows', { required: true });
|
||||
|
||||
const summaryPrice = defineModel<{
|
||||
totalPrice: number;
|
||||
totalDiscount: number;
|
||||
vat: number;
|
||||
finalPrice: number;
|
||||
}>('summaryPrice', {
|
||||
required: true,
|
||||
default: {
|
||||
totalPrice: 0,
|
||||
totalDiscount: 0,
|
||||
vat: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
});
|
||||
|
||||
function calcPrice(c: (typeof rows.value)[number]) {
|
||||
const price = precisionRound(c.pricePerUnit * c.amount);
|
||||
const discount = precisionRound(price * (c.discount || 0));
|
||||
|
|
@ -72,7 +92,7 @@ const columns = [
|
|||
},
|
||||
{
|
||||
name: 'pricePerUnit',
|
||||
align: 'center',
|
||||
align: 'right',
|
||||
label: 'quotation.pricePerUnit',
|
||||
field: 'pricePerUnit',
|
||||
},
|
||||
|
|
@ -90,7 +110,7 @@ const columns = [
|
|||
},
|
||||
{
|
||||
name: 'sumPrice',
|
||||
align: 'center',
|
||||
align: 'right',
|
||||
label: 'quotation.sumPrice',
|
||||
field: 'sumPrice',
|
||||
},
|
||||
|
|
@ -101,6 +121,13 @@ const columns = [
|
|||
field: 'action',
|
||||
},
|
||||
] satisfies QTableProps['columns'];
|
||||
|
||||
watch(
|
||||
() => summary.value,
|
||||
() => {
|
||||
summaryPrice.value = summary.value;
|
||||
},
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="column">
|
||||
|
|
@ -148,17 +175,15 @@ const columns = [
|
|||
</template>
|
||||
|
||||
<template v-slot:body-cell-pricePerUnit="{ props }">
|
||||
<q-td align="center">
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
type="number"
|
||||
style="width: 70px"
|
||||
readonly
|
||||
class="bordered rounded"
|
||||
min="0"
|
||||
v-model="props.row.pricePerUnit"
|
||||
/>
|
||||
<q-td align="right">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
(props.row.pricePerUnit = agentPrice
|
||||
? props.row.product.agentPrice
|
||||
: props.row.product.price),
|
||||
2,
|
||||
)
|
||||
}}
|
||||
</q-td>
|
||||
</template>
|
||||
|
||||
|
|
@ -177,34 +202,26 @@ const columns = [
|
|||
|
||||
<template v-slot:body-cell-tax="{ props }">
|
||||
<q-td align="center">
|
||||
<div class="row justify-around items-center">
|
||||
<q-checkbox
|
||||
:model-value="Number(props.row.vat) === 7"
|
||||
size="xs"
|
||||
:label="$t('quotation.calTax')"
|
||||
@click="props.row.vat ? (props.row.vat = 0) : (props.row.vat = 7)"
|
||||
/>
|
||||
<q-input
|
||||
dense
|
||||
min="0"
|
||||
outlined
|
||||
type="number"
|
||||
readonly
|
||||
class="bordered rounded"
|
||||
style="width: 70px"
|
||||
v-model="props.row.vat"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<span class="text-caption no-padding">%</span>
|
||||
</template>
|
||||
</q-input>
|
||||
</div>
|
||||
<q-input
|
||||
dense
|
||||
min="0"
|
||||
outlined
|
||||
type="number"
|
||||
readonly
|
||||
class="bordered rounded"
|
||||
style="width: 70px"
|
||||
v-model="props.row.vat"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<span class="text-caption no-padding">%</span>
|
||||
</template>
|
||||
</q-input>
|
||||
</q-td>
|
||||
</template>
|
||||
|
||||
<template v-slot:body-cell-sumPrice="{ props }">
|
||||
<q-td align="center">
|
||||
{{ calcPrice(props.row) }}
|
||||
<q-td align="right">
|
||||
{{ formatNumberDecimal(calcPrice(props.row), 2) }}
|
||||
</q-td>
|
||||
</template>
|
||||
|
||||
|
|
@ -229,20 +246,28 @@ const columns = [
|
|||
>
|
||||
<div class="row">
|
||||
{{ $t('quotation.allProductPrice') }}
|
||||
<span class="q-ml-auto">{{ summary.totalPrice }} ฿</span>
|
||||
<span class="q-ml-auto">
|
||||
{{ formatNumberDecimal(summary.totalPrice, 2) }} ฿
|
||||
</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
{{ $t('general.discount') }}
|
||||
<span class="q-ml-auto">{{ summary.totalDiscount }} ฿</span>
|
||||
<span class="q-ml-auto">
|
||||
{{ formatNumberDecimal(summary.totalDiscount, 2) }} ฿
|
||||
</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
{{ $t('quotation.tax') }}
|
||||
<span class="q-ml-auto">{{ summary.vat }} ฿</span>
|
||||
<span class="q-ml-auto">
|
||||
{{ formatNumberDecimal(summary.vat, 2) }} ฿
|
||||
</span>
|
||||
</div>
|
||||
<q-separator spaced="md" />
|
||||
<div class="row text-bold text-body2" style="color: var(--foreground)">
|
||||
{{ $t('quotation.totalPrice') }}
|
||||
<span class="q-ml-auto">{{ summary.finalPrice }} ฿</span>
|
||||
<span class="q-ml-auto">
|
||||
{{ formatNumberDecimal(summary.finalPrice, 2) }} ฿
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue