All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 14m19s
146 lines
5.6 KiB
Plaintext
146 lines
5.6 KiB
Plaintext
@page "/stock/productimport"
|
|
@using phronCare.UIBlazor.Services.Stock
|
|
|
|
@inject IJSRuntime JS
|
|
@inject IToastService toastService
|
|
@inject NavigationManager Navigation
|
|
@inject LSProductService productService
|
|
|
|
<h3 class="mb-4">Importación masiva de productos</h3>
|
|
|
|
<div class="mb-3">
|
|
<button class="btn btn-primary" @onclick="DownloadTemplate">Descargar plantilla Excel</button>
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label for="fileUpload" class="form-label fw-semibold">Seleccionar archivo Excel</label>
|
|
<div class="input-group">
|
|
<label class="input-group-text bg-light border-secondary" for="fileUpload">📎</label>
|
|
<InputFile id="fileUpload" class="form-control" OnChange="HandleFileSelected" accept=".xlsx" />
|
|
</div>
|
|
</div>
|
|
|
|
@if (UploadedFile != null)
|
|
{
|
|
<div class="mb-4">
|
|
<button class="btn btn-warning" @onclick="ProcessFile">Procesar archivo Excel</button>
|
|
</div>
|
|
}
|
|
|
|
@if (PreviewItems != null)
|
|
{
|
|
<h5 class="mt-4">Vista previa</h5>
|
|
<table class="table table-sm table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>Cód. Fábrica</th>
|
|
<th>Nombre</th>
|
|
<th>Descripción</th>
|
|
<th>Tipo</th>
|
|
<th>Trazabilidad</th>
|
|
<th>División</th>
|
|
<th>Unidad</th>
|
|
<th>Plus</th>
|
|
<th>Cód. Ext.</th>
|
|
<th>Errores</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var item in PreviewItems)
|
|
{
|
|
<tr class="@(item.HasError ? "table-danger" : null)">
|
|
<td>@item.FactoryCode</td>
|
|
<td>@item.Name</td>
|
|
<td>@item.Description</td>
|
|
<td>@item.ProductType</td>
|
|
<td>@item.TraceabilityType</td>
|
|
<td>@item.DivisionCode</td>
|
|
<td>@item.UnitCode</td>
|
|
<td>@(item.PlusProcess ? "Sí" : "No")</td>
|
|
<td>@item.ExternalCode</td>
|
|
<td>@item.ErrorMessage</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="mt-3 d-flex justify-content-end gap-2">
|
|
<button class="btn btn-outline-secondary" @onclick="SimulateImport">Simular importación</button>
|
|
<button class="btn btn-success" @onclick="ConfirmImport" disabled="@(PreviewItems.All(x => x.HasError))">Importar productos</button>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private List<ProductImportPreviewDto>? PreviewItems;
|
|
private IBrowserFile? UploadedFile;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
PreviewItems = new List<ProductImportPreviewDto>
|
|
{
|
|
new() { FactoryCode = "ZIM001", Name = "Clavo tibial largo", Description = "Clavo para tibia", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = true, ExternalCode = "EXT001" },
|
|
new() { FactoryCode = "ZIM002", Name = "Tornillo esponjoso", Description = "Tornillo de 6.5mm", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = false, ExternalCode = "EXT002" },
|
|
new() { FactoryCode = "ZIM003", Name = "Placa de compresión", Description = "Placa DCP 4.5", ProductType = 1, TraceabilityType = 2, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = false, ExternalCode = "EXT003" },
|
|
new() { FactoryCode = "ZIM004", Name = "Caja instrumental", Description = "Caja para implantes", ProductType = 2, TraceabilityType = 1, DivisionCode = "ZIM", UnitCode = "CJ", PlusProcess = false, ExternalCode = "EXT004", ErrorMessage = "Unidad no reconocida" },
|
|
new() { FactoryCode = "ZIM005", Name = "Perno cortical", Description = "Perno de fijación", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = true, ExternalCode = "EXT005" }
|
|
};
|
|
}
|
|
|
|
private async Task DownloadTemplate()
|
|
{
|
|
try
|
|
{
|
|
await productService.DownloadTemplateAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
toastService.ShowError($"Error al descargar la plantilla: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private async Task HandleFileSelected(InputFileChangeEventArgs e)
|
|
{
|
|
UploadedFile = e.File;
|
|
//PreviewItems = null; // Limpiar preview anterior
|
|
}
|
|
|
|
private async Task ProcessFile()
|
|
{
|
|
if (UploadedFile == null) return;
|
|
|
|
using var stream = UploadedFile.OpenReadStream(10 * 1024 * 1024);
|
|
using var ms = new MemoryStream();
|
|
await stream.CopyToAsync(ms);
|
|
var content = ms.ToArray();
|
|
|
|
// Aquí deberías llamar al backend para validar y obtener la vista previa
|
|
// Por ahora se simula con los datos ya cargados en OnInitialized
|
|
// PreviewItems = await Http.PostAsJsonAsync(...)
|
|
}
|
|
|
|
private async Task SimulateImport()
|
|
{
|
|
// Lógica futura para simular importación
|
|
}
|
|
|
|
private async Task ConfirmImport()
|
|
{
|
|
// Lógica futura para guardar los productos
|
|
}
|
|
|
|
public class ProductImportPreviewDto
|
|
{
|
|
public string FactoryCode { get; set; } = string.Empty;
|
|
public string Name { get; set; } = string.Empty;
|
|
public string Description { get; set; } = string.Empty;
|
|
public int ProductType { get; set; }
|
|
public int TraceabilityType { get; set; }
|
|
public string DivisionCode { get; set; } = string.Empty;
|
|
public string UnitCode { get; set; } = string.Empty;
|
|
public bool PlusProcess { get; set; }
|
|
public string ExternalCode { get; set; } = string.Empty;
|
|
public string? ErrorMessage { get; set; }
|
|
public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage);
|
|
}
|
|
}
|