the abandoned fba repricing feature

* Merge master into branch (#15)

* Bug fix

* Bug fix when retriving shipment stock status id

* Various bug fixs and improvements to stock SKU reconciliation

* Last MWS report import date time saved

* master into branch (#16)

* Bug fix

* Bug fix when retriving shipment stock status id

* Various bug fixs and improvements to stock SKU reconciliation

* Last MWS report import date time saved

* wip

* wip

* wip

* wip

* wip

* some extra tidying up to get it to complie and the main merge is complete

* wip
This commit is contained in:
Bobbie Hodgetts
2024-04-17 13:23:33 +01:00
committed by GitHub
parent a7bc00e73a
commit f1d7119306
19 changed files with 355 additions and 44 deletions

View File

@@ -12,13 +12,11 @@ namespace bnhtrade.Core.Logic.Export
{
public class AmazonSubmitFile
{
private string sqlConnectionString;
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
private Log.LogEvent log = new Log.LogEvent();
public AmazonSubmitFile(string sqlConnectionString)
public AmazonSubmitFile()
{
this.sqlConnectionString = sqlConnectionString;
}
public void SubmitInventoryLoader(MemoryStream stream)

View File

@@ -9,17 +9,29 @@ namespace bnhtrade.Core.Logic.Product
public class GetCompetitivePrice
{
private Dictionary<string, Model.Product.CompetitivePrice> competitivePrices;
private int newConditionId = Data.Database.Constants.GetProductConditionIdNew();
private string sqlConnectionString;
private int newConditionId = (int)Data.Database.Constants.SkuCondition.New;
private Data.Database.Product.ReadCompetitivePrice read;
private List<string> productIdList;
private List<string> conditionIdList;
private Data.Database.Product.ReadCompetitivePrice dbRead;
private Dictionary<int, decimal> newConditionMultipier;
public GetCompetitivePrice(string sqlConnectionString)
public GetCompetitivePrice()
{
this.sqlConnectionString = sqlConnectionString;
// was poart of a fba repricing feature, that, for now, is being abandoned
throw new NotImplementedException();
dbRead = new Data.Database.Product.ReadCompetitivePrice();
newConditionMultipier = new Dictionary<int, decimal>();
}

View File

@@ -8,15 +8,13 @@ namespace bnhtrade.Core.Logic.Sku
{
public class GetSkuInfo
{
private string sqlConnectionString;
private Data.Database.Sku.ReadSku dbSkuInfo;
private Logic.Product.GetProductInfo getProductInfo;
private Logic.Sku.GetSkuConditionInfo getConditionInfo;
private Logic.Account.GetTaxCodeInfo getTaxCodeInfo;
public GetSkuInfo(string sqlConnection)
public GetSkuInfo()
{
this.sqlConnectionString = sqlConnection;
Init();
}

View File

@@ -13,11 +13,10 @@ namespace bnhtrade.Core.Logic.Sku.Price
{
public class FbaPricing
{
private string sqlConnectionString;
private bnhtrade.Core.Logic.Log.LogEvent log = new Log.LogEvent();
string err = "FbaPricing Error: ";
private string marginSchemeTaxCode = Data.Database.Constants.GetMarginSchemeTaxCode();
private int newConditionId = Data.Database.Constants.GetProductConditionIdNew();
private int newConditionId = (int)Data.Database.Constants.SkuCondition.New;
private List<Model.Sku.Price.SkuRepriceInfo> skuInfo;
private Dictionary<string, Model.Product.CompetitivePrice> competitivePrices;
DateTime newTimeStamp = DateTime.UtcNow;
@@ -28,7 +27,25 @@ namespace bnhtrade.Core.Logic.Sku.Price
public FbaPricing(string sqlConnectionString)
{
this.sqlConnectionString = sqlConnectionString;
// was part of a fba repricing feature, that, for now, is being abandoned
throw new NotImplementedException();
taxCalc = new Account.TaxCalculation();
newTimeStamp = DateTime.UtcNow;
marginSchemeMargin = taxCalc.GetMarginMultiplier(newTimeStamp);
@@ -45,11 +62,14 @@ 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 statusTypeList = new List<int>();
statusTypeList.Add((int)Data.Database.Constants.StockStatusType.FbaInventoryActive);
statusTypeList.Add((int)Data.Database.Constants.StockStatusType.FbaShipment);
var fbaSkuStock = new Logic.Stock.GetStatusTypeBalance().BySku(statusTypeList);
// retrive SKU info
var getSku = new Logic.Sku.GetSkuInfo(sqlConnectionString);
var getSku = new Logic.Sku.GetSkuInfo();
var skuInfoDict = getSku.ConvertToDictionary(getSku.BySkuNumber(fbaSkuStock.Keys.ToList()));
@@ -65,7 +85,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
// get current sku base pricing details (stock quantity, competative price, VAT info, etc.)
// pull current sku base pricing details (stock quantity, competative price, VAT info, etc.) from the database
skuInfo = new Data.Database.Sku.Price.ReadParameter().Execute();
if (skuInfo == null || !skuInfo.Any())
{
@@ -78,18 +98,18 @@ namespace bnhtrade.Core.Logic.Sku.Price
var loader = new List<Model.Export.AmazonIventoryLoaderFile>();
var crDictionary = new Dictionary<string, Model.Sku.Price.PriceInfo>();
// open needed classes
// instanlise needed classes
var readAge = new Data.Database.Import.AmazonFbaInventoryAgeRead();
// get current db pricing
// get current pricing from database
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);
var readComp = new Logic.Product.GetCompetitivePrice();
readComp.EstimatePrice = true;
var compPrices = readComp.Execute(skuInfo);
// loop through skus returnd from stock query
// loop through sku pricing returned from database
for (int i = 0; i < skuInfo.Count(); i++)
{
var existing = skuInfo[i];
@@ -122,7 +142,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
cr.InventoryAgeMax = invAge.Value.MaxAge;
// get minimum prices
cr.UnitMinPriceCost = GetMinPriceCost(i);
cr.UnitMinPriceCost = GetPriceBreakEven(i);
cr.UnitMinPriceProfit = GetMinPriceProfit(i);
cr.UnitPurchaseCost = skuInfo[i].UnitCostAverage;
@@ -224,12 +244,17 @@ namespace bnhtrade.Core.Logic.Sku.Price
}
}
private Dictionary<string, Model.Sku.Price.SkuRepriceInfo> GetSkuPricingInfo()
{
throw new NotImplementedException();
}
/// <summary>
/// Get the minimum sale price to break even.
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
private decimal GetMinPriceCost(int i)
private decimal GetPriceBreakEven(int i)
{
decimal costPrice = skuInfo[i].UnitCostAverage;
decimal agentFeeFixed = skuInfo[i].AgentFeeFixed;
@@ -353,7 +378,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
lastPriceUpdate = new DateTime(lastPriceUpdate.Year, lastPriceUpdate.Month, lastPriceUpdate.Day);
DateTime today = new DateTime(newTimeStamp.Year, newTimeStamp.Month, newTimeStamp.Day);
// will only update once on tue, wed or thurs each week.
// will only update once on tue, wed or thurs each week. <------- Why??? don't know what my reasoning was for this
if (today.DayOfWeek == DayOfWeek.Tuesday || today.DayOfWeek == DayOfWeek.Wednesday || today.DayOfWeek == DayOfWeek.Thursday)
{
if (today > lastPriceUpdate.AddDays(3))
@@ -432,8 +457,8 @@ namespace bnhtrade.Core.Logic.Sku.Price
csv.WriteRecords(exportList);
}
// submit file to database and amazon mws
var submit = new Logic.Export.AmazonSubmitFile(sqlConnectionString);
// submit file to database and amazon
var submit = new Logic.Export.AmazonSubmitFile();
return; // remove after testing

View File

@@ -1,53 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Sku.Price
{
public class SkuRepriceInfo
{
public int SkuId { get; set; }
public string SkuNumber { get; set; }
public int TotalQuantity { get; set; }
public decimal UnitCostAverage { get; set; }
public int ProductId { get; set; }
public int ConditionId { get; set; }
public string TaxCode { get; set; }
public decimal ProfitMargin { get; set; }
/// <summary>
/// Agent fee as ratio of selling price (i.e. 20% = 0.2)
/// </summary>
public decimal AgentFeeMargin { get; set; }
/// <summary>
/// Total of agent fixed fees
/// </summary>
public decimal AgentFeeFixed { get; set; }
/// <summary>
/// Tax margin as a ratio of 1 (i.e. 20% = 0.2)
/// </summary>
public decimal VatMargin { get; set; }
public string TaxRateName { get; set; }
public bool IsFixedPrice { get; set; }
public decimal CompetitivePriceMultiplierNew { get; set; }
public decimal TotalCost { get; set; }
public decimal PriceMinProfit { get; set; }
}
}