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 + {