change in material price endpoints for base price and discounts

This commit is contained in:
dibakor 2026-07-28 14:21:55 +06:00
parent 5b35e0b044
commit 240cb8ba2a
5 changed files with 125 additions and 15 deletions

View File

@ -719,6 +719,14 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models
ZDS2 = 3 ZDS2 = 3
} }
public enum MaterialPriceTypeEnum : short
{
BasePrice = 1,
Discount = 2,
VatPrice = 3,
SourceTaxPrice = 4,
}
public enum UserPlatFormType : short public enum UserPlatFormType : short
{ {
SAP=1, SAP=1,
@ -753,8 +761,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models
CancelledByApprover = 5, CancelledByApprover = 5,
[Description("Approved")] [Description("Approved")]
Approved = 6, Approved = 6,
[Description("Sent To SAP")] [Description("Delivered in SAP")]
SentToSAP = 7, Delivered = 7,
} }

View File

@ -89,4 +89,7 @@ public class GetMaterialPriceByCodeRequest
[StringLength(10, ErrorMessage = "Distributor Channel Code cannot exceed 10 characters.")] [StringLength(10, ErrorMessage = "Distributor Channel Code cannot exceed 10 characters.")]
public string? DistributorChannelCode { get; set; } public string? DistributorChannelCode { get; set; }
public DateTime? ValidFrom { get; set; }
public DateTime? ValidTo { get; set; }
} }

View File

@ -15,4 +15,3 @@ public class IntegrationDeliveryReqResponse : ResponseBase
public string DeliveryDocumentNo{ get; set; } = string.Empty; public string DeliveryDocumentNo{ get; set; } = string.Empty;
public DateTime DeliveryDate { get; set; } public DateTime DeliveryDate { get; set; }
} }

View File

@ -5,8 +5,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
public class IntegrationMaterialPriceResponse : ResponseBase public class IntegrationMaterialPriceResponse : ResponseBase
{ {
public int MaterialPriceId { get; set; } public int MaterialPriceId { get; set; }
public string SalesOrg { get; set; } public string? SalesOrg { get; set; }
public string DistributionChannel { get; set; } public string? DistributionChannel { get; set; }
public string? CustomerNumber { get; set; } public string? CustomerNumber { get; set; }
public string? CustomerGroupCode { get; set; } public string? CustomerGroupCode { get; set; }
public string MaterialCode { get; set; } public string MaterialCode { get; set; }
@ -28,3 +28,12 @@ public class MaterialIntegrationPriceReqResponse : ResponseBase
public string? CustomerGroupCode { get; set; } public string? CustomerGroupCode { get; set; }
public bool IsUpdated { get; set; } public bool IsUpdated { get; set; }
} }
public class MaterialPriceTypeResponse
{
public int PriceTypeId { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public MaterialPriceTypeEnum PriceType { get; set; }
}

View File

@ -12,6 +12,7 @@ using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems; using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
using System; using System;
using System.Data; using System.Data;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations; namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
@ -288,14 +289,35 @@ public class IntegrationService : IIntegrationService
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true); using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try try
{ {
var materialPriceType = await GetMaterialPriceTypeAsync(tc, request.ConditionType) ;
if(materialPriceType.PriceType == MaterialPriceTypeEnum.BasePrice)
{
if (string.IsNullOrWhiteSpace(request.SalesOrg) || string.IsNullOrWhiteSpace(request.DistributionChannel))
throw new Exception("For Discount, Customer Group is required.");
}
if(materialPriceType.PriceType == MaterialPriceTypeEnum.Discount)
{
if(string.IsNullOrWhiteSpace(request.CustomerGroupCode))
throw new Exception("For Base Price, Sales Organization, and Distribution Channel are required.");
}
DateTime? fromValid = null;
DateTime? toValid = null;
if(request.Slabs != null && request.Slabs.Count>0)
{
fromValid = request.Slabs.Max(x => x.ValidFrom);
toValid = request.Slabs.Max(x => x.ValidTo);
}
IntegrationMaterialPriceResponse meterialPrice = await GetMaterialPriceByCodeAndConditionTypeAsync(tc, IntegrationMaterialPriceResponse meterialPrice = await GetMaterialPriceByCodeAndConditionTypeAsync(tc,
new GetMaterialPriceByCodeRequest() { MaterialCode = request.MaterialCode, ConditionType = request.ConditionType, new GetMaterialPriceByCodeRequest() { MaterialCode = request.MaterialCode, ConditionType = request.ConditionType,
SalesOrg=request.SalesOrg, CustomerNumber = request.CustomerNumber,CustomerGroupCode = request.CustomerGroupCode, SalesOrg=request.SalesOrg, CustomerNumber = request.CustomerNumber,CustomerGroupCode = request.CustomerGroupCode,
DistributorChannelCode = request.DistributionChannel}); DistributorChannelCode = request.DistributionChannel,ValidFrom = fromValid, ValidTo = toValid});
if (meterialPrice != null && !string.IsNullOrWhiteSpace(meterialPrice.MaterialCode)) InactiveMaterialPriceByCodeAndConditionType(tc,
{
DeleteMaterialPriceByCodeAndConditionType(tc,
new GetMaterialPriceByCodeRequest() new GetMaterialPriceByCodeRequest()
{ {
MaterialCode = request.MaterialCode, MaterialCode = request.MaterialCode,
@ -303,8 +325,13 @@ public class IntegrationService : IIntegrationService
SalesOrg = request.SalesOrg, SalesOrg = request.SalesOrg,
CustomerNumber = request.CustomerNumber, CustomerNumber = request.CustomerNumber,
CustomerGroupCode = request.CustomerGroupCode, CustomerGroupCode = request.CustomerGroupCode,
DistributorChannelCode = request.DistributionChannel DistributorChannelCode = request.DistributionChannel,
}); ValidFrom = fromValid,
ValidTo = toValid
}, materialPriceType.PriceType);
if (meterialPrice != null && !string.IsNullOrWhiteSpace(meterialPrice.MaterialCode))
{
UpdateMaterialPrice(tc, request); UpdateMaterialPrice(tc, request);
response.IsUpdated = true; response.IsUpdated = true;
} }
@ -1151,7 +1178,9 @@ public class IntegrationService : IIntegrationService
SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType), SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType),
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerNumber)? null : request.CustomerNumber ), SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerNumber)? null : request.CustomerNumber ),
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerGroupCode)? null : request.CustomerGroupCode ), SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerGroupCode)? null : request.CustomerGroupCode ),
SqlHelperExtension.CreateInParam("@DistributorChannelCode", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.DistributorChannelCode)? null : request.DistributorChannelCode ) SqlHelperExtension.CreateInParam("@DistributorChannelCode", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.DistributorChannelCode)? null : request.DistributorChannelCode ),
SqlHelperExtension.CreateInParam("@FromValid", SqlDbType.DateTime, request.ValidFrom),
SqlHelperExtension.CreateInParam("@ToValid", SqlDbType.DateTime, request.ValidTo)
]; ];
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialPriceByMaterialCodeAndConditionType", parameterValues: p)) using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialPriceByMaterialCodeAndConditionType", parameterValues: p))
@ -1161,8 +1190,8 @@ public class IntegrationService : IIntegrationService
response = new IntegrationMaterialPriceResponse() response = new IntegrationMaterialPriceResponse()
{ {
MaterialPriceId = dr.GetInt32(0), MaterialPriceId = dr.GetInt32(0),
SalesOrg = dr.GetString(1), SalesOrg = dr.IsDBNull(1) ? null : dr.GetString(1),
DistributionChannel = dr.GetString(2), DistributionChannel = dr.IsDBNull(2) ? null : dr.GetString(2),
CustomerNumber = dr.IsDBNull(3) ? null : dr.GetString(3), CustomerNumber = dr.IsDBNull(3) ? null : dr.GetString(3),
CustomerGroupCode = dr.IsDBNull(4) ? null : dr.GetString(4), CustomerGroupCode = dr.IsDBNull(4) ? null : dr.GetString(4),
MaterialCode = dr.GetString(5), MaterialCode = dr.GetString(5),
@ -1213,6 +1242,33 @@ public class IntegrationService : IIntegrationService
return response; return response;
} }
private bool InactiveMaterialPriceByCodeAndConditionType(TransactionContext tc, GetMaterialPriceByCodeRequest request, MaterialPriceTypeEnum priceType)
{
bool response = false;
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg),
SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode),
SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType),
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerNumber)? null : request.CustomerNumber ),
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerGroupCode)? null : request.CustomerGroupCode ),
SqlHelperExtension.CreateInParam("@DistributorChannelCode", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.DistributorChannelCode)? null : request.DistributorChannelCode ),
SqlHelperExtension.CreateInParam("@PriceType", SqlDbType.Int, (int) priceType)
];
_ = tc.ExecuteNonQuerySp("dbo.InActiveMaterialPriceByMaterialCodeAndConditionType", parameterValues: p);
}
catch (Exception ex)
{
throw DBCustomError.GenerateCustomError(ex);
}
return response;
}
private bool CreateMaterialPrice(TransactionContext tc, IntegrationMaterialPriceRequest request) private bool CreateMaterialPrice(TransactionContext tc, IntegrationMaterialPriceRequest request)
{ {
bool response = false; bool response = false;
@ -1290,6 +1346,39 @@ public class IntegrationService : IIntegrationService
return returnValue; return returnValue;
} }
private async Task<MaterialPriceTypeResponse> GetMaterialPriceTypeAsync(TransactionContext tc, string conditionType)
{
MaterialPriceTypeResponse response = new MaterialPriceTypeResponse();
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, conditionType)
];
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialPriceTypeByConditionType", parameterValues: p))
{
if (dr.Read())
{
response = new MaterialPriceTypeResponse()
{
PriceTypeId = dr.GetInt32(0),
Code = dr.GetString(1),
Name = dr.GetString(2),
PriceType =(MaterialPriceTypeEnum)dr.GetInt32(3)
};
}
dr.Close();
}
}
catch (Exception ex)
{
throw DBCustomError.GenerateCustomError(ex);
}
return response;
}
#endregion #endregion
#region Material Free Goods Private Functions #region Material Free Goods Private Functions
@ -1647,6 +1736,8 @@ public class IntegrationService : IIntegrationService
return returnValue; return returnValue;
} }
private bool CreateDeliveryInovoiceDocument(TransactionContext tc, IntegrationDeliveryDocumentRequest request) private bool CreateDeliveryInovoiceDocument(TransactionContext tc, IntegrationDeliveryDocumentRequest request)
{ {
bool returnValue = false; bool returnValue = false;