feat: quotation api

This commit is contained in:
Methapon Metanipat 2024-09-30 12:04:58 +07:00
parent 64754f695d
commit 92f8a2abab
2 changed files with 309 additions and 0 deletions

View file

@ -0,0 +1,67 @@
import { ref } from 'vue';
import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import { Quotation, QuotationFull, QuotationPayload } from './types';
import { PaginationResult } from 'src/types';
export const quotationStore = defineStore('quotation-store', () => {
const data = ref<Quotation[]>([]);
const page = ref<number>(1);
const pageMax = ref<number>(1);
async function getQuotation(id: string) {
const res = await api.get<QuotationFull>(`/quotation/${id}`);
if (res.status < 400) {
return res.data;
}
return null;
}
async function getQuotationList() {
const res = await api.get<PaginationResult<Quotation>>('/quotation');
if (res.status < 400) {
return res.data;
}
return null;
}
async function createQuotation(payload: QuotationPayload) {
const res = await api.post('/quotation', payload);
if (res.status < 400) {
return res.data;
}
return null;
}
async function editQuotation(payload: QuotationPayload & { id: string }) {
const res = await api.put(`/quotation/${payload.id}`, {
...payload,
id: undefined,
});
if (res.status < 400) {
return res.data;
}
return null;
}
async function deleteQuottaion(id: string) {
const res = await api.delete(`/quotation/${id}`);
if (res.status < 400) {
return res.data;
}
return null;
}
return {
data,
page,
pageMax,
getQuotation,
getQuotationList,
createQuotation,
editQuotation,
deleteQuottaion,
};
});

View file

@ -0,0 +1,242 @@
import { Status } from '../types';
export type Quotation = {
worker: {
id: string;
quotationId: string;
employeeId: string;
code: string;
no: number;
}[];
service: {
_count: { work: number };
work: {
id: string;
serviceId: string;
name: string;
order: number;
attributes: any;
_count: { productOnWork: number };
}[];
id: string;
refServiceId: string; // Can be used to get image if still exists
quotationId: string;
code: string;
name: string;
detail: string;
attributes: any;
};
id: string;
finalPrice: number;
vatExcluded: number;
vat: number;
totalDiscount: number;
totalPrice: number;
urgent: boolean;
workerCount: number;
payBillDate: string | Date;
paySplitCount: number;
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
date: string | Date;
dueDate: string | Date;
documentReceivePoint: string;
contactTel: string;
contactName: string;
workName: string;
actorName: string;
code: string;
statusOrder: number;
status: Status;
customerBranchId: string;
createdByUserId: string;
createdAt: string | Date;
updatedByUserId: string;
updatedAt: string | Date;
};
export type QuotationFull = {
worker: {
id: string;
quotationId: string;
employeeId: string;
code: string;
no: number;
employee: {
workerStatus: string;
workerType: string;
nationality: string;
dateOfBirth: string;
nrcNo: string;
selectedImage: string;
middleNameEN: string;
middleName: string;
subDistrictId: string;
districtId: string;
provinceId: string;
streetEN: string;
street: string;
mooEN: string;
moo: string;
soiEN: string;
soi: string;
addressEN: string;
address: string;
gender: string;
lastNameEN: string;
lastName: string;
firstNameEN: string;
firstName: string;
namePrefix: string;
updatedByUserId: string;
updatedAt: string;
createdByUserId: string;
createdAt: string;
code: string;
statusOrder: 0;
status: Status;
customerBranchId: string;
id: string;
};
}[];
service: {
_count: { work: number };
work: {
id: string;
serviceId: string;
name: string;
order: number;
attributes: any;
productOnWork: {
product: {
productGroupId: string;
shared: boolean;
expenseType: string;
vatIncluded: boolean;
serviceCharge: number;
agentPrice: number;
price: number;
process: number;
detail: string;
remark: string;
selectedImage: string;
name: string;
updatedByUserId: string;
updatedAt: string;
createdByUserId: string;
createdAt: string;
code: string;
statusOrder: 0;
status: Status;
id: string;
};
pricePerUnit: number;
discount: number;
amount: number;
productId: string;
workId: string;
order: number;
vat: number;
}[];
_count: { productOnWork: number };
}[];
id: string;
refServiceId: string; // Can be used to get image if still exists
quotationId: string;
code: string;
name: string;
detail: string;
attributes: any;
};
id: string;
finalPrice: number;
vatExcluded: number;
vat: number;
totalDiscount: number;
totalPrice: number;
urgent: boolean;
workerCount: number;
payBillDate: string | Date;
paySplitCount: number;
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
date: string | Date;
dueDate: string | Date;
documentReceivePoint: string;
contactTel: string;
contactName: string;
workName: string;
actorName: string;
code: string;
statusOrder: number;
status: Status;
customerBranchId: string;
createdByUserId: string;
createdAt: string | Date;
updatedByUserId: string;
updatedAt: string | Date;
};
export type QuotationPayload = {
service: [
{
work: [
{
product: [
{
vat: number; // 0..1
discount: 1; // 0..1
amount: 0; // int
id: string;
},
];
excluded: boolean;
id: string;
},
];
id: string;
},
];
urgent: boolean;
customerBranchId: string;
worker: (
| string
| {
lastNameEN: string;
lastName: string;
middleNameEN: string;
middleName: string;
firstNameEN: string;
firstName: string;
namePrefix: string;
nationality: string;
gender: string;
dateOfBirth: Date;
}
)[];
workerCount: 0;
payBillDate: Date;
paySplit: Date[];
paySplitCount: number; // int
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
dueDate: Date;
documentReceivePoint: string;
contactTel: string;
contactName: string;
workName: string;
actorName: string;
status: Status;
};