119 lines
4.3 KiB
C#
119 lines
4.3 KiB
C#
using CPRNIMS.Domain.Contracts.Reports;
|
|
using CPRNIMS.Domain.UIContracts.Account;
|
|
using CPRNIMS.Domain.UIContracts.Inventory;
|
|
using CPRNIMS.Infrastructure.Dto.Inventory.Request;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.WebApps.Controllers.Base;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using FastReport;
|
|
using FastReport.Web;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CPRNIMS.WebApps.Controllers.Inventory
|
|
{
|
|
public class RISMgmtController : BaseMethod
|
|
{
|
|
private readonly IRIS _ris;
|
|
private readonly IReportBuilder _builder;
|
|
private readonly IWebHostEnvironment _env;
|
|
public RISMgmtController(ErrorLogHelper errorMessageService,
|
|
IWebHostEnvironment webHostEnvironment, TokenHelper tokenHelper
|
|
, IRIS ris, IAccount account, IReportBuilder builder)
|
|
: base(errorMessageService, webHostEnvironment, tokenHelper, account)
|
|
{
|
|
_ris = ris;
|
|
_builder = builder;
|
|
_env = webHostEnvironment;
|
|
|
|
}
|
|
|
|
public IActionResult RISReport(DateTime? dateFrom, DateTime? dateTo, CancellationToken ct)
|
|
{
|
|
return View();
|
|
}
|
|
public async Task<IActionResult> RISReportPdf(DateTime? dateFrom, DateTime? dateTo, CancellationToken ct)
|
|
{
|
|
var from = dateFrom ?? DateTime.Today.AddDays(-15);
|
|
var to = dateTo ?? DateTime.Today;
|
|
|
|
var templatePath = Path.Combine(_env.WebRootPath, "Reports", "RIS_v2.frx");
|
|
var report = await _builder.RISBuildAsync(from, to, templatePath, ct);
|
|
report.Prepare();
|
|
|
|
using var pdf = new FastReport.Export.PdfSimple.PDFSimpleExport();
|
|
using var ms = new MemoryStream();
|
|
pdf.Export(report, ms);
|
|
|
|
return File(ms.ToArray(), "application/pdf",
|
|
$"RIS-Report-{from:yyyyMMdd}-{to:yyyyMMdd}.pdf");
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateRIS([FromBody] CreateRISRequest request,CancellationToken ct)
|
|
{
|
|
var result = await _ris.CreateRIS(request,ct);
|
|
if (!result.success)
|
|
return BadRequest(new { success = false, message = result.message });
|
|
|
|
return Ok(new { success = true, message = result.message });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> ApproveRIS([FromBody] ApproveRISRequest request,CancellationToken ct)
|
|
{
|
|
var result = await _ris.ApproveRIS(request, ct);
|
|
|
|
if (!result.success)
|
|
return BadRequest(new { success = false, message = result.message });
|
|
|
|
return Ok(new { success = true, message = result.message });
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CancelRIS([FromBody] CancelRISRequest request,CancellationToken ct)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Reason))
|
|
return BadRequest(new{success = false,message = "A reason for cancellation is required."});
|
|
|
|
var result = await _ris.CancelRIS(request, ct);
|
|
|
|
if (!result.success)
|
|
return BadRequest(new { success = false, message = result.message });
|
|
|
|
return Ok(new { success = true, message = result.message });
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetRIS(
|
|
[FromQuery] string? searchRISNo,string? searchItemName,string? searchIssuedTo,string? discipline,string? status,
|
|
int pageNumber = 1,int pageSize = 12,CancellationToken ct = default)
|
|
{
|
|
short? statusCode = status switch
|
|
{
|
|
"0" => 0,
|
|
"1" => 1,
|
|
"2" => 2,
|
|
_ => null
|
|
};
|
|
|
|
var result = await _ris.GetRISPaged(new RISPagedRequest
|
|
{
|
|
SearchRISNo = searchRISNo,
|
|
SearchItemName = searchItemName,
|
|
SearchIssuedTo = searchIssuedTo,
|
|
Discipline = discipline,
|
|
Status = statusCode,
|
|
PageNumber = pageNumber,
|
|
PageSize = pageSize
|
|
}, ct);
|
|
|
|
return Json(new
|
|
{
|
|
data = result.Data,
|
|
recordsTotal = result.RecordsTotal,
|
|
departmentList = result.DepartmentList,
|
|
disciplineList = result.DisciplineList
|
|
});
|
|
}
|
|
}
|
|
}
|