feat(wip): customer(employee) branch

This commit is contained in:
Methapon2001 2024-08-09 15:09:46 +07:00
parent 622b25b900
commit e853f6bf91
4 changed files with 341 additions and 36 deletions

View file

@ -232,6 +232,140 @@ export const useCustomerForm = defineStore('form-customer', () => {
};
});
export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
const customerStore = useCustomerStore();
const defaultFormData: CustomerBranchCreate = {
id: '',
code: '',
branchNo: 1,
address: '',
addressEN: '',
provinceId: '',
districtId: '',
subDistrictId: '',
zipCode: '',
email: '',
telephoneNo: '',
name: '',
status: 'CREATED',
taxNo: '',
nameEN: '',
legalPersonNo: '',
registerName: '',
registerDate: new Date(),
authorizedCapital: '',
employmentOffice: '',
bussinessType: '',
bussinessTypeEN: '',
jobPosition: '',
jobPositionEN: '',
jobDescription: '',
saleEmployee: '',
payDate: new Date(),
wageRate: 0,
};
let resetFormData = structuredClone(defaultFormData);
const currentFormData = ref<CustomerBranchCreate>(
structuredClone(defaultFormData),
);
const state = ref<{
dialogType: 'info' | 'create' | 'edit';
dialogOpen: boolean;
dialogModal: boolean;
currentCustomerId: string;
}>({
dialogType: 'info',
dialogOpen: false,
dialogModal: false,
currentCustomerId: '',
});
async function initForm(form: 'create'): Promise<void>;
async function initForm(form: 'info' | 'edit', id: string): Promise<void>;
async function initForm(form: 'info' | 'create' | 'edit', id?: string) {
state.value.dialogType = form;
resetFormData = structuredClone(defaultFormData);
if (!id) return;
const _data = await customerStore.getBranchById(id);
if (!_data) return;
resetFormData = {
id: _data.id,
code: _data.code,
branchNo: _data.branchNo,
address: _data.address,
addressEN: _data.addressEN,
provinceId: _data.provinceId,
districtId: _data.districtId,
subDistrictId: _data.subDistrictId,
zipCode: _data.zipCode,
email: _data.email,
telephoneNo: _data.telephoneNo,
name: _data.name,
status: undefined,
taxNo: _data.taxNo,
nameEN: _data.nameEN,
legalPersonNo: _data.legalPersonNo,
registerName: _data.registerName,
registerDate: new Date(_data.registerDate),
authorizedCapital: _data.authorizedCapital,
employmentOffice: _data.employmentOffice,
bussinessType: _data.bussinessType,
bussinessTypeEN: _data.bussinessTypeEN,
jobPosition: _data.jobPosition,
jobPositionEN: _data.jobPositionEN,
jobDescription: _data.jobDescription,
saleEmployee: _data.saleEmployee,
payDate: new Date(_data.payDate),
wageRate: _data.wageRate,
};
currentFormData.value = structuredClone(resetFormData);
}
function isFormDataDifferent() {
return (
JSON.stringify(resetFormData) !== JSON.stringify(currentFormData.value)
);
}
async function submitForm() {
if (!state.value.currentCustomerId) {
throw new Error(
'Employer id cannot be found. Did you properly set employer id?',
);
}
if (!currentFormData.value.id) {
await customerStore.createBranch({
...currentFormData.value,
customerId: state.value.currentCustomerId,
});
} else {
await customerStore.editBranchById(currentFormData.value.id, {
...currentFormData.value,
id: undefined,
});
}
}
return {
state,
initForm,
currentFormData,
isFormDataDifferent,
submitForm,
};
});
export const useEmployeeForm = defineStore('form-employee', () => {
const customerStore = useCustomerStore();
const employeeStore = useEmployeeStore();