NonInventPurchasingSystem/CPRNIMS.WebApi/Controllers/Finance/RRMgmtController.cs
2026-01-26 14:21:31 +08:00

94 lines
3.0 KiB
C#

using CPRNIMS.Domain.Contracts.Finance;
using CPRNIMS.Domain.Services;
using CPRNIMS.Infrastructure.Dto.Finance;
using CPRNIMS.Infrastructure.Dto.Items;
using CPRNIMS.Infrastructure.Dto.SMTP;
using CPRNIMS.Infrastructure.Helper;
using CPRNIMS.Infrastructure.ViewModel.Common;
using CPRNIMS.Infrastructure.ViewModel.PR;
using CPRNIMS.WebApi.Controllers.Base;
using Microsoft.AspNetCore.Mvc;
using System.Text;
namespace CPRNIMS.WebApi.Controllers.Finance
{
public class RRMgmtController : BaseController
{
private readonly IRR _rr;
public RRMgmtController(ErrorMessageService errorMessageService,
IWebHostEnvironment webHostEnvironment, SMTPHelper sMTPHelper,
IConfiguration configuration, SMTPHelper smptHelper, IRR rr) :
base(errorMessageService, webHostEnvironment, sMTPHelper, configuration)
{
_rr = rr;
}
#region Get
[HttpPost("GetAllClosedPO")]
public async Task<IActionResult> GetAllClosedPO(RRDetailsDto itemCodeDto)
{
try
{
var allPR = await _rr.GetAllClosedPO(itemCodeDto);
return Ok(allPR);
}
catch (Exception ex)
{
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
await PostErrorMessage(message, "WebApi");
throw;
}
}
[HttpPost("GetRRDetailByPO")]
public async Task<IActionResult> GetRRDetailByPO(RRDetailsDto itemDto)
{
try
{
var myPR = await _rr.GetRRDetailByPO(itemDto);
return Ok(myPR);
}
catch (Exception ex)
{
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
await PostErrorMessage(message, "WebApi");
throw;
}
}
#endregion
#region Post Put
[HttpPost("PostPutPayment")]
public async Task<IActionResult> PostPutPayment([FromBody] PRVM viewModel)
{
try
{
foreach (var items in viewModel.ItemList.PRDetailsId)
{
var index = viewModel.ItemList.PRDetailsId.IndexOf(items);
var rrDto = new RRDetailsDto
{
UserId = viewModel.UserId,
PONo = viewModel.PONo,
POTypeId = viewModel.POTypeId,
PRDetailsId = viewModel.ItemList.PRDetailsId[index],
};
var pR = await _rr.PostPutPayment(rrDto);
}
return Ok(new { success = true });
}
catch (Exception ex)
{
var errorMessage = ex.InnerException?.ToString() ?? ex.Message.ToString();
await PostErrorMessage(errorMessage + "PostPutPayment", "WebApi");
throw;
}
}
#endregion
}
}