diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index 3d6108ae..39826b63 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -105,6 +105,9 @@ const $q = useQuasar(); const { currentFormData: quotationFormData, currentFormState: quotationFormState, + + invoicePayload: invoiceFormData, + newWorkerList, fileItemNewWorker, quotationFull, @@ -140,6 +143,7 @@ const workerList = ref([]); const selectedProductGroup = ref(''); const selectedInstallmentNo = ref([]); +const selectedInstallment = ref(); const agentPrice = ref(false); function getPrice( @@ -248,6 +252,79 @@ const productServiceList = ref< Required[] >([]); +async function fetchStatus() { + statusQuotationForm.value = [ + { + title: 'ใบเสนอราคา', + status: getStatus(quotationFormData.value.quotationStatus, -1, -1), + handler: () => (view.value = View.Quotation), + }, + { + title: 'ลูกค้าตอบรับ', + status: getStatus(quotationFormData.value.quotationStatus, 0, -1), + handler: () => (view.value = View.Accepted), + }, + { + title: 'ใบแจ้งหนี้', + status: getStatus(quotationFormData.value.quotationStatus, 4, 0), + handler: () => { + view.value = + quotationFormData.value.payCondition === 'Full' || + quotationFormData.value.payCondition === 'BillFull' + ? View.Invoice + : View.InvoicePre; + }, + }, + { + title: 'ชำระเงิน', + status: getStatus(quotationFormData.value.quotationStatus, 4, 1), + handler: () => { + view.value = + quotationFormData.value.payCondition === 'Full' || + quotationFormData.value.payCondition === 'BillFull' + ? View.Payment + : View.PaymentPre; + }, + }, + { + title: 'ใบเสร็จรับเงิน', + status: getStatus(quotationFormData.value.quotationStatus, 4, 1), + handler: () => { + view.value = + quotationFormData.value.payCondition === 'Full' || + quotationFormData.value.payCondition === 'BillFull' + ? View.Receipt + : View.ReceiptPre; + }, + }, + { + title: 'เสร็จสิ้น', + status: getStatus(quotationFormData.value.quotationStatus, 5, 4), + handler: () => { + view.value = View.Complete; + }, + }, + ]; +} + +async function fetchQuotation() { + if ( + currentQuotationId.value !== undefined && + quotationFormState.value.mode && + quotationFormState.value.mode !== 'create' + ) { + await quotationForm.assignFormData( + currentQuotationId.value, + quotationFormState.value.mode, + ); + await assignWorkerToSelectedWorker(); + } + + await assignToProductServiceList(); + + await fetchStatus(); +} + async function closeTab() { if (quotationFormState.value.mode === 'edit') { quotationForm.resetForm(); @@ -306,16 +383,33 @@ async function submitAccepted() { action: async () => { if (!quotationFormData.value.id) return; - await quotationForm.accepted(quotationFormData.value.id); + const res = await quotationForm.accepted(quotationFormData.value.id); + if (res) { + await fetchQuotation(); + } }, cancel: () => {}, }); } +async function convertInvoiceToSubmit() { + if (quotationFormData.value.id) { + invoiceFormData.value = { + installmentNo: selectedInstallmentNo.value, + amount: summaryPrice.value.finalPrice, + quotationId: quotationFormData.value.id, + }; + + const res = await quotationForm.submitInvoice(); + if (res) view.value = View.Payment; + } +} + async function convertDataToFormSubmit() { quotationFormData.value.productServiceList = JSON.parse( JSON.stringify( productServiceList.value.map((v) => ({ + installmentNo: v.installmentNo, workerIndex: v.workerIndex, discount: v.discount, amount: v.amount, @@ -386,6 +480,7 @@ async function convertDataToFormSubmit() { if (res === true) { quotationFormState.value.mode = 'info'; + await fetchQuotation(); } } @@ -493,19 +588,24 @@ function convertToTable(nodes: Node[]) { }; const list = nodes.flatMap(_recursive).map((v) => v.value); + quotationFormData.value.paySplitCount = Math.max( + ...list.map((v) => v.installmentNo || 0), + ); + list.forEach((v) => { v.amount = Math.max(selectedWorker.value.length, 1); if (!v.workerIndex) v.workerIndex = []; for (let i = 0; i < selectedWorker.value.length; i++) { v.workerIndex.push(i); } + + if (!v.installmentNo) { + v.installmentNo = quotationFormData.value.paySplitCount; + } }); productServiceList.value = list; - quotationFormData.value.paySplitCount = Math.max( - ...list.map((v) => v.installmentNo || 0), - ); quotationFormData.value.paySplit = Array.apply( null, new Array(quotationFormData.value.paySplitCount), @@ -627,17 +727,7 @@ onMounted(async () => { quotationFormData.value.customerBranchId = parsed.customerBranchId; currentQuotationId.value = parsed.quotationId; agentPrice.value = parsed.agentPrice; - if ( - currentQuotationId.value !== undefined && - quotationFormState.value.mode && - quotationFormState.value.mode !== 'create' - ) { - await quotationForm.assignFormData( - currentQuotationId.value, - quotationFormState.value.mode, - ); - await assignWorkerToSelectedWorker(); - } + await fetchQuotation(); sessionData.value = parsed; } @@ -647,63 +737,20 @@ onMounted(async () => { if (locale.value === 'eng') optionStore.globalOption = rawOption.eng; if (locale.value === 'tha') optionStore.globalOption = rawOption.tha; - await assignToProductServiceList(); - - statusQuotationForm.value = [ - { - title: 'ใบเสนอราคา', - status: getStatus(quotationFormData.value.quotationStatus, -1, -1), - handler: () => (view.value = View.Quotation), - }, - { - title: 'ลูกค้าตอบรับ', - status: getStatus(quotationFormData.value.quotationStatus, 0, -1), - handler: () => (view.value = View.Accepted), - }, - { - title: 'ใบแจ้งหนี้', - status: getStatus(quotationFormData.value.quotationStatus, 4, 0), - handler: () => { - quotationFormData.value.payCondition === 'Full' || - quotationFormData.value.payCondition === 'BillFull' - ? View.Invoice - : View.InvoicePre; - }, - }, - { - title: 'ชำระเงิน', - status: getStatus(quotationFormData.value.quotationStatus, 4, 1), - handler: () => { - view.value = - quotationFormData.value.payCondition === 'Full' || - quotationFormData.value.payCondition === 'BillFull' - ? View.Payment - : View.PaymentPre; - }, - }, - { - title: 'ใบเสร็จรับเงิน', - status: getStatus(quotationFormData.value.quotationStatus, 4, 1), - handler: () => { - view.value = - quotationFormData.value.payCondition === 'Full' || - quotationFormData.value.payCondition === 'BillFull' - ? View.Receipt - : View.ReceiptPre; - }, - }, - { - title: 'เสร็จสิ้น', - status: getStatus(quotationFormData.value.quotationStatus, 5, 4), - handler: () => { - view.value = View.Complete; - }, - }, - ]; + await fetchStatus(); pageState.isLoaded = true; }); +watch( + () => quotationFormData.value.status, + () => { + fetchStatus(); + + statusQuotationForm.value.filter((v) => v.title === 'ลูกค้าตอบรับ'); + }, +); + watch( () => quotationFormData.value.customerBranchId, async (v) => { @@ -934,13 +981,6 @@ const view = ref(View.Quotation); /> {{ value.title }} -
- -
- - - - - +
(View.Quotation); @@ -1344,6 +1386,48 @@ const view = ref(View.Quotation); > {{ $t('general.view', { msg: $t('general.example') }) }} + +
+ + {{ $t('general.view', { msg: $t('general.example') }) }} + +
+ +
+ + {{ $t('quotation.selectInvoice') }} + +
+ +
+ + {{ $t('quotation.approveInvoice') }} + +
+
(View.Quotation); @click="quotationFormState.mode = 'edit'" solid /> + + {{ $t('quotation.customerAcceptance') }} +
diff --git a/src/pages/05_quotation/QuotationFormInfo.vue b/src/pages/05_quotation/QuotationFormInfo.vue index 53891773..e63de60d 100644 --- a/src/pages/05_quotation/QuotationFormInfo.vue +++ b/src/pages/05_quotation/QuotationFormInfo.vue @@ -77,7 +77,7 @@ const summaryPrice = defineModel<{ const finalDiscount = defineModel('finalDiscount', { default: 0 }); const finalDiscount4Show = ref(finalDiscount.value.toString()); -const payTypeOpion = computed(() => [ +const payTypeOption = computed(() => [ { value: 'Full', label: t('quotation.type.fullAmountCash'), @@ -201,7 +201,7 @@ watch( { const { t } = useI18n(); const quotationStore = useQuotationStore(); const employeeStore = useEmployeeStore(); + const invoiceStore = useInvoice(); const quotationFull = ref(undefined); + const invoicePayload = ref( + DEFAULT_DATA_INVOICE, + ); const newWorkerList = ref< (EmployeeWorker & { attachment?: { @@ -122,7 +136,7 @@ export const useQuotationForm = defineStore('form-quotation', () => { payBillDate: data.payBillDate ? new Date(data.payBillDate) : undefined, paySplit: data.paySplit.map((p, index) => ({ no: index + 1, - date: p.date, + invoice: p.invoice, amount: p.amount, })), worker: data.worker.map((v) => @@ -144,6 +158,8 @@ export const useQuotationForm = defineStore('form-quotation', () => { if (mode === 'assign') return; currentFormState.value.mode = mode; + + console.log(currentFormData.value); } async function submitQuotation() { @@ -242,6 +258,22 @@ export const useQuotationForm = defineStore('form-quotation', () => { return false; } + async function submitInvoice() { + let status = false; + + if (invoicePayload.value.id === undefined) { + const res = await invoiceStore.creatInvoice(invoicePayload.value); + if (res) status = true; + } + + if (invoicePayload.value.id !== undefined) { + const res = await invoiceStore.editInvoice(invoicePayload.value); + if (res) status = true; + } + + return status; + } + return { DEFAULT_DATA, currentFormState, @@ -250,12 +282,16 @@ export const useQuotationForm = defineStore('form-quotation', () => { fileItemNewWorker, quotationFull, + invoicePayload, + isFormDataDifferent, injectNewEmployee, assignFormData, dialogDelete, resetForm, + submitInvoice, + accepted, submitQuotation,