Files
lux/Lux.API/Controllers/ReportController.cs
Samuele Locatelli 0e7e0aaed0 packages update
Update gestione generazione fabbisogni a livello di ordine
update metodo API x recupero filtrato x CodGroup
2026-04-30 11:50:24 +02:00

206 lines
7.2 KiB
C#

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
/// <summary>
/// Costruttore metodo
/// </summary>
/// <param name="offService"></param>
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
/// <summary>
/// Chiamata GET: riceve OffertID, restituisce Json Offerta + righe
/// GET: api/report/offert/1
/// </summary>
/// <param name="id">id univoco</param>
/// <returns></returns>
[HttpGet("offert/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: riceve OrderID, restituisce Json Ordine + righe
/// GET: api/report/offert/1
/// </summary>
/// <param name="id">id univoco</param>
/// <returns></returns>
[HttpGet("order/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: riceve TemplateID, restituisce Json Template (catalogo) + righe
/// GET: api/report/offert/1
/// </summary>
/// <param name="id">id univoco</param>
/// <returns></returns>
[HttpGet("template/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: fornisce un elenco di righe MatReq x un ordine intero
/// GET: api/report/matreq-sale-ord/45
/// </summary>
/// <param name="id">id univoco</param>
/// <param name="codGroup">codGruppo per selezionare solo un tpo di item</param>
/// <returns></returns>
[HttpGet("matreq-sale-ord/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: fornisce un elenco di righe MatReq x una riga ordine
/// GET: api/report/matreq-sale-ord/45
/// </summary>
/// <param name="id">id univoco</param>
/// <returns></returns>
[HttpGet("matreq-sale-ord-row/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: Fornisce un BuyOrder (Ordine fornitore) + righe dato ID
/// GET: api/report/buyorder/1
/// </summary>
/// <param name="id">id univoco</param>
/// <returns></returns>
[HttpGet("buyorder/{id}")]
public async Task<IActionResult> 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);
}
/// <summary>
/// Chiamata GET: riceve ELENCO Offerte dato periodo
/// GET: api/report/offert-list/?from=2026-01-01&to=2026-04-01
/// </summary>
/// <param name="from">dataora inizio</param>
/// <param name="to">dataora fine</param>
/// <returns></returns>
[HttpGet("offert-list")]
public async Task<IActionResult> OffertList(DateTime from, DateTime to)
{
Stopwatch sw = new Stopwatch();
sw.Start();
// recupera dal DB l'offerta con le righe relative
List<OfferModel> 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
}
}