This commit is contained in:
parent
5ca4f7e112
commit
d70c686cc8
4 changed files with 63 additions and 89 deletions
|
|
@ -58,16 +58,15 @@ const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([
|
||||||
|
|
||||||
function calcPrice(c: (typeof rows.value)[number]) {
|
function calcPrice(c: (typeof rows.value)[number]) {
|
||||||
const originalPrice = c.pricePerUnit;
|
const originalPrice = c.pricePerUnit;
|
||||||
const finalPriceWithVat = precisionRound(
|
const finalPricePerUnit = precisionRound(
|
||||||
originalPrice + originalPrice * (config.value?.vat || 0.07),
|
originalPrice +
|
||||||
|
(c.product[props.agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
||||||
|
? originalPrice * (config.value?.vat || 0.07)
|
||||||
|
: 0),
|
||||||
);
|
);
|
||||||
const finalPriceNoVat = finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
const price = finalPricePerUnit * c.amount - c.discount;
|
||||||
|
|
||||||
const price = finalPriceNoVat * c.amount - c.discount;
|
return precisionRound(price);
|
||||||
const vat = c.product[props.agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
|
||||||
? (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07)
|
|
||||||
: 0;
|
|
||||||
return precisionRound(price + vat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const discount4Show = ref<string[]>([]);
|
const discount4Show = ref<string[]>([]);
|
||||||
|
|
@ -435,8 +434,20 @@ watch(
|
||||||
<q-td align="right">
|
<q-td align="right">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
|
props.row.product[
|
||||||
|
agentPrice ? 'agentPriceCalcVat' : 'calcVat'
|
||||||
|
]
|
||||||
|
? precisionRound(
|
||||||
|
(props.row.pricePerUnit *
|
||||||
|
(1 + (config?.vat || 0.07)) *
|
||||||
|
props.row.amount -
|
||||||
|
props.row.discount) /
|
||||||
|
(1 + (config?.vat || 0.07)),
|
||||||
|
)
|
||||||
|
: precisionRound(
|
||||||
props.row.pricePerUnit * props.row.amount -
|
props.row.pricePerUnit * props.row.amount -
|
||||||
props.row.discount,
|
props.row.discount,
|
||||||
|
),
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|
@ -448,9 +459,12 @@ watch(
|
||||||
agentPrice ? 'agentPriceCalcVat' : 'calcVat'
|
agentPrice ? 'agentPriceCalcVat' : 'calcVat'
|
||||||
]
|
]
|
||||||
? precisionRound(
|
? precisionRound(
|
||||||
(props.row.pricePerUnit * props.row.amount -
|
((props.row.pricePerUnit *
|
||||||
props.row.discount) *
|
(1 + (config?.vat || 0.07)) *
|
||||||
(config?.vat || 0.07),
|
props.row.amount -
|
||||||
|
props.row.discount) /
|
||||||
|
(1 + (config?.vat || 0.07))) *
|
||||||
|
0.07,
|
||||||
)
|
)
|
||||||
: 0,
|
: 0,
|
||||||
2,
|
2,
|
||||||
|
|
|
||||||
|
|
@ -248,32 +248,23 @@ function getPrice(
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalPrice = c.pricePerUnit;
|
|
||||||
const finalPriceWithVat = precisionRound(
|
|
||||||
originalPrice * (1 + (config.value?.vat || 0.07)),
|
|
||||||
);
|
|
||||||
const finalPriceNoVat =
|
|
||||||
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
|
||||||
|
|
||||||
const price = finalPriceNoVat * c.amount;
|
|
||||||
const vat =
|
|
||||||
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
|
||||||
|
|
||||||
const calcVat =
|
const calcVat =
|
||||||
c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat'];
|
c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat'];
|
||||||
|
const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0;
|
||||||
|
|
||||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
const price = precisionRound(
|
||||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
(c.pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
|
||||||
a.vat = calcVat ? precisionRound(a.vat + vat) : a.vat;
|
(1 + vatFactor),
|
||||||
|
);
|
||||||
|
const vat = price * vatFactor;
|
||||||
|
|
||||||
|
a.totalPrice = precisionRound(a.totalPrice + price + c.discount);
|
||||||
|
a.totalDiscount = precisionRound(a.totalDiscount + c.discount);
|
||||||
|
a.vat = precisionRound(a.vat + vat);
|
||||||
a.vatExcluded = calcVat
|
a.vatExcluded = calcVat
|
||||||
? a.vatExcluded
|
? a.vatExcluded
|
||||||
: precisionRound(a.vatExcluded + price);
|
: precisionRound(a.vatExcluded + price);
|
||||||
a.finalPrice = precisionRound(
|
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
|
||||||
a.totalPrice -
|
|
||||||
a.totalDiscount +
|
|
||||||
a.vat -
|
|
||||||
Number(quotationFormData.value.discount || 0),
|
|
||||||
);
|
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,9 @@ watch(
|
||||||
<span class="q-ml-auto">
|
<span class="q-ml-auto">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
summaryPrice.totalPrice - summaryPrice.totalDiscount,
|
summaryPrice.totalPrice -
|
||||||
|
summaryPrice.totalDiscount -
|
||||||
|
summaryPrice.vatExcluded,
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { onMounted, nextTick, ref, watch } from 'vue';
|
import { onMounted, nextTick, ref, watch, toRaw } from 'vue';
|
||||||
import { precisionRound } from 'src/utils/arithmetic';
|
import { precisionRound } from 'src/utils/arithmetic';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import ThaiBahtText from 'thai-baht-text';
|
import ThaiBahtText from 'thai-baht-text';
|
||||||
|
|
@ -175,6 +175,8 @@ enum View {
|
||||||
const view = ref<View>(View.Quotation);
|
const view = ref<View>(View.Quotation);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
await configStore.getConfig();
|
||||||
|
|
||||||
const currentDocumentType = new URL(window.location.href).searchParams.get(
|
const currentDocumentType = new URL(window.location.href).searchParams.get(
|
||||||
'type',
|
'type',
|
||||||
);
|
);
|
||||||
|
|
@ -259,18 +261,6 @@ onMounted(async () => {
|
||||||
productList.value =
|
productList.value =
|
||||||
(data?.value?.productServiceList ?? data.value?.productServiceList).map(
|
(data?.value?.productServiceList ?? data.value?.productServiceList).map(
|
||||||
(v) => {
|
(v) => {
|
||||||
const originalPrice = v.pricePerUnit;
|
|
||||||
const finalPriceWithVat = precisionRound(
|
|
||||||
originalPrice * (1 + (config.value?.vat || 0.07)),
|
|
||||||
);
|
|
||||||
const finalPriceNoVat =
|
|
||||||
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
|
||||||
|
|
||||||
const price = finalPriceNoVat * v.amount - v.discount;
|
|
||||||
const vat =
|
|
||||||
(finalPriceNoVat * v.amount - v.discount) *
|
|
||||||
(config.value?.vat || 0.07);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: v.product.id,
|
id: v.product.id,
|
||||||
code: v.product.code,
|
code: v.product.code,
|
||||||
|
|
@ -279,8 +269,8 @@ onMounted(async () => {
|
||||||
pricePerUnit: v.pricePerUnit || 0,
|
pricePerUnit: v.pricePerUnit || 0,
|
||||||
discount: v.discount || 0,
|
discount: v.discount || 0,
|
||||||
vat: v.vat || 0,
|
vat: v.vat || 0,
|
||||||
value: precisionRound(price + (v.product.calcVat ? vat : 0)),
|
value: 0,
|
||||||
calcVat: v.product.calcVat,
|
calcVat: v.vat > 0,
|
||||||
product: v.product,
|
product: v.product,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -292,23 +282,15 @@ onMounted(async () => {
|
||||||
[]
|
[]
|
||||||
).reduce(
|
).reduce(
|
||||||
(a, c) => {
|
(a, c) => {
|
||||||
const originalPrice = c.pricePerUnit;
|
const calcVat = c.vat > 0;
|
||||||
const finalPriceWithVat = precisionRound(
|
const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0;
|
||||||
originalPrice * (1 + (config.value?.vat || 0.07)),
|
const price =
|
||||||
);
|
(c.pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
|
||||||
const finalPriceNoVat =
|
(1 + vatFactor);
|
||||||
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
|
||||||
|
|
||||||
const price = finalPriceNoVat * c.amount;
|
a.totalPrice = precisionRound(a.totalPrice + price + c.discount);
|
||||||
const vat =
|
|
||||||
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
|
||||||
|
|
||||||
const calcVat =
|
|
||||||
c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat'];
|
|
||||||
|
|
||||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
|
||||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
||||||
a.vat = calcVat ? precisionRound(a.vat + vat) : a.vat;
|
a.vat = calcVat ? precisionRound(a.vat + c.vat) : a.vat;
|
||||||
a.vatExcluded = calcVat
|
a.vatExcluded = calcVat
|
||||||
? a.vatExcluded
|
? a.vatExcluded
|
||||||
: precisionRound(a.vatExcluded + price);
|
: precisionRound(a.vatExcluded + price);
|
||||||
|
|
@ -334,16 +316,12 @@ onMounted(async () => {
|
||||||
|
|
||||||
function calcPrice(c: Product) {
|
function calcPrice(c: Product) {
|
||||||
const originalPrice = c.pricePerUnit;
|
const originalPrice = c.pricePerUnit;
|
||||||
const finalPriceWithVat = precisionRound(
|
const finalPricePerUnit = precisionRound(
|
||||||
originalPrice + originalPrice * (config.value?.vat || 0.07),
|
originalPrice +
|
||||||
|
(c.calcVat ? originalPrice * (config.value?.vat || 0.07) : 0),
|
||||||
);
|
);
|
||||||
const finalPriceNoVat = finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
const price = finalPricePerUnit * c.amount - c.discount;
|
||||||
|
return precisionRound(price);
|
||||||
const price = finalPriceNoVat * c.amount - c.discount;
|
|
||||||
const vat = c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']
|
|
||||||
? (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07)
|
|
||||||
: 0;
|
|
||||||
return precisionRound(price + vat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function closeTab() {
|
async function closeTab() {
|
||||||
|
|
@ -429,10 +407,7 @@ function print() {
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
v.pricePerUnit +
|
v.pricePerUnit * (1 + (v.vat > 0 ? config?.vat || 0.07 : 0)),
|
||||||
(v.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
|
||||||
? v.pricePerUnit * (config?.vat || 0.07)
|
|
||||||
: 0),
|
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|
@ -441,17 +416,7 @@ function print() {
|
||||||
{{ formatNumberDecimal(v.discount, 2) }}
|
{{ formatNumberDecimal(v.discount, 2) }}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{
|
{{ Math.round((v.vat > 0 ? config?.vat || 0.07 : 0) * 100) }}%
|
||||||
formatNumberDecimal(
|
|
||||||
v.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
|
||||||
? precisionRound(
|
|
||||||
(v.pricePerUnit * v.amount - v.discount) *
|
|
||||||
(config?.vat || 0.07),
|
|
||||||
)
|
|
||||||
: 0,
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{ formatNumberDecimal(calcPrice(v), 2) }}
|
{{ formatNumberDecimal(calcPrice(v), 2) }}
|
||||||
|
|
@ -511,7 +476,9 @@ function print() {
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
summaryPrice.totalPrice - summaryPrice.totalDiscount,
|
summaryPrice.totalPrice -
|
||||||
|
summaryPrice.totalDiscount -
|
||||||
|
summaryPrice.vatExcluded,
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue