inactive previous foc and discount when again comes
This commit is contained in:
parent
0529139358
commit
4d9a467558
|
|
@ -301,6 +301,15 @@ 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
|
||||||
{
|
{
|
||||||
|
if(request.CalculationType!="A" && request.CalculationType !="B" )
|
||||||
|
{
|
||||||
|
throw new Exception(string.Format("Calculation Type is not correct. Calcultion Type:{0}",request.CalculationType));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(request.CalculationType.Equals("C"))
|
||||||
|
{
|
||||||
|
request.CalculationType = "B";
|
||||||
|
}
|
||||||
var materialPriceType = await GetMaterialPriceTypeAsync(tc, request.ConditionType) ;
|
var materialPriceType = await GetMaterialPriceTypeAsync(tc, request.ConditionType) ;
|
||||||
|
|
||||||
var validationMessages = Validate(request, materialPriceType.PriceType);
|
var validationMessages = Validate(request, materialPriceType.PriceType);
|
||||||
|
|
@ -314,6 +323,8 @@ public class IntegrationService : IIntegrationService
|
||||||
|
|
||||||
meterialPrice = await GetMaterialPriceByRecordNoAsync(tc, request.ConditionRecNo, materialPriceType.PriceType);
|
meterialPrice = await GetMaterialPriceByRecordNoAsync(tc, request.ConditionRecNo, materialPriceType.PriceType);
|
||||||
|
|
||||||
|
InactiveAllPreviousDiscountAsync(tc, request.ConditionType, request.CustomerGroupCode, request.MaterialCode?? null);
|
||||||
|
|
||||||
if (meterialPrice != null && !string.IsNullOrWhiteSpace(meterialPrice.ConditionType))
|
if (meterialPrice != null && !string.IsNullOrWhiteSpace(meterialPrice.ConditionType))
|
||||||
{
|
{
|
||||||
DeleteMaterialPriceByRecordNo(tc, request.ConditionRecNo);
|
DeleteMaterialPriceByRecordNo(tc, request.ConditionRecNo);
|
||||||
|
|
@ -382,6 +393,7 @@ public class IntegrationService : IIntegrationService
|
||||||
{
|
{
|
||||||
IntegrationMaterialFreeGoodsResponse meterialFreeGoods = await GetMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
|
IntegrationMaterialFreeGoodsResponse meterialFreeGoods = await GetMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
|
||||||
|
|
||||||
|
InactiveAllPreviousFOCAsync(tc, request.CustomerPriceGroup, request.MaterialCode);
|
||||||
if (meterialFreeGoods != null && meterialFreeGoods.FreeGoodsId >0)
|
if (meterialFreeGoods != null && meterialFreeGoods.FreeGoodsId >0)
|
||||||
{
|
{
|
||||||
DeleteMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
|
DeleteMaterialFreeGoodsByRecordNoAsync(tc, request.ConditionRecNo);
|
||||||
|
|
@ -1316,6 +1328,52 @@ public class IntegrationService : IIntegrationService
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private bool InactiveAllPreviousDiscountAsync(TransactionContext tc, string conditionType, string discountCode, string? materialCode)
|
||||||
|
{
|
||||||
|
bool response = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam("@conditionType", SqlDbType.VarChar, conditionType),
|
||||||
|
SqlHelperExtension.CreateInParam("@discountCode", SqlDbType.VarChar, discountCode),
|
||||||
|
SqlHelperExtension.CreateInParam("@materialCode", SqlDbType.VarChar, materialCode),
|
||||||
|
];
|
||||||
|
|
||||||
|
_ = tc.ExecuteNonQuerySp("dbo.InactiveAllPreviousDiscount", parameterValues: p);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool InactiveAllPreviousFOCAsync(TransactionContext tc, string discountCode, string materialCode)
|
||||||
|
{
|
||||||
|
bool response = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam("@focCode", SqlDbType.VarChar, discountCode),
|
||||||
|
SqlHelperExtension.CreateInParam("@materialCode", SqlDbType.VarChar, materialCode),
|
||||||
|
];
|
||||||
|
|
||||||
|
_ = tc.ExecuteNonQuerySp("dbo.InactiveAllPreviousFOC", parameterValues: p);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
private bool InactiveMaterialPriceByCodeAndConditionType(TransactionContext tc, GetMaterialPriceByCodeRequest request, MaterialPriceTypeEnum priceType)
|
private bool InactiveMaterialPriceByCodeAndConditionType(TransactionContext tc, GetMaterialPriceByCodeRequest request, MaterialPriceTypeEnum priceType)
|
||||||
{
|
{
|
||||||
bool response = false;
|
bool response = false;
|
||||||
|
|
|
||||||
|
|
@ -533,6 +533,11 @@ namespace OnlineSalesAutoCrop.CoreAPI
|
||||||
"ApiLogs"
|
"ApiLogs"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var logErrorDirectory = Path.Combine(
|
||||||
|
env.ContentRootPath,
|
||||||
|
"ApiErrorLogs"
|
||||||
|
);
|
||||||
|
|
||||||
context.Request.EnableBuffering();
|
context.Request.EnableBuffering();
|
||||||
|
|
||||||
string requestBody = "";
|
string requestBody = "";
|
||||||
|
|
@ -599,7 +604,16 @@ namespace OnlineSalesAutoCrop.CoreAPI
|
||||||
var fileName =
|
var fileName =
|
||||||
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}.json";
|
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}.json";
|
||||||
|
|
||||||
var filePath = Path.Combine(logDirectory, fileName);
|
string filePath = string.Empty;
|
||||||
|
|
||||||
|
if(context.Response.StatusCode ==200 || context.Response.StatusCode == 201)
|
||||||
|
{
|
||||||
|
filePath = Path.Combine(logDirectory, fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filePath = Path.Combine(logErrorDirectory, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
await File.WriteAllTextAsync(filePath, json);
|
await File.WriteAllTextAsync(filePath, json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user