soporte sin conexion. modal para buscar articulos
This commit is contained in:
@@ -109,6 +109,84 @@ public class ContabilidadGeneralController : Controller
|
||||
return Json(new { success = false, message = "Error al guardar los movimientos. Verifique que el mes no esté cerrado." });
|
||||
}
|
||||
|
||||
// ==================== Sincronización Offline ====================
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SincronizarOffline([FromBody] List<BulkSaveRequest> transacciones)
|
||||
{
|
||||
if (transacciones == null || !transacciones.Any())
|
||||
return BadRequest("No hay transacciones para sincronizar.");
|
||||
|
||||
var resultados = new List<object>();
|
||||
|
||||
foreach (var request in transacciones)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request.ReporteId <= 0)
|
||||
{
|
||||
resultados.Add(new {
|
||||
success = false,
|
||||
reporteId = request.ReporteId,
|
||||
message = "ID de reporte inválido."
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
var movimientos = request.Movimientos.Select(m => new MovimientoGeneral
|
||||
{
|
||||
Id = m.Id,
|
||||
Tipo = m.Tipo,
|
||||
CategoriaIngresoId = m.CategoriaIngresoId,
|
||||
CategoriaEgresoId = m.CategoriaEgresoId,
|
||||
Monto = m.Monto,
|
||||
Fecha = DateTime.SpecifyKind(m.Fecha, DateTimeKind.Utc),
|
||||
Descripcion = m.Descripcion ?? "",
|
||||
NumeroComprobante = m.NumeroComprobante
|
||||
}).ToList();
|
||||
|
||||
var success = await _contabilidadService.GuardarMovimientosBulkAsync(request.ReporteId, movimientos);
|
||||
|
||||
if (success)
|
||||
{
|
||||
resultados.Add(new {
|
||||
success = true,
|
||||
reporteId = request.ReporteId,
|
||||
message = "Sincronizado exitosamente"
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
resultados.Add(new {
|
||||
success = false,
|
||||
reporteId = request.ReporteId,
|
||||
message = "Error al guardar. El mes puede estar cerrado."
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultados.Add(new {
|
||||
success = false,
|
||||
reporteId = request.ReporteId,
|
||||
message = $"Error: {ex.Message}"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var exitosos = resultados.Count(r => (bool)((dynamic)r).success);
|
||||
var fallidos = resultados.Count - exitosos;
|
||||
|
||||
return Json(new {
|
||||
success = exitosos > 0,
|
||||
total = transacciones.Count,
|
||||
exitosos = exitosos,
|
||||
fallidos = fallidos,
|
||||
resultados = resultados
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ==================== Cerrar Mes ====================
|
||||
|
||||
[HttpPost]
|
||||
|
||||
@@ -44,7 +44,7 @@ public class MovimientosInventarioController : Controller
|
||||
{
|
||||
var articulo = await _articuloService.GetByIdAsync(articuloId.Value);
|
||||
if (articulo == null) return NotFound();
|
||||
|
||||
|
||||
ViewBag.ArticuloId = articulo.Id;
|
||||
ViewBag.ArticuloNombre = $"{articulo.Codigo} - {articulo.Nombre}";
|
||||
ViewBag.UbicacionActual = articulo.UbicacionNombre;
|
||||
@@ -53,13 +53,44 @@ public class MovimientosInventarioController : Controller
|
||||
ViewBag.CantidadGlobal = articulo.CantidadGlobal; // For LOTE validation?
|
||||
}
|
||||
|
||||
ViewBag.Articulos = new SelectList((await _articuloService.GetAllAsync()).Select(x => new { x.Id, Nombre = $"{x.Codigo} - {x.Nombre}" }), "Id", "Nombre", articuloId);
|
||||
ViewBag.Articulos =
|
||||
new SelectList(
|
||||
(await _articuloService.GetAllAsync()).Select(x => new { x.Id, Nombre = $"{x.Codigo} - {x.Nombre}" }),
|
||||
"Id", "Nombre", articuloId);
|
||||
ViewBag.Ubicaciones = new SelectList(await _ubicacionService.GetAllAsync(), "Id", "Nombre");
|
||||
ViewBag.Estados = new SelectList(await _estadoService.GetAllAsync(), "Id", "Nombre");
|
||||
|
||||
ViewBag.Estados = new SelectList(await _estadoService.GetAllAsync(), "Id", "Nombre");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> BuscarArticulos(string term)
|
||||
{
|
||||
var articulos = await _articuloService.GetAllAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(term))
|
||||
{
|
||||
term = term.ToLower();
|
||||
articulos = articulos
|
||||
.Where(a =>
|
||||
(a.Nombre != null && a.Nombre.ToLower().Contains(term)) ||
|
||||
(a.Codigo != null && a.Codigo.ToLower().Contains(term)) ||
|
||||
(a.Descripcion != null && a.Descripcion.ToLower().Contains(term)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Limit results
|
||||
var resultados = articulos.Take(20).Select(a => new {
|
||||
a.Id,
|
||||
a.Codigo,
|
||||
a.Nombre,
|
||||
Ubicacion = a.UbicacionNombre ?? "Sin ubicación",
|
||||
Stock = a.CantidadGlobal
|
||||
});
|
||||
|
||||
return Json(resultados);
|
||||
}
|
||||
|
||||
// POST: MovimientosInventario/RegistrarTraslado
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
|
||||
Reference in New Issue
Block a user