Add improved production UI

This commit is contained in:
Urtzi Alfaro
2025-09-23 12:49:35 +02:00
parent 8d54202e91
commit 4ae8e14e55
35 changed files with 6848 additions and 415 deletions

View File

@@ -1,79 +1,360 @@
import { apiClient } from '../client';
import type {
ProductionBatchCreate,
ProductionBatchStatusUpdate,
/**
* Production API Service - Handles all production-related API calls
*/
import { apiClient } from '../client/apiClient';
import {
// Types
ProductionBatchResponse,
ProductionBatchCreate,
ProductionBatchUpdate,
ProductionBatchStatusUpdate,
ProductionBatchListResponse,
ProductionBatchFilters,
ProductionScheduleResponse,
ProductionScheduleCreate,
ProductionScheduleUpdate,
ProductionScheduleFilters,
ProductionCapacityResponse,
ProductionCapacityFilters,
QualityCheckResponse,
QualityCheckCreate,
QualityCheckFilters,
ProductionPerformanceAnalytics,
YieldTrendsAnalytics,
TopDefectsAnalytics,
EquipmentEfficiencyAnalytics,
CapacityBottlenecks,
ProductionDashboardSummary,
DailyProductionRequirements,
ProductionScheduleData,
ProductionCapacityStatus,
ProductionRequirements,
ProductionYieldMetrics,
BatchStatistics,
} from '../types/production';
export class ProductionService {
private readonly baseUrl = '/production';
private baseUrl = '/production';
getDashboardSummary(tenantId: string): Promise<ProductionDashboardSummary> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard-summary`);
// ================================================================
// PRODUCTION BATCH ENDPOINTS
// ================================================================
async getBatches(
tenantId: string,
filters?: ProductionBatchFilters
): Promise<ProductionBatchListResponse> {
const params = new URLSearchParams();
if (filters?.status) params.append('status', filters.status);
if (filters?.product_id) params.append('product_id', filters.product_id);
if (filters?.order_id) params.append('order_id', filters.order_id);
if (filters?.start_date) params.append('start_date', filters.start_date);
if (filters?.end_date) params.append('end_date', filters.end_date);
if (filters?.page) params.append('page', filters.page.toString());
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/batches${queryString ? `?${queryString}` : ''}`;
return apiClient.get<ProductionBatchListResponse>(url);
}
getDailyRequirements(tenantId: string, date?: string): Promise<DailyProductionRequirements> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/daily-requirements`, { params });
async getBatch(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
return apiClient.get<ProductionBatchResponse>(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
}
getProductionRequirements(tenantId: string, date?: string): Promise<ProductionRequirements> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/requirements`, { params });
async createBatch(
tenantId: string,
batchData: ProductionBatchCreate
): Promise<ProductionBatchResponse> {
return apiClient.post<ProductionBatchResponse>(
`/tenants/${tenantId}${this.baseUrl}/batches`,
batchData
);
}
createProductionBatch(tenantId: string, batchData: ProductionBatchCreate): Promise<ProductionBatchResponse> {
return apiClient.post(`/tenants/${tenantId}${this.baseUrl}/batches`, batchData);
}
getActiveBatches(tenantId: string): Promise<ProductionBatchListResponse> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/batches/active`);
}
getBatchDetails(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
}
updateBatchStatus(
async updateBatch(
tenantId: string,
batchId: string,
statusUpdate: ProductionBatchStatusUpdate
batchData: ProductionBatchUpdate
): Promise<ProductionBatchResponse> {
return apiClient.put(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/status`, statusUpdate);
return apiClient.put<ProductionBatchResponse>(
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`,
batchData
);
}
getProductionSchedule(
async deleteBatch(tenantId: string, batchId: string): Promise<void> {
return apiClient.delete<void>(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
}
async updateBatchStatus(
tenantId: string,
batchId: string,
statusData: ProductionBatchStatusUpdate
): Promise<ProductionBatchResponse> {
return apiClient.patch<ProductionBatchResponse>(
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/status`,
statusData
);
}
async startBatch(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
return apiClient.post<ProductionBatchResponse>(
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/start`
);
}
async completeBatch(
tenantId: string,
batchId: string,
completionData?: { actual_quantity?: number; notes?: string }
): Promise<ProductionBatchResponse> {
return apiClient.post<ProductionBatchResponse>(
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/complete`,
completionData || {}
);
}
async getBatchStatistics(
tenantId: string,
startDate?: string,
endDate?: string
): Promise<ProductionScheduleData> {
const params: Record<string, string> = {};
if (startDate) params.start_date = startDate;
if (endDate) params.end_date = endDate;
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/schedule`, { params });
): Promise<BatchStatistics> {
const params = new URLSearchParams();
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/batches/stats${queryString ? `?${queryString}` : ''}`;
return apiClient.get<BatchStatistics>(url);
}
getCapacityStatus(tenantId: string, date?: string): Promise<ProductionCapacityStatus> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/capacity/status`, { params });
// ================================================================
// PRODUCTION SCHEDULE ENDPOINTS
// ================================================================
async getSchedules(
tenantId: string,
filters?: ProductionScheduleFilters
): Promise<{ schedules: ProductionScheduleResponse[]; total_count: number; page: number; page_size: number }> {
const params = new URLSearchParams();
if (filters?.start_date) params.append('start_date', filters.start_date);
if (filters?.end_date) params.append('end_date', filters.end_date);
if (filters?.is_finalized !== undefined) params.append('is_finalized', filters.is_finalized.toString());
if (filters?.page) params.append('page', filters.page.toString());
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/schedules${queryString ? `?${queryString}` : ''}`;
return apiClient.get(url);
}
getYieldMetrics(
async getSchedule(tenantId: string, scheduleId: string): Promise<ProductionScheduleResponse> {
return apiClient.get<ProductionScheduleResponse>(`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`);
}
async createSchedule(
tenantId: string,
scheduleData: ProductionScheduleCreate
): Promise<ProductionScheduleResponse> {
return apiClient.post<ProductionScheduleResponse>(
`/tenants/${tenantId}${this.baseUrl}/schedules`,
scheduleData
);
}
async updateSchedule(
tenantId: string,
scheduleId: string,
scheduleData: ProductionScheduleUpdate
): Promise<ProductionScheduleResponse> {
return apiClient.put<ProductionScheduleResponse>(
`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`,
scheduleData
);
}
async deleteSchedule(tenantId: string, scheduleId: string): Promise<void> {
return apiClient.delete<void>(`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`);
}
async finalizeSchedule(tenantId: string, scheduleId: string): Promise<ProductionScheduleResponse> {
return apiClient.post<ProductionScheduleResponse>(
`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}/finalize`
);
}
async getTodaysSchedule(tenantId: string): Promise<ProductionScheduleResponse | null> {
return apiClient.get<ProductionScheduleResponse | null>(`/tenants/${tenantId}${this.baseUrl}/schedules/today`);
}
// ================================================================
// PRODUCTION CAPACITY ENDPOINTS
// ================================================================
async getCapacity(
tenantId: string,
filters?: ProductionCapacityFilters
): Promise<{ capacity: ProductionCapacityResponse[]; total_count: number; page: number; page_size: number }> {
const params = new URLSearchParams();
if (filters?.resource_type) params.append('resource_type', filters.resource_type);
if (filters?.date) params.append('date', filters.date);
if (filters?.availability !== undefined) params.append('availability', filters.availability.toString());
if (filters?.page) params.append('page', filters.page.toString());
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/capacity${queryString ? `?${queryString}` : ''}`;
return apiClient.get(url);
}
async getCapacityByDate(tenantId: string, date: string): Promise<ProductionCapacityResponse[]> {
return apiClient.get<ProductionCapacityResponse[]>(`/tenants/${tenantId}${this.baseUrl}/capacity/date/${date}`);
}
async getCapacityByResource(tenantId: string, resourceId: string): Promise<ProductionCapacityResponse[]> {
return apiClient.get<ProductionCapacityResponse[]>(`/tenants/${tenantId}${this.baseUrl}/capacity/resource/${resourceId}`);
}
// ================================================================
// QUALITY CHECK ENDPOINTS
// ================================================================
async getQualityChecks(
tenantId: string,
filters?: QualityCheckFilters
): Promise<{ quality_checks: QualityCheckResponse[]; total_count: number; page: number; page_size: number }> {
const params = new URLSearchParams();
if (filters?.batch_id) params.append('batch_id', filters.batch_id);
if (filters?.product_id) params.append('product_id', filters.product_id);
if (filters?.start_date) params.append('start_date', filters.start_date);
if (filters?.end_date) params.append('end_date', filters.end_date);
if (filters?.pass_fail !== undefined) params.append('pass_fail', filters.pass_fail.toString());
if (filters?.page) params.append('page', filters.page.toString());
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/quality-checks${queryString ? `?${queryString}` : ''}`;
return apiClient.get(url);
}
async getQualityCheck(tenantId: string, checkId: string): Promise<QualityCheckResponse> {
return apiClient.get<QualityCheckResponse>(`/tenants/${tenantId}${this.baseUrl}/quality-checks/${checkId}`);
}
async createQualityCheck(
tenantId: string,
checkData: QualityCheckCreate
): Promise<QualityCheckResponse> {
return apiClient.post<QualityCheckResponse>(
`/tenants/${tenantId}${this.baseUrl}/quality-checks`,
checkData
);
}
async getQualityChecksByBatch(tenantId: string, batchId: string): Promise<QualityCheckResponse[]> {
return apiClient.get<QualityCheckResponse[]>(`/tenants/${tenantId}${this.baseUrl}/quality-checks/batch/${batchId}`);
}
// ================================================================
// ANALYTICS ENDPOINTS
// ================================================================
async getPerformanceAnalytics(
tenantId: string,
startDate: string,
endDate: string
): Promise<ProductionYieldMetrics> {
const params = { start_date: startDate, end_date: endDate };
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/metrics/yield`, { params });
): Promise<ProductionPerformanceAnalytics> {
return apiClient.get<ProductionPerformanceAnalytics>(
`/tenants/${tenantId}${this.baseUrl}/analytics/performance?start_date=${startDate}&end_date=${endDate}`
);
}
async getYieldTrends(
tenantId: string,
period: 'week' | 'month' = 'week'
): Promise<YieldTrendsAnalytics> {
return apiClient.get<YieldTrendsAnalytics>(
`/tenants/${tenantId}${this.baseUrl}/analytics/yield-trends?period=${period}`
);
}
async getTopDefects(
tenantId: string,
startDate?: string,
endDate?: string
): Promise<TopDefectsAnalytics> {
const params = new URLSearchParams();
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/analytics/defects${queryString ? `?${queryString}` : ''}`;
return apiClient.get<TopDefectsAnalytics>(url);
}
async getEquipmentEfficiency(
tenantId: string,
startDate?: string,
endDate?: string
): Promise<EquipmentEfficiencyAnalytics> {
const params = new URLSearchParams();
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/analytics/equipment-efficiency${queryString ? `?${queryString}` : ''}`;
return apiClient.get<EquipmentEfficiencyAnalytics>(url);
}
async getCapacityBottlenecks(
tenantId: string,
days: number = 7
): Promise<CapacityBottlenecks> {
return apiClient.get<CapacityBottlenecks>(
`/tenants/${tenantId}${this.baseUrl}/analytics/capacity-bottlenecks?days=${days}`
);
}
// ================================================================
// DASHBOARD ENDPOINTS
// ================================================================
async getDashboardSummary(tenantId: string): Promise<ProductionDashboardSummary> {
return apiClient.get<ProductionDashboardSummary>(`/tenants/${tenantId}${this.baseUrl}/dashboard/summary`);
}
async getDailyProductionPlan(tenantId: string, date?: string): Promise<any> {
const queryString = date ? `?date=${date}` : '';
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/daily-plan${queryString}`);
}
async getProductionRequirements(tenantId: string, date: string): Promise<any> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/requirements/${date}`);
}
async getCapacityOverview(tenantId: string, date?: string): Promise<any> {
const queryString = date ? `?date=${date}` : '';
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/capacity-overview${queryString}`);
}
async getQualityOverview(
tenantId: string,
startDate?: string,
endDate?: string
): Promise<any> {
const params = new URLSearchParams();
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
const queryString = params.toString();
const url = `/tenants/${tenantId}${this.baseUrl}/dashboard/quality-overview${queryString ? `?${queryString}` : ''}`;
return apiClient.get(url);
}
}
export const productionService = new ProductionService();
export const productionService = new ProductionService();
export default productionService;