feat: use util calc price

This commit is contained in:
Methapon Metanipat 2024-10-04 13:22:47 +07:00
parent e538998472
commit 5b13ff98b9

View file

@ -1,10 +1,10 @@
<script lang="ts" setup>
import { computed } 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 { computed } from 'vue';
const calTax = defineModel('calTax', { default: false });
defineEmits<{
(e: 'delete', index: number): void;
@ -14,26 +14,25 @@ const rows = defineModel<
Required<QuotationPayload['productServiceList'][number]>[]
>('rows', { required: true });
function calcPrice(data: (typeof rows.value)[number]) {
const price = data.pricePerUnit * data.amount;
const discount = Math.round(price * data.discount) / 100;
const vat = Math.round((price - discount) * data.vat) / 100;
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 (price * 100 - discount * 100 + vat * 100) / 100;
return precisionRound(price - discount + vat);
}
const summary = computed(() =>
rows.value.reduce(
(a, c) => {
const price = c.pricePerUnit * c.amount;
const discount = Math.round(price * c.discount) / 100;
const vat = Math.round((price - discount) * c.vat) / 100;
const price = precisionRound(c.pricePerUnit * c.amount);
const discount = precisionRound(price - (c.discount || 0));
const vat = precisionRound((price - discount) * c.vat);
a.totalPrice = (a.totalPrice * 100 + price * 100) / 100;
a.totalDiscount = (a.totalDiscount * 100 + discount * 100) / 100;
a.vat = (a.vat * 100 + vat * 100) / 100;
a.finalPrice =
(a.finalPrice * 100 + price * 100 - discount * 100 + vat * 100) / 100;
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + discount);
a.vat = precisionRound(a.vat + vat);
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
return a;
},
@ -172,11 +171,7 @@ const columns = [
type="number"
style="width: 70px"
v-model="props.row.discount"
>
<template v-slot:append>
<span class="text-caption no-padding">%</span>
</template>
</q-input>
/>
</q-td>
</template>