379 lines
16 KiB
C#
379 lines
16 KiB
C#
using CPRNIMS.Domain.Contracts.PR;
|
|
using CPRNIMS.Domain.Services;
|
|
using CPRNIMS.Infrastructure.Dto.PO;
|
|
using CPRNIMS.Infrastructure.Dto.PR;
|
|
using CPRNIMS.Infrastructure.Entities.PO;
|
|
using CPRNIMS.Infrastructure.Entities.Purchasing;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.Models.Common;
|
|
using CPRNIMS.Infrastructure.ViewModel.Common;
|
|
using CPRNIMS.Infrastructure.ViewModel.PR;
|
|
using CPRNIMS.WebApi.Controllers.Base;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text;
|
|
|
|
|
|
namespace CPRNIMS.WebApi.Controllers.PR
|
|
{
|
|
[Security.AuthorizeRoles("PRMgmt")]
|
|
public class PRMgmtController : BaseController
|
|
{
|
|
private readonly IPRequest _pRequest;
|
|
private readonly SMTPHelper _smptHelper;
|
|
private readonly IConfiguration _config;
|
|
|
|
public PRMgmtController(ErrorMessageService errorMessageService,
|
|
IWebHostEnvironment webHostEnvironment, SMTPHelper sMTPHelper,
|
|
IConfiguration configuration, IPRequest pRequest) :
|
|
base(errorMessageService, webHostEnvironment, configuration)
|
|
{
|
|
_config = configuration;
|
|
_smptHelper = sMTPHelper;
|
|
_pRequest = pRequest;
|
|
}
|
|
#region POST PUT
|
|
[HttpPost("ApprovedSelectedPRItem")]
|
|
public async Task<IActionResult> ApprovedSelectedPRItem([FromBody] PRVM PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(async () =>
|
|
{
|
|
var results = new List<object>();
|
|
|
|
if (PRDto.PRList?.PRDetailsId?.Count > 0)
|
|
{
|
|
for (int i = 0; i < PRDto.PRList.PRDetailsId.Count; i++)
|
|
{
|
|
var dto = new PRDto
|
|
{
|
|
PRDetailsId = PRDto.PRList.PRDetailsId[i],
|
|
ItemNo = PRDto.PRList.ItemNo[i],
|
|
UserId = PRDto.UserId,
|
|
Status = 1
|
|
};
|
|
|
|
var result = await _pRequest.PostPRApproveReject(dto);
|
|
results.Add(new { PONo = dto.PONo, Result = result });
|
|
}
|
|
}
|
|
|
|
return new
|
|
{
|
|
ProcessedCount = results.Count,
|
|
Results = results
|
|
};
|
|
},
|
|
nameof(ApprovedSelectedPRItem), true);
|
|
}
|
|
[HttpPost("PostPutDeniedItem")]
|
|
public async Task<IActionResult> PostPutDeniedItem([FromBody] PRVM viewModel)
|
|
{
|
|
try
|
|
{
|
|
var baseTemplate = "n/a";
|
|
baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "RejectNotification.cshtml");
|
|
|
|
foreach (var items in viewModel.ItemList.PRDetailsId)
|
|
{
|
|
var index = viewModel.ItemList.PRDetailsId.IndexOf(items);
|
|
|
|
var prDto = new PRDto
|
|
{
|
|
PRDetailsId = viewModel.ItemList.PRDetailsId[index],
|
|
ItemNo = viewModel.ItemList.ItemNo[index],
|
|
PRNo = viewModel.ItemList.PRNo[index],
|
|
UserId = viewModel.UserId,
|
|
POTypeId = viewModel.POTypeId,
|
|
EmailAddress = viewModel.EmailAddress,
|
|
DocTypeId = viewModel.DocTypeId,
|
|
Remarks = viewModel.Remarks,
|
|
AppsModuleId=6
|
|
};
|
|
|
|
var notifications = await _pRequest.GetNotificationById(prDto);
|
|
var notif = notifications.First();
|
|
var message = new StringBuilder(baseTemplate);
|
|
|
|
message.Replace("@ViewBag.PRNo", Convert.ToString(prDto.PRNo));
|
|
message.Replace("@ViewBag.ItemNo", Convert.ToString(prDto.ItemNo));
|
|
message.Replace("@ViewBag.Remarks", Convert.ToString(viewModel.Remarks) ?? "N/A");
|
|
var email = notif.EmailAddress;
|
|
var messageDetails = new EmailMessageDetailsVM
|
|
{
|
|
Recipient = notif.EmailAddress,
|
|
CC = _config["SMTP:CC"],
|
|
Message = message.ToString(),
|
|
//Subject = $"CNPS - Requestor approved alternative offer for PRNo. {getNotif[0].PRNo} | ItemNo. {getNotif[0].ItemNo} - {getNotif[0].ItemName}",
|
|
Subject = "CPNS -PR Item denied by approver",
|
|
SenderEmail = _configuration["SMTP:SenderEmail"],
|
|
DisplayName = _configuration["SMTP:DisplayName"],
|
|
NewPassword = _configuration["SMTP:Password"],
|
|
OutGoingPort = 587,
|
|
Server = _configuration["SMTP:Server"],
|
|
UserName = _configuration["SMTP:UserName"],
|
|
};
|
|
await _pRequest.PostPutDeniedItem(prDto);
|
|
await _smptHelper.SendEmailAsync(messageDetails);
|
|
}
|
|
return Ok(new { success = true, MessCode =1 });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
await PostErrorMessage(message + "PostPutDeniedItem", "WebApi");
|
|
return Ok(new { success = false, MessCode = 0 });
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost("PostPRApproveReject")]
|
|
public async Task<IActionResult> PostPRApproveReject(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.PostPRApproveReject(PRDto),
|
|
nameof(PostPRApproveReject), true
|
|
);
|
|
}
|
|
[HttpPost("PutItemDetail")]
|
|
public async Task<IActionResult> PutItemDetail(PRDto PRDto)
|
|
{
|
|
try
|
|
{
|
|
var getNotif = await _pRequest.GetNotifUserKey(PRDto);
|
|
var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "PRItemUpdate.cshtml");
|
|
|
|
var message = new StringBuilder(baseTemplate);
|
|
|
|
message.Replace("@ViewBag.ItemNo", getNotif[0].ItemNo.ToString());
|
|
message.Replace("@ViewBag.PRNo", getNotif[0].PRNo.ToString());
|
|
message.Replace("@ViewBag.FullName", getNotif[0].FullName);
|
|
|
|
var messageDetails = new EmailMessageDetailsVM
|
|
{
|
|
Recipient = getNotif[0].Email,
|
|
Bcc = getNotif[0].RequestorEmail,
|
|
CC = _config["SMTP:CC"],
|
|
Message = message.ToString(),
|
|
Subject = "Non-Inventory - PR Item Detail Changes",
|
|
SenderEmail = _configuration["SMTP:SenderEmail"],
|
|
DisplayName = _configuration["SMTP:DisplayName"],
|
|
NewPassword = _configuration["SMTP:Password"],
|
|
OutGoingPort = 587,
|
|
Server = _configuration["SMTP:Server"],
|
|
UserName = _configuration["SMTP:UserName"],
|
|
};
|
|
|
|
var po = await _pRequest.PutItemDetail(PRDto);
|
|
|
|
await _smptHelper.SendEmailAsync(messageDetails);
|
|
|
|
return Ok(new { success = true, data = po ,messCode = 1});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
await PostErrorMessage(message + "PutItemDetail", "WebApi");
|
|
return Ok(new { success = false, messCode = 0 });
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost("PutSupplierAlterOffer")]
|
|
public async Task<IActionResult> PutSupplierAlterOffer(PRDto PRDto)
|
|
{
|
|
try
|
|
{
|
|
await _pRequest.PutSupplierAlterOffer(PRDto);
|
|
|
|
var getNotif = await _pRequest.GetSupplierAlterOfferDetails(PRDto);
|
|
var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "AlternativeOffer.cshtml");
|
|
|
|
var message = new StringBuilder(baseTemplate);
|
|
|
|
message.Replace("@ViewBag.ItemNo", getNotif[0].ItemNo.ToString());
|
|
message.Replace("@ViewBag.PRNo", getNotif[0].PRNo.ToString());
|
|
message.Replace("@ViewBag.ItemName", getNotif[0].ItemName);
|
|
message.Replace("@ViewBag.RequestedBy", getNotif[0].RequestedBy);
|
|
message.Replace("@ViewBag.CanvassBy", getNotif[0].CanvassBy);
|
|
|
|
var messageDetails = new EmailMessageDetailsVM
|
|
{
|
|
Recipient = getNotif[0].EmailAddress,
|
|
CC = _config["SMTP:CC"],
|
|
Message = message.ToString(),
|
|
Subject = $"CNPS - Requestor approved alternative offer for PRNo. {getNotif[0].PRNo} | ItemNo. {getNotif[0].ItemNo} - {getNotif[0].ItemName}",
|
|
SenderEmail = _configuration["SMTP:SenderEmail"],
|
|
DisplayName = _configuration["SMTP:DisplayName"],
|
|
NewPassword = _configuration["SMTP:Password"],
|
|
OutGoingPort = 587,
|
|
Server = _configuration["SMTP:Server"],
|
|
UserName = _configuration["SMTP:UserName"],
|
|
};
|
|
await _smptHelper.SendEmailAsync(messageDetails);
|
|
return Ok(new { success = true, messCode = 1 });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = ex.InnerException?.ToString() ?? ex.Message.ToString();
|
|
await PostErrorMessage(message + "PutItemDetail", "WebApi");
|
|
return Ok(new { success = false, messCode = 0 });
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost("PRItemRemoval")]
|
|
public async Task<IActionResult> PRItemRemoval(PRDto prDto)
|
|
{
|
|
try
|
|
{
|
|
var removal = await _pRequest.PRItemRemoval(prDto);
|
|
|
|
if (removal.MessageCode == 1)
|
|
{
|
|
var notifications = await _pRequest.GetNotificationById(prDto);
|
|
|
|
if (notifications.Any())
|
|
{
|
|
var notif = notifications.First();
|
|
|
|
var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "PRItemRemoval.cshtml");
|
|
var message = new StringBuilder(baseTemplate)
|
|
.Replace("@ViewBag.ItemNo", notif.ItemNo.ToString())
|
|
.Replace("@ViewBag.PRNo", notif.PRNo.ToString())
|
|
.Replace("@ViewBag.ItemName", notif.ItemName)
|
|
.Replace("@ViewBag.ItemName2", notif.ItemName)
|
|
.Replace("@ViewBag.UpdatedBy", notif.UpdatedBy)
|
|
.Replace("@ViewBag.Remarks", prDto.Remarks);
|
|
|
|
var messageDetails = new EmailMessageDetailsVM
|
|
{
|
|
Recipient = notif.EmailAddress,
|
|
CC = _config["SMTP:CC"],
|
|
Message = message.ToString(),
|
|
Subject = $"CNPS - PR Item Removal for PRNo. {notif.PRNo} | ItemNo. {notif.ItemNo} - {notif.ItemName}",
|
|
SenderEmail = _configuration["SMTP:SenderEmail"],
|
|
DisplayName = _configuration["SMTP:DisplayName"],
|
|
NewPassword = _configuration["SMTP:Password"],
|
|
OutGoingPort = 587,
|
|
Server = _configuration["SMTP:Server"],
|
|
UserName = _configuration["SMTP:UserName"],
|
|
};
|
|
await _smptHelper.SendEmailAsync(messageDetails);
|
|
}
|
|
}
|
|
return Ok(new { success = true, messCode = removal.MessageCode, message = removal.Message });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var errorMessage = ex.InnerException?.Message ?? ex.Message;
|
|
return Ok(new { success = false, messCode = 0, message = errorMessage });
|
|
}
|
|
}
|
|
[HttpPost("PostPutProjectCode")]
|
|
public async Task<IActionResult> PostPutProjectCode([FromBody] PRDto prDto)
|
|
{
|
|
var results = await _pRequest.PostPutProjectCode(prDto);
|
|
|
|
return Ok( new { data = results, message =results.message, messCode=results.messCode });
|
|
}
|
|
#endregion
|
|
#region Get
|
|
[HttpPost("GetProjectCodes")]
|
|
public async Task<IActionResult> GetProjectCodes(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetProjectCodes(PRDto),
|
|
nameof(GetProjectCodes), false
|
|
);
|
|
}
|
|
[HttpPost("GetApproverName")]
|
|
public async Task<IActionResult> GetApproverName(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetApproverName(PRDto),
|
|
nameof(GetApproverName), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRStatusById")]
|
|
public async Task<IActionResult> GetPRStatusById(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetPRStatusById(PRDto),
|
|
nameof(GetPRStatusById), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRDetailByPRNo")]
|
|
public async Task<IActionResult> GetPRDetailByPRNo(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetPRDetailByPRNo(PRDto),
|
|
nameof(GetPRDetailByPRNo), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRListByPRNo")]
|
|
public async Task<IActionResult> GetPRListByPRNo(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetPRListByPRNo(PRDto),
|
|
nameof(GetPRListByPRNo), false
|
|
);
|
|
}
|
|
[HttpPost("GetAllPR")]
|
|
public async Task<IActionResult> GetAllPR(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetAllPR(PRDto),
|
|
nameof(GetAllPR), false
|
|
);
|
|
}
|
|
[HttpPost("GetMyPR")]
|
|
public async Task<IActionResult> GetMyPR(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetMyPR(PRDto),
|
|
nameof(GetMyPR), false
|
|
);
|
|
}
|
|
|
|
[HttpPost("GetPRByRRId")]
|
|
public async Task<IActionResult> GetPRByRRId(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetPRByRRId(PRDto),
|
|
nameof(GetPRByRRId), false
|
|
);
|
|
}
|
|
[HttpPost("GetSupplierAlterOfferDetails")]
|
|
public async Task<IActionResult> GetSupplierAlterOfferDetails(PRDto PrDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetSupplierAlterOfferDetails(PrDto),
|
|
nameof(GetSupplierAlterOfferDetails), false
|
|
);
|
|
}
|
|
[HttpPost("GetSupplierAlternativeOffer")]
|
|
public async Task<IActionResult> GetSupplierAlternativeOffer(PRDto PrDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetSupplierAlternativeOffer(PrDto),
|
|
nameof(GetSupplierAlternativeOffer), false
|
|
);
|
|
}
|
|
[HttpPost("GetDashBoard")]
|
|
public async Task<IActionResult> GetDashBoard(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetDashBoard(PRDto),
|
|
nameof(GetDashBoard), false
|
|
);
|
|
}
|
|
[HttpPost("GetDetailedPRTracking")]
|
|
public async Task<IActionResult> GetDetailedPRTracking(PRDto PRDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _pRequest.GetDetailedPRTracking(PRDto),
|
|
nameof(GetDetailedPRTracking), false
|
|
);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|