feat: show profit
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 10s

This commit is contained in:
Thanaphon Frappet 2025-03-07 15:54:25 +07:00
parent 2a2613d72c
commit c750ed5fee
4 changed files with 276 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import {
ReportProduct,
ReportQuotation,
ReportSale,
ReportProfit,
} from './types';
import { baseUrl } from '../utils';
import { getToken } from 'src/services/keycloak';
@ -120,6 +121,31 @@ export async function getReportPayment(params?: {
return null;
}
export async function getReportProfit(params?: {
years?: number;
startDate?: string | Date;
endDate?: string | Date;
}) {
let opts = params || {};
if (params?.years) {
const currentYear = new Date().getFullYear();
opts.startDate = new Date(currentYear - params.years, 0, 1); // ✅ 1 ม.ค. ของปีที่ต้องการ
opts.endDate = new Date(currentYear, 11, 31); // ✅ 31 ธ.ค. ของปีปัจจุบัน
}
const res = await api.get<ReportProfit>(`/${ENDPOINT}/profit`, {
params: {
startDate: opts.startDate,
endDate: opts.endDate,
},
});
if (res.status < 400) {
return res.data;
}
return null;
}
export const useReportStore = defineStore('report-store', () => {
const dataReportQuotation = ref<ReportQuotation[]>([]);
const dataReportInvoice = ref<Report[]>([]);
@ -127,6 +153,7 @@ export const useReportStore = defineStore('report-store', () => {
const dataReportSale = ref<ReportSale>();
const dataReportProduct = ref<ReportProduct[]>([]);
const dataReportPayment = ref<ReportPayment[]>([]);
const dataReportProfit = ref<ReportProfit>();
return {
dataReportQuotation,
@ -135,6 +162,7 @@ export const useReportStore = defineStore('report-store', () => {
dataReportSale,
dataReportProduct,
dataReportPayment,
dataReportProfit,
downloadReportQuotation,
getReportQuotation,
@ -147,5 +175,6 @@ export const useReportStore = defineStore('report-store', () => {
downloadReportProduct,
getReportProduct,
getReportPayment,
getReportProfit,
};
});

View file

@ -50,3 +50,16 @@ export type ReportSale = {
bySale: (User & { _count: number })[];
byProductGroup: (Omit<ProductGroup, '_count'> & { _count: number })[];
};
export type ReportProfit = {
dataset: {
netProfit: number;
expenses: number;
income: number;
year: number;
month: number;
}[];
netProfit: number;
expenses: number;
income: number;
};