diff --git a/src/SIGCM.Infrastructure/Services/PricingService.cs b/src/SIGCM.Infrastructure/Services/PricingService.cs index 9900870..8d2969f 100644 --- a/src/SIGCM.Infrastructure/Services/PricingService.cs +++ b/src/SIGCM.Infrastructure/Services/PricingService.cs @@ -22,12 +22,19 @@ public class PricingService public async Task CalculateAsync(CalculatePriceRequest request) { // 0. Obtener el Producto para saber el Precio Base - var product = await _productRepo.GetByIdAsync(request.ProductId); - if (product == null) return new CalculatePriceResponse + // Si ProductId = 0, el llamador no seleccionó un producto (ej: FastEntryPage legacy). + // En ese caso fallamos graciosamente con precio base 0. + decimal productBasePrice = 0; + if (request.ProductId > 0) { - TotalPrice = 0, - Details = "Producto no encontrado." - }; + var product = await _productRepo.GetByIdAsync(request.ProductId); + if (product == null) return new CalculatePriceResponse + { + TotalPrice = 0, + Details = "Producto no encontrado." + }; + productBasePrice = await _productRepo.GetCurrentPriceAsync(request.ProductId, request.StartDate == default ? DateTime.UtcNow : request.StartDate); + } // 1. Obtener Reglas var pricing = await _repo.GetByCategoryIdAsync(request.CategoryId); @@ -53,10 +60,8 @@ public class PricingService var words = cleanText.Split(new[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int realWordCount = words.Length; - // 3. Costo Base y Excedente - // Obtenemos el precio actual del producto vigenciado, fallback a BasePrice (usando el repo) - decimal productBasePrice = await _productRepo.GetCurrentPriceAsync(request.ProductId, request.StartDate == default ? DateTime.UtcNow : request.StartDate); - decimal currentCost = productBasePrice; // Precio base incluye N palabras + // 3. Costo Base y Excedente (productBasePrice ya viene resuelto desde sección 0) + decimal currentCost = productBasePrice; // Precio base del Producto seleccionado // ¿Cuántas palabras extra cobramos?