Complete FOC for Integration

This commit is contained in:
dibakor 2026-07-29 13:54:40 +06:00
parent 769e973f48
commit 93be7ab99c
2 changed files with 80 additions and 32 deletions

View File

@ -9,14 +9,14 @@ public class IntegrationMaterialFreeGoodsResponse : ResponseBase
public string DistributionChannel { get; set; }
public string? CustomerNumber { get; set; } // nullable
public string? CustomerPriceGroup { get; set; }
public string MaterialCode { get; set; }
public decimal MinOrderQuantity { get; set; }
public decimal ForQuantity { get; set; }
public string UnitOfMeasure { get; set; }
public decimal FreeQuantity { get; set; }
public string FocUnitOfMeasure { get; set; }
public DateTime ValidFrom { get; set; }
public DateTime ValidTo { get; set; }
public string? MaterialCode { get; set; }
public decimal? MinOrderQuantity { get; set; }
public decimal? ForQuantity { get; set; }
public string? UnitOfMeasure { get; set; }
public decimal? FreeQuantity { get; set; }
public string? FocUnitOfMeasure { get; set; }
public DateTime? ValidFrom { get; set; }
public DateTime? ValidTo { get; set; }
public string? Status { get; set; }
}

View File

@ -370,32 +370,12 @@ public class IntegrationService : IIntegrationService
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
DateTime? fromValid = null;
DateTime? toValid = null;
IntegrationMaterialFreeGoodsResponse meterialFreeGoods = await GetMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
if (request.Slabs != null && request.Slabs.Count > 0)
if (meterialFreeGoods != null && meterialFreeGoods.FreeGoodsId >0)
{
fromValid =request.Slabs.Max(x => x.ValidFrom);
toValid = request.Slabs.Max(x => x.ValidTo);
}
IntegrationMaterialFreeGoodsResponse meterialFreeGoods = await GetMaterialFreeGoodsByFilterAsync(tc,
new GetMaterialFreeGoodsByFilterRequest() { SalesOrg = request.SalesOrg, DistributionChannel = request.DistributionChannel,
CustomerPriceGroup = request.CustomerPriceGroup,MaterialCode = request.MaterialCode, CustomerNumber = request.CustomerNumber,
ValidFrom = fromValid, ValidTo= toValid});
InActiveMaterialFreeGoodsByFilter(tc,
new GetMaterialFreeGoodsByFilterRequest()
{
SalesOrg = request.SalesOrg,
DistributionChannel = request.DistributionChannel,
CustomerPriceGroup = request.CustomerPriceGroup,
MaterialCode = request.MaterialCode,
CustomerNumber = request.CustomerNumber
});
if (meterialFreeGoods != null && !string.IsNullOrWhiteSpace(meterialFreeGoods.MaterialCode))
{
UpdateMaterialFreeGoods(tc, request);
DeleteMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
CreateMaterialFreeGoods(tc, request);
response.IsUpdated = true;
}
else
@ -1488,6 +1468,51 @@ public class IntegrationService : IIntegrationService
return response;
}
private async Task<IntegrationMaterialFreeGoodsResponse> GetMaterialFreeGoodsByRecordNoAsync(
TransactionContext tc, int recordNo)
{
IntegrationMaterialFreeGoodsResponse response = new IntegrationMaterialFreeGoodsResponse();
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@ConditionRecordNo", SqlDbType.NVarChar, recordNo),
];
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetAllMaterialFreeGoodsByRecordNo", parameterValues: p))
{
while (dr.Read())
{
response = new IntegrationMaterialFreeGoodsResponse()
{
FreeGoodsId = dr.GetInt32(0),
SalesOrg = dr.GetString(1),
DistributionChannel = dr.GetString(2),
CustomerNumber = dr.IsDBNull(3) ? null : dr.GetString(3),
CustomerPriceGroup = dr.IsDBNull(4) ? null : dr.GetString(4),
MaterialCode = dr.IsDBNull(5) ? null : dr.GetString(5),
MinOrderQuantity = dr.IsDBNull(6) ? null : dr.GetDecimal(6),
ForQuantity = dr.IsDBNull(7) ? null : dr.GetDecimal(7),
UnitOfMeasure = dr.IsDBNull(8) ? null : dr.GetString(8),
FreeQuantity = dr.IsDBNull(9) ? null : dr.GetDecimal(9),
FocUnitOfMeasure = dr.IsDBNull(10) ? null : dr.GetString(10),
ValidFrom = dr.IsDBNull(11) ? null : dr.GetDateTime(11),
ValidTo = dr.IsDBNull(12) ? null : dr.GetDateTime(12),
Status = dr.IsDBNull(13) ? null : dr.GetString(13)
};
}
dr.Close();
}
}
catch (Exception ex)
{
throw DBCustomError.GenerateCustomError(ex);
}
return response;
}
private bool DeleteMaterialFreeGoodsByFilter(
TransactionContext tc, GetMaterialFreeGoodsByFilterRequest request)
@ -1515,6 +1540,28 @@ public class IntegrationService : IIntegrationService
return response;
}
private bool DeleteMaterialFreeGoodsByRecordNoAsync(
TransactionContext tc, int conditionRecNo)
{
bool response = false;
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@ConditionRecNo", SqlDbType.Int, conditionRecNo)
];
_ = tc.ExecuteNonQuerySp("dbo.DeleteMaterialFOCByRecordNo", parameterValues: p);
response = true;
}
catch (Exception ex)
{
throw DBCustomError.GenerateCustomError(ex);
}
return response;
}
private bool InActiveMaterialFreeGoodsByFilter(
TransactionContext tc, GetMaterialFreeGoodsByFilterRequest request)
{
@ -1564,6 +1611,7 @@ public class IntegrationService : IIntegrationService
SqlHelperExtension.CreateInParam("@ValidFrom", SqlDbType.Date, item.ValidFrom),
SqlHelperExtension.CreateInParam("@ValidTo", SqlDbType.Date, item.ValidTo),
SqlHelperExtension.CreateInParam("@Status", SqlDbType.NVarChar, item.Status),
SqlHelperExtension.CreateInParam("@ConditionRecNo", SqlDbType.Int, request.ConditionRecNo),
];
_ = tc.ExecuteNonQuerySp(spName: "dbo.InsertIntegrationMaterialFreeGoods", parameterValues: p);