diff --git a/src/stores/report/index.ts b/src/stores/report/index.ts new file mode 100644 index 00000000..0f0ab14f --- /dev/null +++ b/src/stores/report/index.ts @@ -0,0 +1,71 @@ +import { ref } from 'vue'; +import { defineStore } from 'pinia'; +import { Pagination, Status } from '../types'; +import { api } from 'src/boot/axios'; +import { Report, ReportProduct, ReportQuotation, ReportSale } from './types'; + +const ENDPOINT = 'report'; + +export async function getReportQuotation() { + const res = await api.get(`/${ENDPOINT}/quotation`); + if (res.status < 400) { + res.data; + return res.data; + } + return null; +} + +export async function getReportInvoice() { + const res = await api.get(`/${ENDPOINT}/invoice`); + if (res.status < 400) { + return res.data; + } + return null; +} + +export async function getReportReceipt() { + const res = await api.get(`/${ENDPOINT}/receipt`); + if (res.status < 400) { + return res.data; + } + return null; +} + +export async function getReportSale() { + const res = await api.get(`/${ENDPOINT}/sale`); + + if (res.status < 400) { + return res.data; + } + return null; +} + +export async function getReportProduct() { + const res = await api.get(`/${ENDPOINT}/Product`); + if (res.status < 400) { + return res.data; + } + return null; +} + +export const useReportStore = defineStore('report-store', () => { + const dataReportQuotation = ref([]); + const dataReportInvoice = ref([]); + const dataReportReceipt = ref([]); + const dataReportSale = ref(); + const dataReportProduct = ref([]); + + return { + dataReportQuotation, + dataReportInvoice, + dataReportReceipt, + dataReportSale, + dataReportProduct, + + getReportQuotation, + getReportInvoice, + getReportReceipt, + getReportSale, + getReportProduct, + }; +}); diff --git a/src/stores/report/types.ts b/src/stores/report/types.ts new file mode 100644 index 00000000..92215ae3 --- /dev/null +++ b/src/stores/report/types.ts @@ -0,0 +1,41 @@ +import { QuotationStatus } from 'src/stores/quotations/types'; +import { ProductGroup } from '../product-service/types'; +import { User } from '../user'; +import { CustomerBranch } from '../customer'; + +export type ReportQuotation = { + updatedAt: Date | null; + createdAt: Date | null; + status: QuotationStatus; + code: string; +}; + +export enum Status { + PaymentInProcess = 'PaymentInProcess', + PaymentSuccess = 'PaymentSuccess', + PaymentWait = 'PaymentWait', + PaymentRetry = 'PaymentRetry', +} + +// use with Invoice and Receipt +export type Report = { + createdAt: Date | null; + status: Status; + code: string; +}; + +export type ReportProduct = { + updatedAt: Date | null; + createdAt: Date | null; + order: number; + did: number; + sale: number; + name: string; + code: string; +}; + +export type ReportSale = { + byCustomer: (Omit & { _count: number })[]; + bySale: (User & { _count: number })[]; + byProductGroup: (Omit & { _count: number })[]; +};