mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 16:35:24 +02:00
fix: correctly format weight and kg columns to 2 decimals
This commit is contained in:
+13
-14
@@ -82,16 +82,15 @@ export default function App() {
|
|||||||
const header = (rawHeaders[idx] || '').toLowerCase();
|
const header = (rawHeaders[idx] || '').toLowerCase();
|
||||||
|
|
||||||
// Skip Article No, Barcodes, and other code-like fields
|
// Skip Article No, Barcodes, and other code-like fields
|
||||||
if (header.includes('id') || header.includes('no') || header.includes('code') ||
|
// But allow if it's a weight/measure column (e.g. Article NW (kg))
|
||||||
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
|
if ((header.includes('id') || header.includes('no') || header.includes('code') ||
|
||||||
|
header.includes('art.') || header.includes('barcode') || header.includes('article')) &&
|
||||||
|
!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
|
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
|
||||||
const isPriceCol = priceKeywords.some(kw => header.includes(kw));
|
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
|
||||||
|
|
||||||
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
|
|
||||||
const isWeightCol = header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg');
|
|
||||||
|
|
||||||
if (typeof val === 'number') {
|
if (typeof val === 'number') {
|
||||||
return Number(val.toFixed(2));
|
return Number(val.toFixed(2));
|
||||||
@@ -100,7 +99,7 @@ export default function App() {
|
|||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
const normalized = val.trim().replace(',', '.');
|
const normalized = val.trim().replace(',', '.');
|
||||||
const num = parseFloat(normalized);
|
const num = parseFloat(normalized);
|
||||||
if (!isNaN(num) && (isPriceCol || isWeightCol || val.includes('.') || val.includes(','))) {
|
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
|
||||||
return num.toFixed(2);
|
return num.toFixed(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,14 +157,14 @@ export default function App() {
|
|||||||
|
|
||||||
if (header.includes('id') || header.includes('no') || header.includes('code') ||
|
if (header.includes('id') || header.includes('no') || header.includes('code') ||
|
||||||
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
|
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
|
||||||
|
// But allow if it's a weight/measure column (e.g. Article NW (kg))
|
||||||
|
if (!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
|
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
|
||||||
const isPriceCol = priceKeywords.some(kw => header.includes(kw));
|
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
|
||||||
|
|
||||||
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
|
|
||||||
const isWeightCol = header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg');
|
|
||||||
|
|
||||||
if (typeof val === 'number') {
|
if (typeof val === 'number') {
|
||||||
return Number(val.toFixed(2));
|
return Number(val.toFixed(2));
|
||||||
@@ -174,7 +173,7 @@ export default function App() {
|
|||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
const normalized = val.trim().replace(',', '.');
|
const normalized = val.trim().replace(',', '.');
|
||||||
const num = parseFloat(normalized);
|
const num = parseFloat(normalized);
|
||||||
if (!isNaN(num) && (isPriceCol || isWeightCol || val.includes('.') || val.includes(','))) {
|
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
|
||||||
return num.toFixed(2);
|
return num.toFixed(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,16 +22,15 @@ export function MatrixView({ data, headers }: MatrixViewProps) {
|
|||||||
const h = header.toLowerCase();
|
const h = header.toLowerCase();
|
||||||
|
|
||||||
// Do NOT format columns that are clearly IDs, barcodes, or codes
|
// Do NOT format columns that are clearly IDs, barcodes, or codes
|
||||||
if (h.includes('id') || h.includes('no') || h.includes('code') || h.includes('art.') || h.includes('barcode') || h.includes('article')) {
|
// But allow if it's a weight/measure column (e.g. Article NW (kg))
|
||||||
|
if ((h.includes('id') || h.includes('no') || h.includes('code') || h.includes('art.') || h.includes('barcode') || h.includes('article')) &&
|
||||||
|
!(h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg'))) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of keywords that typically indicate a price or numeric value to format
|
// List of keywords that typically indicate a price, measure or numeric value to format
|
||||||
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
|
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
|
||||||
const isPriceCol = priceKeywords.some(kw => h.includes(kw));
|
const shouldFormat = formatKeywords.some(kw => h.includes(kw));
|
||||||
|
|
||||||
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
|
|
||||||
const isWeightCol = h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg');
|
|
||||||
|
|
||||||
// Handle numbers
|
// Handle numbers
|
||||||
if (typeof val === 'number') {
|
if (typeof val === 'number') {
|
||||||
@@ -45,8 +44,8 @@ export function MatrixView({ data, headers }: MatrixViewProps) {
|
|||||||
const num = parseFloat(normalized);
|
const num = parseFloat(normalized);
|
||||||
|
|
||||||
if (!isNaN(num)) {
|
if (!isNaN(num)) {
|
||||||
// Format if it's a price column, weight column, OR if it already has a decimal separator (.)
|
// Format if header contains keywords OR if it already looks like a decimal
|
||||||
if (isPriceCol || isWeightCol || val.includes('.') || val.includes(',')) {
|
if (shouldFormat || val.includes('.') || val.includes(',')) {
|
||||||
return num.toFixed(2);
|
return num.toFixed(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user