Add a new analitycs page for production
This commit is contained in:
@@ -56,11 +56,11 @@ export const useProductionDashboard = (
|
||||
export const useDailyProductionRequirements = (
|
||||
tenantId: string,
|
||||
date?: string,
|
||||
options?: Omit<UseQueryOptions<DailyProductionRequirements, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<any, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<DailyProductionRequirements, ApiError>({
|
||||
return useQuery<any, ApiError>({
|
||||
queryKey: productionKeys.dailyRequirements(tenantId, date),
|
||||
queryFn: () => productionService.getDailyRequirements(tenantId, date),
|
||||
queryFn: () => productionService.getDailyProductionPlan(tenantId, date),
|
||||
enabled: !!tenantId,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
...options,
|
||||
@@ -70,11 +70,13 @@ export const useDailyProductionRequirements = (
|
||||
export const useProductionRequirements = (
|
||||
tenantId: string,
|
||||
date?: string,
|
||||
options?: Omit<UseQueryOptions<ProductionRequirements, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<any, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<ProductionRequirements, ApiError>({
|
||||
const queryDate = date || new Date().toISOString().split('T')[0];
|
||||
|
||||
return useQuery<any, ApiError>({
|
||||
queryKey: productionKeys.requirements(tenantId, date),
|
||||
queryFn: () => productionService.getProductionRequirements(tenantId, date),
|
||||
queryFn: () => productionService.getProductionRequirements(tenantId, queryDate),
|
||||
enabled: !!tenantId,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
...options,
|
||||
@@ -117,11 +119,11 @@ export const useProductionSchedule = (
|
||||
tenantId: string,
|
||||
startDate?: string,
|
||||
endDate?: string,
|
||||
options?: Omit<UseQueryOptions<ProductionScheduleData, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<any, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<ProductionScheduleData, ApiError>({
|
||||
return useQuery<any, ApiError>({
|
||||
queryKey: productionKeys.schedule(tenantId, startDate, endDate),
|
||||
queryFn: () => productionService.getProductionSchedule(tenantId, startDate, endDate),
|
||||
queryFn: () => productionService.getSchedules(tenantId, { start_date: startDate, end_date: endDate }),
|
||||
enabled: !!tenantId,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
...options,
|
||||
@@ -131,11 +133,11 @@ export const useProductionSchedule = (
|
||||
export const useCapacityStatus = (
|
||||
tenantId: string,
|
||||
date?: string,
|
||||
options?: Omit<UseQueryOptions<ProductionCapacityStatus, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<any, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<ProductionCapacityStatus, ApiError>({
|
||||
return useQuery<any, ApiError>({
|
||||
queryKey: productionKeys.capacity(tenantId, date),
|
||||
queryFn: () => productionService.getCapacityStatus(tenantId, date),
|
||||
queryFn: () => date ? productionService.getCapacityByDate(tenantId, date) : productionService.getCapacity(tenantId),
|
||||
enabled: !!tenantId,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
...options,
|
||||
@@ -146,11 +148,11 @@ export const useYieldMetrics = (
|
||||
tenantId: string,
|
||||
startDate: string,
|
||||
endDate: string,
|
||||
options?: Omit<UseQueryOptions<ProductionYieldMetrics, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<any, ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<ProductionYieldMetrics, ApiError>({
|
||||
return useQuery<any, ApiError>({
|
||||
queryKey: productionKeys.yieldMetrics(tenantId, startDate, endDate),
|
||||
queryFn: () => productionService.getYieldMetrics(tenantId, startDate, endDate),
|
||||
queryFn: () => productionService.getYieldTrends(tenantId, startDate, endDate),
|
||||
enabled: !!tenantId && !!startDate && !!endDate,
|
||||
staleTime: 15 * 60 * 1000, // 15 minutes (metrics are less frequently changing)
|
||||
...options,
|
||||
|
||||
@@ -384,4 +384,76 @@ export interface BatchStatistics {
|
||||
on_time_rate: number;
|
||||
period_start: string;
|
||||
period_end: string;
|
||||
}
|
||||
|
||||
// Additional types needed for hooks
|
||||
export interface DailyProductionRequirements {
|
||||
date: string;
|
||||
total_planned_units: number;
|
||||
total_completed_units: number;
|
||||
products: Array<{
|
||||
product_id: string;
|
||||
product_name: string;
|
||||
planned_quantity: number;
|
||||
completed_quantity: number;
|
||||
required_materials: Array<{
|
||||
ingredient_id: string;
|
||||
ingredient_name: string;
|
||||
required_amount: number;
|
||||
unit: string;
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProductionScheduleData {
|
||||
schedules: Array<{
|
||||
id: string;
|
||||
date: string;
|
||||
shift_start: string;
|
||||
shift_end: string;
|
||||
total_batches_planned: number;
|
||||
staff_count: number;
|
||||
utilization_percentage: number;
|
||||
is_active: boolean;
|
||||
is_finalized: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProductionCapacityStatus {
|
||||
date: string;
|
||||
total_capacity: number;
|
||||
utilized_capacity: number;
|
||||
utilization_percentage: number;
|
||||
equipment_utilization: Array<{
|
||||
equipment_id: string;
|
||||
equipment_name: string;
|
||||
capacity: number;
|
||||
utilization: number;
|
||||
status: 'operational' | 'maintenance' | 'down';
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProductionRequirements {
|
||||
date: string;
|
||||
products: Array<{
|
||||
product_id: string;
|
||||
product_name: string;
|
||||
required_quantity: number;
|
||||
planned_quantity: number;
|
||||
priority: ProductionPriority;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProductionYieldMetrics {
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
overall_yield: number;
|
||||
products: Array<{
|
||||
product_id: string;
|
||||
product_name: string;
|
||||
average_yield: number;
|
||||
best_yield: number;
|
||||
worst_yield: number;
|
||||
batch_count: number;
|
||||
}>;
|
||||
}
|
||||
Reference in New Issue
Block a user