using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.Services.Sales; namespace Lux.API.Controllers { [Route("api/[controller]")] [ApiController] public class ReportController : ControllerBase { #region Public Constructors /// /// Costruttore metodo /// /// public ReportController(IOfferService offService, IOrderService ordService) { _offService = offService; _ordService = ordService; // 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 OfferModel? offData = await _offService.GetByIdAsync(id); sw.Stop(); Log.Info($"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.Info($"Order | {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 JsonSerializerSettings JSSettings; #endregion Private Fields } }