🚀 Auto-deploy: GPI atualizado em 03/04/2026 20:05:48

This commit is contained in:
2026-04-03 20:05:48 +00:00
parent 242d67c509
commit 34f60b25e6
3 changed files with 57 additions and 53 deletions

View File

@@ -79,11 +79,12 @@ export const StockDashboard: React.FC = () => {
await Promise.all( await Promise.all(
items.map(async (item) => { items.map(async (item) => {
try { try {
const movements = await stockService.getMovements(item._id!); const itemId = item.id || (item as any)._id;
movementsMap.set(item._id!, movements); if (!itemId) return;
const movements = await stockService.getMovements(itemId);
movementsMap.set(itemId, movements);
} catch (error) { } catch (error) {
console.error(`Error fetching movements for ${item._id}:`, error); console.error(`Error fetching movements for ${item.id}:`, error);
movementsMap.set(item._id!, []);
} }
}) })
); );
@@ -117,8 +118,8 @@ export const StockDashboard: React.FC = () => {
const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : ''; const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : '';
return ( return (
item.rrNumber.toLowerCase().includes(searchLower) || (item.rrNumber || '').toLowerCase().includes(searchLower) ||
item.batchNumber.toLowerCase().includes(searchLower) || (item.batchNumber || '').toLowerCase().includes(searchLower) ||
productName.toLowerCase().includes(searchLower) || productName.toLowerCase().includes(searchLower) ||
manufacturer.toLowerCase().includes(searchLower) manufacturer.toLowerCase().includes(searchLower)
); );
@@ -130,7 +131,8 @@ export const StockDashboard: React.FC = () => {
filteredItems.forEach(item => { filteredItems.forEach(item => {
const productName = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).name : 'Unknown'; const productName = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).name : 'Unknown';
const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : ''; const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : '';
const key = `${(item.dataSheetId as any)._id || item.dataSheetId}-${item.color}`; const dsId = (item.dataSheetId as any).id || (item.dataSheetId as any)._id || item.dataSheetId;
const key = `${dsId}-${item.color}`;
if (!groups.has(key)) { if (!groups.has(key)) {
groups.set(key, { groups.set(key, {
@@ -295,7 +297,7 @@ export const StockDashboard: React.FC = () => {
<td className="px-6 py-4 font-bold text-lg"> <td className="px-6 py-4 font-bold text-lg">
<span className={isLowStock ? 'text-red-500 animate-blink flex items-center gap-2' : 'text-green-500'}> <span className={isLowStock ? 'text-red-500 animate-blink flex items-center gap-2' : 'text-green-500'}>
{isLowStock && <AlertCircle size={16} />} {isLowStock && <AlertCircle size={16} />}
{group.totalQty.toFixed(1)} {group.unit} {(group.totalQty || 0).toFixed(1)} {group.unit}
</span> </span>
{group.minStock > 0 && ( {group.minStock > 0 && (
<span className="block text-[10px] text-text-muted font-normal"> <span className="block text-[10px] text-text-muted font-normal">
@@ -313,11 +315,11 @@ export const StockDashboard: React.FC = () => {
{/* Expanded Item Rows */} {/* Expanded Item Rows */}
{isExpanded && group.items.map(item => { {isExpanded && group.items.map(item => {
const itemId = item.id || (item as any)._id;
const isExpired = item.expirationDate && new Date(item.expirationDate) < new Date(); const isExpired = item.expirationDate && new Date(item.expirationDate) < new Date();
// Check individual item min stock for legacy reasons? No, rely on group.
return ( return (
<tr key={item._id} className="bg-surface-soft/50 hover:bg-surface-hover/80 transition-colors border-l-4 border-l-primary/20"> <tr key={itemId} className="bg-surface-soft/50 hover:bg-surface-hover/80 transition-colors border-l-4 border-l-primary/20">
<td className="px-6 py-3"></td> {/* Indentation */} <td className="px-6 py-3"></td> {/* Indentation */}
<td className="px-6 py-3 font-mono text-xs text-text-muted"> <td className="px-6 py-3 font-mono text-xs text-text-muted">
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
@@ -371,7 +373,7 @@ export const StockDashboard: React.FC = () => {
<Edit size={16} /> <Edit size={16} />
</button> </button>
<button <button
onClick={(e) => { e.stopPropagation(); handleDelete(item._id!); }} onClick={(e) => { e.stopPropagation(); handleDelete(itemId!); }}
className="p-1.5 text-red-500 hover:bg-red-500/10 rounded-lg" className="p-1.5 text-red-500 hover:bg-red-500/10 rounded-lg"
title="Excluir" title="Excluir"
> >

View File

@@ -287,7 +287,7 @@ export const YieldStudyDashboard: React.FC = () => {
const dilutionFactor = 100 - study.dilutionPercent; const dilutionFactor = 100 - study.dilutionPercent;
const svFactor = sv * dilutionFactor; const svFactor = sv * dilutionFactor;
const calculatedEpu = svFactor > 0 const calculatedEpu = svFactor > 0
? Number((study.targetDft * 10000 / svFactor).toFixed(1)) ? Number((((study.targetDft || 0) * 10000) / svFactor).toFixed(1))
: 0; : 0;
let totalWeight = 0; let totalWeight = 0;
@@ -320,8 +320,8 @@ export const YieldStudyDashboard: React.FC = () => {
return { return {
...cat, ...cat,
litrosPeso: Number(litrosPeso.toFixed(2)), litrosPeso: Number((litrosPeso || 0).toFixed(2)),
litrosArea: litrosArea > 0 ? Number(litrosArea.toFixed(2)) : undefined litrosArea: litrosArea > 0 ? Number((litrosArea || 0).toFixed(2)) : undefined
}; };
}); });
@@ -332,10 +332,10 @@ export const YieldStudyDashboard: React.FC = () => {
...study, ...study,
categories: updatedCategories, categories: updatedCategories,
totalWeight, totalWeight,
estimatedPaintVolume: Number(totalVolumeByWeight.toFixed(2)), estimatedPaintVolume: Number((totalVolumeByWeight || 0).toFixed(2)),
estimatedReducerVolume: Number(reducerVolByWeight.toFixed(2)), estimatedReducerVolume: Number((reducerVolByWeight || 0).toFixed(2)),
estimatedPaintVolumeByArea: Number(totalVolumeByArea.toFixed(2)), estimatedPaintVolumeByArea: Number((totalVolumeByArea || 0).toFixed(2)),
estimatedReducerVolumeByArea: Number(reducerVolByArea.toFixed(2)), estimatedReducerVolumeByArea: Number((reducerVolByArea || 0).toFixed(2)),
calculatedEpu: calculatedEpu calculatedEpu: calculatedEpu
} as YieldStudy & { calculatedEpu: number }); } as YieldStudy & { calculatedEpu: number });
}; };
@@ -353,11 +353,11 @@ export const YieldStudyDashboard: React.FC = () => {
// Data for deviation projection // Data for deviation projection
// Data for deviation projection - Lógica Direta (Mais DFT = Mais Tinta) // Data for deviation projection - Lógica Direta (Mais DFT = Mais Tinta)
const projectionData = selectedStudy ? [ const projectionData = selectedStudy ? [
{ dft: (selectedStudy.targetDft * 0.8).toFixed(0), vol: Number((selectedStudy.estimatedPaintVolume * 0.8).toFixed(1)), label: `-20%` }, { dft: ((selectedStudy.targetDft || 0) * 0.8).toFixed(0), vol: Number(((selectedStudy.estimatedPaintVolume || 0) * 0.8).toFixed(1)), label: `-20%` },
{ dft: (selectedStudy.targetDft * 0.9).toFixed(0), vol: Number((selectedStudy.estimatedPaintVolume * 0.9).toFixed(1)), label: `-10%` }, { dft: ((selectedStudy.targetDft || 0) * 0.9).toFixed(0), vol: Number(((selectedStudy.estimatedPaintVolume || 0) * 0.9).toFixed(1)), label: `-10%` },
{ dft: selectedStudy.targetDft.toFixed(0), vol: selectedStudy.estimatedPaintVolume, label: 'ALVO' }, { dft: (selectedStudy.targetDft || 0).toFixed(0), vol: (selectedStudy.estimatedPaintVolume || 0), label: 'ALVO' },
{ dft: (selectedStudy.targetDft * 1.1).toFixed(0), vol: Number((selectedStudy.estimatedPaintVolume * 1.1).toFixed(1)), label: '+10%' }, { dft: ((selectedStudy.targetDft || 0) * 1.1).toFixed(0), vol: Number(((selectedStudy.estimatedPaintVolume || 0) * 1.1).toFixed(1)), label: '+10%' },
{ dft: (selectedStudy.targetDft * 1.3).toFixed(0), vol: Number((selectedStudy.estimatedPaintVolume * 1.3).toFixed(1)), label: '+30%' }, { dft: ((selectedStudy.targetDft || 0) * 1.3).toFixed(0), vol: Number(((selectedStudy.estimatedPaintVolume || 0) * 1.3).toFixed(1)), label: '+30%' },
] : []; ] : [];
if (loading) return <div className="p-8 text-center text-text-muted">Carregando estudos...</div>; if (loading) return <div className="p-8 text-center text-text-muted">Carregando estudos...</div>;
@@ -466,11 +466,11 @@ export const YieldStudyDashboard: React.FC = () => {
<div className="grid grid-cols-2 gap-4"> <div className="grid grid-cols-2 gap-4">
<div className="flex flex-col"> <div className="flex flex-col">
<span className="text-[9px] font-black text-text-muted uppercase tracking-[0.2em] mb-1">Carga Total</span> <span className="text-[9px] font-black text-text-muted uppercase tracking-[0.2em] mb-1">Carga Total</span>
<span className="text-sm font-black text-text-main">{study.totalWeight.toFixed(1)} t</span> <span className="text-sm font-black text-text-main">{(study.totalWeight || 0).toFixed(1)} t</span>
</div> </div>
<div className="flex flex-col"> <div className="flex flex-col">
<span className="text-[9px] font-black text-text-muted uppercase tracking-[0.2em] mb-1">Target DFT</span> <span className="text-[9px] font-black text-text-muted uppercase tracking-[0.2em] mb-1">Target DFT</span>
<span className="text-sm font-black text-text-main">{study.targetDft} <span className="text-[10px] text-text-muted">μm</span></span> <span className="text-sm font-black text-text-main">{(study.targetDft || 0)} <span className="text-[10px] text-text-muted">μm</span></span>
</div> </div>
</div> </div>
</div> </div>
@@ -558,9 +558,9 @@ export const YieldStudyDashboard: React.FC = () => {
const sheet = findSheet(selectedStudy.dataSheetId); const sheet = findSheet(selectedStudy.dataSheetId);
let sv = sheet?.solidsVolume || 60; let sv = sheet?.solidsVolume || 60;
if (sv <= 1) sv *= 100; if (sv <= 1) sv *= 100;
const dilFactor = 100 - selectedStudy.dilutionPercent; const dilFactor = 100 - (selectedStudy.dilutionPercent || 0);
const svFactor = sv * dilFactor; const svFactor = sv * dilFactor;
return svFactor > 0 ? (selectedStudy.targetDft * 10000 / svFactor).toFixed(1) : '0'; return svFactor > 0 ? ((selectedStudy.targetDft || 0) * 10000 / svFactor).toFixed(1) : '0';
})() })()
} <span className="text-xs">µm</span> } <span className="text-xs">µm</span>
</div> </div>
@@ -572,19 +572,19 @@ export const YieldStudyDashboard: React.FC = () => {
const hasRealSV = sheet?.solidsVolume && sheet.solidsVolume > 0; const hasRealSV = sheet?.solidsVolume && sheet.solidsVolume > 0;
let sv = sheet?.solidsVolume || 60; let sv = sheet?.solidsVolume || 60;
if (sv <= 1) sv *= 100; if (sv <= 1) sv *= 100;
return ( return (
<> <>
<span className={`text-[9px] font-black uppercase tracking-wider ${hasRealSV ? 'text-success' : 'text-amber-500'}`}> <span className={`text-[9px] font-black uppercase tracking-wider ${hasRealSV ? 'text-success' : 'text-amber-500'}`}>
SV da Tinta {hasRealSV ? '✓' : '⚠️'} SV da Tinta {hasRealSV ? '✓' : '⚠️'}
</span> </span>
<div className={`text-2xl font-black leading-none ${hasRealSV ? 'text-text-main' : 'text-amber-500'}`}> <div className={`text-2xl font-black leading-none ${hasRealSV ? 'text-text-main' : 'text-amber-500'}`}>
{sv.toFixed(0)} <span className="text-xs">%</span> {(sv || 0).toFixed(0)} <span className="text-xs">%</span>
</div> </div>
<span className="text-[8px] text-text-muted"> <span className="text-[8px] text-text-muted">
{hasRealSV ? 'Sólidos por Volume' : 'Valor padrão (edite a ficha)'} {hasRealSV ? 'Sólidos por Volume' : 'Valor padrão (edite a ficha)'}
</span> </span>
</> </>
); );
})()} })()}
</div> </div>
</div> </div>
@@ -617,13 +617,13 @@ export const YieldStudyDashboard: React.FC = () => {
<div className="flex justify-between items-center"> <div className="flex justify-between items-center">
<span className="text-[10px] font-bold text-text-muted uppercase">Taxa Média</span> <span className="text-[10px] font-bold text-text-muted uppercase">Taxa Média</span>
<span className="text-sm font-black text-text-main"> <span className="text-sm font-black text-text-main">
{selectedStudy.totalWeight > 0 ? ((selectedStudy.estimatedPaintVolume / selectedStudy.totalWeight).toFixed(2)) : '0.00'} <span className="text-[10px] text-text-muted">L/t</span> {selectedStudy.totalWeight > 0 ? (((selectedStudy.estimatedPaintVolume || 0) / selectedStudy.totalWeight).toFixed(2)) : '0.00'} <span className="text-[10px] text-text-muted">L/t</span>
</span> </span>
</div> </div>
<div className="flex justify-between items-center"> <div className="flex justify-between items-center">
<span className="text-[10px] font-bold text-text-muted uppercase">Peso Total</span> <span className="text-[10px] font-bold text-text-muted uppercase">Peso Total</span>
<span className="text-sm font-black text-primary"> <span className="text-sm font-black text-primary">
{selectedStudy.totalWeight.toFixed(2)} TON {(selectedStudy.totalWeight || 0).toFixed(2)} TON
</span> </span>
</div> </div>
</div> </div>
@@ -926,7 +926,7 @@ export const YieldStudyDashboard: React.FC = () => {
<div className="grid grid-cols-4 gap-4 mb-8"> <div className="grid grid-cols-4 gap-4 mb-8">
<div className="border border-gray-300 rounded-xl p-4 space-y-1"> <div className="border border-gray-300 rounded-xl p-4 space-y-1">
<span className="text-[8px] font-black text-gray-500 uppercase tracking-widest">Peso Total (Ton)</span> <span className="text-[8px] font-black text-gray-500 uppercase tracking-widest">Peso Total (Ton)</span>
<div className="text-xl font-black">{selectedStudy.totalWeight.toFixed(2)}</div> <div className="text-xl font-black">{(selectedStudy.totalWeight || 0).toFixed(2)}</div>
<p className="text-[7px] text-gray-400 font-bold uppercase">Soma das categorias</p> <p className="text-[7px] text-gray-400 font-bold uppercase">Soma das categorias</p>
</div> </div>
<div className="border border-gray-300 rounded-xl p-4 space-y-1"> <div className="border border-gray-300 rounded-xl p-4 space-y-1">
@@ -941,7 +941,7 @@ export const YieldStudyDashboard: React.FC = () => {
</div> </div>
<div className="border border-gray-300 rounded-xl p-4 space-y-1 border-black bg-gray-50"> <div className="border border-gray-300 rounded-xl p-4 space-y-1 border-black bg-gray-50">
<span className="text-[8px] font-black text-gray-500 uppercase tracking-widest">Taxa Média</span> <span className="text-[8px] font-black text-gray-500 uppercase tracking-widest">Taxa Média</span>
<div className="text-xl font-black">{selectedStudy.totalWeight > 0 ? (selectedStudy.estimatedPaintVolume / selectedStudy.totalWeight).toFixed(2) : '0.00'} <span className="text-[10px]">L/t</span></div> <div className="text-xl font-black">{selectedStudy.totalWeight > 0 ? ((selectedStudy.estimatedPaintVolume || 0) / selectedStudy.totalWeight).toFixed(2) : '0.00'} <span className="text-[10px]">L/t</span></div>
<p className="text-[7px] text-gray-400 font-bold uppercase">Rendimento Global</p> <p className="text-[7px] text-gray-400 font-bold uppercase">Rendimento Global</p>
</div> </div>
</div> </div>
@@ -969,7 +969,7 @@ export const YieldStudyDashboard: React.FC = () => {
<td className="py-3 pr-4"> <td className="py-3 pr-4">
<div className="text-[11px] font-black text-gray-800">{cat.name}</div> <div className="text-[11px] font-black text-gray-800">{cat.name}</div>
</td> </td>
<td className="py-3 text-center text-[10px] font-bold text-amber-700">{cat.weight.toFixed(2)}</td> <td className="py-3 text-center text-[10px] font-bold text-amber-700">{(cat.weight || 0).toFixed(2)}</td>
<td className="py-3 text-center text-[10px] font-bold text-blue-700">{cat.area ? Math.round(cat.area) : '--'}</td> <td className="py-3 text-center text-[10px] font-bold text-blue-700">{cat.area ? Math.round(cat.area) : '--'}</td>
<td className="py-3 text-center text-[10px] font-bold text-amber-700">{cat.historicalYield}</td> <td className="py-3 text-center text-[10px] font-bold text-amber-700">{cat.historicalYield}</td>
<td className="py-3 text-center text-[10px] font-bold text-blue-700">{cat.efficiency}%</td> <td className="py-3 text-center text-[10px] font-bold text-blue-700">{cat.efficiency}%</td>

View File

@@ -1,11 +1,12 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { supabase } from '../config/supabase.js'; import { supabase } from '../config/supabase.js';
import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
export const getAllStudies = async (req: Request, res: Response) => { export const getAllStudies = async (req: Request, res: Response) => {
try { try {
const { data, error } = await supabase.from('yield_studies').select('*'); const { data, error } = await supabase.from('yield_studies').select('*');
if (error && error.code !== '42P01') throw error; if (error && error.code !== '42P01') throw error;
res.json(data || []); res.json(toCamelCase(data || []));
} catch (error: unknown) { } catch (error: unknown) {
res.json([]); res.json([]);
} }
@@ -13,15 +14,16 @@ export const getAllStudies = async (req: Request, res: Response) => {
export const createStudy = async (req: Request, res: Response) => { export const createStudy = async (req: Request, res: Response) => {
try { try {
const payload = { ...req.body, organization_id: req.appUser?.organizationId };
const { data, error } = await supabase const { data, error } = await supabase
.from('yield_studies') .from('yield_studies')
.insert({ ...req.body, organization_id: req.appUser?.organizationId }) .insert(toSnakeCase(payload))
.select() .select()
.single(); .single();
if (error) throw error; if (error) throw error;
res.status(201).json(data); res.status(201).json(toCamelCase(data));
} catch (error: unknown) { } catch (error: unknown) {
res.json(req.body); res.status(400).json({ error: (error as any).message });
} }
}; };
@@ -29,14 +31,14 @@ export const updateStudy = async (req: Request, res: Response) => {
try { try {
const { data, error } = await supabase const { data, error } = await supabase
.from('yield_studies') .from('yield_studies')
.update(req.body) .update(toSnakeCase(req.body))
.eq('id', req.params.id) .eq('id', req.params.id)
.select() .select()
.single(); .single();
if (error) throw error; if (error) throw error;
res.json(data); res.json(toCamelCase(data));
} catch (error: unknown) { } catch (error: unknown) {
res.json(req.body); res.status(400).json({ error: (error as any).message });
} }
}; };
@@ -45,6 +47,6 @@ export const deleteStudy = async (req: Request, res: Response) => {
await supabase.from('yield_studies').delete().eq('id', req.params.id); await supabase.from('yield_studies').delete().eq('id', req.params.id);
res.status(204).send(); res.status(204).send();
} catch (error: unknown) { } catch (error: unknown) {
res.status(204).send(); res.status(500).json({ error: (error as any).message });
} }
}; };