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

@@ -93,6 +93,8 @@ namespace bnhtrade.Core.Data.Database.Account
return resultList;
}
taxcodeList = taxcodeList.Distinct().ToList();
whereBuilder.Innit();
whereBuilder.In("TaxCode", taxcodeList, "WHERE");
@@ -118,6 +120,8 @@ namespace bnhtrade.Core.Data.Database.Account
return resultList;
}
skuNumberList = skuNumberList.Distinct().ToList();
string sql = @"
SELECT tblSku.skuSkuNumber
,tblAccountTaxCode.TaxCode
@@ -167,6 +171,8 @@ namespace bnhtrade.Core.Data.Database.Account
return resultList;
}
lineItemCode = lineItemCode.Distinct().ToList();
string sql = @"
SELECT tblAccountInvoiceLineItem.ItemCode
,tblAccountTaxCode.TaxCode

View File

@@ -33,9 +33,28 @@ namespace bnhtrade.Core.Data.Database
return "Amazon.co.uk";
}
public static int GetProductConditionIdNew()
/// <summary>
/// Returns the sql table ID for a condition type
/// </summary>
public enum SkuCondition
{
return 10;
New = 10,
LikeNew = 11,
VeryGood = 12,
Good = 13,
Acceptable = 14,
// add the rest as needed
}
/// <summary>
/// Returns the sql table ID for a stock status type
/// </summary>
public enum StockStatusType
{
FbaInventoryActive = 3,
FbaShipment = 4,
FbaShippingPlan = 5,
// add the rest as needed
}
}
}

View File

@@ -11,6 +11,7 @@ namespace bnhtrade.Core.Data.Database.Product
{
private List<string> filterByAsin;
private List<int> filterByProductId;
private Data.Database.SqlWhereBuilder sqlWhereBuilder = new SqlWhereBuilder();
public ReadProduct()
{
@@ -157,6 +158,7 @@ namespace bnhtrade.Core.Data.Database.Product
}
}
}
return returnList;
}

View File

@@ -0,0 +1,130 @@
using MarketplaceWebServiceProducts.Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Product
{
public class UpdateAmazonFeeEstimate : Connection
{
public UpdateAmazonFeeEstimate(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void ByFeesEstimateResult(FeesEstimateResult updateItem)
{
ByFeesEstimateResult(new List<FeesEstimateResult> { updateItem });
}
public void ByFeesEstimateResult(List<FeesEstimateResult> updateList)
{
foreach (var item in updateList)
{
bool isSellerSku = false;
if (item.FeesEstimateIdentifier.IdType == "SellerSKU")
{
isSellerSku = true;
}
else if (item.FeesEstimateIdentifier.IdType != "ASIN")
{
// Amazon have updated API to include other identifiers?
throw new Exception(
"New FeesEstimateIdentifier encountered/unsupported of type '" + item.FeesEstimateIdentifier + "'.");
}
string asin = item.FeesEstimateIdentifier.IdValue;
bool isAmazonFulfilled = item.FeesEstimateIdentifier.IsAmazonFulfilled;
DateTime timeOfFeeEstimation = item.FeesEstimate.TimeOfFeesEstimation;
decimal totalFeeEstimate = item.FeesEstimate.TotalFeesEstimate.Amount;
string currencyCode = item.FeesEstimate.TotalFeesEstimate.CurrencyCode;
decimal priceToEstimateFeeListingPrice = item.FeesEstimateIdentifier.PriceToEstimateFees.ListingPrice.Amount;
decimal priceToEstimateFeeShipping = 0;
if (item.FeesEstimateIdentifier.PriceToEstimateFees.Shipping != null)
{ priceToEstimateFeeShipping = item.FeesEstimateIdentifier.PriceToEstimateFees.Shipping.Amount; }
decimal priceToEstimateFeePoints = 0;
if (item.FeesEstimateIdentifier.PriceToEstimateFees.Points != null)
{ priceToEstimateFeePoints = item.FeesEstimateIdentifier.PriceToEstimateFees.Points.PointsMonetaryValue.Amount; }
decimal referralFee = 0m;
decimal variableClosingFee = 0m;
decimal fulfillmentFees = 0m;
decimal perItemFee = 0m;
decimal otherFee_Exception = 0m;
FeeDetailList feeDetailList = item.FeesEstimate.FeeDetailList;
List<FeeDetail> feeDetail = feeDetailList.FeeDetail;
foreach (FeeDetail feeDetailItem in feeDetail)
{
if (feeDetailItem.FeeType == "AmazonReferralFee" || feeDetailItem.FeeType == "ReferralFee")
{ referralFee = feeDetailItem.FinalFee.Amount; }
else if (feeDetailItem.FeeType == "VariableClosingFee")
{ variableClosingFee = feeDetailItem.FinalFee.Amount; }
else if (feeDetailItem.FeeType == "PerItemFee")
{ perItemFee = feeDetailItem.FinalFee.Amount; }
else if (feeDetailItem.FeeType == "FBAFees" || feeDetailItem.FeeType == "FulfillmentFees")
{ fulfillmentFees = feeDetailItem.FinalFee.Amount; }
else
{ otherFee_Exception = otherFee_Exception + feeDetailItem.FinalFee.Amount; }
}
// build sql statement
string sqlProductId;
if (isSellerSku)
{
sqlProductId = "(SELECT tblSku.skuProductID FROM tblSku INNER JOIN tblProduct ON tblSku.skuProductID = tblProduct.prdProductID WHERE tblProduct.prdAmazonASIN = @asin)";
}
else
{
sqlProductId = "(SELECT prdProductID FROM tblProduct WHERE prdAmazonASIN = @asin)";
}
string sql = @"
UPDATE tblAmazonFeeEstimate SET
IsAmazonFulfilled=@isAmazonFulfilled, TimeOfFeeEstimation=@timeOfFeeEstimation,
TotalFeeEstimate=@totalFeeEstimate, PriceToEstimateFeeListingPrice=@priceToEstimateFeeListingPrice,
PriceToEstimateFeeShipping=@priceToEstimateFeeShipping, PriceToEstimateFeePoints=@priceToEstimateFeePoints,
ReferralFee=@referralFee, VariableClosingFee=@variableClosingFee, PerItemFee=@perItemFee, FBAFee=@fbaFee,
OtherFee_Exception=@otherFee_Exception, currencyCode=CurrencyCode
WHERE ProductID = " + sqlProductId + @"
IF @@ROWCOUNT = 0
INSERT INTO tblAmazonFeeEstimate (
ProductID, IsAmazonFulfilled, TimeOfFeeEstimation, TotalFeeEstimate, PriceToEstimateFeeListingPrice,
PriceToEstimateFeeShipping, PriceToEstimateFeePoints, ReferralFee, VariableClosingFee, PerItemFee, FBAFee,
OtherFee_Exception, CurrencyCode
) VALUES (
" + sqlProductId + @", @isAmazonFulfilled, @timeOfFeeEstimation, @totalFeeEstimate, @priceToEstimateFeeListingPrice,
@priceToEstimateFeeShipping, @priceToEstimateFeePoints, @referralFee, @variableClosingFee, @perItemFee, @fbaFee,
@otherFee_Exception, @currencyCode
)
";
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
using (SqlCommand sqlCommand = new SqlCommand(sql, sqlConn))
{
sqlCommand.Parameters.AddWithValue("@asin", asin);
sqlCommand.Parameters.AddWithValue("@isAmazonFulfilled", isAmazonFulfilled);
sqlCommand.Parameters.AddWithValue("@timeOfFeeEstimation", timeOfFeeEstimation);
sqlCommand.Parameters.AddWithValue("@totalFeeEstimate", totalFeeEstimate);
sqlCommand.Parameters.AddWithValue("@priceToEstimateFeeListingPrice", priceToEstimateFeeListingPrice);
sqlCommand.Parameters.AddWithValue("@priceToEstimateFeeShipping", priceToEstimateFeeShipping);
sqlCommand.Parameters.AddWithValue("@priceToEstimateFeePoints", priceToEstimateFeePoints);
sqlCommand.Parameters.AddWithValue("@referralFee", referralFee);
sqlCommand.Parameters.AddWithValue("@variableClosingFee", variableClosingFee);
sqlCommand.Parameters.AddWithValue("@perItemFee", perItemFee);
sqlCommand.Parameters.AddWithValue("@fbaFee", fulfillmentFees);
sqlCommand.Parameters.AddWithValue("@otherFee_Exception", otherFee_Exception);
sqlCommand.Parameters.AddWithValue("@currencyCode", currencyCode);
sqlCommand.ExecuteNonQuery();
}
}
}
}
}
}

View File

@@ -50,6 +50,8 @@ namespace bnhtrade.Core.Data.Database
return;
}
var distinctList = orValueList.Distinct().ToList();
string sqlWhere = @"
";
@@ -61,7 +63,7 @@ namespace bnhtrade.Core.Data.Database
sqlWhere += " " + columnReference + " IN ( ";
var paramters = new Dictionary<string, object>();
int listCount = orValueList.Count();
int listCount = distinctList.Count();
for (int i = 0; i < listCount; i++, parameterCount++)
{
if (i > 0)
@@ -71,7 +73,7 @@ namespace bnhtrade.Core.Data.Database
string param = "@parameter" + parameterCount;
sqlWhere += param;
paramters.Add(param, orValueList[i]);
paramters.Add(param, distinctList[i]);
}
sqlWhere += " )";