Improve planning data normalization
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m25s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m25s
This commit is contained in:
@@ -11,6 +11,7 @@ import { exportToCSV, fetchCuttingSettings, fetchProductAnalytics, saveCuttingSe
|
||||
import { encodeProductGroupKey, parseProductName, sortProductSizes } from '../productParsing';
|
||||
import { formatColorLabel } from '../displayFormatters';
|
||||
import { getDominantProductType, getProductTypeConfig, productTypeOptions, resolveProductType, type ProductTypeKey } from '../productClassification';
|
||||
import { getPlanningStock } from '../planningStock';
|
||||
|
||||
type StockRisk = 'rupture' | 'critical' | 'attention' | 'monitor' | 'healthy' | 'no_sales';
|
||||
type StockStatusFilter = 'all' | StockRisk;
|
||||
@@ -262,7 +263,8 @@ const Products = () => {
|
||||
const normalizedSearch = searchTerm.trim().toLowerCase();
|
||||
const skuRows = productAnalytics.map(product => {
|
||||
const dailySales = product.quantitySold / days;
|
||||
const risk = classifyStockRisk(product.stock, dailySales);
|
||||
const planningStock = getPlanningStock(product.stock);
|
||||
const risk = classifyStockRisk(planningStock, dailySales);
|
||||
const style = riskStyles[risk];
|
||||
const metadata = parseProductName(product.name);
|
||||
const productType = resolveProductType(product.name, planningSettings.productOverrides[product.id]);
|
||||
@@ -270,7 +272,7 @@ const Products = () => {
|
||||
return {
|
||||
...product,
|
||||
dailySales,
|
||||
daysOfCover: dailySales > 0 ? product.stock / dailySales : null,
|
||||
daysOfCover: dailySales > 0 ? planningStock / dailySales : null,
|
||||
risk,
|
||||
riskLabel: style.label,
|
||||
baseName: metadata.baseName,
|
||||
@@ -302,10 +304,11 @@ const Products = () => {
|
||||
const quantitySold = group.reduce((total, product) => total + product.quantitySold, 0);
|
||||
const revenue = group.reduce((total, product) => total + product.revenue, 0);
|
||||
const stock = group.reduce((total, product) => total + product.stock, 0);
|
||||
const planningStock = group.reduce((total, product) => total + getPlanningStock(product.stock), 0);
|
||||
const orderLineCount = group.reduce((total, product) => total + product.orderLineCount, 0);
|
||||
const dailySales = quantitySold / days;
|
||||
const daysOfCover = dailySales > 0 ? stock / dailySales : null;
|
||||
const risk = classifyStockRisk(stock, dailySales);
|
||||
const daysOfCover = dailySales > 0 ? planningStock / dailySales : null;
|
||||
const risk = classifyStockRisk(planningStock, dailySales);
|
||||
const style = riskStyles[risk];
|
||||
const colorTotals = new Map<string, number>();
|
||||
const sizeTotals = new Map<string, number>();
|
||||
|
||||
Reference in New Issue
Block a user