Merge 2500278b1f into 8cb0b72474
This commit is contained in:
commit
c69629bece
|
|
@ -3,6 +3,7 @@ using line_gestao_api.Data;
|
||||||
using line_gestao_api.Dtos;
|
using line_gestao_api.Dtos;
|
||||||
using line_gestao_api.Models;
|
using line_gestao_api.Models;
|
||||||
using line_gestao_api.Services;
|
using line_gestao_api.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
@ -503,6 +504,7 @@ namespace line_gestao_api.Controllers
|
||||||
// ✅ 8. IMPORT EXCEL
|
// ✅ 8. IMPORT EXCEL
|
||||||
// ==========================================================
|
// ==========================================================
|
||||||
[HttpPost("import-excel")]
|
[HttpPost("import-excel")]
|
||||||
|
[Authorize]
|
||||||
[Consumes("multipart/form-data")]
|
[Consumes("multipart/form-data")]
|
||||||
[RequestSizeLimit(50_000_000)]
|
[RequestSizeLimit(50_000_000)]
|
||||||
public async Task<ActionResult<ImportResultDto>> ImportExcel([FromForm] ImportExcelForm form)
|
public async Task<ActionResult<ImportResultDto>> ImportExcel([FromForm] ImportExcelForm form)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
namespace line_gestao_api.Dtos;
|
namespace line_gestao_api.Dtos;
|
||||||
|
|
||||||
public sealed class ParcelamentoListDto
|
public class ParcelamentoListDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public int? AnoRef { get; set; }
|
public int? AnoRef { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,15 @@ public sealed class ParcelamentosImportService
|
||||||
var map = BuildHeaderMap(headerRow);
|
var map = BuildHeaderMap(headerRow);
|
||||||
|
|
||||||
var colLinha = GetCol(map, "LINHA");
|
var colLinha = GetCol(map, "LINHA");
|
||||||
|
var colAnoRef = GetColAny(map, "ANO REF", "ANOREF", "ANO REF.", "ANO REFERENCIA", "ANO REFERÊNCIA");
|
||||||
|
var colItem = GetCol(map, "ITEM");
|
||||||
var colCliente = GetCol(map, "CLIENTE");
|
var colCliente = GetCol(map, "CLIENTE");
|
||||||
var colQtParcelas = GetColAny(map, "QT PARCELAS", "QT. PARCELAS", "QT PARCELAS (NN/TT)", "QTDE PARCELAS");
|
var colQtParcelas = GetColAny(map, "QT PARCELAS", "QT. PARCELAS", "QT PARCELAS (NN/TT)", "QTDE PARCELAS");
|
||||||
var colValorCheio = GetColAny(map, "VALOR CHEIO");
|
var colValorCheio = GetColAny(map, "VALOR CHEIO");
|
||||||
var colDesconto = GetColAny(map, "DESCONTO");
|
var colDesconto = GetColAny(map, "DESCONTO");
|
||||||
var colValorComDesconto = GetColAny(map, "VALOR C/ DESCONTO", "VALOR COM DESCONTO");
|
var colValorComDesconto = GetColAny(map, "VALOR C/ DESCONTO", "VALOR COM DESCONTO");
|
||||||
|
|
||||||
if (colLinha == 0 || colValorComDesconto == 0)
|
if (colLinha == 0 || colValorComDesconto == 0 || colAnoRef == 0 || colItem == 0)
|
||||||
{
|
{
|
||||||
return new ParcelamentosImportSummaryDto
|
return new ParcelamentosImportSummaryDto
|
||||||
{
|
{
|
||||||
|
|
@ -77,7 +79,7 @@ public sealed class ParcelamentosImportService
|
||||||
new ParcelamentosImportErrorDto
|
new ParcelamentosImportErrorDto
|
||||||
{
|
{
|
||||||
LinhaExcel = headerRowIndex,
|
LinhaExcel = headerRowIndex,
|
||||||
Motivo = "Colunas obrigatórias não encontradas (LINHA / VALOR C/ DESCONTO)."
|
Motivo = "Colunas obrigatórias não encontradas (LINHA / ANO REF / ITEM / VALOR C/ DESCONTO)."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -99,7 +101,7 @@ public sealed class ParcelamentosImportService
|
||||||
for (int row = headerRowIndex + 1; row <= lastRow; row++)
|
for (int row = headerRowIndex + 1; row <= lastRow; row++)
|
||||||
{
|
{
|
||||||
var linhaValue = GetCellString(ws, row, colLinha);
|
var linhaValue = GetCellString(ws, row, colLinha);
|
||||||
var itemStr = GetCellString(ws, row, 4);
|
var itemStr = GetCellString(ws, row, colItem);
|
||||||
if (string.IsNullOrWhiteSpace(itemStr) && string.IsNullOrWhiteSpace(linhaValue))
|
if (string.IsNullOrWhiteSpace(itemStr) && string.IsNullOrWhiteSpace(linhaValue))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
@ -107,7 +109,7 @@ public sealed class ParcelamentosImportService
|
||||||
|
|
||||||
summary.Lidos++;
|
summary.Lidos++;
|
||||||
|
|
||||||
var anoRef = TryNullableInt(GetCellString(ws, row, 3));
|
var anoRef = TryNullableInt(GetCellString(ws, row, colAnoRef));
|
||||||
var item = TryNullableInt(itemStr);
|
var item = TryNullableInt(itemStr);
|
||||||
|
|
||||||
if (!item.HasValue)
|
if (!item.HasValue)
|
||||||
|
|
@ -127,7 +129,7 @@ public sealed class ParcelamentosImportService
|
||||||
{
|
{
|
||||||
LinhaExcel = row,
|
LinhaExcel = row,
|
||||||
Motivo = "AnoRef inválido ou vazio.",
|
Motivo = "AnoRef inválido ou vazio.",
|
||||||
Valor = GetCellString(ws, row, 3)
|
Valor = GetCellString(ws, row, colAnoRef)
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +203,12 @@ public sealed class ParcelamentosImportService
|
||||||
private static IXLWorksheet? FindWorksheet(XLWorkbook wb)
|
private static IXLWorksheet? FindWorksheet(XLWorkbook wb)
|
||||||
{
|
{
|
||||||
return wb.Worksheets.FirstOrDefault(w => NormalizeHeader(w.Name) == NormalizeHeader("PARCELAMENTOS DE APARELHOS"))
|
return wb.Worksheets.FirstOrDefault(w => NormalizeHeader(w.Name) == NormalizeHeader("PARCELAMENTOS DE APARELHOS"))
|
||||||
?? wb.Worksheets.FirstOrDefault(w => NormalizeHeader(w.Name) == NormalizeHeader("PARCELAMENTOS"));
|
?? wb.Worksheets.FirstOrDefault(w => NormalizeHeader(w.Name) == NormalizeHeader("PARCELAMENTOS"))
|
||||||
|
?? wb.Worksheets.FirstOrDefault(w =>
|
||||||
|
{
|
||||||
|
var normalized = NormalizeHeader(w.Name);
|
||||||
|
return normalized.Contains("PARCELAMENTO") || normalized.Contains("PARCELAMENTOS") || normalized.Contains("PARECALEMENTO");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int FindHeaderRow(IXLWorksheet ws)
|
private static int FindHeaderRow(IXLWorksheet ws)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue