5.0 KiB
5.0 KiB
Metrics System Changes
Schema Changes
Product Identifiers
- Changed
product_idtopidthroughout all metrics tables and queries - Changed
category_idtocat_idin category-related queries
Purchase Orders
- Changed status check from
status = 'closed'toreceiving_status >= 30 - Added comment
-- Partial or fully receivedfor clarity - Now using
received_dateinstead of relying on status changes
New Product Fields
- Added support for
notions_inv_count - Added support for
date_last_sold - Added support for
total_sold - Using
visibleflag for active product counts
Field Size Updates
- Increased size of financial fields to handle larger numbers:
- Changed category metrics
total_valuefromDECIMAL(10,3)toDECIMAL(15,3) - Changed brand metrics financial fields from
DECIMAL(10,2)toDECIMAL(15,2) - Affects
total_stock_cost,total_stock_retail,total_revenue
- Changed category metrics
Metrics File Changes
Product Metrics (product-metrics.js)
- Updated SQL queries to use new field names
- Enhanced stock status calculations
- Added financial metrics:
gross_profitgmroiavg_margin_percentinventory_value
- Improved reorder quantity calculations with:
- Enhanced safety stock calculation
- Lead time consideration
- Service level factors
- Added NaN/NULL value handling:
- Added
sanitizeValuehelper function - Properly converts JavaScript NaN to SQL NULL
- Ensures all numeric fields have valid values
- Added
Vendor Metrics (vendor-metrics.js)
- Updated field references to use
pid - Modified purchase order status checks
- Enhanced vendor performance metrics:
- Order fill rate calculation
- On-time delivery rate
- Lead time tracking
Category Metrics (category-metrics.js)
- Updated to use
cat_idinstead ofcategory_id - Enhanced category performance tracking:
- Active vs total products
- Category growth rate
- Turnover rate
- Added time-based metrics for:
- Product counts
- Revenue tracking
- Margin analysis
- Added NULL brand handling:
- Uses 'Unbranded' for NULL brand values
- Maintains data integrity in category sales metrics
Brand Metrics (brand-metrics.js)
- Updated product references to use
pid - Enhanced brand performance metrics:
- Stock value calculations
- Revenue tracking
- Growth rate analysis
- Added time-based aggregates for:
- Stock levels
- Sales performance
- Margin analysis
- Increased field sizes to handle large retailers
Sales Forecasts (sales-forecasts.js)
- Updated to use new product identifiers
- Enhanced forecast calculations:
- Day-of-week patterns
- Seasonality factors
- Confidence levels
- Added category-level forecasts with:
- Units and revenue predictions
- Confidence scoring
- Seasonal adjustments
Time Aggregates (time-aggregates.js)
- Updated field references to use
pid - Enhanced financial metrics:
- GMROI calculations
- Profit margin tracking
- Added inventory value tracking
- Improved purchase order integration
Database Impact
Tables Modified
product_metricsvendor_metricsvendor_time_metricscategory_metricscategory_time_metricsbrand_metricsbrand_time_metricssales_forecastscategory_forecastsproduct_time_aggregates
New Fields Added
Several tables have new fields for:
- Enhanced financial tracking
- Improved inventory metrics
- Better performance monitoring
- More accurate forecasting
Frontend Considerations
Data Access Changes
- All product lookups need to use
pidinstead ofproduct_id - Category references should use
cat_id - Purchase order status checks need updating
- Handle 'Unbranded' as a valid brand value
New Features Available
- Enhanced stock status indicators
- More detailed financial metrics
- Improved forecasting data
- Better category and brand performance tracking
UI Updates Needed
- Update all API calls to use new field names
- Modify data displays for new metrics
- Add new financial performance indicators
- Update stock status logic
- Enhance forecast displays
API Route Updates Needed
Product Routes
- Update ID field references
- Modify stock status calculations
- Add new financial metrics endpoints
Category Routes
- Update to use
cat_id - Add new performance metrics
- Include time-based aggregates
Vendor Routes
- Update product reference handling
- Add enhanced performance metrics
- Include new time-based data
Reporting Routes
- Update all ID references
- Add new metrics support
- Include enhanced forecasting data
Migration Considerations
Data Migration
- Update existing records to use new IDs
- Backfill new metrics where possible
- Verify data integrity after changes
- Handle NULL to 'Unbranded' brand conversion
Code Updates
- Update all API endpoints
- Modify database queries
- Update frontend components
- Revise reporting logic
Testing Requirements
- Verify ID changes throughout system
- Test new metrics calculations
- Validate forecasting accuracy
- Check performance impact
- Verify NULL value handling