diff --git a/CPRNIMS.Domain/Contracts/PR/IPRequest.cs b/CPRNIMS.Domain/Contracts/PR/IPRequest.cs index 5957585..bde3479 100644 --- a/CPRNIMS.Domain/Contracts/PR/IPRequest.cs +++ b/CPRNIMS.Domain/Contracts/PR/IPRequest.cs @@ -18,10 +18,10 @@ namespace CPRNIMS.Domain.Contracts.PR Task> GetForReceiving(PRDto PRDto); Task> GetDashBoard(PRDto PRDto); Task> GetMyPR(PRDto PRDto); - Task> GetAllPR(PRDto PRDto); + Task> GetAllPR(PRDto PRDto); Task> GetPRListByPRNo(PRDto PRDto); Task> GetNotifUserKey(PRDto PRDto); - Task> GetPRDetailByPRNo(PRDto PRDto); + Task> GetPRDetailByPRNo(PRDto PRDto); Task> GetPRStatusById(PRDto PRDto); Task> GetDetailedPRTracking(PRDto PRDto); Task> GetSupplierAlternativeOffer(PRDto PRDto); diff --git a/CPRNIMS.Domain/Services/PR/PRequest.cs b/CPRNIMS.Domain/Services/PR/PRequest.cs index 8fe02d4..5e9b45d 100644 --- a/CPRNIMS.Domain/Services/PR/PRequest.cs +++ b/CPRNIMS.Domain/Services/PR/PRequest.cs @@ -25,7 +25,7 @@ namespace CPRNIMS.Domain.Services.PR _dbContext = dbContext; } #region Get - public async Task> GetAllPR(PRDto PRDto) + public async Task> GetAllPR(PRDto PRDto) { var allItems = await _dbContext.PRLists .FromSqlRaw($"EXEC GetAllPR @UserId,@IsArchived", @@ -33,7 +33,7 @@ namespace CPRNIMS.Domain.Services.PR new SqlParameter("@IsArchived", PRDto.IsArchived)) .ToListAsync(); - return allItems ?? new List(); + return allItems ?? new List(); } public async Task> GetApproverName(PRDto PRDto) { @@ -109,15 +109,15 @@ namespace CPRNIMS.Domain.Services.PR return allItems ?? new List(); } - public async Task> GetPRDetailByPRNo(PRDto PRDto) + public async Task> GetPRDetailByPRNo(PRDto PRDto) { - var allItems = await _dbContext.PRDetails + var allItems = await _dbContext.PRItemLists .FromSqlRaw($"EXEC GetPRDetailByPRNo @UserId, @PRNo", new SqlParameter("@UserId", PRDto.UserId), new SqlParameter("@PRNo", PRDto.PRNo)) .ToListAsync(); - return allItems ?? new List(); + return allItems ?? new List(); } public async Task> GetPRStatusById(PRDto PRDto) { diff --git a/CPRNIMS.Domain/UIContracts/PR/IPRequest.cs b/CPRNIMS.Domain/UIContracts/PR/IPRequest.cs index 16ed3b2..2d93601 100644 --- a/CPRNIMS.Domain/UIContracts/PR/IPRequest.cs +++ b/CPRNIMS.Domain/UIContracts/PR/IPRequest.cs @@ -36,5 +36,6 @@ namespace CPRNIMS.Domain.UIContracts.PR Task PutAlternativeOffer(User user, PRVM viewModel); Task PutSupplierAlterOffer(User user, PRVM viewModel); Task PRItemRemoval(User user, PRVM viewModel); + Task ApprovedSelectedPRItem(User user, PRVM viewModel); } } diff --git a/CPRNIMS.Domain/UIServices/PR/PRequest.cs b/CPRNIMS.Domain/UIServices/PR/PRequest.cs index 53dd429..d93e017 100644 --- a/CPRNIMS.Domain/UIServices/PR/PRequest.cs +++ b/CPRNIMS.Domain/UIServices/PR/PRequest.cs @@ -248,6 +248,11 @@ namespace CPRNIMS.Domain.UIServices.PR return await SendPostApiRequest(user, viewModel, _configuration["LLI:NonInvent:PRMgmt:PRItemRemoval"]); } + public async Task ApprovedSelectedPRItem(User user, PRVM viewModel) + { + return await SendPostApiRequest(user, viewModel, + _configuration["LLI:NonInvent:PRMgmt:ApprovedSelectedPRItem"]); + } #endregion } } \ No newline at end of file diff --git a/CPRNIMS.Infrastructure/Database/NonInventoryDbContext.cs b/CPRNIMS.Infrastructure/Database/NonInventoryDbContext.cs index a334542..963a302 100644 --- a/CPRNIMS.Infrastructure/Database/NonInventoryDbContext.cs +++ b/CPRNIMS.Infrastructure/Database/NonInventoryDbContext.cs @@ -46,6 +46,7 @@ namespace CPRNIMS.Infrastructure.Database public virtual DbSet Approved { get; set; } public virtual DbSet SMTPCredentials { get; set; } public virtual DbSet PRDetails { get; set; } + public virtual DbSet PRItemLists { get; set; } public virtual DbSet NotificationByIds { get; set; } public virtual DbSet AlternativeOffers { get; set; } public virtual DbSet AlternativeOfferDetails { get; set; } diff --git a/CPRNIMS.Infrastructure/Dto/PR/PRList.cs b/CPRNIMS.Infrastructure/Dto/PR/PRList.cs new file mode 100644 index 0000000..70dd345 --- /dev/null +++ b/CPRNIMS.Infrastructure/Dto/PR/PRList.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CPRNIMS.Infrastructure.Dto.PR +{ + public class PRList + { + public List? PRDetailsId { get; set; } + public List? ItemNo { get; set; } + } +} diff --git a/CPRNIMS.Infrastructure/Entities/Purchasing/PRItemList.cs b/CPRNIMS.Infrastructure/Entities/Purchasing/PRItemList.cs new file mode 100644 index 0000000..7f31302 --- /dev/null +++ b/CPRNIMS.Infrastructure/Entities/Purchasing/PRItemList.cs @@ -0,0 +1,41 @@ +using CPRNIMS.Infrastructure.Entities.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CPRNIMS.Infrastructure.Entities.Purchasing +{ + public class PRItemList : CommonProperties + { + [Key] + public long PRDetailsId { get; set; } + public long ItemCodeId { get; set; } + public short ItemClassId { get; set; } + public string? Department { get; set; } + public string? ItemCategoryName { get; set; } + public string? UserId { get; set; } + public string? ItemName { get; set; } + public decimal TotalAmount { get; set; } + public string? ItemDescription { get; set; } + public short Status { get; set; } + public string? StatusName { get; set; } + public bool IsActive { get; set; } + public long ItemNo { get; set; } + public string? ItemLocalName { get; set; } + public decimal Qty { get; set; } + public string? NewPRNo { get; set; } + public string? ItemClassName { get; set; } + public string? UOMName { get; set; } + public string? ItemColorName { get; set; } + public string? ItemAttachPath { get; set; } + public long PRNo { get; set; } + public string? Remarks { get; set; } + public DateTime DateNeeded { get; set; } + public bool Queue { get; set; } + public string? AttestedBy { get; set; } + public string? ApprovedBy { get; set; } + } +} diff --git a/CPRNIMS.Infrastructure/ViewModel/PR/PRVM.cs b/CPRNIMS.Infrastructure/ViewModel/PR/PRVM.cs index 5dd97ad..e1f6db6 100644 --- a/CPRNIMS.Infrastructure/ViewModel/PR/PRVM.cs +++ b/CPRNIMS.Infrastructure/ViewModel/PR/PRVM.cs @@ -1,4 +1,5 @@ -using CPRNIMS.Infrastructure.Entities.Common; +using CPRNIMS.Infrastructure.Dto.PR; +using CPRNIMS.Infrastructure.Entities.Common; using System; using System.Collections.Generic; using System.Linq; @@ -123,5 +124,6 @@ namespace CPRNIMS.Infrastructure.ViewModel.PR public int AlternativeOfferId { get; set; } public string? AggreDescription { get; set; } public ItemReceivingList? ItemList { get; set; } + public PRList? PRList { get; set; } } } diff --git a/CPRNIMS.WebApi/Controllers/Inventory/InventoryMgmtController.cs b/CPRNIMS.WebApi/Controllers/Inventory/InventoryMgmtController.cs index ca0aeeb..f126061 100644 --- a/CPRNIMS.WebApi/Controllers/Inventory/InventoryMgmtController.cs +++ b/CPRNIMS.WebApi/Controllers/Inventory/InventoryMgmtController.cs @@ -28,18 +28,7 @@ namespace CPRNIMS.WebApi.Controllers.Inventory [HttpPost("GetInventoryByUserId")] public async Task GetInventoryByUserId(InventoryDto itemCodeDto) { - try - { - var allPR = await _inventory.GetInventoryByUserId(itemCodeDto); - - return Ok(allPR); - } - catch (Exception ex) - { - var message = ex.InnerException?.ToString() ?? ex.Message.ToString(); - await PostErrorMessage(message + "GetInventoryByUserId", "WebApi"); - throw; - } + return Ok(await _inventory.GetInventoryByUserId(itemCodeDto)); } [HttpPost("GetRequestedItemByUserId")] public async Task GetRequestedItemByUserId(InventoryDto itemCodeDto) diff --git a/CPRNIMS.WebApi/Controllers/PR/PRMgmtController.cs b/CPRNIMS.WebApi/Controllers/PR/PRMgmtController.cs index 698ce04..7b7f687 100644 --- a/CPRNIMS.WebApi/Controllers/PR/PRMgmtController.cs +++ b/CPRNIMS.WebApi/Controllers/PR/PRMgmtController.cs @@ -28,6 +28,38 @@ namespace CPRNIMS.WebApi.Controllers.PR _pRequest = pRequest; } #region POST PUT + [HttpPost("ApprovedSelectedPRItem")] + public async Task ApprovedSelectedPRItem([FromBody] PRVM PRDto) + { + return await ExecuteWithErrorHandling(async () => + { + var results = new List(); + + 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 PostPutDeniedItem([FromBody] PRVM viewModel) { diff --git a/CPRNIMS.WebApps/Controllers/Inventory/InventoryMgmtController.cs b/CPRNIMS.WebApps/Controllers/Inventory/InventoryMgmtController.cs index 8224032..1ca392c 100644 --- a/CPRNIMS.WebApps/Controllers/Inventory/InventoryMgmtController.cs +++ b/CPRNIMS.WebApps/Controllers/Inventory/InventoryMgmtController.cs @@ -80,16 +80,8 @@ namespace CPRNIMS.WebApps.Controllers.Inventory } public async Task GetInventoryByUserId(InventoryVM viewModels) { - try - { - response = await _inventory.GetInventoryByUserId(GetUser(), viewModels); - return GetResponse(response); - } - catch (Exception ex) - { - var message = ex.InnerException?.ToString() ?? ex.Message.ToString(); - throw; - } + response = await _inventory.GetInventoryByUserId(GetUser(), viewModels); + return GetResponse(response); } public async Task GetRequestedItemByUserId(InventoryVM viewModels) { diff --git a/CPRNIMS.WebApps/Controllers/PR/PRMgmtController.cs b/CPRNIMS.WebApps/Controllers/PR/PRMgmtController.cs index d07432a..42913e5 100644 --- a/CPRNIMS.WebApps/Controllers/PR/PRMgmtController.cs +++ b/CPRNIMS.WebApps/Controllers/PR/PRMgmtController.cs @@ -1,4 +1,5 @@ using CPRNIMS.Domain.UIContracts.PR; +using CPRNIMS.Infrastructure.Dto.PR; using CPRNIMS.Infrastructure.Helper; using CPRNIMS.Infrastructure.ViewModel.PR; using CPRNIMS.WebApps.Controllers.Base; @@ -97,8 +98,38 @@ namespace CPRNIMS.WebApps.Controllers.PR return GetResponse(response); } + private PRList MapToPRItemList(IEnumerable prList) + { + if (prList == null || !prList.Any()) + { + return new PRList + { + PRDetailsId = new List(), + ItemNo = new List(), + }; + } + + return new PRList + { + PRDetailsId = prList.SelectMany(ic => ic.PRDetailsId).ToList(), + ItemNo = prList.SelectMany(ic => ic.ItemNo).ToList() + }; + } #endregion #region POST PUT + public async Task ApprovedSelectedPRItem(PRVM viewModel, + List PRList) + { + viewModel.PRList = MapToPRItemList(PRList); + + var postPutItem = await _pRequest.ApprovedSelectedPRItem(GetUser(), viewModel); + + if (postPutItem.messCode != 0) + { + return Json(new { success = true }); + } + return Json(new { success = false, Response = postPutItem.Message }); + } public async Task PostPutDeniedItem(PRVM viewModel, List ItemList) { if (ItemList.Count > 0) diff --git a/CPRNIMS.WebApps/Views/PRMgmt/Index.cshtml b/CPRNIMS.WebApps/Views/PRMgmt/Index.cshtml index 2d16064..7772cd1 100644 --- a/CPRNIMS.WebApps/Views/PRMgmt/Index.cshtml +++ b/CPRNIMS.WebApps/Views/PRMgmt/Index.cshtml @@ -77,6 +77,6 @@ @await Html.PartialAsync("PagesView/PR/_PRTracking") - + @await Html.PartialAsync("PagesView/PR/_PRScripts") \ No newline at end of file diff --git a/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRScripts.cshtml b/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRScripts.cshtml index d675c8b..51e8de6 100644 --- a/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRScripts.cshtml +++ b/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRScripts.cshtml @@ -1,16 +1,19 @@  - - - + + + + - + - - + + + + diff --git a/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRTracking.cshtml b/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRTracking.cshtml index dccafef..92f08b8 100644 --- a/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRTracking.cshtml +++ b/CPRNIMS.WebApps/Views/Shared/PagesView/PR/_PRTracking.cshtml @@ -187,8 +187,8 @@ -