refactor: add page invoice

This commit is contained in:
Thanaphon Frappet 2024-10-29 18:02:20 +07:00
parent 1f4edc7363
commit f4d225985a
4 changed files with 313 additions and 180 deletions

View file

@ -10,8 +10,11 @@ import {
QuotationFull,
} from 'src/stores/quotations/types';
import { InvoicePayload } from 'src/stores/payment/types';
// NOTE: Import stores
import { useQuotationStore } from 'stores/quotations';
import { useInvoice } from 'stores/payment';
import useEmployeeStore from 'stores/employee';
import { getName } from 'src/services/keycloak';
@ -36,12 +39,23 @@ const DEFAULT_DATA: QuotationPayload = {
remark: undefined,
};
const DEFAULT_DATA_INVOICE: InvoicePayload = {
quotationId: '',
amount: 0,
productServiceListId: [],
installmentNo: [],
};
export const useQuotationForm = defineStore('form-quotation', () => {
const { t } = useI18n();
const quotationStore = useQuotationStore();
const employeeStore = useEmployeeStore();
const invoiceStore = useInvoice();
const quotationFull = ref<QuotationFull | undefined>(undefined);
const invoicePayload = ref<InvoicePayload & { id?: string }>(
DEFAULT_DATA_INVOICE,
);
const newWorkerList = ref<
(EmployeeWorker & {
attachment?: {
@ -122,7 +136,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
payBillDate: data.payBillDate ? new Date(data.payBillDate) : undefined,
paySplit: data.paySplit.map((p, index) => ({
no: index + 1,
date: p.date,
invoice: p.invoice,
amount: p.amount,
})),
worker: data.worker.map((v) =>
@ -144,6 +158,8 @@ export const useQuotationForm = defineStore('form-quotation', () => {
if (mode === 'assign') return;
currentFormState.value.mode = mode;
console.log(currentFormData.value);
}
async function submitQuotation() {
@ -242,6 +258,22 @@ export const useQuotationForm = defineStore('form-quotation', () => {
return false;
}
async function submitInvoice() {
let status = false;
if (invoicePayload.value.id === undefined) {
const res = await invoiceStore.creatInvoice(invoicePayload.value);
if (res) status = true;
}
if (invoicePayload.value.id !== undefined) {
const res = await invoiceStore.editInvoice(invoicePayload.value);
if (res) status = true;
}
return status;
}
return {
DEFAULT_DATA,
currentFormState,
@ -250,12 +282,16 @@ export const useQuotationForm = defineStore('form-quotation', () => {
fileItemNewWorker,
quotationFull,
invoicePayload,
isFormDataDifferent,
injectNewEmployee,
assignFormData,
dialogDelete,
resetForm,
submitInvoice,
accepted,
submitQuotation,