77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
|
|
// NOTE at type
|
|
import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
|
|
|
export const useQuotationForm = defineStore('form-quotation', () => {
|
|
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<QuotationPayload>(structuredClone(resetFormData));
|
|
|
|
function isFormDataDifferent() {
|
|
const { ...resetData } = resetFormData;
|
|
const { ...currData } = currentFormData.value;
|
|
|
|
return JSON.stringify(resetData) !== JSON.stringify(currData);
|
|
}
|
|
|
|
function injectNewEmployee(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,
|
|
|
|
injectNewEmployee,
|
|
};
|
|
});
|