From 4d3f956a0366e07fba80b324d76cdb34abdc20a2 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 12 Jan 2025 16:11:55 -0500 Subject: [PATCH] =?UTF-8?q?Layout=20tweaks=C3=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings/CalculationSettings.tsx | 2 +- .../src/components/settings/Configuration.tsx | 630 ------------------ .../settings/PerformanceMetrics.tsx | 2 +- .../components/settings/StockManagement.tsx | 2 +- inventory/src/pages/Settings.tsx | 11 +- 5 files changed, 10 insertions(+), 637 deletions(-) delete mode 100644 inventory/src/components/settings/Configuration.tsx diff --git a/inventory/src/components/settings/CalculationSettings.tsx b/inventory/src/components/settings/CalculationSettings.tsx index 433f8fe..85cc12f 100644 --- a/inventory/src/components/settings/CalculationSettings.tsx +++ b/inventory/src/components/settings/CalculationSettings.tsx @@ -66,7 +66,7 @@ export function CalculationSettings() { }; return ( -
+
{/* Sales Velocity Configuration Card */} diff --git a/inventory/src/components/settings/Configuration.tsx b/inventory/src/components/settings/Configuration.tsx deleted file mode 100644 index 0d7a319..0000000 --- a/inventory/src/components/settings/Configuration.tsx +++ /dev/null @@ -1,630 +0,0 @@ -import { useState, useEffect } from 'react'; -import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { toast } from "sonner"; -import config from '../../config'; - -interface StockThreshold { - id: number; - category_id: number | null; - vendor: string | null; - critical_days: number; - reorder_days: number; - overstock_days: number; - low_stock_threshold: number; - min_reorder_quantity: number; - category_name?: string; - threshold_scope?: string; -} - -interface LeadTimeThreshold { - id: number; - category_id: number | null; - vendor: string | null; - target_days: number; - warning_days: number; - critical_days: number; -} - -interface SalesVelocityConfig { - id: number; - category_id: number | null; - vendor: string | null; - daily_window_days: number; - weekly_window_days: number; - monthly_window_days: number; -} - -interface ABCClassificationConfig { - id: number; - a_threshold: number; - b_threshold: number; - classification_period_days: number; -} - -interface SafetyStockConfig { - id: number; - category_id: number | null; - vendor: string | null; - coverage_days: number; - service_level: number; -} - -interface TurnoverConfig { - id: number; - category_id: number | null; - vendor: string | null; - calculation_period_days: number; - target_rate: number; -} - -export function Configuration() { - const [stockThresholds, setStockThresholds] = useState({ - id: 1, - category_id: null, - vendor: null, - critical_days: 7, - reorder_days: 14, - overstock_days: 90, - low_stock_threshold: 5, - min_reorder_quantity: 1 - }); - - const [leadTimeThresholds, setLeadTimeThresholds] = useState({ - id: 1, - category_id: null, - vendor: null, - target_days: 14, - warning_days: 21, - critical_days: 30 - }); - - const [salesVelocityConfig, setSalesVelocityConfig] = useState({ - id: 1, - category_id: null, - vendor: null, - daily_window_days: 30, - weekly_window_days: 7, - monthly_window_days: 90 - }); - - const [abcConfig, setAbcConfig] = useState({ - id: 1, - a_threshold: 20.0, - b_threshold: 50.0, - classification_period_days: 90 - }); - - const [safetyStockConfig, setSafetyStockConfig] = useState({ - id: 1, - category_id: null, - vendor: null, - coverage_days: 14, - service_level: 95.0 - }); - - const [turnoverConfig, setTurnoverConfig] = useState({ - id: 1, - category_id: null, - vendor: null, - calculation_period_days: 30, - target_rate: 1.0 - }); - - useEffect(() => { - const loadConfig = async () => { - try { - const response = await fetch(`${config.apiUrl}/config`, { - credentials: 'include' - }); - if (!response.ok) { - throw new Error('Failed to load configuration'); - } - const data = await response.json(); - setStockThresholds(data.stockThresholds); - setLeadTimeThresholds(data.leadTimeThresholds); - setSalesVelocityConfig(data.salesVelocityConfig); - setAbcConfig(data.abcConfig); - setSafetyStockConfig(data.safetyStockConfig); - setTurnoverConfig(data.turnoverConfig); - } catch (error) { - toast.error(`Failed to load configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - loadConfig(); - }, []); - - const handleUpdateStockThresholds = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/stock-thresholds/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(stockThresholds) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update stock thresholds'); - } - - toast.success('Stock thresholds updated successfully'); - } catch (error) { - toast.error(`Failed to update thresholds: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - const handleUpdateLeadTimeThresholds = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/lead-time-thresholds/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(leadTimeThresholds) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update lead time thresholds'); - } - - toast.success('Lead time thresholds updated successfully'); - } catch (error) { - toast.error(`Failed to update thresholds: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - const handleUpdateSalesVelocityConfig = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/sales-velocity/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(salesVelocityConfig) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update sales velocity configuration'); - } - - toast.success('Sales velocity configuration updated successfully'); - } catch (error) { - toast.error(`Failed to update configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - const handleUpdateABCConfig = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/abc-classification/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(abcConfig) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update ABC classification configuration'); - } - - toast.success('ABC classification configuration updated successfully'); - } catch (error) { - toast.error(`Failed to update configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - const handleUpdateSafetyStockConfig = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/safety-stock/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(safetyStockConfig) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update safety stock configuration'); - } - - toast.success('Safety stock configuration updated successfully'); - } catch (error) { - toast.error(`Failed to update configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - const handleUpdateTurnoverConfig = async () => { - try { - const response = await fetch(`${config.apiUrl}/config/turnover/1`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - credentials: 'include', - body: JSON.stringify(turnoverConfig) - }); - - if (!response.ok) { - const data = await response.json().catch(() => ({})); - throw new Error(data.error || 'Failed to update turnover configuration'); - } - - toast.success('Turnover configuration updated successfully'); - } catch (error) { - toast.error(`Failed to update configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); - } - }; - - return ( - - - Stock Management - Performance Metrics - Calculation Settings - - - - {/* Stock Thresholds Card */} - - - Stock Thresholds - Configure stock level thresholds for inventory management - - -
-
-
- - setStockThresholds(prev => ({ - ...prev, - critical_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setStockThresholds(prev => ({ - ...prev, - reorder_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setStockThresholds(prev => ({ - ...prev, - overstock_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setStockThresholds(prev => ({ - ...prev, - low_stock_threshold: parseInt(e.target.value) || 0 - }))} - /> -
-
- - setStockThresholds(prev => ({ - ...prev, - min_reorder_quantity: parseInt(e.target.value) || 1 - }))} - /> -
-
- -
-
-
- - {/* Safety Stock Configuration Card */} - - - Safety Stock - Configure safety stock parameters - - -
-
-
- - setSafetyStockConfig(prev => ({ - ...prev, - coverage_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setSafetyStockConfig(prev => ({ - ...prev, - service_level: parseFloat(e.target.value) || 0 - }))} - /> -
-
- -
-
-
-
- - - {/* Lead Time Thresholds Card */} - - - Lead Time Thresholds - Configure lead time thresholds for vendor performance - - -
-
-
- - setLeadTimeThresholds(prev => ({ - ...prev, - target_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setLeadTimeThresholds(prev => ({ - ...prev, - warning_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setLeadTimeThresholds(prev => ({ - ...prev, - critical_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- -
-
-
- - {/* ABC Classification Card */} - - - ABC Classification - Configure ABC classification parameters - - -
-
-
- - setAbcConfig(prev => ({ - ...prev, - a_threshold: parseFloat(e.target.value) || 0 - }))} - /> -
-
- - setAbcConfig(prev => ({ - ...prev, - b_threshold: parseFloat(e.target.value) || 0 - }))} - /> -
-
- - setAbcConfig(prev => ({ - ...prev, - classification_period_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- -
-
-
- - {/* Turnover Configuration Card */} - - - Turnover Rate - Configure turnover rate calculations - - -
-
-
- - setTurnoverConfig(prev => ({ - ...prev, - calculation_period_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setTurnoverConfig(prev => ({ - ...prev, - target_rate: parseFloat(e.target.value) || 0 - }))} - /> -
-
- -
-
-
-
- - - {/* Sales Velocity Configuration Card */} - - - Sales Velocity Windows - Configure time windows for sales velocity calculations - - -
-
-
- - setSalesVelocityConfig(prev => ({ - ...prev, - daily_window_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setSalesVelocityConfig(prev => ({ - ...prev, - weekly_window_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- - setSalesVelocityConfig(prev => ({ - ...prev, - monthly_window_days: parseInt(e.target.value) || 1 - }))} - /> -
-
- -
-
-
-
-
- ); -} \ No newline at end of file diff --git a/inventory/src/components/settings/PerformanceMetrics.tsx b/inventory/src/components/settings/PerformanceMetrics.tsx index f3b95f4..c2df4eb 100644 --- a/inventory/src/components/settings/PerformanceMetrics.tsx +++ b/inventory/src/components/settings/PerformanceMetrics.tsx @@ -142,7 +142,7 @@ export function PerformanceMetrics() { }; return ( -
+
{/* Lead Time Thresholds Card */} diff --git a/inventory/src/components/settings/StockManagement.tsx b/inventory/src/components/settings/StockManagement.tsx index 3c13487..f892fcf 100644 --- a/inventory/src/components/settings/StockManagement.tsx +++ b/inventory/src/components/settings/StockManagement.tsx @@ -109,7 +109,7 @@ export function StockManagement() { }; return ( -
+
{/* Stock Thresholds Card */} diff --git a/inventory/src/pages/Settings.tsx b/inventory/src/pages/Settings.tsx index 0fda3bd..8e2124e 100644 --- a/inventory/src/pages/Settings.tsx +++ b/inventory/src/pages/Settings.tsx @@ -9,15 +9,18 @@ export function Settings() {

Settings

-

Manage your inventory system settings and configurations

Data Management Stock Management - Performance Metrics - Calculation Settings + + Performance Metrics + + + Calculation Settings + @@ -38,4 +41,4 @@ export function Settings() {
); -} \ No newline at end of file +}