199 lines
6.8 KiB
C#
199 lines
6.8 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.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(
|
|
IOfferService offService,
|
|
IOrderService ordService,
|
|
ITemplateService tplService,
|
|
IMatReqService mrService)
|
|
{
|
|
_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: riceve un elenco di righe MatReq x un ordine intero
|
|
/// GET: api/report/matreq-sale-ord/45
|
|
/// </summary>
|
|
/// <param name="id">id univoco</param>
|
|
/// <returns></returns>
|
|
[HttpGet("matreq-sale-ord/{id}")]
|
|
public async Task<IActionResult> MatReqSaleOrder(int id)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// recupera dal DB l'offerta con le righe relative
|
|
var ordData = await _mrService.GetByOrderAsync(id);
|
|
|
|
sw.Stop();
|
|
Log.Debug($"MatReqSaleOrder | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(ordData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata GET: riceve 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);
|
|
}
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Chiamata GET: riceve TemplateID, restituisce Json Template (catalogo) + righe
|
|
/// GET: api/report/matreq-buy-ord/1
|
|
/// </summary>
|
|
/// <param name="id">id univoco</param>
|
|
/// <returns></returns>
|
|
[HttpGet("matreq-buy-ord/{id}")]
|
|
public async Task<IActionResult> MatReqBuyOrder(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.Info($"Template | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(ordData);
|
|
}
|
|
#endif
|
|
|
|
/// <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 IMatReqService _mrService;
|
|
private JsonSerializerSettings JSSettings;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |