feat: report inventory

This commit is contained in:
efrilm
2025-08-14 03:17:17 +07:00
parent e2f18ac9bb
commit 16ad569297
4 changed files with 428 additions and 8 deletions
+41
View File
@@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query'
import {
CategoryReport,
DashboardReport,
InventoryReport,
PaymentReport,
ProductSalesReport,
ProfitLossReport,
@@ -194,3 +195,43 @@ export function useCategoryAnalytics(params: AnalyticQueryParams = {}) {
}
})
}
export function useInventoryAnalytics(params: AnalyticQueryParams = {}) {
const today = new Date()
const monthAgo = new Date()
monthAgo.setDate(today.getDate() - 30)
const defaultDateTo = formatDateDDMMYYYY(today)
const defaultDateFrom = formatDateDDMMYYYY(monthAgo)
const { date_from = defaultDateFrom, date_to = defaultDateTo, ...filters } = params
const user = (() => {
try {
return JSON.parse(localStorage.getItem('user') || '{}')
} catch {
return {}
}
})()
const outletId = user?.outlet_id //
return useQuery<InventoryReport>({
queryKey: ['analytics-inventory', { date_from, date_to, ...filters }],
queryFn: async () => {
const queryParams = new URLSearchParams()
queryParams.append('date_from', date_from)
queryParams.append('date_to', date_to)
Object.entries(filters).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
queryParams.append(key, value.toString())
}
})
const res = await api.get(`/inventory/report/details/${outletId}?${queryParams.toString()}`)
return res.data.data
}
})
}