mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
Migration from Amazon MWS to Selling Partner API
This commit is contained in:
@@ -17,9 +17,8 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
private bnhtrade.Core.Logic.Log.LogEvent log = new Log.LogEvent();
|
||||
string err = "FbaPricing Error: ";
|
||||
private string marginSchemeTaxCode = Data.Database.Constants.GetMarginSchemeTaxCode();
|
||||
int repriceHoldOnSalePeriod = 14; // days
|
||||
private int newConditionId = Data.Database.Constants.GetProductConditionIdNew();
|
||||
private List<Model.Sku.Price.SkuPriceParameter> skuInfo;
|
||||
private List<Model.Sku.Price.SkuRepriceInfo> skuInfo;
|
||||
private Dictionary<string, Model.Product.CompetitivePrice> competitivePrices;
|
||||
DateTime newTimeStamp = DateTime.UtcNow;
|
||||
private int repriceIncrementDivisor = 60;
|
||||
@@ -35,6 +34,8 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
marginSchemeMargin = taxCalc.GetMarginMultiplier(newTimeStamp);
|
||||
}
|
||||
|
||||
public int RepriceHoldOnSalePeriod { get; set; } = 14; // days
|
||||
|
||||
public void Update(bool overrideDayCheck = false)
|
||||
{
|
||||
UpdatePrecheck();
|
||||
@@ -43,8 +44,29 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
{
|
||||
string orderChannel = Data.Database.Constants.GetOrderChannelAmazonUk(); ; // may in future enable other order channels
|
||||
|
||||
// get SKU quantities in stock on FBA
|
||||
var statusTypeList = new List<int> { 3, 4 };
|
||||
var fbaSkuStock = new Logic.Stock.GetStatusTypeBalance().BySku(statusTypeList);
|
||||
|
||||
// retrive SKU info
|
||||
var getSku = new Logic.Sku.GetSkuInfo(sqlConnectionString);
|
||||
var skuInfoDict = getSku.ConvertToDictionary(getSku.BySkuNumber(fbaSkuStock.Keys.ToList()));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// get current sku base pricing details (stock quantity, competative price, VAT info, etc.)
|
||||
skuInfo = new Data.Database.Sku.Price.ReadParameter(sqlConnectionString).Execute();
|
||||
skuInfo = new Data.Database.Sku.Price.ReadParameter().Execute();
|
||||
if (skuInfo == null || !skuInfo.Any())
|
||||
{
|
||||
err += "Querying the database returned no records.";
|
||||
@@ -57,10 +79,10 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
var crDictionary = new Dictionary<string, Model.Sku.Price.PriceInfo>();
|
||||
|
||||
// open needed classes
|
||||
var readAge = new Data.Database.Import.ReadFbaInventoryAge(sqlConnectionString);
|
||||
var readAge = new Data.Database.Import.AmazonFbaInventoryAgeRead();
|
||||
|
||||
// get current db pricing
|
||||
var dbDictionary = new Data.Database.Sku.Price.ReadPricingDetail(sqlConnectionString).ReadDictionary(skuInfo.Select(o => o.SkuNumber).ToList(), orderChannel);
|
||||
var dbDictionary = new Data.Database.Sku.Price.ReadPricingDetail().ReadDictionary(skuInfo.Select(o => o.SkuNumber).ToList(), orderChannel);
|
||||
|
||||
// get required competivie prices
|
||||
var readComp = new Logic.Product.GetCompetitivePrice(sqlConnectionString);
|
||||
@@ -248,7 +270,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
|
||||
if (skuInfo[i].TaxCode == marginSchemeTaxCode) // taxcodeinfo now has ismarginscheme boolean
|
||||
{
|
||||
price = (costPrice + agentFeeFixed - (costPrice * marginSchemeMargin))
|
||||
price = (costPrice + agentFeeFixed - (costPrice * marginSchemeMargin))
|
||||
/ (1 - profitMargin - agentFeeMargin - marginSchemeMargin);
|
||||
}
|
||||
else
|
||||
@@ -300,8 +322,8 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
{
|
||||
if (!saleCountInPeriod.Any())
|
||||
{
|
||||
saleCountInPeriod = new Data.Database.Import.ReadFbaSaleShipment(sqlConnectionString)
|
||||
.GetSaleCount(skuInfo.Select(x => x.SkuNumber).ToList(), DateTime.Now.AddDays(repriceHoldOnSalePeriod * -1), DateTime.Now);
|
||||
saleCountInPeriod = new Data.Database.Import.AmazonFbaSaleShipment()
|
||||
.ReadSaleCount(skuInfo.Select(x => x.SkuNumber).ToList(), DateTime.Now.AddDays(RepriceHoldOnSalePeriod * -1), DateTime.Now);
|
||||
}
|
||||
if (saleCountInPeriod.ContainsKey(skuInfo[i].SkuNumber))
|
||||
{
|
||||
@@ -313,6 +335,11 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares current date and last reprice date to check if SKU can be repriced
|
||||
/// </summary>
|
||||
/// <param name="lastPriceUpdate">The date & time the SKU was lasted repriced</param>
|
||||
/// <returns></returns>
|
||||
private bool OkayToReprice(DateTime lastPriceUpdate)
|
||||
{
|
||||
if (lastPriceUpdate == default(DateTime))
|
||||
@@ -338,6 +365,10 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
return update;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the pricing info to databse
|
||||
/// </summary>
|
||||
/// <param name="crDictionary">Current repricing data in Dictonary form by SKU number</param>
|
||||
private void SaveToDatabase(Dictionary<string, Model.Sku.Price.PriceInfo> crDictionary)
|
||||
{
|
||||
var validate = new Core.Logic.Validate.SkuPriceInfo();
|
||||
@@ -348,7 +379,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
new Data.Database.Sku.Price.CreatePricingDetail(sqlConnectionString).Executue(crDictionary.Values.ToList());
|
||||
new Data.Database.Sku.Price.CreatePricingDetail().Executue(crDictionary.Values.ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -409,4 +440,4 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
submit.SubmitInventoryLoader(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user