2024-10-01 15:02:18 +07:00
|
|
|
import { defineStore } from 'pinia';
|
2024-10-02 14:05:36 +07:00
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
2024-10-03 09:47:43 +07:00
|
|
|
// NOTE: Import types
|
2024-10-02 14:05:36 +07:00
|
|
|
import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
2024-10-01 15:02:18 +07:00
|
|
|
|
2024-10-03 09:47:43 +07:00
|
|
|
// NOTE: Import stores
|
2024-10-03 09:41:06 +07:00
|
|
|
import { useQuotationStore } from 'stores/quotations';
|
|
|
|
|
|
2024-10-01 15:02:18 +07:00
|
|
|
export const useQuotationForm = defineStore('form-quotation', () => {
|
2024-10-03 09:42:42 +07:00
|
|
|
const quotationStore = useQuotationStore();
|
|
|
|
|
|
2024-10-02 14:05:36 +07:00
|
|
|
const defaultFormData: QuotationPayload = {
|
2024-10-03 09:47:43 +07:00
|
|
|
productServiceList: [],
|
2024-10-02 14:05:36 +07:00
|
|
|
urgent: false,
|
|
|
|
|
customerBranchId: '',
|
|
|
|
|
worker: [],
|
|
|
|
|
workerCount: 0,
|
|
|
|
|
payBillDate: new Date(),
|
|
|
|
|
paySplit: [],
|
|
|
|
|
paySplitCount: 0,
|
|
|
|
|
payCondition: 'Full',
|
|
|
|
|
dueDate: new Date(),
|
|
|
|
|
documentReceivePoint: '',
|
|
|
|
|
contactTel: '',
|
|
|
|
|
contactName: '',
|
|
|
|
|
workName: '',
|
|
|
|
|
actorName: '',
|
|
|
|
|
status: 'CREATED',
|
|
|
|
|
};
|
2024-10-03 09:47:43 +07:00
|
|
|
let resetFormData = structuredClone(defaultFormData);
|
2024-10-02 14:05:36 +07:00
|
|
|
|
|
|
|
|
const currentFormData = ref<QuotationPayload>(structuredClone(resetFormData));
|
|
|
|
|
|
|
|
|
|
function isFormDataDifferent() {
|
|
|
|
|
const { ...resetData } = resetFormData;
|
|
|
|
|
const { ...currData } = currentFormData.value;
|
|
|
|
|
|
|
|
|
|
return JSON.stringify(resetData) !== JSON.stringify(currData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 09:41:06 +07:00
|
|
|
function resetForm(clean = false) {
|
|
|
|
|
if (clean) {
|
|
|
|
|
currentFormData.value = structuredClone(defaultFormData);
|
|
|
|
|
resetFormData = structuredClone(defaultFormData);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentFormData.value = structuredClone(resetFormData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 09:47:43 +07:00
|
|
|
async function assignFormData(id: string) {
|
|
|
|
|
const data = await quotationStore.getQuotation(id);
|
|
|
|
|
|
|
|
|
|
if (!data) return; // NOTE: Error should be handled globally by axios instance
|
|
|
|
|
}
|
2024-10-03 09:41:06 +07:00
|
|
|
|
|
|
|
|
function submiQuotationt() {}
|
|
|
|
|
|
2024-10-03 09:28:47 +07:00
|
|
|
function injectNewEmployee(data: EmployeeWorker) {
|
2024-10-02 14:05:36 +07:00
|
|
|
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,
|
|
|
|
|
|
2024-10-03 09:28:47 +07:00
|
|
|
injectNewEmployee,
|
2024-10-03 09:41:06 +07:00
|
|
|
isFormDataDifferent,
|
|
|
|
|
resetForm,
|
|
|
|
|
assignFormData,
|
|
|
|
|
|
|
|
|
|
submiQuotationt,
|
2024-10-02 14:05:36 +07:00
|
|
|
};
|
2024-10-01 15:02:18 +07:00
|
|
|
});
|