diff --git a/src/pages/05_quotation/MainPage.vue b/src/pages/05_quotation/MainPage.vue index fc0a51cf..d9f8502b 100644 --- a/src/pages/05_quotation/MainPage.vue +++ b/src/pages/05_quotation/MainPage.vue @@ -4,7 +4,7 @@ import { onMounted, reactive, ref } from 'vue'; import { useRouter } from 'vue-router'; import { storeToRefs } from 'pinia'; -// at stores +// NOTE at stores import useProductServiceStore from 'src/stores/product-service'; import { useQuotationStore } from 'src/stores/quotations'; import { baseUrl, waitAll } from 'src/stores/utils'; @@ -12,12 +12,13 @@ import useCustomerStore from 'stores/customer'; import useEmployeeStore from 'stores/employee'; import useFlowStore from 'src/stores/flow'; import useOcrStore from 'stores/ocr'; +import useMyBranch from 'stores/my-branch'; -// at type +// NOTE at type import { CustomerBranchCreate } from 'stores/customer/types'; import { Employee } from 'src/stores/employee/types'; -// at component +// NOTE at component import BasicInformation from 'components/03_customer-management/employee/BasicInformation.vue'; import FormReferDocument from 'src/components/05_quotation/FormReferDocument.vue'; import { UploadFileGroup, noticeJobEmployment } from 'components/upload-file'; @@ -81,17 +82,19 @@ type Node = { children?: Node[]; }; -const employeeStore = useEmployeeStore(); -const ocrStore = useOcrStore(); const customerFormStore = useCustomerForm(); const employeeFormStore = useEmployeeForm(); +const employeeStore = useEmployeeStore(); const customerStore = useCustomerStore(); const flowStore = useFlowStore(); +const userBranch = useMyBranch(); +const ocrStore = useOcrStore(); const { state: customerFormState, currentFormData: customerFormData } = storeToRefs(customerFormStore); const { state: employeeFormState, currentFromDataEmployee } = storeToRefs(employeeFormStore); +const { currentMyBranch } = storeToRefs(userBranch); const currentCustomerId = ref(); const refreshImageState = ref(false); @@ -299,7 +302,13 @@ const formDataEmployee = ref({ dateOfBirth: new Date(), }); -const formDataCustomerBranch = ref({ +const formDataCustomerBranch = ref< + CustomerBranchCreate & { + id?: string; + branchCode?: string; + codeCustomer?: string; + } +>({ customerCode: '', customerId: '', legalPersonNo: '', @@ -311,7 +320,7 @@ const formDataCustomerBranch = ref({ lastNameEN: '', telephoneNo: '', gender: '', - birthDate: '', + birthDate: new Date().toString(), businessType: '', jobPosition: '', jobDescription: '', @@ -363,7 +372,7 @@ function setDefaultCustomerd() { lastNameEN: '', telephoneNo: '', gender: '', - birthDate: '', + birthDate: new Date().toString(), businessType: '', jobPosition: '', jobDescription: '', @@ -403,6 +412,19 @@ function setDefaultCustomerd() { ]; } +function submitCustomer() { + if (currentMyBranch.value === undefined) return; + + const { code, customerCode, birthDate, ...payload } = + formDataCustomerBranch.value; + + customerFormData.value.customerBranch = [{ ...payload }]; + customerFormData.value.registeredBranchId = currentMyBranch.value.id; + customerFormStore.submitFormCustomer(); + customerFormState.value.dialogType = 'info'; + customerFormState.value.editCustomerId = '218554'; +} + function triggerCreateEmployee() { employeeFormStore.resetFormDataEmployee(true); employeeFormState.value.dialogType = 'create'; @@ -1038,7 +1060,6 @@ watch(() => pageState.currentTab, fetchQuotationList); @click=" () => { triggerCreateEmployee(); - console.log('asdassdasd'); } " /> @@ -1114,7 +1135,11 @@ watch(() => pageState.currentTab, fetchQuotationList); }) : `${$t('customer.employer')} ` " - :submit="() => {}" + :submit=" + () => { + submitCustomer(); + } + " :close=" () => { customerFormState.dialogModal = false; @@ -1190,7 +1215,7 @@ watch(() => pageState.currentTab, fetchQuotationList); pageState.currentTab, fetchQuotationList); pageState.currentTab, fetchQuotationList); pageState.currentTab, fetchQuotationList); v-model:authorized-capital=" formDataCustomerBranch.authorizedCapital " + v-model:telephone-no="formDataCustomerBranch.telephoneNo" /> pageState.currentTab, fetchQuotationList); v-model:wage-rate="formDataCustomerBranch.wageRate" v-model:wage-rate-text="formDataCustomerBranch.wageRateText" /> - { - return {}; + const defaultFormData: QuotationPayload = { + service: [ + { + work: [ + { + product: [ + { + vat: 0, + discount: 1, + amount: 0, + id: '', + }, + ], + excluded: false, + id: '', + }, + ], + id: '', + }, + ], + urgent: false, + customerBranchId: '', + worker: [], + workerCount: 0, + payBillDate: new Date(), + paySplit: [], + paySplitCount: 0, + payCondition: 'Full', + dueDate: new Date(), + documentReceivePoint: '', + contactTel: '', + contactName: '', + workName: '', + actorName: '', + status: 'CREATED', + }; + let resetFormData = structuredClone(defaultFormData); + + const currentFormData = ref(structuredClone(resetFormData)); + + function isFormDataDifferent() { + const { ...resetData } = resetFormData; + const { ...currData } = currentFormData.value; + + return JSON.stringify(resetData) !== JSON.stringify(currData); + } + + function submitEmployee(data: EmployeeWorker) { + currentFormData.value.worker.push({ + alienReferencNumber: data.alienReferencNumber, + documentExpireDate: data.documentExpireDate, + lastNameEN: data.lastNameEN, + lastName: data.lastName, + middleNameEN: data.middleNameEN, + middleName: data.middleName, + firstNameEN: data.firstNameEN, + firstName: data.firstName, + namePrefix: data.namePrefix, + nationality: data.nationality, + gender: data.gender, + dateOfBirth: data.dateOfBirth, + }); + } + + return { + currentFormData, + + submitEmployee, + }; });