feat: update payment stores

This commit is contained in:
Methapon Metanipat 2024-10-30 10:57:42 +07:00
parent 71a273f7f0
commit b6242c199f
2 changed files with 68 additions and 2 deletions

View file

@ -2,7 +2,7 @@ import { ref } from 'vue';
import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import { PaginationResult } from 'src/types';
import { Invoice, InvoicePayload, Payment } from './types';
import { Invoice, InvoicePayload, Payment, Receipt } from './types';
export const usePayment = defineStore('payment-store', () => {
const data = ref<{}[]>([]);
@ -17,6 +17,7 @@ export const usePayment = defineStore('payment-store', () => {
return res.data;
}
async function getPaymentList(opts?: {
page?: number;
pageSize?: number;
@ -32,6 +33,23 @@ export const usePayment = defineStore('payment-store', () => {
return res.data;
}
async function updatePayment(paymentId: string, payload: Payment) {
const res = await api.put<Payment & { id: string }>(
`/payment/${paymentId}`,
payload,
);
if (res.status >= 400) return null;
return res.data;
}
async function deletePayment(paymentId: string) {
const res = await api.delete<Payment & { id: string }>(
`/payment/${paymentId}`,
);
if (res.status >= 400) return null;
return res.data;
}
return {
data,
page,
@ -40,6 +58,48 @@ export const usePayment = defineStore('payment-store', () => {
getPayment,
getPaymentList,
updatePayment,
deletePayment,
};
});
export const useReceipt = defineStore('receipt-store', () => {
const data = ref<{}[]>([]);
const page = ref<number>(1);
const pageMax = ref<number>(1);
const pageSize = ref<number>(30);
async function getReceipt(id: string) {
const res = await api.get<Receipt>(`/receipt/${id}`);
if (res.status >= 400) return null;
return res.data;
}
async function getReceiptList(opts?: {
page?: number;
pageSize?: number;
query?: string;
quotationId?: string;
}) {
const res = await api.get<PaginationResult<Receipt>>('/receipt', {
params: opts,
});
if (res.status >= 400) return null;
return res.data;
}
return {
data,
page,
pageSize,
pageMax,
getReceipt,
getReceiptList,
};
});

View file

@ -24,4 +24,10 @@ export type InvoicePayload = {
installmentNo?: number[];
};
export type Payment = Invoice;
export type Payment = {
paymentStatus: string;
date: Date;
amount: number;
};
export type Receipt = Payment;