feat: price vat

This commit is contained in:
Methapon Metanipat 2024-10-07 15:14:33 +07:00
parent fb5e10fe04
commit c5b3e4dbd7
3 changed files with 73 additions and 53 deletions

View file

@ -1,13 +1,15 @@
<script lang="ts" setup>
import { computed, watch } from 'vue';
import { precisionRound } from 'src/utils/arithmetic';
import { QTableProps } from 'quasar';
import ThaiBahtText from 'thai-baht-text';
import { toWords } from 'number-to-words';
import { storeToRefs } from 'pinia';
import TableComponents from 'src/components/TableComponents.vue';
import { QuotationPayload } from 'src/stores/quotations/types';
import { precisionRound } from 'src/utils/arithmetic';
import TableComponents from 'components/TableComponents.vue';
import { QuotationPayload } from 'stores/quotations/types';
import { formatNumberDecimal } from 'stores/utils';
import { QTableProps } from 'quasar';
import { useConfigStore } from 'stores/config';
defineProps<{
agentPrice: boolean;
@ -17,6 +19,10 @@ defineEmits<{
(e: 'delete', index: number): void;
}>();
const configStore = useConfigStore();
const { data: config } = storeToRefs(configStore);
const rows = defineModel<
Required<QuotationPayload['productServiceList'][number]>[]
>('rows', { required: true });
@ -37,22 +43,21 @@ const summaryPrice = defineModel<{
});
function calcPrice(c: (typeof rows.value)[number]) {
const price = precisionRound(c.pricePerUnit * c.amount);
const discount = precisionRound(price * (c.discount || 0));
const vat = precisionRound((price - discount) * c.vat);
return precisionRound(price - discount + vat);
return precisionRound(
c.pricePerUnit * c.amount - c.discount + c.vat * c.amount,
);
}
const summary = computed(() =>
rows.value.reduce(
(a, c) => {
const price = precisionRound(c.pricePerUnit * c.amount);
const discount = precisionRound(price - (c.discount || 0));
const vat = precisionRound((price - discount) * c.vat);
const vat = precisionRound(
(c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07),
);
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + discount);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
a.vat = precisionRound(a.vat + vat);
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
@ -184,14 +189,7 @@ watch(
<template v-slot:body-cell-pricePerUnit="{ props }">
<q-td align="right">
{{
formatNumberDecimal(
(props.row.pricePerUnit = agentPrice
? props.row.product.agentPrice
: props.row.product.price),
2,
)
}}
{{ formatNumberDecimal(props.row.pricePerUnit, 2) }}
</q-td>
</template>
@ -210,20 +208,13 @@ watch(
<template v-slot:body-cell-tax="{ props }">
<q-td align="center">
<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>
{{
precisionRound(
(props.row.pricePerUnit * props.row.amount -
props.row.discount) *
(config?.vat || 0.07),
)
}}
</q-td>
</template>