diff --git a/CPRNIMS.Domain/CPRNIMS.Domain.csproj b/CPRNIMS.Domain/CPRNIMS.Domain.csproj
index cb1b764..ae1b559 100644
--- a/CPRNIMS.Domain/CPRNIMS.Domain.csproj
+++ b/CPRNIMS.Domain/CPRNIMS.Domain.csproj
@@ -8,6 +8,7 @@
+
diff --git a/CPRNIMS.Domain/Contracts/PO/IPurchaseOrder.cs b/CPRNIMS.Domain/Contracts/PO/IPurchaseOrder.cs
index 6474bfd..fb65b5c 100644
--- a/CPRNIMS.Domain/Contracts/PO/IPurchaseOrder.cs
+++ b/CPRNIMS.Domain/Contracts/PO/IPurchaseOrder.cs
@@ -15,6 +15,8 @@ namespace CPRNIMS.Domain.Contracts.PO
public interface IPurchaseOrder
{
#region Get
+ Task GetPOFormDataAsync(long? poId);
+ Task> GetPOListByTerm(PODto itemDto);
Task> GetIncomingShipment(PODto itemDto);
Task> GetIndexCard(PODto poDto);
Task> GetForPOApprovalByPRNo(PODto PODto);
diff --git a/CPRNIMS.Domain/Services/PO/PurchaseOrder.cs b/CPRNIMS.Domain/Services/PO/PurchaseOrder.cs
index a098b7e..2dc2b9a 100644
--- a/CPRNIMS.Domain/Services/PO/PurchaseOrder.cs
+++ b/CPRNIMS.Domain/Services/PO/PurchaseOrder.cs
@@ -1,8 +1,6 @@
using CPRNIMS.Domain.Contracts.PO;
using CPRNIMS.Infrastructure.Database;
-using CPRNIMS.Infrastructure.Dto.Items;
using CPRNIMS.Infrastructure.Dto.PO;
-using CPRNIMS.Infrastructure.Dto.PR;
using CPRNIMS.Infrastructure.Entities.Canvass;
using CPRNIMS.Infrastructure.Entities.Common;
using CPRNIMS.Infrastructure.Entities.LocalDb.NonInvent;
@@ -10,6 +8,7 @@ using CPRNIMS.Infrastructure.Entities.PO;
using CPRNIMS.Infrastructure.Helper;
using CPRNIMS.Infrastructure.ViewModel.Common;
using CPRNIMS.Infrastructure.ViewModel.PO;
+using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Data;
@@ -30,6 +29,32 @@ namespace CPRNIMS.Domain.Services.PO
_smptHelper = smptHelper;
}
#region Get
+ public async Task GetPOFormDataAsync(long? poId)
+ {
+ // Reuse the connection from your existing DbContext
+ var conn = _dbContext.Database.GetDbConnection();
+
+ var param = new DynamicParameters();
+ param.Add("@POId", poId, DbType.Int64);
+
+ // Open only if not already open (EF Core may have it open already)
+ if (conn.State != ConnectionState.Open)
+ await conn.OpenAsync();
+
+ using var multi = await conn.QueryMultipleAsync(
+ "GetExistingPOFormData",
+ param,
+ commandType: CommandType.StoredProcedure
+ );
+
+ return new POFormData
+ {
+ Header = await multi.ReadFirstOrDefaultAsync(),
+ LineItems = (await multi.ReadAsync()).ToList(),
+ Charges = (await multi.ReadAsync()).ToList(),
+ DocsRequired = (await multi.ReadAsync()).ToList()
+ };
+ }
public async Task> GetIncoterms(PODto itemDto)
{
return await _dbContext.Incoterms.ToListAsync();
@@ -41,21 +66,13 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task> GetSuppliers(PODto itemDto)
{
- try
- {
- var allItems = await _dbContext.Suppliers
- .FromSqlRaw($"EXEC GetSuppliers @UserId,@SupplierName",
- new SqlParameter("@UserId", itemDto.UserId),
- new SqlParameter("@SupplierName", itemDto.SupplierName))
- .ToListAsync();
+ var allItems = await _dbContext.Suppliers
+ .FromSqlRaw($"EXEC GetSuppliers @UserId,@SupplierName",
+ new SqlParameter("@UserId", itemDto.UserId),
+ new SqlParameter("@SupplierName", itemDto.SupplierName))
+ .ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetPRWOCanvass(PODto itemDto)
{
@@ -69,55 +86,31 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task> GetCreatedPO(PODto pODto)
{
- try
- {
- var createdPOs = await _dbContext.CreatedPOs
- .FromSqlRaw($"EXEC GetCreatedPO @UserId",
- new SqlParameter("@UserId", pODto.UserId))
- .ToListAsync();
+ var createdPOs = await _dbContext.CreatedPOs
+ .FromSqlRaw($"EXEC GetCreatedPO @UserId",
+ new SqlParameter("@UserId", pODto.UserId))
+ .ToListAsync();
- return createdPOs ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return createdPOs ?? new List();
}
public async Task> GetMyCreatedPO(PODto pODto)
{
- try
- {
- var createdPOs = await _dbContext.CreatedPOs
- .FromSqlRaw($"EXEC GetMyCreatedPO @UserId",
- new SqlParameter("@UserId", pODto.UserId))
- .ToListAsync();
+ var createdPOs = await _dbContext.CreatedPOs
+ .FromSqlRaw($"EXEC GetMyCreatedPO @UserId",
+ new SqlParameter("@UserId", pODto.UserId))
+ .ToListAsync();
- return createdPOs ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return createdPOs ?? new List();
}
public async Task> GetApprovedPO(PODto PODto)
{
- try
- {
- var allItems = await _dbContext.ApprovedPOs
- .FromSqlRaw($"EXEC GetApprovedPO @UserId ,@IsArchived",
- new SqlParameter("@UserId", PODto.UserId),
- new SqlParameter("@IsArchived", PODto.IsArchived))
- .ToListAsync();
+ var allItems = await _dbContext.ApprovedPOs
+ .FromSqlRaw($"EXEC GetApprovedPO @UserId ,@IsArchived",
+ new SqlParameter("@UserId", PODto.UserId),
+ new SqlParameter("@IsArchived", PODto.IsArchived))
+ .ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetApprovedPOPerEmail(PODto PODto)
{
@@ -134,24 +127,16 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task> GetCreatedPOPerSupId(PODto pODto)
{
- try
- {
- var allItems = await _dbContext.CreatedPOPerSupIds
- .FromSqlRaw("EXEC GetCreatedPOPerSupId @UserId,@SupplierId,@POTypeId,@PONo,@IsManual",
- new SqlParameter("@UserId", pODto.UserId),
- new SqlParameter("@SupplierId", pODto.SupplierId),
- new SqlParameter("@POTypeId", pODto.POTypeId),
- new SqlParameter("@PONo", pODto.PONo),
- new SqlParameter("@IsManual", pODto.IsManual))
- .ToListAsync();
+ var allItems = await _dbContext.CreatedPOPerSupIds
+ .FromSqlRaw("EXEC GetCreatedPOPerSupId @UserId,@SupplierId,@POTypeId,@PONo,@IsManual",
+ new SqlParameter("@UserId", pODto.UserId),
+ new SqlParameter("@SupplierId", pODto.SupplierId),
+ new SqlParameter("@POTypeId", pODto.POTypeId),
+ new SqlParameter("@PONo", pODto.PONo),
+ new SqlParameter("@IsManual", pODto.IsManual))
+ .ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetDocRequired(PODto pODto)
{
@@ -160,103 +145,54 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task> GetForBiddingApproval(PODto PODto)
{
- try
- {
-
- var allItems = await _dbContext.BiddingApprovals
+ var allItems = await _dbContext.BiddingApprovals
.FromSqlRaw($"EXEC GetForBiddingApproval @UserId",
new SqlParameter("@UserId", PODto.UserId))
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetForPO(PODto PODto)
{
- try
- {
- var allItems = await _dbContext.ForPOs
+ var allItems = await _dbContext.ForPOs
.FromSqlRaw($"EXEC GetForPO @UserId",
new SqlParameter("@UserId", PODto.UserId))
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetForPOApproval(PODto PODto)
{
- try
- {
- var allItems = await _dbContext.ForPOApprovals
+ var allItems = await _dbContext.ForPOApprovals
.FromSqlRaw($"EXEC GetForPOApproval @UserId = '{PODto.UserId}'")
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task>
GetForPOApprovalByPRNo(PODto PODto)
{
- try
- {
- var allItems = await _dbContext.PurchaseOrders
- .FromSqlRaw($"EXEC GetForPOApprovalByPRNo @UserId = '{PODto.UserId}',@PRNo = '{PODto.PRNo}'")
- .ToListAsync();
+ var allItems = await _dbContext.PurchaseOrders
+ .FromSqlRaw($"EXEC GetForPOApprovalByPRNo @UserId = '{PODto.UserId}',@PRNo = '{PODto.PRNo}'")
+ .ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetForPOPerSuppEmail(PODto PODto)
{
- try
- {
- var allItems = await _dbContext.ItemListForPOs
+ var allItems = await _dbContext.ItemListForPOs
.FromSqlRaw($"EXEC GetForPOPerSuppEmail @UserId = '{PODto.UserId}',@EmailAddress = '{PODto.EmailAddress}',@POTypeId = '{PODto.POTypeId}',@PONo = '{PODto.PONo}',@IsArchived = '{PODto.IsArchived}'")
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetLatestPO(PODto pODto)
{
- try
- {
- var allItems = await _dbContext.CentralPONos
+ var allItems = await _dbContext.CentralPONos
.FromSqlRaw($"EXEC GetLatestPO")
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetLatestPO2(PODto pODto)
{
@@ -345,25 +281,15 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task> GetSupplierBidById(PODto itemDto)
{
- try
- {
- var allItems = await _dbContext.RFQPerSuppliers
- .FromSqlRaw($"EXEC GetSupplierBidById @CanvassDetailId = '{itemDto.CanvassDetailId}'")
- .ToListAsync();
+ var allItems = await _dbContext.RFQPerSuppliers
+ .FromSqlRaw($"EXEC GetSupplierBidById @CanvassDetailId = '{itemDto.CanvassDetailId}'")
+ .ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetSupplierBidByItem(PODto itemDto)
{
- try
- {
- var allItems = await _dbContext.RFQPerSuppliers
+ var allItems = await _dbContext.RFQPerSuppliers
.FromSqlRaw($"EXEC GetSupplierBidByItem @UserId,@Status,@ItemNo,@CanvassId,@IsHistory,@PRDetailsId",
new SqlParameter("@UserId", itemDto.UserId),
new SqlParameter("@Status", itemDto.Status),
@@ -373,13 +299,7 @@ namespace CPRNIMS.Domain.Services.PO
new SqlParameter("@PRDetailsId", itemDto.PRDetailsId))
.ToListAsync();
- return allItems ?? new List();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return allItems ?? new List();
}
public async Task> GetPRPOSummaryReport(PODto itemDto)
{
@@ -420,170 +340,130 @@ namespace CPRNIMS.Domain.Services.PO
return allItems ?? new List();
}
+ public async Task> GetPOListByTerm(PODto itemDto)
+ {
+ return await _dbContext.POs
+ .Where(p => !p.IsCancel && !p.IsPOClosed &&
+ p.IsActive && p.PONo.StartsWith(itemDto.PONo ?? "N/A"))
+ .Take(50)
+ .AsNoTracking()
+ .ToListAsync();
+ }
#endregion
#region PostPut
public async Task PostApprovedPO(PODto PODto)
{
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync("EXEC PostApprovedPO @UserId, @PONo",
- new SqlParameter("@PONo", PODto.PONo != null ? PODto.PONo : 0L),
- new SqlParameter("@UserId", PODto.UserId));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync("EXEC PostApprovedPO @UserId, @PONo",
+ new SqlParameter("@PONo", PODto.PONo != null ? PODto.PONo : 0L),
+ new SqlParameter("@UserId", PODto.UserId));
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task PostApprovedSuggested(PODto PODto)
{
- try
- {
- await _dbContext.Database
+ await _dbContext.Database
.ExecuteSqlRawAsync("EXEC PostSuggestedSupp @UserId, @CanvassDetailId, @ItemNo, @SupplierId,@CanvassId",
new SqlParameter("@CanvassDetailId", PODto.CanvassDetailId != null ? PODto.CanvassDetailId : 0L),
new SqlParameter("@UserId", PODto.UserId),
new SqlParameter("@ItemNo", PODto.ItemNo != null ? PODto.ItemNo : 0L),
new SqlParameter("@SupplierId", PODto.SupplierId),
new SqlParameter("@CanvassId", PODto.CanvassId));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task PostApprovedSupplier(PODto PODto)
- {
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync("EXEC PostApprovedSupplier @UserId, @CanvassDetailId, @ItemNo",
+ { await _dbContext.Database
+ .ExecuteSqlRawAsync("EXEC PostApprovedSupplier @UserId, @CanvassDetailId, @ItemNo",
new SqlParameter("@CanvassDetailId", PODto.CanvassDetailId != null ? PODto.CanvassDetailId : 0L),
new SqlParameter("@UserId", PODto.UserId),
new SqlParameter("@ItemNo", PODto.ItemNo));
- return new Suppliers();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return new Suppliers();
}
public async Task PostPOToSupplier(PODto PODto)
{
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync("EXEC PostPOToSupplier @UserId, @POTypeId, @EmailAddress,@PONumber",
- new SqlParameter("@POTypeId", PODto.POTypeId),
- new SqlParameter("@UserId", PODto.UserId),
- new SqlParameter("@EmailAddress", PODto.EmailAddress),
- new SqlParameter("@PONumber", PODto.PONo));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync("EXEC PostPOToSupplier @UserId, @POTypeId, @EmailAddress,@PONumber",
+ new SqlParameter("@POTypeId", PODto.POTypeId),
+ new SqlParameter("@UserId", PODto.UserId),
+ new SqlParameter("@EmailAddress", PODto.EmailAddress),
+ new SqlParameter("@PONumber", PODto.PONo));
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task PostPutPO(PODto PODto)
{
- try
+ if (PODto.UserId == "89da2977-c70f-4df9-94d4-9a610aa999ea" ||
+ PODto.UserId == "ac95500c-4b73-4df8-bdcb-965f9fafec30")
{
- if (PODto.UserId == "89da2977-c70f-4df9-94d4-9a610aa999ea" ||
- PODto.UserId == "ac95500c-4b73-4df8-bdcb-965f9fafec30")
+ await _dbContext.Database
+ .ExecuteSqlRawAsync($"EXEC PostPutPO @UserId,@POTypeId,@SupplierId,@PONumber,@PORemarks,@IncoTermsId,@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@DeliverTo",
+ new SqlParameter("@UserId", PODto.UserId),
+ new SqlParameter("@POTypeId", PODto.POTypeId),
+ new SqlParameter("@SupplierId", PODto.SupplierId),
+ new SqlParameter("@PONumber", PODto.PONo),
+ new SqlParameter("@PORemarks", PODto.PORemarks ?? "N/A"),
+ new SqlParameter("@IncoTermsId", 1),
+ new SqlParameter("@PODId", 1),
+ new SqlParameter("@ProfInvoiceNo", PODto.ProfInvoiceNo ?? "N/A"),
+ new SqlParameter("@ProfInvoiceDate", DateTime.Now),
+ new SqlParameter("@PaymentTermsId", 1),
+ new SqlParameter("@ShippingInstructionId", 1),
+ new SqlParameter("@DeliverTo", PODto.DeliverTo));
+ }
+ else
+ {
+ if (!isUpdated)
{
- await _dbContext.Database
- .ExecuteSqlRawAsync($"EXEC PostPutPO @UserId,@POTypeId,@SupplierId,@PONumber,@PORemarks,@IncoTermsId,@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@DeliverTo",
- new SqlParameter("@UserId", PODto.UserId),
- new SqlParameter("@POTypeId", PODto.POTypeId),
- new SqlParameter("@SupplierId", PODto.SupplierId),
- new SqlParameter("@PONumber", PODto.PONo),
- new SqlParameter("@PORemarks", PODto.PORemarks ?? "N/A"),
- new SqlParameter("@IncoTermsId", 1),
- new SqlParameter("@PODId", 1),
- new SqlParameter("@ProfInvoiceNo", PODto.ProfInvoiceNo ?? "N/A"),
- new SqlParameter("@ProfInvoiceDate", DateTime.Now),
- new SqlParameter("@PaymentTermsId", 1),
- new SqlParameter("@ShippingInstructionId", 1),
- new SqlParameter("@DeliverTo", PODto.DeliverTo));
+ PODto.PONo = await GetLatestPOById(PODto);//Retrieve and Update SystemSettings
}
- else
- {
- if (!isUpdated)
- {
- PODto.PONo = await GetLatestPOById(PODto);//Retrieve and Update SystemSettings
- }
- await _dbContext.Database
- .ExecuteSqlRawAsync($"EXEC PostPutPO @UserId,@POTypeId,@SupplierId,@PONumber,@PORemarks,@IncoTermsId,@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@DeliverTo",
- new SqlParameter("@UserId", PODto.UserId),
- new SqlParameter("@POTypeId", PODto.POTypeId),
- new SqlParameter("@SupplierId", PODto.SupplierId),
- new SqlParameter("@PONumber", formattedPONumber),
- new SqlParameter("@PORemarks", PODto.PORemarks ?? "N/A"),
- new SqlParameter("@IncoTermsId", 1),
- new SqlParameter("@PODId", 1),
- new SqlParameter("@ProfInvoiceNo", PODto.ProfInvoiceNo ?? "N/A"),
- new SqlParameter("@ProfInvoiceDate", DateTime.Now),
- new SqlParameter("@PaymentTermsId", 1),
- new SqlParameter("@ShippingInstructionId", 1),
- new SqlParameter("@DeliverTo", PODto.DeliverTo));
- }
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
+ await _dbContext.Database
+ .ExecuteSqlRawAsync($"EXEC PostPutPO @UserId,@POTypeId,@SupplierId,@PONumber,@PORemarks,@IncoTermsId,@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@DeliverTo",
+ new SqlParameter("@UserId", PODto.UserId),
+ new SqlParameter("@POTypeId", PODto.POTypeId),
+ new SqlParameter("@SupplierId", PODto.SupplierId),
+ new SqlParameter("@PONumber", formattedPONumber),
+ new SqlParameter("@PORemarks", PODto.PORemarks ?? "N/A"),
+ new SqlParameter("@IncoTermsId", 1),
+ new SqlParameter("@PODId", 1),
+ new SqlParameter("@ProfInvoiceNo", PODto.ProfInvoiceNo ?? "N/A"),
+ new SqlParameter("@ProfInvoiceDate", DateTime.Now),
+ new SqlParameter("@PaymentTermsId", 1),
+ new SqlParameter("@ShippingInstructionId", 1),
+ new SqlParameter("@DeliverTo", PODto.DeliverTo));
}
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
private void PutLocalCentralPo(PODto PODto)
{
- try
+ string columnName;
+ string updatedPONo = "";
+ // Determine the column to update based on POTypeId
+ switch (PODto.POTypeId)
{
- string columnName;
- string updatedPONo = "";
- // Determine the column to update based on POTypeId
- switch (PODto.POTypeId)
- {
- case 1: // SI
- // Remove the first two characters from PONo
- updatedPONo = PODto.PONo;
- columnName = "PONoVatInc";
- break;
- case 2: // DR
- updatedPONo = PODto.PONo;
- columnName = "PONoVatEx";
- break;
- case 3: // IMPORT
- updatedPONo = PODto.PONo;
- columnName = "IPONoVatInc";
- break;
- default:
- throw new ArgumentException("Invalid POTypeId.");
- }
+ case 1: // SI
+ // Remove the first two characters from PONo
+ updatedPONo = PODto.PONo;
+ columnName = "PONoVatInc";
+ break;
+ case 2: // DR
+ updatedPONo = PODto.PONo;
+ columnName = "PONoVatEx";
+ break;
+ case 3: // IMPORT
+ updatedPONo = PODto.PONo;
+ columnName = "IPONoVatInc";
+ break;
+ default:
+ throw new ArgumentException("Invalid POTypeId.");
+ }
- // Build the SQL query
- string query = $@"
+ // Build the SQL query
+ string query = $@"
UPDATE [dbo].[SystemSettings]
SET {columnName} = @UpdatedPONo
WHERE {columnName} IS NOT NULL";
- // Execute the raw SQL query
- _dbLocalContext.Database.ExecuteSqlRaw(query, new SqlParameter("@UpdatedPONo", updatedPONo));
- }
- catch (Exception ex)
- {
- ex.ToString();
- throw;
- }
+ // Execute the raw SQL query
+ _dbLocalContext.Database.ExecuteSqlRaw(query, new SqlParameter("@UpdatedPONo", updatedPONo));
}
public async Task PostPutCustomPO(PODto pODto)
{
@@ -693,107 +573,68 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task PostSuppDocRequirements(PODto poDto)
{
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync("EXEC PostSuppDocRequirements @UserId,@DocRequirementId,@PONumber",
- new SqlParameter("@DocRequirementId", poDto.DocRequirementId),
- new SqlParameter("@UserId", poDto.UserId),
- new SqlParameter("@PONumber", formattedPONumber));
- return new DocRequired();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync("EXEC PostSuppDocRequirements @UserId,@DocRequirementId,@PONumber",
+ new SqlParameter("@DocRequirementId", poDto.DocRequirementId),
+ new SqlParameter("@UserId", poDto.UserId),
+ new SqlParameter("@PONumber", formattedPONumber));
+ return new DocRequired();
}
public async Task PostSuppCharges(PODto poDto)
{
- try
- {
- await _dbContext.Database
+ await _dbContext.Database
.ExecuteSqlRawAsync("EXEC PostSuppCharges @UserId,@PONo,@OtherChargesId,@POTypeId,@Amount",
new SqlParameter("@UserId", poDto.UserId),
new SqlParameter("@PONo", formattedPONumber),
new SqlParameter("@OtherChargesId", poDto.OtherChargesId),
new SqlParameter("@POTypeId", poDto.POTypeId),
new SqlParameter("@Amount", poDto.Amount));
- return new OtherCharges();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ return new OtherCharges();
}
public async Task PutPRItemDetails(PODto pODto)
{
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync($"EXEC PutPRItemDetails @UserId,@ItemName,@Specification,@Qty,@UOMId,@PRDetailsId",
- new SqlParameter("@UserId", pODto.UserId),
- new SqlParameter("@ItemName", pODto.ItemName),
- new SqlParameter("@Specification", pODto.Specification),
- new SqlParameter("@Qty", pODto.Qty),
- new SqlParameter("@UOMId", pODto.UOMId),
- new SqlParameter("@PRDetailsId", pODto.PRDetailsId));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync($"EXEC PutPRItemDetails @UserId,@ItemName,@Specification,@Qty,@UOMId,@PRDetailsId",
+ new SqlParameter("@UserId", pODto.UserId),
+ new SqlParameter("@ItemName", pODto.ItemName),
+ new SqlParameter("@Specification", pODto.Specification),
+ new SqlParameter("@Qty", pODto.Qty),
+ new SqlParameter("@UOMId", pODto.UOMId),
+ new SqlParameter("@PRDetailsId", pODto.PRDetailsId));
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task PutPOItemDetail(PODto pODto)
{
- try
- {
- await _dbContext.Database
- .ExecuteSqlRawAsync($"EXEC PutPOItemDetail @UserId,@UOMId,@Qty,@PRDetailsId,@Remarks,@ItemDescription,@Specification,@PONo,@UnitPrice,@PaymentTermsId,@PODId",
- new SqlParameter("@UserId", pODto.UserId),
- new SqlParameter("@UOMId", pODto.UOMId),
- new SqlParameter("@Qty", pODto.Qty),
- new SqlParameter("@PRDetailsId", pODto.PRDetailsId),
- new SqlParameter("@Remarks", pODto.PORemarks),
- new SqlParameter("@ItemDescription", pODto.ItemDescription),
- new SqlParameter("@Specification", pODto.Specification),
- new SqlParameter("@PONo", pODto.PONo),
- new SqlParameter("@UnitPrice", pODto.UnitPrice),
- new SqlParameter("@PaymentTermsId", pODto.PaymentTermsId),
- new SqlParameter("@PODId", pODto.PODId));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException ex)
- {
- ex.ToString();
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync($"EXEC PutPOItemDetail @UserId,@UOMId,@Qty,@PRDetailsId,@Remarks,@ItemDescription,@Specification,@PONo,@UnitPrice,@PaymentTermsId,@PODId",
+ new SqlParameter("@UserId", pODto.UserId),
+ new SqlParameter("@UOMId", pODto.UOMId),
+ new SqlParameter("@Qty", pODto.Qty),
+ new SqlParameter("@PRDetailsId", pODto.PRDetailsId),
+ new SqlParameter("@Remarks", pODto.PORemarks),
+ new SqlParameter("@ItemDescription", pODto.ItemDescription),
+ new SqlParameter("@Specification", pODto.Specification),
+ new SqlParameter("@PONo", pODto.PONo),
+ new SqlParameter("@UnitPrice", pODto.UnitPrice),
+ new SqlParameter("@PaymentTermsId", pODto.PaymentTermsId),
+ new SqlParameter("@PODId", pODto.PODId));
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task PutMyPONo(PODto pODto)
{
- try
+ string oldPONo = pODto.PONo;
+ if (!isUpdated)
{
- string oldPONo = pODto.PONo;
- if (!isUpdated)
- {
- await GetLatestPOById(pODto);
- }
+ await GetLatestPOById(pODto);
+ }
- await _dbContext.Database
- .ExecuteSqlRawAsync($"EXEC PutMyPONo @UserId,@OldPONo,@NewPONo,@PORemarks",
- new SqlParameter("@UserId", pODto.UserId),
- new SqlParameter("@OldPONo", oldPONo),
- new SqlParameter("@NewPONo", formattedPONumber),
- new SqlParameter("@PORemarks", pODto.PORemarks));
- return new Infrastructure.Entities.PO.PurchaseOrder();
- }
- catch (SqlException)
- {
- throw;
- }
+ await _dbContext.Database
+ .ExecuteSqlRawAsync($"EXEC PutMyPONo @UserId,@OldPONo,@NewPONo,@PORemarks",
+ new SqlParameter("@UserId", pODto.UserId),
+ new SqlParameter("@OldPONo", oldPONo),
+ new SqlParameter("@NewPONo", formattedPONumber),
+ new SqlParameter("@PORemarks", pODto.PORemarks));
+ return new Infrastructure.Entities.PO.PurchaseOrder();
}
public async Task> GetPOItemDetail(PODto pODto)
{
@@ -909,103 +750,71 @@ namespace CPRNIMS.Domain.Services.PO
}
public async Task DeleteIncShip(PODto poDto)
{
- try
- {
- var inc = await _dbContext.IncomingShipments
- .FirstOrDefaultAsync(i => i.POId == poDto.POId);
+ var inc = await _dbContext.IncomingShipments
+ .FirstOrDefaultAsync(i => i.POId == poDto.POId);
- if (inc != null)
- {
- inc.IsActive = false;
- _dbContext.SaveChanges();
- }
- return true;
- }
- catch (Exception ex)
+ if (inc != null)
{
- return false;
+ inc.IsActive = false;
+ _dbContext.SaveChanges();
}
+ return true;
}
public string EMailTemplate(string relativePath, string emailTemplate)
{
- try
- {
- string basePath = AppContext.BaseDirectory;
- string templateFolderPath = Path.Combine(basePath, relativePath);
- string templateFilePath = Path.Combine(templateFolderPath, emailTemplate);
+ string basePath = AppContext.BaseDirectory;
+ string templateFolderPath = Path.Combine(basePath, relativePath);
+ string templateFilePath = Path.Combine(templateFolderPath, emailTemplate);
- if (System.IO.File.Exists(templateFilePath))
- {
- return System.IO.File.ReadAllText(templateFilePath);
- }
- else
- {
- Console.WriteLine($"File not found: {templateFilePath}");
- return "Template file not found";
- }
- }
- catch (Exception ex)
+ if (System.IO.File.Exists(templateFilePath))
{
- var errorMessage = ex.ToString();
- throw new Exception($"Error loading email template: {errorMessage}", ex);
+ return System.IO.File.ReadAllText(templateFilePath);
+ }
+ else
+ {
+ Console.WriteLine($"File not found: {templateFilePath}");
+ return "Template file not found";
}
}
public async Task PostIncShipFollowUp(PODto itemDto, List shipFollowUp)
{
- try
- {
- var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "IncShipFollowUp.cshtml");
+ var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "IncShipFollowUp.cshtml");
- // Use the passed data instead of re-querying
- foreach (var incShip in shipFollowUp)
+ // Use the passed data instead of re-querying
+ foreach (var incShip in shipFollowUp)
+ {
+ var message = new StringBuilder(baseTemplate);
+ message.Replace("@ViewBag.PONo", Convert.ToString(incShip.PONo));
+ message.Replace("@ViewBag.ProfInvoiceNo", Convert.ToString(incShip.ProfInvoiceNo));
+ message.Replace("@ViewBag.DeliveryDate", Convert.ToString(incShip.DeliveryDate));
+ message.Replace("@ViewBag.Supplier", Convert.ToString(incShip.SupplierName));
+ message.Replace("@ViewBag.Signature", Convert.ToString(incShip.Signature));
+
+ var messageDetails = new EmailMessageDetailsVM
{
- var message = new StringBuilder(baseTemplate);
- message.Replace("@ViewBag.PONo", Convert.ToString(incShip.PONo));
- message.Replace("@ViewBag.ProfInvoiceNo", Convert.ToString(incShip.ProfInvoiceNo));
- message.Replace("@ViewBag.DeliveryDate", Convert.ToString(incShip.DeliveryDate));
- message.Replace("@ViewBag.Supplier", Convert.ToString(incShip.SupplierName));
- message.Replace("@ViewBag.Signature", Convert.ToString(incShip.Signature));
+ Recipient = incShip.EmailAddress,
+ Message = message.ToString(),
+ Subject = incShip.Subject,
+ CC = incShip.CC,
+ IsSuccess = false,
+ SenderEmail = incShip.UserName,
+ DisplayName = "llipurchasing.com",
+ NewPassword = incShip.Password,
+ OutGoingPort = 587,
+ Server = incShip.Server,
+ UserName = incShip.UserName
+ };
- var messageDetails = new EmailMessageDetailsVM
- {
- Recipient = incShip.EmailAddress,
- Message = message.ToString(),
- Subject = incShip.Subject,
- CC = incShip.CC,
- IsSuccess = false,
- SenderEmail = incShip.UserName,
- DisplayName = "llipurchasing.com",
- NewPassword = incShip.Password,
- OutGoingPort = 587,
- Server = incShip.Server,
- UserName = incShip.UserName
- };
-
- await _smptHelper.SendEmailAsync(messageDetails);
- }
- }
- catch (Exception ex)
- {
- var errorMessage = ex.InnerException?.ToString() ?? ex.Message.ToString();
- // Log the error properly
- throw;
+ await _smptHelper.SendEmailAsync(messageDetails);
}
}
public async Task PostIncShipFollowUp(PODto itemDto)
{
- try
- {
- var shipFollowUp = await GetIncomingShipment(itemDto);
- await PostIncShipFollowUp(itemDto, shipFollowUp);
- return true;
- }
- catch (Exception ex)
- {
- ex.ToString();
- return false;
- }
-
+ var shipFollowUp = await GetIncomingShipment(itemDto);
+ await PostIncShipFollowUp(itemDto, shipFollowUp);
+ return true;
}
+
#endregion
}
}
diff --git a/CPRNIMS.Domain/UIContracts/PO/ICustomPOService.cs b/CPRNIMS.Domain/UIContracts/PO/ICustomPOService.cs
new file mode 100644
index 0000000..f1bf3fc
--- /dev/null
+++ b/CPRNIMS.Domain/UIContracts/PO/ICustomPOService.cs
@@ -0,0 +1,14 @@
+using CPRNIMS.Infrastructure.Entities.PO;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Domain.UIContracts.PO
+{
+ public interface ICustomPOService
+ {
+ Task GetPOFormDataAsync(long? poId = null);
+ }
+}
diff --git a/CPRNIMS.Domain/UIContracts/PO/IPurchaseOrder.cs b/CPRNIMS.Domain/UIContracts/PO/IPurchaseOrder.cs
index 6517421..fc84e34 100644
--- a/CPRNIMS.Domain/UIContracts/PO/IPurchaseOrder.cs
+++ b/CPRNIMS.Domain/UIContracts/PO/IPurchaseOrder.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace CPRNIMS.Domain.UIContracts.PO
{
- public interface IPurchaseOrder
+ public interface IPurchaseOrder
{
#region Get
Task> GetSupplierBidById(User user, POVM viewModel);
@@ -40,6 +40,7 @@ namespace CPRNIMS.Domain.UIContracts.PO
Task?> GetIndexCard(User user, POVM viewModel);
Task?> GetPortOfDischarge(User user, POVM viewModels);
Task?> GetIncomingShipment(User user, POVM viewModels);
+ Task?> GetPOListByTerm(User user, POVM viewModels);
#endregion
#region Post Put
Task PostApprovedSupplier(User user, POVM viewModel);
diff --git a/CPRNIMS.Domain/UIServices/PO/CustomPOService.cs b/CPRNIMS.Domain/UIServices/PO/CustomPOService.cs
new file mode 100644
index 0000000..7a9c563
--- /dev/null
+++ b/CPRNIMS.Domain/UIServices/PO/CustomPOService.cs
@@ -0,0 +1,76 @@
+using CPRNIMS.Domain.UIContracts.PO;
+using CPRNIMS.Infrastructure.Entities.PO;
+using CPRNIMS.Infrastructure.Helper;
+using Google.Apis.Services;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http.Headers;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Domain.UIServices.PO
+{
+ public class CustomPOService : ICustomPOService
+ {
+ private readonly IHttpClientFactory _httpClientFactory;
+ private readonly TokenHelper _tokenHelper;
+ private readonly IConfiguration _configuration;
+ private readonly ILogger _logger;
+
+ public CustomPOService(
+ IHttpClientFactory httpClientFactory,
+ TokenHelper tokenHelper,
+ IConfiguration configuration,
+ ILogger logger)
+ {
+ _httpClientFactory = httpClientFactory;
+ _tokenHelper = tokenHelper;
+ _configuration = configuration;
+ _logger = logger;
+ }
+
+ public async Task GetPOFormDataAsync(long? poId = null)
+ {
+ try
+ {
+ var token = await _tokenHelper.GetValidTokenAsync();
+ if (string.IsNullOrEmpty(token))
+ throw new UnauthorizedAccessException("No valid token available.");
+
+ var httpClient = _httpClientFactory.CreateClient("AuthApi");
+ httpClient.DefaultRequestHeaders.Authorization =
+ new AuthenticationHeaderValue("Bearer", token);
+
+ var url = _configuration["LLI:NonInvent:POMgmt:GetPOFormData"];
+ if (poId.HasValue)
+ url += $"?poId={poId}";
+
+ var response = await httpClient.GetAsync(url);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ _logger.LogError("GetPOFormData failed: {StatusCode}", response.StatusCode);
+ return new POFormData(); // return empty rather than throw
+ }
+
+ var json = await response.Content.ReadAsStringAsync();
+
+ var result = JsonSerializer.Deserialize(json, new JsonSerializerOptions
+ {
+ PropertyNameCaseInsensitive = true
+ });
+
+ return result ?? new POFormData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error in GetPOFormDataAsync");
+ return new POFormData();
+ }
+ }
+ }
+}
diff --git a/CPRNIMS.Domain/UIServices/PO/PurchaseOrder.cs b/CPRNIMS.Domain/UIServices/PO/PurchaseOrder.cs
index b59320a..8ba3416 100644
--- a/CPRNIMS.Domain/UIServices/PO/PurchaseOrder.cs
+++ b/CPRNIMS.Domain/UIServices/PO/PurchaseOrder.cs
@@ -126,6 +126,12 @@ namespace CPRNIMS.Domain.UIServices.PO
#endregion
#region Get
+
+ public async Task?> GetPOListByTerm(User user, POVM viewModel)
+ {
+ return await SendGetApiRequest(user, viewModel,
+ _configuration["LLI:NonInvent:POMgmt:GetPOListByTerm"]);
+ }
public async Task?> GetIncomingShipment(User user, POVM viewModel)
{
return await SendGetApiRequest(user, viewModel,
diff --git a/CPRNIMS.Infrastructure/Entities/PO/PO.cs b/CPRNIMS.Infrastructure/Entities/PO/PO.cs
index e018523..c352178 100644
--- a/CPRNIMS.Infrastructure/Entities/PO/PO.cs
+++ b/CPRNIMS.Infrastructure/Entities/PO/PO.cs
@@ -13,12 +13,15 @@ namespace CPRNIMS.Infrastructure.Entities.PO
{
[Key]
public long POId { get; set; }
- public long PONo { get; set; }
- public bool Submit { get; set; }
+ public string PONo { get; set; }
public bool IsActive { get; set; }
public bool IsPOClosed { get; set; }
+ public bool IsCancel { get; set; }
public string? UserId { get; set; }
- public DateTime CreatedDate { get; set; }
- public DateTime UpdatedDate { get; set; }
+ public byte Status { get; set; }
+ public byte PaymentTermsId { get; set; }
+ public byte PODId { get; set; }
+ public byte POTypeId { get; set; }
+ public DateTime? UpdatedDate { get; set; }
}
}
diff --git a/CPRNIMS.Infrastructure/Entities/PO/POCharges.cs b/CPRNIMS.Infrastructure/Entities/PO/POCharges.cs
new file mode 100644
index 0000000..2ec1c6b
--- /dev/null
+++ b/CPRNIMS.Infrastructure/Entities/PO/POCharges.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Infrastructure.Entities.PO
+{
+ public class POCharges
+ {
+ [Key]
+ public int OtherChargesId { get; set; }
+ public string? OtherChargesName { get; set; }
+ public decimal Amount { get; set; }
+ }
+}
diff --git a/CPRNIMS.Infrastructure/Entities/PO/POFormData.cs b/CPRNIMS.Infrastructure/Entities/PO/POFormData.cs
new file mode 100644
index 0000000..7489be6
--- /dev/null
+++ b/CPRNIMS.Infrastructure/Entities/PO/POFormData.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Infrastructure.Entities.PO
+{
+ public class POFormData
+ {
+ public POHeader? Header { get; set; }
+ public List? LineItems { get; set; }
+ public List? Charges { get; set; }
+ public List? DocsRequired { get; set; }
+ }
+}
diff --git a/CPRNIMS.Infrastructure/Entities/PO/POHeader.cs b/CPRNIMS.Infrastructure/Entities/PO/POHeader.cs
new file mode 100644
index 0000000..ef5ab22
--- /dev/null
+++ b/CPRNIMS.Infrastructure/Entities/PO/POHeader.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Infrastructure.Entities.PO
+{
+ public class POHeader
+ {
+ [Key]
+ public long POId { get; set; }
+ public string? PONo { get; set; }
+ public int SupplierId { get; set; }
+ public string? SupplierName { get; set; }
+ public DateTime DeliveryDate { get; set; }
+ public DateTime? ProfInvoiceDate { get; set; }
+ public string? ProfInvoiceNo { get; set; }
+ public string? CurrencyName { get; set; }
+ public string? PaymentTerms { get; set; }
+ public string? Remarks { get; set; }
+ public decimal Discount { get; set; }
+ public decimal GrossAmountUSD { get; set; }
+ public decimal FinalAmountUSD { get; set; }
+ public decimal GrossAmountPHP { get; set; }
+ public decimal FinalAmountPHP { get; set; }
+ public string? POTypeName { get; set; }
+ public string? UserId { get; set; }
+ public byte Status { get; set; }
+ public byte PaymentTermsId { get; set; }
+ public byte PODId { get; set; }
+ public byte POTypeId { get; set; }
+ public byte IncoTermsId { get; set; }
+ }
+}
diff --git a/CPRNIMS.Infrastructure/Entities/PO/POLineItem.cs b/CPRNIMS.Infrastructure/Entities/PO/POLineItem.cs
new file mode 100644
index 0000000..a75b3ff
--- /dev/null
+++ b/CPRNIMS.Infrastructure/Entities/PO/POLineItem.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CPRNIMS.Infrastructure.Entities.PO
+{
+ public class POLineItem
+ {
+ [Key]
+ public long PODetailId { get; set; }
+ public long PRNo { get; set; }
+ public decimal Qty { get; set; }
+ public decimal UnitPrice { get; set; }
+ public decimal TotalAmount { get; set; }
+ public string? UOMName { get; set; }
+ public long ItemNo { get; set; }
+ public string? ItemName { get; set; }
+ public string? Specification { get; set; }
+
+ }
+}
diff --git a/CPRNIMS.Infrastructure/Helper/TokenHelper.cs b/CPRNIMS.Infrastructure/Helper/TokenHelper.cs
index 70f9fa5..594c216 100644
--- a/CPRNIMS.Infrastructure/Helper/TokenHelper.cs
+++ b/CPRNIMS.Infrastructure/Helper/TokenHelper.cs
@@ -256,7 +256,6 @@ namespace CPRNIMS.Infrastructure.Helper
return ExtractClaimsFromToken(tokenClaim.Value);
}
- // Rest of your existing methods...
public HttpClient CreateHttpClientWithDefaultHeaders(string token)
{
string BaseUrl = _configuration["CommonEndpoints:ApiDefaultHeaders:BaseUrl"];
@@ -281,24 +280,6 @@ namespace CPRNIMS.Infrastructure.Helper
return httpClient;
}
-
- public Dictionary DefaultHeaders
- {
- get
- {
- var headersSection = _configuration.GetSection(
- "CommonEndpoints:ApiDefaultHeaders");
- var headers = new Dictionary();
-
- foreach (var childSection in headersSection.GetChildren())
- {
- headers[childSection.Key] = childSection.Value;
- }
-
- return headers;
- }
- }
-
public Dictionary CustomHeaders
{
get
diff --git a/CPRNIMS.WebApi/CPRNIMS.WebApi.csproj b/CPRNIMS.WebApi/CPRNIMS.WebApi.csproj
index 6ceb148..753cb2d 100644
--- a/CPRNIMS.WebApi/CPRNIMS.WebApi.csproj
+++ b/CPRNIMS.WebApi/CPRNIMS.WebApi.csproj
@@ -147,7 +147,6 @@
-
diff --git a/CPRNIMS.WebApi/Controllers/Account/AnonController.cs b/CPRNIMS.WebApi/Controllers/Account/AnonController.cs
index 3efef2e..2d8ef74 100644
--- a/CPRNIMS.WebApi/Controllers/Account/AnonController.cs
+++ b/CPRNIMS.WebApi/Controllers/Account/AnonController.cs
@@ -9,6 +9,7 @@ using CPRNIMS.Infrastructure.Helper;
using CPRNIMS.Infrastructure.Entities.Common;
using CPRNIMS.Infrastructure.ViewModel.Common;
using CPRNIMS.Infrastructure.Dto.Account;
+using System.Threading.Tasks;
namespace CPRNIMS.WebApi.Controllers.Account
{
@@ -36,7 +37,6 @@ namespace CPRNIMS.WebApi.Controllers.Account
_userManager = userManager;
_signInManager = signInManager;
}
-
[AllowAnonymous]
[HttpPost("Login")]
public async Task Login([FromBody] LoginRequest model,
diff --git a/CPRNIMS.WebApi/Controllers/PO/POMgmtController.cs b/CPRNIMS.WebApi/Controllers/PO/POMgmtController.cs
index 32196fd..3484ced 100644
--- a/CPRNIMS.WebApi/Controllers/PO/POMgmtController.cs
+++ b/CPRNIMS.WebApi/Controllers/PO/POMgmtController.cs
@@ -279,6 +279,20 @@ namespace CPRNIMS.WebApi.Controllers.PO
}
#endregion
#region Get
+ [HttpGet("GetPOFormData")]
+ public async Task GetPOFormData(int? poId = null)
+ {
+ var data = await _purchaseOrder.GetPOFormDataAsync(poId);
+ return Ok(data);
+ }
+ [HttpPost("GetPOListByTerm")]
+ public async Task GetPOListByTerm(PODto itemDto)
+ {
+ return await ExecuteWithErrorHandling(
+ () => _purchaseOrder.GetPOListByTerm(itemDto),
+ nameof(GetPOListByTerm), false
+ );
+ }
[HttpPost("GetIncomingShipment")]
public async Task GetIncomingShipment(PODto itemDto)
{
diff --git a/CPRNIMS.WebApps/Common/ServiceExtensions.cs b/CPRNIMS.WebApps/Common/ServiceExtensions.cs
index 9fb20c3..3d5257f 100644
--- a/CPRNIMS.WebApps/Common/ServiceExtensions.cs
+++ b/CPRNIMS.WebApps/Common/ServiceExtensions.cs
@@ -81,7 +81,8 @@ namespace CPRNIMS.WebApps.Common
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
- builder.Services.AddTransient();
+ builder.Services.AddTransient();
+ builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
diff --git a/CPRNIMS.WebApps/Controllers/PO/POMgmtController.cs b/CPRNIMS.WebApps/Controllers/PO/POMgmtController.cs
index d7dff48..454c8e8 100644
--- a/CPRNIMS.WebApps/Controllers/PO/POMgmtController.cs
+++ b/CPRNIMS.WebApps/Controllers/PO/POMgmtController.cs
@@ -1,6 +1,5 @@
using CPRNIMS.Domain.UIContracts.Account;
using CPRNIMS.Domain.UIContracts.PO;
-using CPRNIMS.Infrastructure.Entities.PO;
using CPRNIMS.Infrastructure.Helper;
using CPRNIMS.Infrastructure.ViewModel.PO;
using CPRNIMS.WebApps.Controllers.Base;
@@ -15,12 +14,14 @@ namespace CPRNIMS.WebApps.Controllers.PO
POVM postPutItem;
private readonly IPurchaseOrder _purchaseOrder;
+ private readonly ICustomPOService _customPOService;
public POMgmtController(
ErrorLogHelper errorMessageService, IWebHostEnvironment webHostEnvironment
- , IPurchaseOrder purchaseOrder, TokenHelper tokenHelper,IAccount account
+ , IPurchaseOrder purchaseOrder, TokenHelper tokenHelper,IAccount account, ICustomPOService customPOService
) : base(errorMessageService, webHostEnvironment, tokenHelper, account)
{
_purchaseOrder = purchaseOrder;
+ _customPOService = customPOService;
}
#endregion
#region POST PUT
@@ -207,7 +208,7 @@ namespace CPRNIMS.WebApps.Controllers.PO
return Json(new { success = false, Response = postPutItem.Message });
}
#endregion
- #region Get
+ #region Mapper
private POList MapToPONoList(IEnumerable poList)
{
if (poList == null || !poList.Any())
@@ -267,6 +268,15 @@ namespace CPRNIMS.WebApps.Controllers.PO
Specification = itemList.SelectMany(ic => ic.Specification).ToList()
};
}
+ #endregion
+
+ #region Get
+ [HttpGet]
+ public async Task GetPOFormData(long? poId = null)
+ {
+ var data = await _customPOService.GetPOFormDataAsync(poId);
+ return Ok(data);
+ }
public async Task GetIncomingShipment(POVM viewModels)
{
response = await _purchaseOrder.GetIncomingShipment(GetUser(), viewModels);
@@ -304,7 +314,7 @@ namespace CPRNIMS.WebApps.Controllers.PO
var viewModels = new POVM();
response = await _purchaseOrder.GetForPO(GetUser(), viewModels);
return GetResponse(response);
- }
+ }
public async Task GetForPOPerSuppEmail(POVM viewModels)
{
response = await _purchaseOrder.GetForPOPerSuppEmail(GetUser(), viewModels);
@@ -352,6 +362,24 @@ namespace CPRNIMS.WebApps.Controllers.PO
return Json(new { success = true, data = formattedData });
}
+ public async Task GetPOListByTerm(string query)
+ {
+ var viewModels = new POVM();
+ viewModels.PONo = query;
+ response = await _purchaseOrder.GetPOListByTerm(GetUser(), viewModels);
+ if (response == null)
+ {
+ response = new List();
+ }
+ var formattedData = response.Select(item => new
+ {
+ label = item.PONo,
+ value = item.POId,
+ value2 = item.POTypeId
+ });
+
+ return Json(new { success = true, data = formattedData });
+ }
public async Task GetPaymentTerms(string query)
{
var viewModels = new POVM();
diff --git a/CPRNIMS.WebApps/ViewComponents/POMgmt/CustomFormPOElemVC.cs b/CPRNIMS.WebApps/ViewComponents/POMgmt/CustomFormPOElemVC.cs
index ca7ce7a..cdcdd96 100644
--- a/CPRNIMS.WebApps/ViewComponents/POMgmt/CustomFormPOElemVC.cs
+++ b/CPRNIMS.WebApps/ViewComponents/POMgmt/CustomFormPOElemVC.cs
@@ -12,7 +12,8 @@ namespace CPRNIMS.WebApps.ViewComponents.POMgmt
{
1 => "~/Views/Components/POMgmt/CustomPO/SIElem.cshtml",
2 => "~/Views/Components/POMgmt/CustomPO/DRElem.cshtml",
- _ => "~/Views/Components/POMgmt/CustomPO/ImportElem.cshtml"
+ 3 => "~/Views/Components/POMgmt/CustomPO/ImportElem.cshtml",
+ _ => "~/Views/Components/POMgmt/CustomPO/PODetailModification.cshtml"
};
return View(viewName);
diff --git a/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/ImportElem.cshtml b/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/ImportElem.cshtml
index c76aa8d..eb1e801 100644
--- a/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/ImportElem.cshtml
+++ b/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/ImportElem.cshtml
@@ -216,5 +216,3 @@
@await Html.PartialAsync("PagesView/PO/_DocRequired")
-
-
diff --git a/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/PODetailModification.cshtml b/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/PODetailModification.cshtml
new file mode 100644
index 0000000..18758ea
--- /dev/null
+++ b/CPRNIMS.WebApps/Views/Components/POMgmt/CustomPO/PODetailModification.cshtml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+ ⚠
+
+
+
+ You Are Modifying an Existing Purchase Order
+
+
+ Any changes made here will directly affect supplier commitments, and financial reports.
+ Please review all details carefully before saving.
+
+
+
+
+
+
+
+ Important:
+ Ensure that all quantities, prices, delivery dates, and supplier details are accurate.
+ Any incorrect modifications may result in discrepancies and processing issues.
+