2024-08-06 16:34:20 +07:00
|
|
|
import { ref, toRaw, watch } from 'vue';
|
2024-08-02 13:58:44 +07:00
|
|
|
import { defineStore } from 'pinia';
|
2024-08-09 17:04:45 +07:00
|
|
|
import { CustomerBranchCreate, CustomerCreate } from 'stores/customer/types';
|
2024-08-09 15:08:25 +07:00
|
|
|
import { Employee, EmployeeCreate } from 'stores/employee/types';
|
2024-08-05 16:53:19 +07:00
|
|
|
|
2024-08-09 15:08:25 +07:00
|
|
|
import useMyBranch from 'stores/my-branch';
|
|
|
|
|
import useCustomerStore from 'stores/customer';
|
|
|
|
|
import useEmployeeStore from 'stores/employee';
|
|
|
|
|
import useFlowStore from 'stores/flow';
|
2024-08-02 13:58:44 +07:00
|
|
|
|
|
|
|
|
export const useCustomerForm = defineStore('form-customer', () => {
|
2024-08-05 16:11:17 +07:00
|
|
|
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
|
|
|
|
|
|
2024-08-02 13:58:44 +07:00
|
|
|
const customerStore = useCustomerStore();
|
|
|
|
|
const branchStore = useMyBranch();
|
|
|
|
|
|
2024-08-06 03:14:31 +00:00
|
|
|
const defaultFormData: CustomerCreate = {
|
2024-08-02 13:58:44 +07:00
|
|
|
status: 'CREATED',
|
|
|
|
|
personName: '',
|
|
|
|
|
customerType: 'CORP',
|
|
|
|
|
customerName: '',
|
|
|
|
|
customerNameEN: '',
|
|
|
|
|
taxNo: '',
|
|
|
|
|
registeredBranchId: branchStore.currentMyBranch?.id || '',
|
2024-08-05 15:09:36 +07:00
|
|
|
customerBranch: [],
|
2024-08-02 13:58:44 +07:00
|
|
|
image: null,
|
|
|
|
|
};
|
2024-08-05 15:09:36 +07:00
|
|
|
let resetFormData = structuredClone(defaultFormData);
|
2024-08-02 13:58:44 +07:00
|
|
|
|
|
|
|
|
const currentFormData = ref<CustomerCreate>(structuredClone(defaultFormData));
|
|
|
|
|
const state = ref<{
|
2024-08-02 16:13:07 +07:00
|
|
|
dialogType: 'info' | 'create' | 'edit';
|
2024-08-02 13:58:44 +07:00
|
|
|
dialogOpen: boolean;
|
2024-08-05 10:14:54 +07:00
|
|
|
dialogModal: boolean;
|
2024-08-02 13:58:44 +07:00
|
|
|
branchIndex: number;
|
2024-08-05 15:09:36 +07:00
|
|
|
customerImageUrl: string;
|
|
|
|
|
imageDialog: boolean;
|
|
|
|
|
imageEdit: boolean;
|
2024-08-07 17:56:59 +07:00
|
|
|
readonly: boolean;
|
2024-08-05 10:25:09 +07:00
|
|
|
editCustomerId?: string;
|
2024-08-08 09:46:51 +07:00
|
|
|
editCustomerCode?: string;
|
2024-08-05 10:25:09 +07:00
|
|
|
editCustomerBranchId?: string;
|
2024-08-02 13:58:44 +07:00
|
|
|
}>({
|
|
|
|
|
dialogType: 'info',
|
|
|
|
|
dialogOpen: false,
|
2024-08-05 10:14:54 +07:00
|
|
|
dialogModal: false,
|
2024-08-05 15:09:36 +07:00
|
|
|
imageDialog: false,
|
2024-08-07 17:56:59 +07:00
|
|
|
branchIndex: -1,
|
|
|
|
|
readonly: true,
|
2024-08-05 15:09:36 +07:00
|
|
|
imageEdit: false,
|
|
|
|
|
customerImageUrl: '',
|
2024-08-05 10:25:09 +07:00
|
|
|
editCustomerId: '',
|
|
|
|
|
editCustomerBranchId: '',
|
2024-08-02 13:58:44 +07:00
|
|
|
});
|
|
|
|
|
|
2024-08-05 15:29:11 +07:00
|
|
|
watch(
|
|
|
|
|
currentFormData,
|
|
|
|
|
(v) => (defaultFormData.customerType = v.customerType),
|
|
|
|
|
);
|
|
|
|
|
|
2024-08-02 13:58:44 +07:00
|
|
|
function isFormDataDifferent() {
|
|
|
|
|
return (
|
2024-08-05 15:09:36 +07:00
|
|
|
JSON.stringify(resetFormData) !== JSON.stringify(currentFormData.value)
|
2024-08-02 13:58:44 +07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 15:29:11 +07:00
|
|
|
function resetForm(clean = false) {
|
2024-08-07 17:56:59 +07:00
|
|
|
state.value.branchIndex = -1;
|
2024-08-05 15:29:11 +07:00
|
|
|
if (clean) {
|
|
|
|
|
defaultFormData.customerType = currentFormData.value.customerType;
|
|
|
|
|
currentFormData.value = structuredClone(defaultFormData);
|
|
|
|
|
currentFormData.value.registeredBranchId =
|
|
|
|
|
branchStore.currentMyBranch?.id || '';
|
2024-08-06 09:37:32 +07:00
|
|
|
resetFormData = structuredClone(defaultFormData);
|
|
|
|
|
resetFormData.registeredBranchId = branchStore.currentMyBranch?.id || '';
|
2024-08-06 11:51:51 +07:00
|
|
|
state.value.editCustomerId = '';
|
2024-08-05 15:29:11 +07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
if (!resetFormData.registeredBranchId) {
|
|
|
|
|
resetFormData.registeredBranchId = branchStore.currentMyBranch?.id || '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 11:51:51 +07:00
|
|
|
if (state.value.dialogType === 'create') {
|
|
|
|
|
state.value.editCustomerId = '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
currentFormData.value = structuredClone(resetFormData);
|
2024-08-02 13:58:44 +07:00
|
|
|
}
|
|
|
|
|
|
2024-08-05 15:29:11 +07:00
|
|
|
async function assignFormData(id?: string) {
|
2024-08-08 17:10:48 +07:00
|
|
|
state.value.readonly = true;
|
|
|
|
|
|
2024-08-05 15:29:11 +07:00
|
|
|
if (!id) {
|
|
|
|
|
resetFormData = structuredClone(defaultFormData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 13:58:44 +07:00
|
|
|
const data = await customerStore.fetchById(id);
|
|
|
|
|
|
|
|
|
|
if (!data) return;
|
|
|
|
|
|
2024-08-08 10:33:45 +07:00
|
|
|
state.value.dialogType = 'edit';
|
2024-08-08 09:46:51 +07:00
|
|
|
state.value.editCustomerId = id;
|
|
|
|
|
state.value.editCustomerCode = data.code;
|
2024-08-05 16:11:17 +07:00
|
|
|
state.value.customerImageUrl = `${apiBaseUrl}/customer/${id}/image`;
|
|
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
resetFormData.registeredBranchId = data.registeredBranchId;
|
|
|
|
|
resetFormData.status = data.status;
|
|
|
|
|
resetFormData.customerType = data.customerType;
|
|
|
|
|
resetFormData.customerName = data.customerName;
|
|
|
|
|
resetFormData.customerNameEN = data.customerNameEN;
|
|
|
|
|
resetFormData.personName = data.personName;
|
|
|
|
|
resetFormData.taxNo = data.taxNo;
|
|
|
|
|
resetFormData.image = null;
|
2024-08-06 11:51:51 +07:00
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
resetFormData.customerBranch = data.branch.map((v) => ({
|
2024-08-02 13:58:44 +07:00
|
|
|
id: v.id,
|
|
|
|
|
code: v.code,
|
|
|
|
|
branchNo: v.branchNo,
|
|
|
|
|
address: v.address,
|
|
|
|
|
addressEN: v.addressEN,
|
2024-08-06 16:34:20 +07:00
|
|
|
provinceId: v.provinceId,
|
|
|
|
|
districtId: v.districtId,
|
|
|
|
|
subDistrictId: v.subDistrictId,
|
2024-08-02 13:58:44 +07:00
|
|
|
zipCode: v.zipCode,
|
|
|
|
|
email: v.email,
|
|
|
|
|
telephoneNo: v.telephoneNo,
|
|
|
|
|
name: v.name,
|
|
|
|
|
status: undefined,
|
|
|
|
|
taxNo: v.taxNo,
|
|
|
|
|
nameEN: v.nameEN,
|
|
|
|
|
legalPersonNo: v.legalPersonNo,
|
|
|
|
|
registerName: v.registerName,
|
|
|
|
|
registerDate: new Date(v.registerDate),
|
|
|
|
|
authorizedCapital: v.authorizedCapital,
|
|
|
|
|
employmentOffice: v.employmentOffice,
|
|
|
|
|
bussinessType: v.bussinessType,
|
|
|
|
|
bussinessTypeEN: v.bussinessTypeEN,
|
|
|
|
|
jobPosition: v.jobPosition,
|
|
|
|
|
jobPositionEN: v.jobPositionEN,
|
|
|
|
|
jobDescription: v.jobDescription,
|
|
|
|
|
saleEmployee: v.saleEmployee,
|
|
|
|
|
payDate: new Date(v.payDate),
|
|
|
|
|
wageRate: v.wageRate,
|
|
|
|
|
}));
|
|
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
currentFormData.value = structuredClone(resetFormData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addCurrentCustomerBranch() {
|
2024-08-06 16:34:20 +07:00
|
|
|
if (currentFormData.value.customerBranch?.some((v) => !v.id)) return;
|
|
|
|
|
|
2024-08-05 15:09:36 +07:00
|
|
|
currentFormData.value.customerBranch?.push({
|
|
|
|
|
id: '',
|
|
|
|
|
code: '',
|
2024-08-06 08:57:07 +07:00
|
|
|
branchNo:
|
|
|
|
|
(currentFormData.value.customerBranch?.at(-1)?.branchNo || 0) + 1,
|
2024-08-05 15:09:36 +07:00
|
|
|
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,
|
|
|
|
|
});
|
2024-08-07 17:56:59 +07:00
|
|
|
state.value.branchIndex =
|
|
|
|
|
(currentFormData.value.customerBranch?.length || 0) - 1;
|
2024-08-05 15:09:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function submitFormCustomer() {
|
|
|
|
|
if (state.value.dialogType === 'info') return;
|
|
|
|
|
|
|
|
|
|
if (state.value.dialogType === 'create') {
|
|
|
|
|
return await customerStore.create(currentFormData.value);
|
2024-08-05 10:14:54 +07:00
|
|
|
}
|
2024-08-05 15:09:36 +07:00
|
|
|
|
|
|
|
|
if (!state.value.editCustomerId) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Form mode is set to edit but no ID is provided. Make sure to set customer ID.',
|
|
|
|
|
);
|
2024-08-05 10:14:54 +07:00
|
|
|
}
|
|
|
|
|
|
2024-08-07 17:56:59 +07:00
|
|
|
const _data = await customerStore.editById(state.value.editCustomerId, {
|
2024-08-05 15:09:36 +07:00
|
|
|
...currentFormData.value,
|
2024-08-05 15:42:00 +07:00
|
|
|
status:
|
|
|
|
|
currentFormData.value.status !== 'CREATED'
|
|
|
|
|
? currentFormData.value.status
|
|
|
|
|
: undefined,
|
2024-08-05 15:09:36 +07:00
|
|
|
image: currentFormData.value.image || undefined,
|
|
|
|
|
customerBranch: undefined,
|
|
|
|
|
});
|
2024-08-07 17:56:59 +07:00
|
|
|
|
|
|
|
|
if (_data) {
|
|
|
|
|
await assignFormData(_data.id);
|
|
|
|
|
state.value.dialogType = 'edit';
|
|
|
|
|
state.value.readonly = true;
|
|
|
|
|
state.value.editCustomerId = _data.id;
|
|
|
|
|
}
|
2024-08-05 10:14:54 +07:00
|
|
|
}
|
|
|
|
|
|
2024-08-02 13:58:44 +07:00
|
|
|
return {
|
|
|
|
|
state,
|
2024-08-05 15:09:36 +07:00
|
|
|
resetFormData,
|
2024-08-02 13:58:44 +07:00
|
|
|
currentFormData,
|
|
|
|
|
isFormDataDifferent,
|
2024-08-05 15:09:36 +07:00
|
|
|
resetForm,
|
2024-08-02 13:58:44 +07:00
|
|
|
assignFormData,
|
2024-08-07 17:56:59 +07:00
|
|
|
submitFormCustomer,
|
2024-08-05 15:09:36 +07:00
|
|
|
addCurrentCustomerBranch,
|
2024-08-02 13:58:44 +07:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-09 15:09:46 +07:00
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-02 13:58:44 +07:00
|
|
|
export const useEmployeeForm = defineStore('form-employee', () => {
|
2024-08-05 16:53:19 +07:00
|
|
|
const customerStore = useCustomerStore();
|
|
|
|
|
const employeeStore = useEmployeeStore();
|
|
|
|
|
const flowStore = useFlowStore();
|
|
|
|
|
const branchStore = useMyBranch();
|
|
|
|
|
|
|
|
|
|
const state = ref<{
|
|
|
|
|
dialogType: 'info' | 'create' | 'edit';
|
2024-08-06 07:55:05 +00:00
|
|
|
imageDialog: boolean;
|
2024-08-06 03:14:31 +00:00
|
|
|
currentTab: string;
|
|
|
|
|
dialogModal: boolean;
|
2024-08-05 16:53:19 +07:00
|
|
|
drawerModal: boolean;
|
|
|
|
|
currentEmployeeCode: string;
|
|
|
|
|
currentEmployee: Employee | null;
|
2024-08-07 18:34:50 +07:00
|
|
|
currentIndex: number;
|
2024-08-05 16:53:19 +07:00
|
|
|
profileUrl: string;
|
|
|
|
|
isEmployeeEdit: boolean;
|
|
|
|
|
profileSubmit: boolean;
|
|
|
|
|
formDataEmployeeSameAddr: boolean;
|
2024-08-06 15:47:33 +07:00
|
|
|
editReadonly: boolean;
|
2024-08-07 13:30:05 +07:00
|
|
|
statusSavePersonal: boolean;
|
2024-08-05 16:53:19 +07:00
|
|
|
infoEmployeePersonCard: {
|
|
|
|
|
id: string;
|
2024-08-07 13:30:05 +07:00
|
|
|
img?: string;
|
2024-08-05 16:53:19 +07:00
|
|
|
name: string;
|
|
|
|
|
male: boolean;
|
|
|
|
|
female: boolean;
|
|
|
|
|
badge: string;
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
}[];
|
|
|
|
|
formDataEmployeeOwner:
|
|
|
|
|
| {
|
|
|
|
|
id: string;
|
|
|
|
|
address: string;
|
|
|
|
|
addressEN: string;
|
|
|
|
|
provinceId: string;
|
|
|
|
|
districtId: string;
|
|
|
|
|
subDistrictId: string;
|
|
|
|
|
zipCode: string;
|
|
|
|
|
}
|
|
|
|
|
| undefined;
|
|
|
|
|
}>({
|
2024-08-07 18:34:50 +07:00
|
|
|
currentIndex: 0,
|
2024-08-07 13:30:05 +07:00
|
|
|
statusSavePersonal: false,
|
2024-08-05 16:53:19 +07:00
|
|
|
drawerModal: false,
|
2024-08-06 07:55:05 +00:00
|
|
|
imageDialog: false,
|
2024-08-06 03:14:31 +00:00
|
|
|
currentTab: 'personalInfo',
|
|
|
|
|
dialogModal: false,
|
2024-08-05 16:53:19 +07:00
|
|
|
dialogType: 'info',
|
|
|
|
|
currentEmployeeCode: '',
|
|
|
|
|
currentEmployee: null,
|
|
|
|
|
profileUrl: '',
|
|
|
|
|
isEmployeeEdit: false,
|
|
|
|
|
profileSubmit: false,
|
2024-08-06 07:55:05 +00:00
|
|
|
formDataEmployeeSameAddr: true,
|
2024-08-06 15:47:33 +07:00
|
|
|
editReadonly: false,
|
2024-08-05 16:53:19 +07:00
|
|
|
infoEmployeePersonCard: [],
|
|
|
|
|
formDataEmployeeOwner: undefined,
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-06 03:14:31 +00:00
|
|
|
const defaultFormData: EmployeeCreate = {
|
2024-08-09 15:27:16 +07:00
|
|
|
id: '',
|
2024-08-05 16:53:19 +07:00
|
|
|
code: '',
|
|
|
|
|
image: null,
|
|
|
|
|
customerBranchId: '',
|
|
|
|
|
nrcNo: '',
|
|
|
|
|
dateOfBirth: null,
|
|
|
|
|
gender: '',
|
|
|
|
|
nationality: '',
|
2024-08-06 07:55:05 +00:00
|
|
|
status: 'CREATED',
|
2024-08-05 16:53:19 +07:00
|
|
|
|
|
|
|
|
firstName: '',
|
|
|
|
|
firstNameEN: '',
|
|
|
|
|
lastName: '',
|
|
|
|
|
lastNameEN: '',
|
|
|
|
|
|
|
|
|
|
addressEN: '',
|
|
|
|
|
address: '',
|
|
|
|
|
zipCode: '',
|
|
|
|
|
|
|
|
|
|
passportType: '',
|
|
|
|
|
passportNumber: '',
|
|
|
|
|
passportIssueDate: null,
|
|
|
|
|
passportExpiryDate: null,
|
|
|
|
|
passportIssuingCountry: '',
|
|
|
|
|
passportIssuingPlace: '',
|
|
|
|
|
previousPassportReference: '',
|
|
|
|
|
|
|
|
|
|
visaType: '',
|
|
|
|
|
visaNumber: '',
|
|
|
|
|
visaIssueDate: null,
|
|
|
|
|
visaExpiryDate: null,
|
|
|
|
|
visaIssuingPlace: '',
|
|
|
|
|
visaStayUntilDate: null,
|
|
|
|
|
tm6Number: '',
|
|
|
|
|
entryDate: null,
|
|
|
|
|
workerStatus: '',
|
|
|
|
|
|
|
|
|
|
subDistrictId: '',
|
|
|
|
|
districtId: '',
|
|
|
|
|
provinceId: '',
|
|
|
|
|
|
|
|
|
|
employeeWork: [
|
|
|
|
|
{
|
|
|
|
|
workEndDate: null,
|
|
|
|
|
workPermitExpireDate: null,
|
|
|
|
|
workPermitIssuDate: null,
|
|
|
|
|
workPermitNo: '',
|
|
|
|
|
workplace: '',
|
|
|
|
|
jobType: '',
|
|
|
|
|
positionName: '',
|
|
|
|
|
ownerName: '',
|
|
|
|
|
remark: '',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
employeeCheckup: [
|
|
|
|
|
{
|
|
|
|
|
coverageExpireDate: null,
|
|
|
|
|
coverageStartDate: null,
|
|
|
|
|
insuranceCompany: '',
|
|
|
|
|
medicalBenefitScheme: '',
|
|
|
|
|
remark: '',
|
|
|
|
|
hospitalName: '',
|
|
|
|
|
provinceId: '',
|
|
|
|
|
checkupResult: '',
|
|
|
|
|
checkupType: '',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
employeeOtherInfo: {
|
|
|
|
|
citizenId: '',
|
|
|
|
|
fatherFirstName: '',
|
|
|
|
|
fatherLastName: '',
|
|
|
|
|
fatherFirstNameEN: '',
|
|
|
|
|
fatherLastNameEN: '',
|
|
|
|
|
fatherBirthPlace: '',
|
|
|
|
|
|
|
|
|
|
motherFirstName: '',
|
|
|
|
|
motherLastName: '',
|
|
|
|
|
motherFirstNameEN: '',
|
|
|
|
|
motherLastNameEN: '',
|
|
|
|
|
motherBirthPlace: '',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
let resetEmployeeData = structuredClone(defaultFormData);
|
2024-08-05 16:53:19 +07:00
|
|
|
const currentFromDataEmployee = ref<EmployeeCreate>(
|
|
|
|
|
structuredClone(defaultFormData),
|
|
|
|
|
);
|
|
|
|
|
|
2024-08-06 15:47:33 +07:00
|
|
|
function isFormDataDifferent() {
|
|
|
|
|
return (
|
|
|
|
|
JSON.stringify(resetEmployeeData) !==
|
|
|
|
|
JSON.stringify(currentFromDataEmployee.value)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
// function resetFormDataEmployee(cb?: (...args: any[]) => unknown) {
|
|
|
|
|
// state.value.dialogType = 'create';
|
|
|
|
|
// currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
|
|
|
|
// cb?.();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
function resetFormDataEmployee(clean = false) {
|
|
|
|
|
if (clean) {
|
2024-08-07 18:34:50 +07:00
|
|
|
state.value.currentTab = 'personalInfo';
|
2024-08-07 13:30:05 +07:00
|
|
|
state.value.formDataEmployeeOwner = undefined;
|
|
|
|
|
resetEmployeeData = structuredClone(defaultFormData);
|
|
|
|
|
state.value.statusSavePersonal = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-05 16:53:19 +07:00
|
|
|
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 15:27:16 +07:00
|
|
|
async function submitOther() {
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeOtherInfo) return;
|
|
|
|
|
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeOtherInfo.id) {
|
|
|
|
|
const res = await employeeStore.createEmployeeOtherInfo(
|
|
|
|
|
currentFromDataEmployee.value?.id || '',
|
|
|
|
|
currentFromDataEmployee.value.employeeOtherInfo,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeOtherInfo.id = res.id;
|
|
|
|
|
currentFromDataEmployee.value.employeeOtherInfo.statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const res = await employeeStore.editByIdEmployeeOtherInfo(
|
|
|
|
|
currentFromDataEmployee.value?.id || '',
|
|
|
|
|
currentFromDataEmployee.value.employeeOtherInfo,
|
|
|
|
|
);
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeOtherInfo.statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 17:04:45 +07:00
|
|
|
async function deleteWorkHistory() {
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeWork) return;
|
|
|
|
|
|
|
|
|
|
const res = await employeeStore.deleteByIdWork({
|
|
|
|
|
employeeId: currentFromDataEmployee.value.id || '',
|
|
|
|
|
workId:
|
|
|
|
|
currentFromDataEmployee.value.employeeWork[state.value.currentIndex]
|
|
|
|
|
?.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteHealthCheck() {
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeCheckup) return;
|
|
|
|
|
|
|
|
|
|
const res = await employeeStore.deleteByIdCheckUp({
|
|
|
|
|
employeeId: currentFromDataEmployee.value.id || '',
|
|
|
|
|
checkUpId:
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
|
|
|
|
|
?.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup.splice(
|
|
|
|
|
state.value.currentIndex,
|
|
|
|
|
1,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 18:34:50 +07:00
|
|
|
async function submitWorkHistory() {
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeWork) return;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!currentFromDataEmployee.value.employeeWork[state.value.currentIndex].id
|
|
|
|
|
) {
|
|
|
|
|
const res = await employeeStore.createEmployeeWork(
|
|
|
|
|
currentFromDataEmployee.value?.id || '',
|
|
|
|
|
currentFromDataEmployee.value.employeeWork[state.value.currentIndex],
|
|
|
|
|
);
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeWork[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].id = res.id;
|
|
|
|
|
currentFromDataEmployee.value.employeeWork[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-08-09 15:27:16 +07:00
|
|
|
const data =
|
|
|
|
|
currentFromDataEmployee.value?.employeeWork[state.value.currentIndex];
|
|
|
|
|
|
2024-08-07 18:34:50 +07:00
|
|
|
const res = await employeeStore.editByIdEmployeeWork(
|
|
|
|
|
currentFromDataEmployee.value?.id || '',
|
2024-08-09 15:27:16 +07:00
|
|
|
data,
|
2024-08-07 18:34:50 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeWork[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function submitHealthCheck() {
|
|
|
|
|
if (!currentFromDataEmployee.value.employeeCheckup) return;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
|
|
|
|
|
.id
|
|
|
|
|
) {
|
|
|
|
|
const res = await employeeStore.createEmployeeCheckup(
|
|
|
|
|
state.value.currentEmployee?.id || '',
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].id = res.id;
|
|
|
|
|
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-08-09 02:10:06 +00:00
|
|
|
const data =
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex];
|
|
|
|
|
|
2024-08-07 18:34:50 +07:00
|
|
|
const res = await employeeStore.editByIdEmployeeCheckup(
|
|
|
|
|
state.value.currentEmployee?.id || '',
|
2024-08-09 02:10:06 +00:00
|
|
|
data,
|
2024-08-07 18:34:50 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
currentFromDataEmployee.value.employeeCheckup[
|
|
|
|
|
state.value.currentIndex
|
|
|
|
|
].statusSave = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 16:33:17 +07:00
|
|
|
async function submitPersonal() {
|
|
|
|
|
if (state.value.dialogType === 'create') {
|
|
|
|
|
const res = await employeeStore.create({
|
|
|
|
|
...currentFromDataEmployee.value,
|
|
|
|
|
customerBranchId: state.value.formDataEmployeeOwner?.id || '',
|
|
|
|
|
|
|
|
|
|
employeeWork: [],
|
|
|
|
|
employeeCheckup: [],
|
|
|
|
|
employeeOtherInfo: undefined,
|
|
|
|
|
});
|
2024-08-07 18:34:50 +07:00
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
if (res) {
|
|
|
|
|
await assignFormDataEmployee(res.id);
|
2024-08-07 18:34:50 +07:00
|
|
|
currentFromDataEmployee.value.id = res.id;
|
2024-08-07 13:30:05 +07:00
|
|
|
state.value.statusSavePersonal = true;
|
|
|
|
|
}
|
2024-08-06 16:33:17 +07:00
|
|
|
}
|
|
|
|
|
if (state.value.dialogType === 'edit') {
|
2024-08-07 13:30:05 +07:00
|
|
|
const res = await employeeStore.editById(
|
|
|
|
|
state.value.currentEmployee?.id || '',
|
|
|
|
|
{
|
|
|
|
|
...currentFromDataEmployee.value,
|
|
|
|
|
status:
|
|
|
|
|
state.value.currentEmployee?.status === 'CREATED'
|
|
|
|
|
? 'ACTIVE'
|
|
|
|
|
: state.value.currentEmployee?.status,
|
|
|
|
|
customerBranchId: state.value.formDataEmployeeOwner?.id || '',
|
|
|
|
|
employeeWork: [],
|
|
|
|
|
employeeCheckup: [],
|
|
|
|
|
employeeOtherInfo: undefined,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (res) {
|
|
|
|
|
await assignFormDataEmployee(res.id);
|
|
|
|
|
state.value.statusSavePersonal = true;
|
|
|
|
|
}
|
2024-08-06 16:33:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
async function assignFormDataEmployee(id?: string) {
|
|
|
|
|
if (!id) {
|
|
|
|
|
resetEmployeeData = structuredClone(defaultFormData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 16:53:19 +07:00
|
|
|
const res = await employeeStore.fetchById(id);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
state.value.currentEmployee = res;
|
|
|
|
|
|
|
|
|
|
const {
|
2024-08-07 13:30:05 +07:00
|
|
|
createdAt,
|
|
|
|
|
createdByUserId,
|
|
|
|
|
statusOrder,
|
2024-08-05 16:53:19 +07:00
|
|
|
province,
|
|
|
|
|
district,
|
|
|
|
|
subDistrict,
|
2024-08-07 13:30:05 +07:00
|
|
|
updatedAt,
|
|
|
|
|
updatedByUserId,
|
2024-08-05 16:53:19 +07:00
|
|
|
createdBy,
|
|
|
|
|
updatedBy,
|
|
|
|
|
profileImageUrl,
|
|
|
|
|
...playlond
|
|
|
|
|
} = res;
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
resetEmployeeData = {
|
2024-08-05 16:53:19 +07:00
|
|
|
...playlond,
|
|
|
|
|
provinceId: province?.id,
|
|
|
|
|
districtId: district?.id,
|
|
|
|
|
subDistrictId: subDistrict?.id,
|
2024-08-07 18:34:50 +07:00
|
|
|
employeeCheckup: structuredClone(
|
|
|
|
|
playlond.employeeCheckup?.length === 0
|
|
|
|
|
? defaultFormData.employeeCheckup
|
|
|
|
|
: playlond.employeeCheckup?.map((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
statusSave: true,
|
|
|
|
|
})),
|
|
|
|
|
),
|
2024-08-09 15:27:16 +07:00
|
|
|
employeeOtherInfo: structuredClone(
|
|
|
|
|
{
|
|
|
|
|
...playlond.employeeOtherInfo,
|
|
|
|
|
statusSave: !!playlond.employeeOtherInfo?.id ? true : false,
|
|
|
|
|
} || {},
|
|
|
|
|
),
|
2024-08-07 18:34:50 +07:00
|
|
|
employeeWork: structuredClone(
|
|
|
|
|
playlond.employeeWork?.length === 0
|
|
|
|
|
? defaultFormData.employeeWork
|
2024-08-09 15:27:16 +07:00
|
|
|
: playlond.employeeWork?.map((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
statusSave: true,
|
|
|
|
|
})),
|
2024-08-07 18:34:50 +07:00
|
|
|
),
|
2024-08-05 16:53:19 +07:00
|
|
|
image: null,
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
|
|
|
|
|
2024-08-05 16:53:19 +07:00
|
|
|
const foundBranch = await customerStore.fetchListCustomeBranchById(
|
|
|
|
|
playlond.customerBranchId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
state.value.currentEmployeeCode = playlond.code;
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
state.value.profileUrl = profileImageUrl || ' ';
|
2024-08-05 16:53:19 +07:00
|
|
|
|
|
|
|
|
profileImageUrl
|
|
|
|
|
? (state.value.profileSubmit = true)
|
|
|
|
|
: (state.value.profileSubmit = false);
|
|
|
|
|
|
|
|
|
|
state.value.formDataEmployeeOwner = { ...foundBranch };
|
|
|
|
|
|
|
|
|
|
if (foundBranch.address === playlond.address) {
|
|
|
|
|
state.value.formDataEmployeeSameAddr = true;
|
|
|
|
|
} else {
|
|
|
|
|
state.value.formDataEmployeeSameAddr = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 13:30:05 +07:00
|
|
|
if (state.value.infoEmployeePersonCard && profileImageUrl !== null) {
|
|
|
|
|
state.value.infoEmployeePersonCard[0].img = profileImageUrl;
|
2024-08-05 16:53:19 +07:00
|
|
|
}
|
|
|
|
|
flowStore.rotate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function employeeFilterOwnerBranch(
|
|
|
|
|
val: string,
|
|
|
|
|
update: (...args: unknown[]) => void,
|
|
|
|
|
) {
|
|
|
|
|
update(async () => {
|
|
|
|
|
const result = await customerStore.fetchListCustomeBranch({
|
|
|
|
|
includeCustomer: true,
|
|
|
|
|
query: val,
|
|
|
|
|
pageSize: 30,
|
|
|
|
|
});
|
|
|
|
|
if (result) employeeStore.ownerOption = result.result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
state,
|
|
|
|
|
currentFromDataEmployee,
|
|
|
|
|
resetEmployeeData,
|
|
|
|
|
|
2024-08-09 15:27:16 +07:00
|
|
|
submitOther,
|
2024-08-07 18:34:50 +07:00
|
|
|
submitWorkHistory,
|
2024-08-06 16:33:17 +07:00
|
|
|
submitPersonal,
|
2024-08-07 18:34:50 +07:00
|
|
|
submitHealthCheck,
|
2024-08-06 16:33:17 +07:00
|
|
|
|
2024-08-09 17:04:45 +07:00
|
|
|
deleteWorkHistory,
|
|
|
|
|
deleteHealthCheck,
|
|
|
|
|
|
2024-08-05 16:53:19 +07:00
|
|
|
resetFormDataEmployee,
|
|
|
|
|
assignFormDataEmployee,
|
|
|
|
|
|
|
|
|
|
employeeFilterOwnerBranch,
|
2024-08-06 15:47:33 +07:00
|
|
|
|
|
|
|
|
isFormDataDifferent,
|
2024-08-05 16:53:19 +07:00
|
|
|
};
|
2024-08-02 13:58:44 +07:00
|
|
|
});
|