3import { useState, useEffect } from 'react';
4import { Icon } from '@/contexts/IconContext';
6interface LowPricedProduct {
16export default function ProductsPricedLowReport() {
17 const [products, setProducts] = useState<LowPricedProduct[]>([]);
18 const [loading, setLoading] = useState(true);
19 const [error, setError] = useState<string | null>(null);
20 const [totalProducts, setTotalProducts] = useState(0);
26 const fetchProducts = async () => {
31 const response = await fetch('/api/v1/elink/advisor/products-priced-low');
32 const data = await response.json();
35 throw new Error(data.error || 'Failed to fetch products');
38 setProducts(data.products || []);
39 setTotalProducts(data.totalProducts || 0);
41 console.error('Error fetching products:', err);
42 setError(err.message);
50 <div className="p-6 min-h-screen bg-bg">
51 <div className="mb-6">
52 <div className="flex items-center gap-3 mb-2">
53 <a href="/pages/reports?source=advisor" className="text-muted hover:text-brand">
54 <Icon name="arrow_back" size={24} />
56 <h1 className="text-3xl font-bold text-text">Products Priced Below Cost</h1>
58 <p className="text-muted ml-9">
59 Products with selling prices below their cost price
62 <div className="flex items-center justify-center py-12">
63 <div className="text-center">
64 <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-brand mx-auto mb-4"></div>
65 <p className="text-muted">Analyzing product pricing...</p>
74 <div className="p-6 min-h-screen bg-bg">
75 <div className="mb-6">
76 <div className="flex items-center gap-3 mb-2">
77 <a href="/pages/reports?source=advisor" className="text-muted hover:text-brand">
78 <Icon name="arrow_back" size={24} />
80 <h1 className="text-3xl font-bold text-text">Products Priced Below Cost</h1>
83 <div className="bg-surface rounded-lg shadow-sm border border-border p-6">
84 <div className="flex items-center gap-3 text-error mb-4">
85 <Icon name="error" size={24} />
86 <span className="font-medium">Error loading products</span>
88 <p className="text-muted mb-4">{error}</p>
90 onClick={fetchProducts}
91 className="px-4 py-2 bg-brand text-white rounded hover:bg-brand2"
101 <div className="p-6 min-h-screen bg-bg">
102 <div className="mb-6">
103 <div className="flex items-center gap-3 mb-2">
104 <a href="/pages/reports?source=advisor" className="text-muted hover:text-brand">
105 <Icon name="arrow_back" size={24} />
107 <h1 className="text-3xl font-bold text-text">Products Priced Below Cost</h1>
109 <p className="text-muted ml-9">
110 Products with selling prices below their cost price
112 {totalProducts > 0 && (
113 <p className="text-muted text-sm ml-9 mt-1">
114 Analyzed {totalProducts} products • Found {products.length} priced below cost
119 <div className="bg-surface rounded-lg shadow-sm border border-border overflow-hidden">
120 <div className="overflow-x-auto">
121 <table className="w-full">
122 <thead className="bg-[var(--brand)] text-surface">
124 <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">
127 <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">
130 <th className="px-6 py-3 text-right text-xs font-medium uppercase tracking-wider">
133 <th className="px-6 py-3 text-right text-xs font-medium uppercase tracking-wider">
136 <th className="px-6 py-3 text-right text-xs font-medium uppercase tracking-wider">
139 <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">
142 <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">
147 <tbody className="divide-y divide-border">
148 {products.length === 0 ? (
150 <td colSpan={7} className="px-6 py-12 text-center">
151 <Icon name="check_circle" size={48} className="text-success mx-auto mb-3" />
152 <p className="text-muted">All products are priced correctly</p>
153 <p className="text-muted text-sm mt-2">No products found with sell price below cost</p>
157 products.map((product) => (
158 <tr key={product.id} className="hover:bg-surface-2">
159 <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-text">
160 {product.sku || <span className="text-muted italic">No SKU</span>}
162 <td className="px-6 py-4 text-sm text-text">
165 <td className="px-6 py-4 whitespace-nowrap text-sm text-right text-muted">
166 ${product.cost.toFixed(2)}
168 <td className="px-6 py-4 whitespace-nowrap text-sm text-right text-error">
169 ${product.sellPrice.toFixed(2)}
171 <td className="px-6 py-4 whitespace-nowrap text-right">
172 <span className={`px-2 py-1 text-xs font-medium rounded ${
173 product.margin < -10 ? 'bg-error/20 text-error' :
174 product.margin < -5 ? 'bg-warning/20 text-warning' :
175 'bg-surface-2 text-muted'
177 {product.margin.toFixed(1)}%
180 <td className="px-6 py-4 text-sm text-muted">
181 {product.salesInfo || <span className="text-muted italic">-</span>}
183 <td className="px-6 py-4 whitespace-nowrap text-sm space-x-3">
185 href={`/pages/products/${product.id}`}
186 className="text-brand hover:text-brand2"
191 href={`/pages/products/${product.id}`}
192 className="text-info hover:text-info/80"