88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type { PaginatedResponse } from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
export interface ProductStockRow {
|
|
itemId: string
|
|
sku: string
|
|
name: string
|
|
brand: string | null
|
|
category: string
|
|
subCategory: string | null
|
|
uom: string
|
|
salePrice: number | null
|
|
costPrice: number | null
|
|
reorderLevel: number | null
|
|
warehouseQty: number
|
|
vehicleQty: number
|
|
totalQty: number
|
|
stockValue: number
|
|
isLowStock: boolean
|
|
isActive: boolean
|
|
}
|
|
|
|
export interface ProductSalesRow {
|
|
itemId: string
|
|
sku: string
|
|
name: string
|
|
orders: number
|
|
stores: number
|
|
qtyOrdered: number
|
|
qtyFulfilled: number
|
|
salesValue: number
|
|
costValue: number | null
|
|
margin: number | null
|
|
marginPercent: number | null
|
|
}
|
|
|
|
export interface ProductReturnRow {
|
|
itemId: string
|
|
sku: string
|
|
name: string
|
|
returnedQty: number
|
|
returnedValue: number
|
|
soldQty: number
|
|
returnPercent: number | null
|
|
qtyByReason: Record<string, number>
|
|
}
|
|
|
|
export interface ProductReportSummary {
|
|
itemCount: number
|
|
totalQty: number
|
|
totalValue: number
|
|
totalSales: number
|
|
}
|
|
|
|
export interface ProductReportParams extends PageParams {
|
|
brandId?: string
|
|
categoryId?: string
|
|
subCategoryId?: string
|
|
warehouseId?: string
|
|
regionId?: string
|
|
routeId?: string
|
|
storeId?: string
|
|
from?: string
|
|
to?: string
|
|
search?: string
|
|
}
|
|
|
|
export interface ProductStockParams extends ProductReportParams {
|
|
activeOnly?: boolean
|
|
lowStockOnly?: boolean
|
|
}
|
|
|
|
export const productReports = {
|
|
stock: (params?: ProductStockParams) =>
|
|
api.get<PaginatedResponse<ProductStockRow>>('/reports/products/stock', { params }).then(r => r.data),
|
|
|
|
sales: (params?: ProductReportParams) =>
|
|
api.get<PaginatedResponse<ProductSalesRow>>('/reports/products/sales', { params }).then(r => r.data),
|
|
|
|
returns: (params?: ProductReportParams) =>
|
|
api.get<PaginatedResponse<ProductReturnRow>>('/reports/products/returns', { params }).then(r => r.data),
|
|
|
|
summary: (params?: Pick<ProductReportParams, 'brandId' | 'categoryId' | 'warehouseId' | 'from' | 'to'>) =>
|
|
api.get<ProductReportSummary>('/reports/products/summary', { params }).then(r => r.data),
|
|
}
|