Export pending data queues to CSV
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 2m26s
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 2m26s
This commit is contained in:
@@ -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 = () => {
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center 2xl:justify-end">
|
||||
<Link
|
||||
to="/registrations"
|
||||
className="inline-flex h-10 items-center justify-center gap-2 rounded-xl border border-dark-border bg-dark-card px-4 text-sm font-bold text-dark-text transition-colors hover:border-brand-primary"
|
||||
<button
|
||||
type="button"
|
||||
onClick={exportActiveQueue}
|
||||
className="inline-flex h-10 items-center justify-center gap-2 rounded-xl border border-dark-border bg-dark-card px-4 text-sm font-bold text-dark-text transition-colors hover:border-brand-primary cursor-pointer"
|
||||
>
|
||||
<PackageSearch className="h-4 w-4 text-brand-primary" />
|
||||
Cadastros
|
||||
</Link>
|
||||
<Download className="h-4 w-4 text-brand-primary" />
|
||||
Exportar CSV
|
||||
</button>
|
||||
<DateRangePicker
|
||||
dateRange={dateRange}
|
||||
onChange={(range) => {
|
||||
|
||||
Reference in New Issue
Block a user