From 8dfbc8ea9e22eb90e0fd9fc7507e1d8a88e83c20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cau=C3=AA=20Faleiros?=
Date: Mon, 24 Aug 2026 10:39:40 -0300
Subject: [PATCH] Export pending data queues to CSV
---
src/pages/PlanningIssues.tsx | 55 ++++++++++++++++++++++++++++++------
1 file changed, 47 insertions(+), 8 deletions(-)
diff --git a/src/pages/PlanningIssues.tsx b/src/pages/PlanningIssues.tsx
index f79a8c4..d104cdb 100644
--- a/src/pages/PlanningIssues.tsx
+++ b/src/pages/PlanningIssues.tsx
@@ -1,13 +1,13 @@
import { useEffect, useMemo, useState } from 'react';
import { Link, useOutletContext } from 'react-router-dom';
-import { AlertTriangle, CheckCircle2, Eye, PackageSearch, Pencil, Search } from 'lucide-react';
+import { AlertTriangle, CheckCircle2, Download, Eye, PackageSearch, Pencil, Search } from 'lucide-react';
import DateRangePicker from '../components/DateRangePicker';
import PaginationControls from '../components/PaginationControls';
import ProductTypeBadge from '../components/ProductTypeBadge';
import RefreshStatus from '../components/RefreshStatus';
import SkuPlanningModal from '../components/SkuPlanningModal';
import { classifyCutFamily, CUT_FAMILY_RULES, type CutFamilyKey } from '../analytics/cutting';
-import { fetchCuttingSettings, fetchProductAnalytics, fetchStock, fetchSupplySummary, saveCuttingSettings } from '../dataService';
+import { exportToCSV, fetchCuttingSettings, fetchProductAnalytics, fetchStock, fetchSupplySummary, saveCuttingSettings } from '../dataService';
import { getProductTypeConfig, resolveProductType, type ProductTypeKey } from '../productClassification';
import { parseProductName } from '../productParsing';
import type { CutProductOverride, CuttingSettings, DateRange, ProductAnalyticsItem, StockData, SupplySummary } from '../types';
@@ -284,6 +284,44 @@ const PlanningIssues = () => {
}
};
+ const exportActiveQueue = () => {
+ const dateSuffix = new Date().toISOString().slice(0, 10);
+
+ if (activeQueue === 'negative_stock') {
+ exportToCSV(visibleNegativeStockRows.map(row => ({
+ sku: row.produto_id,
+ material: row.nome,
+ saldo_informado: Number(row.saldo || 0),
+ planejamento: 'Usa 0 disponível'
+ })), `saldos-negativos-${dateSuffix}`);
+ return;
+ }
+
+ if (activeQueue === 'missing_composition') {
+ exportToCSV(visibleMissingCompositionRows.map(row => ({
+ sku: row.productId,
+ produto: row.name,
+ vendido: row.quantitySold,
+ estoque: row.stockQuantity,
+ corte_sugerido: row.suggestedQuantity,
+ pendencia: 'Sem composição confiável'
+ })), `skus-sem-composicao-${dateSuffix}`);
+ return;
+ }
+
+ exportToCSV(rows.map(row => ({
+ sku: row.id,
+ produto: row.name,
+ tipo: getProductTypeConfig(row.productType).label,
+ familia: row.familyLabel,
+ cor: row.color || 'Não informado',
+ tamanho: row.size || 'Não informado',
+ pendencias: row.issues.map(issue => issueLabels[issue]).join(', '),
+ vendido: row.quantitySold,
+ estoque: row.stockQuantity
+ })), `cadastro-para-corte-${dateSuffix}`);
+ };
+
const activeRowCount = activeQueue === 'negative_stock'
? visibleNegativeStockRows.length
: activeQueue === 'missing_composition'
@@ -307,13 +345,14 @@ const PlanningIssues = () => {
-
-
- Cadastros
-
+
+ Exportar CSV
+
{