521 lines
20 KiB
C#
521 lines
20 KiB
C#
using CPRNIMS.Domain.Contracts.PO;
|
|
using CPRNIMS.Domain.Contracts.SMTP;
|
|
using CPRNIMS.Domain.Services;
|
|
using CPRNIMS.Infrastructure.Dto.PO;
|
|
using CPRNIMS.Infrastructure.Dto.SMTP;
|
|
using CPRNIMS.Infrastructure.Entities.PO;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.ViewModel.Common;
|
|
using CPRNIMS.Infrastructure.ViewModel.PO;
|
|
using CPRNIMS.WebApi.Controllers.Base;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text;
|
|
|
|
namespace CPRNIMS.WebApi.Controllers.PO
|
|
{
|
|
[Security.AuthorizeRoles("POMgmt")]
|
|
public class POMgmtController : BaseController
|
|
{
|
|
private readonly ISMTP _sMTP;
|
|
private readonly SMTPHelper _smtpHelper;
|
|
private readonly IPurchaseOrder _purchaseOrder;
|
|
private readonly IConfiguration _config;
|
|
|
|
public POMgmtController(ErrorMessageService errorMessageService,
|
|
IWebHostEnvironment webHostEnvironment, SMTPHelper sMTPHelper,
|
|
IConfiguration configuration, ISMTP sMTP, IPurchaseOrder purchaseOrder) :
|
|
base(errorMessageService, webHostEnvironment, configuration)
|
|
{
|
|
_smtpHelper = sMTPHelper;
|
|
_sMTP= sMTP;
|
|
_config = configuration;
|
|
_purchaseOrder= purchaseOrder;
|
|
}
|
|
#region Post Put
|
|
[HttpPost("PostIncShipFollowUp")]
|
|
public async Task<IActionResult> PostIncShipFollowUp([FromBody] PODto dto)
|
|
{
|
|
bool isSuccess = await _purchaseOrder.PostIncShipFollowUp(dto);
|
|
return Ok(new
|
|
{
|
|
success = isSuccess,
|
|
messCode = isSuccess ? 1 : 0,
|
|
message = isSuccess ? "Follow up incoming for shipment successfully!"
|
|
: "Follow up incoming for shipment failed!"
|
|
});
|
|
}
|
|
[HttpPost("DeleteIncShip")]
|
|
public async Task<IActionResult> DeleteIncShip(PODto poDto)
|
|
{
|
|
bool isSuccess = await _purchaseOrder.DeleteIncShip(poDto);
|
|
return Ok(new
|
|
{
|
|
success = isSuccess,
|
|
messCode = isSuccess ? 1 : 0,
|
|
message = isSuccess ? "Removal of incoming for shipment successfully!"
|
|
: "Removal of incoming for shipment failed!"
|
|
});
|
|
}
|
|
[HttpPost("PutPOCancel")]
|
|
public async Task<IActionResult> PutPOCancel(PODto poDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(async () =>
|
|
{
|
|
var poResults = new List<CustomPO>();
|
|
var po = await _purchaseOrder.PutPOCancel(poDto);
|
|
poResults.Add(po);
|
|
return new
|
|
{
|
|
CustomPOs = poResults,
|
|
ProcessedCount = poResults.Count
|
|
};
|
|
},
|
|
nameof(PutPOCancel), true);
|
|
}
|
|
[HttpPost("PostPutCustomPO")]
|
|
public async Task<IActionResult> PostPutCustomPO([FromBody] POVM poVM)
|
|
{
|
|
return await ExecuteWithErrorHandling(async () =>
|
|
{
|
|
var poResults = new List<CustomPO>();
|
|
|
|
if (poVM.PRItemList?.PRDetailsId?.Count > 0)
|
|
{
|
|
for (int i = 0; i < poVM.PRItemList.PRDetailsId.Count; i++)
|
|
{
|
|
var poDto = _purchaseOrder.CreatePoDto(
|
|
poVM,
|
|
0,
|
|
0,
|
|
poVM.PRItemList.PRDetailsId[i],
|
|
poVM.PRItemList.UnitPrice[i],
|
|
poVM.PRItemList.Amount[i],
|
|
poVM.PRItemList.PRNo[i],
|
|
poVM.PRItemList.Quantity[i],
|
|
poVM.PRItemList.Specification[i]
|
|
);
|
|
|
|
var po = new CustomPO();
|
|
if(poDto.IsUpdate)
|
|
po=await _purchaseOrder.PutExistingPO(poDto);
|
|
else
|
|
po = await _purchaseOrder.PostPutCustomPO(poDto);
|
|
|
|
poResults.Add(po);
|
|
}
|
|
}
|
|
|
|
await _purchaseOrder.Prerequisite(poVM);
|
|
|
|
return new
|
|
{
|
|
CustomPOs = poResults,
|
|
ProcessedCount = poResults.Count
|
|
};
|
|
},
|
|
nameof(PostPutCustomPO),true);
|
|
}
|
|
[HttpPost("ApprovedSelectedPO")]
|
|
public async Task<IActionResult> ApprovedSelectedPO([FromBody] POVM poVM)
|
|
{
|
|
return await ExecuteWithErrorHandling(async () =>
|
|
{
|
|
var results = new List<object>();
|
|
|
|
if (poVM.POList?.PONo?.Count > 0)
|
|
{
|
|
for (int i = 0; i < poVM.POList.PONo.Count; i++)
|
|
{
|
|
var dto = new PODto
|
|
{
|
|
PONo = poVM.POList.PONo[i],
|
|
UserId = poVM.UserId,
|
|
};
|
|
|
|
var result = await _purchaseOrder.ApprovedSelectedPO(dto);
|
|
results.Add(new { PONo = dto.PONo, Result = result });
|
|
}
|
|
}
|
|
|
|
return new
|
|
{
|
|
ProcessedCount = results.Count,
|
|
Results = results
|
|
};
|
|
},
|
|
nameof(ApprovedSelectedPO), true);
|
|
}
|
|
[HttpPost("PutMyPONo")]
|
|
public async Task<IActionResult> PutMyPONo(PODto pODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PutMyPONo(pODto),
|
|
nameof(PutMyPONo), true
|
|
);
|
|
}
|
|
|
|
[HttpPost("PostPutPO")]
|
|
public async Task<IActionResult> PostPutPO([FromBody] POVM poVM)
|
|
{
|
|
return await ExecuteWithErrorHandling(async () =>
|
|
{
|
|
var poResult = await _purchaseOrder.PostPutPO(_purchaseOrder.CreatePoDto(poVM, 0, 0, 0, 0, 0, 0, 0,"n/a"));
|
|
await _purchaseOrder.Prerequisite(poVM);
|
|
|
|
return new { PoResult = poResult};
|
|
},
|
|
nameof(PostPutPO), true);
|
|
}
|
|
|
|
[HttpPost("PostPOToSupplier")]
|
|
public async Task<IActionResult> PostPOToSupplier(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostPOToSupplier(PODto),
|
|
nameof(PostPOToSupplier), true
|
|
);
|
|
}
|
|
[HttpPost("PostApprovedPO")]
|
|
public async Task<IActionResult> PostApprovedPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostApprovedPO(PODto),
|
|
nameof(PostApprovedPO), true
|
|
);
|
|
}
|
|
[HttpPost("PostApprovedSupplier")]
|
|
public async Task<IActionResult> PostApprovedSupplier(PODto PODto)
|
|
{
|
|
var cred = new SMTPCredentialDto
|
|
{
|
|
SMTPTypeId = 1,//must be dynamic in a future
|
|
UserId = PODto.UserId
|
|
};
|
|
var mySMTP = await _sMTP.GetSMTPCredential(cred);
|
|
var baseTemplate = "n/a";
|
|
|
|
baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "SendToApprovedSupplier.cshtml");
|
|
|
|
var rfq = await _purchaseOrder.GetRFQ(PODto);
|
|
var message = new StringBuilder(baseTemplate);
|
|
var messageDetails = new EmailMessageDetailsVM();
|
|
if (mySMTP.Count > 0)
|
|
{
|
|
messageDetails.Recipient = rfq[0].EmailAddress;
|
|
messageDetails.Message = message.ToString();
|
|
messageDetails.Subject = "LLI - Request For Delivery";
|
|
messageDetails.CC = _config["Canvass:CC"];
|
|
messageDetails.SenderEmail = mySMTP[0].SenderEmail;
|
|
messageDetails.DisplayName = mySMTP[0].SenderDisplayName;
|
|
messageDetails.NewPassword = mySMTP[0].Password;
|
|
messageDetails.OutGoingPort = mySMTP[0].OutgoingPort;
|
|
messageDetails.Server = mySMTP[0].Server;
|
|
messageDetails.UserName = mySMTP[0].SenderUserName;
|
|
messageDetails.IsCanvass = true;
|
|
}
|
|
if (!await _smtpHelper.SendEmailAsync(messageDetails))
|
|
{
|
|
messageDetails.Recipient = rfq[0].EmailAddress;
|
|
messageDetails.Message = message.ToString();
|
|
messageDetails.Subject = "LLI - Request For Delivery";
|
|
messageDetails.CC = _config["Canvass:CC"];
|
|
messageDetails.SenderEmail = _config["SMTP:SenderEmail"];
|
|
messageDetails.DisplayName = "lloydlabinc.com";
|
|
messageDetails.NewPassword = _config["SMTP:Password"];
|
|
messageDetails.OutGoingPort = 587;
|
|
messageDetails.Server = _config["SMTP:Server"];
|
|
messageDetails.UserName = _config["SMTP:UserName"];
|
|
messageDetails.IsSuccess = false;
|
|
await _smtpHelper.SendEmailAsync(messageDetails);
|
|
}
|
|
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostApprovedSupplier(PODto),
|
|
nameof(PostApprovedSupplier), true
|
|
);
|
|
}
|
|
[HttpPost("PostApprovedSuggested")]
|
|
public async Task<IActionResult> PostApprovedSuggested(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostApprovedSuggested(PODto),
|
|
nameof(PostApprovedSuggested), true
|
|
);
|
|
}
|
|
[HttpPost("PutPRItemDetails")]
|
|
public async Task<IActionResult> PutPRItemDetails(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PutPRItemDetails(PODto),
|
|
nameof(PutPRItemDetails), true
|
|
);
|
|
}
|
|
[HttpPost("PutPOItemDetail")]
|
|
public async Task<IActionResult> PutPOItemDetail(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PutPOItemDetail(PODto),
|
|
nameof(PutPOItemDetail), true
|
|
);
|
|
}
|
|
[HttpPost("PostPutDocRequired")]
|
|
public async Task<IActionResult> PostPutDocRequired(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostPutDocRequired(PODto),
|
|
nameof(PostPutDocRequired),true
|
|
);
|
|
}
|
|
[HttpPost("PostPutOtherCharges")]
|
|
public async Task<IActionResult> PostPutOtherCharges(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostPutOtherCharges(PODto),
|
|
nameof(PostPutOtherCharges), true
|
|
);
|
|
}
|
|
[HttpPost("PostPutIncoterms")]
|
|
public async Task<IActionResult> PostPutIncoterms(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.PostPutIncoterms(PODto),
|
|
nameof(PostPutIncoterms), true
|
|
);
|
|
}
|
|
#endregion
|
|
#region Get
|
|
[HttpGet("GetPOFormData")]
|
|
public async Task<IActionResult> GetPOFormData(int? poId = null)
|
|
{
|
|
var data = await _purchaseOrder.GetPOFormDataAsync(poId);
|
|
return Ok(data);
|
|
}
|
|
[HttpPost("GetPOListByTerm")]
|
|
public async Task<IActionResult> GetPOListByTerm(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPOListByTerm(itemDto),
|
|
nameof(GetPOListByTerm), false
|
|
);
|
|
}
|
|
[HttpPost("GetIncomingShipment")]
|
|
public async Task<IActionResult> GetIncomingShipment(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetIncomingShipment(itemDto),
|
|
nameof(GetIncomingShipment), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRPOSummaryItem")]
|
|
public async Task<IActionResult> GetPRPOSummaryItem(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPRPOSummaryItem(itemDto),
|
|
nameof(GetPRPOSummaryItem), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRPOSummaryReport")]
|
|
public async Task<IActionResult> GetPRPOSummaryReport(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPRPOSummaryReport(itemDto),
|
|
nameof(GetPRPOSummaryReport), false
|
|
);
|
|
}
|
|
[HttpPost("GetIncoterms")]
|
|
public async Task<IActionResult> GetIncoterms(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetIncoterms(itemDto),
|
|
nameof(GetIncoterms),false
|
|
);
|
|
}
|
|
[HttpPost("GetIncotermsByName")]
|
|
public async Task<IActionResult> GetIncotermsByName(PODto itemDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetIncotermsByName(itemDto),
|
|
nameof(GetIncoterms), false
|
|
);
|
|
}
|
|
[HttpPost("GetPOItemDetail")]
|
|
public async Task<IActionResult> GetPOItemDetail(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPOItemDetail(PODto),
|
|
nameof(GetPOItemDetail), false
|
|
);
|
|
}
|
|
[HttpPost("GetSupplierBidByItem")]
|
|
public async Task<IActionResult> GetSupplierBidByItem(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetSupplierBidByItem(PODto),
|
|
nameof(GetSupplierBidByItem), false
|
|
);
|
|
}
|
|
[HttpPost("GetSupplierBidById")]
|
|
public async Task<IActionResult> GetSupplierBidById(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetSupplierBidById(PODto),
|
|
nameof(GetSupplierBidById), false
|
|
);
|
|
}
|
|
[HttpPost("GetForBiddingApproval")]
|
|
public async Task<IActionResult> GetForBiddingApproval(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetForBiddingApproval(PODto),
|
|
nameof(GetForBiddingApproval), false
|
|
);
|
|
}
|
|
[HttpPost("GetForPOPerSuppEmail")]
|
|
public async Task<IActionResult> GetForPOPerSuppEmail(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetForPOPerSuppEmail(PODto),
|
|
nameof(GetForPOPerSuppEmail), false
|
|
);
|
|
}
|
|
|
|
[HttpPost("GetForPO")]
|
|
public async Task<IActionResult> GetForPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetForPO(PODto),
|
|
nameof(GetForPO), false
|
|
);
|
|
}
|
|
[HttpPost("GetMyCreatedPO")]
|
|
public async Task<IActionResult> GetMyCreatedPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetMyCreatedPO(PODto),
|
|
nameof(GetMyCreatedPO), false
|
|
);
|
|
}
|
|
[HttpPost("GetCreatedPO")]
|
|
public async Task<IActionResult> GetCreatedPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetCreatedPO(PODto),
|
|
nameof(GetCreatedPO), false
|
|
);
|
|
}
|
|
[HttpPost("GetForPOApprovalByPRNo")]
|
|
public async Task<IActionResult> GetForPOApprovalByPRNo(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetForPOApprovalByPRNo(PODto),
|
|
nameof(GetForPOApprovalByPRNo), false
|
|
);
|
|
}
|
|
[HttpPost("GetForPOApproval")]
|
|
public async Task<IActionResult> GetForPOApproval(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetForPOApproval(PODto),
|
|
nameof(GetForPOApproval), false
|
|
);
|
|
}
|
|
[HttpPost("GetApprovedPO")]
|
|
public async Task<IActionResult> GetApprovedPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetApprovedPO(PODto),
|
|
nameof(GetApprovedPO), false
|
|
);
|
|
}
|
|
[HttpPost("GetApprovedPOPerEmail")]
|
|
public async Task<IActionResult> GetApprovedPOPerEmail(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetApprovedPOPerEmail(PODto),
|
|
nameof(GetApprovedPOPerEmail), false
|
|
);
|
|
}
|
|
[HttpPost("GetCreatedPOPerSupId")]
|
|
public async Task<IActionResult> GetCreatedPOPerSupId(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetCreatedPOPerSupId(PODto),
|
|
nameof(GetCreatedPOPerSupId), false
|
|
);
|
|
}
|
|
[HttpPost("GetPaymentTerms")]
|
|
public async Task<IActionResult> GetPaymentTerms(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPaymentTerms(PODto),
|
|
nameof(GetPaymentTerms), false
|
|
);
|
|
}
|
|
[HttpPost("GetPortOfDischarge")]
|
|
public async Task<IActionResult> GetPortOfDischarge(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPortOfDischarge(PODto),
|
|
nameof(GetPortOfDischarge), false
|
|
);
|
|
}
|
|
[HttpPost("GetLatestPO")]
|
|
public async Task<IActionResult> GetLatestPO(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetLatestPO(PODto),
|
|
nameof(GetLatestPO), false
|
|
);
|
|
}
|
|
[HttpPost("GetLatestPO2")]
|
|
public async Task<IActionResult> GetLatestPO2(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetLatestPO2(PODto),
|
|
nameof(GetLatestPO2), false
|
|
);
|
|
}
|
|
[HttpPost("GetDocRequired")]
|
|
public async Task<IActionResult> GetDocRequired(PODto PODto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetDocRequired(PODto),
|
|
nameof(GetDocRequired), false
|
|
);
|
|
}
|
|
[HttpPost("GetOtherCharges")]
|
|
public async Task<IActionResult> GetOtherCharges(PODto poDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetOtherCharges(poDto),
|
|
nameof(GetOtherCharges), false
|
|
);
|
|
}
|
|
[HttpPost("GetSuppliers")]
|
|
public async Task<IActionResult> GetSuppliers(PODto poDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetSuppliers(poDto),
|
|
nameof(GetSuppliers), false
|
|
);
|
|
}
|
|
[HttpPost("GetPRWOCanvass")]
|
|
public async Task<IActionResult> GetPRWOCanvass(PODto poDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetPRWOCanvass(poDto),
|
|
nameof(GetPRWOCanvass), false
|
|
);
|
|
}
|
|
[HttpPost("GetIndexCard")]
|
|
public async Task<IActionResult> GetIndexCard(PODto poDto)
|
|
{
|
|
return await ExecuteWithErrorHandling(
|
|
() => _purchaseOrder.GetIndexCard(poDto),
|
|
nameof(GetIndexCard), false
|
|
);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|