From 310464f83481e80b717d550021990afe32300e9c Mon Sep 17 00:00:00 2001
From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
Date: Tue, 28 Jan 2025 09:44:18 +0700
Subject: [PATCH 1/9] feat: add separate price vat calc
---
.../04_product-service/PriceDataComponent.vue | 563 +++++++++---------
src/components/05_quotation/ProductItem.vue | 6 +-
src/pages/04_product-service/MainPage.vue | 26 +-
src/pages/05_quotation/QuotationForm.vue | 7 +-
.../QuotationFormProductSelect.vue | 10 +-
src/stores/product-service/types.ts | 8 +
src/stores/quotations/types.ts | 4 +
7 files changed, 344 insertions(+), 280 deletions(-)
diff --git a/src/components/04_product-service/PriceDataComponent.vue b/src/components/04_product-service/PriceDataComponent.vue
index be383300..d4121129 100644
--- a/src/components/04_product-service/PriceDataComponent.vue
+++ b/src/components/04_product-service/PriceDataComponent.vue
@@ -1,7 +1,7 @@
+
+
+
+
+ {{ $t('general.information', { msg: $t('taskOrder.productList') }) }}
+
+
+
+
+
+
+
+
+
+ {{ col.label && $t(col.label) }}
+ {{ col.label === 'quotation.vat' ? '%' : '' }}
+
+
+
+
+
+
+
+
+ {{ props.rowIndex + 1 }}
+
+
+ {{ props.row.product.code }}
+
+
+
+
+
+
+
+
+
+ {{ props.row.product.name }}
+
+
+ {{ props.row.list.length }}
+
+
+ {{
+ formatNumberDecimal(
+ calcPricePerUnit(props.row.product) +
+ (props.row.product.calcVat
+ ? calcPricePerUnit(props.row.product) *
+ (config?.vat || 0.07)
+ : 0),
+ 2,
+ )
+ }}
+
+
+
+
+ {{
+ formatNumberDecimal(
+ calcPrice(props.row.product, props.row.list.length),
+ 2,
+ )
+ }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{
+ $t('general.numberOf', {
+ msg: $t('productService.product.product'),
+ })
+ }}
+
+
{{ taskList.length }}
+
+
+
+
+
From 5c3d2f149996d1b47ba177194e79d5208e1a334a Mon Sep 17 00:00:00 2001
From: Thanaphon Frappet
Date: Thu, 30 Jan 2025 14:05:20 +0700
Subject: [PATCH 7/9] refactor: add agent price
---
src/pages/05_quotation/QuotationForm.vue | 2 ++
src/pages/05_quotation/form.ts | 1 +
src/stores/quotations/index.ts | 2 +-
src/stores/quotations/types.ts | 1 +
4 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue
index 62d0dea2..23a6221d 100644
--- a/src/pages/05_quotation/QuotationForm.vue
+++ b/src/pages/05_quotation/QuotationForm.vue
@@ -427,6 +427,7 @@ async function fetchQuotation() {
const id = currentQuotationId.value || quotationFormData.value.id || '';
await quotationForm.assignFormData(id, quotationFormState.value.mode);
+
tempPaySplitCount.value = quotationFormData.value.paySplitCount || 0;
tempPaySplit.value = JSON.parse(
JSON.stringify(quotationFormData.value.paySplit),
@@ -609,6 +610,7 @@ async function convertDataToFormSubmit() {
status: quotationFormData.value.status,
discount: quotationFormData.value.discount,
remark: quotationFormData.value.remark || '',
+ agentPrice: agentPrice.value,
};
newWorkerList.value = [];
diff --git a/src/pages/05_quotation/form.ts b/src/pages/05_quotation/form.ts
index f18997e7..5f54dc2c 100644
--- a/src/pages/05_quotation/form.ts
+++ b/src/pages/05_quotation/form.ts
@@ -39,6 +39,7 @@ export const DEFAULT_DATA: QuotationPayload = {
_count: { worker: 0 },
status: 'CREATED',
remark: '#[quotation-labor]
#[quotation-payment]',
+ agentPrice: false,
};
const DEFAULT_DATA_INVOICE: InvoicePayload = {
diff --git a/src/stores/quotations/index.ts b/src/stores/quotations/index.ts
index 775dc7ac..f62339ae 100644
--- a/src/stores/quotations/index.ts
+++ b/src/stores/quotations/index.ts
@@ -119,7 +119,7 @@ export const useQuotationStore = defineStore('quotation-store', () => {
}
async function editQuotation(data: QuotationPayload & { id: string }) {
- const { _count, ...payload } = data;
+ const { _count, agentPrice, ...payload } = data;
const res = await api.put(`/quotation/${data.id}`, {
...payload,
quotationStatus:
diff --git a/src/stores/quotations/types.ts b/src/stores/quotations/types.ts
index 16db7bb5..be855586 100644
--- a/src/stores/quotations/types.ts
+++ b/src/stores/quotations/types.ts
@@ -371,6 +371,7 @@ export type QuotationPayload = {
status?: Status;
remark?: string;
quotationStatus?: QuotationStatus;
+ agentPrice?: boolean;
};
export type EmployeeWorker = {
From ae8844087040bfe150401d35dc93dcc58fef4f83 Mon Sep 17 00:00:00 2001
From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
Date: Thu, 30 Jan 2025 14:26:45 +0700
Subject: [PATCH 8/9] refactor: use price in quotation instead
---
src/pages/11_credit-note/FormPage.vue | 36 +++-------
.../expansion/ProductExpansion.vue | 67 ++++++-------------
2 files changed, 31 insertions(+), 72 deletions(-)
diff --git a/src/pages/11_credit-note/FormPage.vue b/src/pages/11_credit-note/FormPage.vue
index f773e361..c0485725 100644
--- a/src/pages/11_credit-note/FormPage.vue
+++ b/src/pages/11_credit-note/FormPage.vue
@@ -111,7 +111,7 @@ const formTaskList = ref<
let taskListGroup = computed(() => {
const cacheData = formTaskList.value.reduce<
{
- product: RequestWork['productService']['product'];
+ product: RequestWork['productService'];
list: RequestWork[];
}[]
>((acc, curr) => {
@@ -129,7 +129,7 @@ let taskListGroup = computed(() => {
exist.list.push(task.requestWork);
} else {
acc.push({
- product: task.requestWork.productService.product,
+ product: task.requestWork.productService,
list: [record],
});
}
@@ -189,42 +189,28 @@ async function initStatus() {
function getPrice(
list: {
- product: RequestWork['productService']['product'];
+ product: RequestWork['productService'];
list: RequestWork[];
}[],
) {
return list.reduce(
(a, c) => {
- const agentPrice = !!quotationData.value?.agentPrice;
- const pricePerUnit = agentPrice ? c.product.agentPrice : c.product.price;
+ const pricePerUnit =
+ c.product.pricePerUnit - c.product.discount / c.product.amount;
const amount = c.list.length;
- const discount = 0;
- const priceNoVat = c.product[
- agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded'
- ]
- ? pricePerUnit / (1 + (config.value?.vat || 0.07))
- : pricePerUnit;
- const priceDiscountNoVat = priceNoVat * amount - discount;
+ const priceNoVat = pricePerUnit;
+ const priceDiscountNoVat = priceNoVat * amount;
const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
- // const rawVat = rawVatTotal / amount;
a.totalPrice = a.totalPrice + priceDiscountNoVat;
- a.totalDiscount = a.totalDiscount + Number(discount);
- a.vat = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
- ? a.vat + rawVatTotal
- : a.vat;
- a.vatExcluded = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
- ? a.vatExcluded
- : a.vat + rawVatTotal;
- a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
+ a.vat = c.product.vat !== 0 ? a.vat + rawVatTotal : a.vat;
+ a.finalPrice = a.totalPrice + a.vat;
return a;
},
{
totalPrice: 0,
- totalDiscount: 0,
vat: 0,
- vatExcluded: 0,
finalPrice: 0,
},
);
@@ -754,12 +740,12 @@ onMounted(async () => {
"
/>
-
{{ $t('general.hintRemark') }}
diff --git a/src/pages/11_credit-note/expansion/ProductExpansion.vue b/src/pages/11_credit-note/expansion/ProductExpansion.vue
index 57d76198..af4e6ea3 100644
--- a/src/pages/11_credit-note/expansion/ProductExpansion.vue
+++ b/src/pages/11_credit-note/expansion/ProductExpansion.vue
@@ -1,33 +1,26 @@