using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.Services.Catalog; using EgwCoreLib.Lux.Data.Services.Sales; using EgwCoreLib.Lux.Data.Services.Supplier; using EgwCoreLib.Lux.Data.Services.Warehouse; namespace Lux.API.Controllers { [Route("api/[controller]")] [ApiController] public class ReportController : ControllerBase { #region Public Constructors /// /// Costruttore metodo /// /// public ReportController( IBuyOrderService buyOrdService, IOfferService offService, IOrderService ordService, ITemplateService tplService, IMatReqService mrService) { _boService = buyOrdService; _offService = offService; _ordService = ordService; _tplService = tplService; _mrService = mrService; // Configurazione serializzatore JSON per risolvere errore di loop circolare JSSettings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; } #endregion Public Constructors #region Public Methods /// /// Chiamata GET: riceve OffertID, restituisce Json Offerta + righe /// GET: api/report/offert/1 /// /// id univoco /// [HttpGet("offert/{id}")] public async Task Offert(int id) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var offData = await _offService.GetByIdAsync(id); sw.Stop(); Log.Debug($"Offert | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(offData); } /// /// Chiamata GET: riceve OrderID, restituisce Json Ordine + righe /// GET: api/report/offert/1 /// /// id univoco /// [HttpGet("order/{id}")] public async Task Order(int id) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var ordData = await _ordService.GetByIdAsync(id, false); sw.Stop(); Log.Debug($"Order | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(ordData); } /// /// Chiamata GET: riceve TemplateID, restituisce Json Template (catalogo) + righe /// GET: api/report/offert/1 /// /// id univoco /// [HttpGet("template/{id}")] public async Task Template(int id) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var ordData = await _tplService.GetByIdAsync(id); sw.Stop(); Log.Debug($"Template | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(ordData); } /// /// Chiamata GET: fornisce un elenco di righe MatReq x un ordine intero /// GET: api/report/matreq-sale-ord/45 /// /// id univoco /// codGruppo per selezionare solo un tpo di item /// [HttpGet("matreq-sale-ord/{id}")] public async Task MatReqSaleOrder(int id, string codGroup = "") { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var ordData = await _mrService.GetByOrderAsync(id); if (!string.IsNullOrWhiteSpace(codGroup)) { ordData = ordData.Where(x => x.CodGroup.Equals(codGroup, StringComparison.InvariantCultureIgnoreCase)).ToList(); } sw.Stop(); Log.Debug($"MatReqSaleOrder | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(ordData); } /// /// Chiamata GET: fornisce un elenco di righe MatReq x una riga ordine /// GET: api/report/matreq-sale-ord/45 /// /// id univoco /// [HttpGet("matreq-sale-ord-row/{id}")] public async Task MatReqSaleOrderRow(int id) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var ordData = await _mrService.GetByOrderRowAsync(id); sw.Stop(); Log.Debug($"MatReqSaleOrderRow | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(ordData); } /// /// Chiamata GET: Fornisce un BuyOrder (Ordine fornitore) + righe dato ID /// GET: api/report/buyorder/1 /// /// id univoco /// [HttpGet("buyorder/{id}")] public async Task BuyOrder(int id) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative var ordData = await _boService.GetByIdAsync(id); sw.Stop(); Log.Info($"Template | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(ordData); } /// /// Chiamata GET: riceve ELENCO Offerte dato periodo /// GET: api/report/offert-list/?from=2026-01-01&to=2026-04-01 /// /// dataora inizio /// dataora fine /// [HttpGet("offert-list")] public async Task OffertList(DateTime from, DateTime to) { Stopwatch sw = new Stopwatch(); sw.Start(); // recupera dal DB l'offerta con le righe relative List offData = await _offService.GetFiltAsync(from, to); sw.Stop(); Log.Info($"OffertList | {from} --> {to} | {sw.Elapsed.TotalMilliseconds:N3} ms"); return Ok(offData); } [HttpGet("version")] public string version() { var version = Assembly .GetExecutingAssembly() .GetName() .Version? .ToString() ?? "unknown"; return version; } #endregion Public Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private IOfferService _offService; private IOrderService _ordService; private ITemplateService _tplService; private IBuyOrderService _boService; private IMatReqService _mrService; private JsonSerializerSettings JSSettings; #endregion Private Fields } }