feat: add vat excluded calc
This commit is contained in:
parent
8749e48178
commit
369a7a406d
4 changed files with 18 additions and 73 deletions
|
|
@ -1,17 +1,14 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import { QTableProps } from 'quasar';
|
||||
import { toWords } from 'number-to-words';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
import WorkerItem from './WorkerItem.vue';
|
||||
import DeleteButton from '../button/DeleteButton.vue';
|
||||
import { commaInput } from 'stores/utils';
|
||||
import { precisionRound } from 'src/utils/arithmetic';
|
||||
import { QuotationPayload } from 'stores/quotations/types';
|
||||
import { formatNumberDecimal } from 'stores/utils';
|
||||
import { useConfigStore } from 'stores/config';
|
||||
import { Product, Service, Work } from 'src/stores/product-service/types';
|
||||
|
||||
const props = defineProps<{
|
||||
readonly?: boolean;
|
||||
|
|
@ -40,23 +37,6 @@ const rows = defineModel<
|
|||
Required<QuotationPayload['productServiceList'][number]>[]
|
||||
>('rows', { required: true });
|
||||
|
||||
const finalDiscount = defineModel<number>('finalDiscount', { default: 0 });
|
||||
|
||||
const summaryPrice = defineModel<{
|
||||
totalPrice: number;
|
||||
totalDiscount: number;
|
||||
vat: number;
|
||||
finalPrice: number;
|
||||
}>('summaryPrice', {
|
||||
required: true,
|
||||
default: {
|
||||
totalPrice: 0,
|
||||
totalDiscount: 0,
|
||||
vat: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([
|
||||
{ title: '', opened: [] },
|
||||
]);
|
||||
|
|
@ -69,32 +49,6 @@ function calcPrice(c: (typeof rows.value)[number]) {
|
|||
);
|
||||
}
|
||||
|
||||
const summary = computed(() =>
|
||||
rows.value.reduce(
|
||||
(a, c) => {
|
||||
const price = precisionRound(c.pricePerUnit * c.amount);
|
||||
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 + Number(c.discount));
|
||||
a.vat = precisionRound(a.vat + vat);
|
||||
a.finalPrice = precisionRound(
|
||||
a.totalPrice - a.totalDiscount + a.vat - Number(finalDiscount.value),
|
||||
);
|
||||
|
||||
return a;
|
||||
},
|
||||
{
|
||||
totalPrice: 0,
|
||||
totalDiscount: 0,
|
||||
vat: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
name: 'order',
|
||||
|
|
@ -152,15 +106,6 @@ const columns = [
|
|||
},
|
||||
] satisfies QTableProps['columns'];
|
||||
|
||||
const EngBahtText = (number: number) => {
|
||||
const [baht, satang] = number.toString().split('.');
|
||||
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(title: string, index: number) {
|
||||
currentBtnOpen.value[0].title = title;
|
||||
currentBtnOpen.value[0].opened.map((_, i) => {
|
||||
|
|
@ -252,13 +197,6 @@ function handleCheck(
|
|||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => summary.value,
|
||||
() => {
|
||||
summaryPrice.value = summary.value;
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.employeeRows,
|
||||
(a, b) => {
|
||||
|
|
@ -311,7 +249,7 @@ watch(
|
|||
>
|
||||
<template #header="{ cols }">
|
||||
<q-tr style="background-color: hsla(var(--info-bg) / 0.07)">
|
||||
<q-th v-for="(v, i) in cols" :key="v">
|
||||
<q-th v-for="v in cols" :key="v">
|
||||
{{ $t(v.label) }}
|
||||
</q-th>
|
||||
<q-th auto-width />
|
||||
|
|
@ -374,11 +312,13 @@ watch(
|
|||
<q-td align="right">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
precisionRound(
|
||||
(props.row.pricePerUnit * props.row.amount -
|
||||
props.row.discount) *
|
||||
(config?.vat || 0.07),
|
||||
),
|
||||
props.row.product.calcVat
|
||||
? precisionRound(
|
||||
(props.row.pricePerUnit * props.row.amount -
|
||||
props.row.discount) *
|
||||
(config?.vat || 0.07),
|
||||
)
|
||||
: 0,
|
||||
2,
|
||||
)
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,10 @@ const summaryPrice = computed(() =>
|
|||
|
||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
||||
a.vat = precisionRound(a.vat + vat);
|
||||
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat;
|
||||
a.vatExcluded = c.product.calcVat
|
||||
? a.vatExcluded
|
||||
: precisionRound(a.vat + vat);
|
||||
a.finalPrice = precisionRound(
|
||||
a.totalPrice -
|
||||
a.totalDiscount +
|
||||
|
|
@ -146,6 +149,7 @@ const summaryPrice = computed(() =>
|
|||
totalPrice: 0,
|
||||
totalDiscount: 0,
|
||||
vat: 0,
|
||||
vatExcluded: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
),
|
||||
|
|
@ -759,7 +763,7 @@ async function searchEmployee(text: string) {
|
|||
<ProductItem
|
||||
:readonly="readonly"
|
||||
:agent-price="agentPrice"
|
||||
:employeeRows="
|
||||
:employee-rows="
|
||||
selectedWorker.map((e: Employee) => ({
|
||||
foreignRefNo: '123456789',
|
||||
employeeName:
|
||||
|
|
@ -777,7 +781,6 @@ async function searchEmployee(text: string) {
|
|||
"
|
||||
@delete="toggleDeleteProduct"
|
||||
v-model:rows="productServiceList"
|
||||
v-model:summary-price="summaryPrice"
|
||||
/>
|
||||
</div>
|
||||
</q-expansion-item>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ const summaryPrice = defineModel<{
|
|||
totalPrice: number;
|
||||
totalDiscount: number;
|
||||
vat: number;
|
||||
vatExlucded: number;
|
||||
finalPrice: number;
|
||||
}>('summaryPrice', {
|
||||
required: true,
|
||||
|
|
@ -543,7 +544,7 @@ watch(
|
|||
<div class="row">
|
||||
{{ $t('general.totalVatExcluded') }}
|
||||
<span class="q-ml-auto">
|
||||
{{ formatNumberDecimal(0, 2) || 0 }}
|
||||
{{ formatNumberDecimal(summaryPrice.vatExcluded, 2) || 0 }}
|
||||
฿
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ type ProductRelation = {
|
|||
agentPrice: number;
|
||||
serviceCharge: number;
|
||||
vatIncluded: boolean;
|
||||
calcVat: boolean;
|
||||
expenseType: string;
|
||||
status: Status;
|
||||
statusOrder: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue