diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs index 5d24667..e8f83e4 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/MobileMasterDataResponse.cs @@ -179,6 +179,8 @@ public class GetDiscountMaterialResponse { public string DiscountCode { get; set; } public string CustomerCode { get; set; } + public string SalesOrgCode { get; set; } + public string TeritoryCode { get; set; } public string? MaterialCode { get; set; } public string UnitOfMeasurement { get; set; } public string CalculationType { get; set; } @@ -202,6 +204,8 @@ public class GetFOCMaterialResponse { public string FOCCode { get; set; } public string CustomerCode { get; set; } + public string SalesOrgCode { get; set; } + public string TeritoryCode { get; set; } public string MaterialCode { get; set; } public string? UnitOfMeasurement { get; set; } public decimal? MinimumOrderQty { get; set; } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs index 7b26076..902534d 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/MobileMasterDataService.cs @@ -831,6 +831,8 @@ public class MobileMasterDataService : IMobileMasterDataService StartDate = dr.GetDateTime(6), EndDate = dr.GetDateTime(7), Threshold = dr.GetDecimal(8), + SalesOrgCode = dr.GetString(9), + TeritoryCode = dr.GetString(10) }); } dr.Close(); @@ -947,6 +949,8 @@ public class MobileMasterDataService : IMobileMasterDataService FOCUnitOfMeasurement = dr.IsDBNull(7) ? null : dr.GetString(7), StartDate = dr.GetDateTime(8), EndDate = dr.GetDateTime(9), + SalesOrgCode =dr.GetString(10), + TeritoryCode =dr.GetString(11), }); } dr.Close(); diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs index 43df29c..d748d97 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs @@ -70,27 +70,33 @@ public class OrderService : IOrderService foreach (var item in request.Items) { + + if(!item.IsFocItem && item.UnitPrice<=0) + { + throw new Exception(string.Format("No base price is available for this material of this customer distributor channel.Material:{0}-{1}", item.MaterialCode,item.MaterialName)); + } + item.ItemId = 0; item.OrderId = request.OrderId; } - //var materialStock = await _httpService.GetMaterialStockAsync(request.PlantCode); - //if(materialStock is null || materialStock?.Count==0) - //{ - // throw new Exception($"Material Stocks not found against this Plant Code-{request.PlantCode}"); - //} - + var materialStock = await _httpService.GetMaterialStockAsync(request.PlantCode); + if (materialStock is null || materialStock?.Count == 0) + { + throw new Exception($"Material Stocks not found against this Plant Code-{request.PlantCode}"); + } - //foreach (var item in request.Items) - //{ - // decimal currentStock = materialStock.FirstOrDefault(x => x.MaterialCode == item.MaterialCode)?.AvailableStock ?? 0; - // if(currentStock x.MaterialCode == item.MaterialCode)?.AvailableStock ?? 0; + + if (currentStock < item.ApprovedQuantity) + { + throw new Exception($"Insufficient stock is available for Material Code '{item.MaterialCode}' in Plant Code '{request.PlantCode}'."); + } + } + // 2. Insert vs update decision bool isUpdate = existingOrder != null && existingOrder.OrderId > 0 ; @@ -182,6 +188,11 @@ public class OrderService : IOrderService { var customerLedger = await _httpService.GetCustomerLedgerAsync(request.CustomerCode, customer.CompanyCode); + if(customerLedger == null) + { + throw new Exception(string.Format("Customer ledger is not found for this customer. Customer Code:{0}",request.CustomerCode)); + } + var creditBalance = customer.CreditLimit- (customerLedger.CurrentBalance + usedCreditBalance); if(creditBalance < request.NetValue) diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs index f395602..a42e040 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs @@ -602,7 +602,7 @@ namespace OnlineSalesAutoCrop.CoreAPI }); var fileName = - $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}.json"; + $"{ context.Request.Path.ToString().Split('/').Last() }-{ DateTime.Now:yyyy-MM-dd_HH-mm-ss-fff}.json"; string filePath = string.Empty;