mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.SKU
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class GetSkuId
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.SKU
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
class GetSku : Connection
|
||||
{
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlClient;
|
||||
using System.Transactions;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class CreatePricingDetail : Connection
|
||||
{
|
||||
public CreatePricingDetail(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public void Executue(List<Model.Sku.Price.PriceInfo> newInfo)
|
||||
{
|
||||
if (newInfo == null || !newInfo.Any())
|
||||
{ return; }
|
||||
|
||||
using (var scope = new TransactionScope())
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
// write new item to table
|
||||
for (int i = 0; i < newInfo.Count(); i++)
|
||||
{
|
||||
string sql = @"
|
||||
INSERT INTO tblSkuPriceType (
|
||||
SkuID
|
||||
,[OrderChannelID]
|
||||
,[PriceInfoTimeStamp]
|
||||
,[OrderChannelQuantity]
|
||||
,[UnitPurchaseCost]
|
||||
,[UnitMinPriceProfit]
|
||||
,[UnitMinPriceCost]
|
||||
,[UnitMinPriceDestory]
|
||||
,[InventoryAgeMin]
|
||||
,[InventoryAgeMax]
|
||||
,[SkuPriceTypeID]
|
||||
,[CompetitivePrice]
|
||||
,[MinPrice]
|
||||
,[MaxPrice]
|
||||
,[RepriceIncrement]
|
||||
,[ReviewRequired]
|
||||
)
|
||||
VALUES (
|
||||
(SELECT skuSkuID FROM tblSku WHERE skuSkuNumber=@skuNumber)
|
||||
,(SELECT OrderChannelID FROM tblOrderChannel WHERE OrderChannel=@orderChannel)
|
||||
,@priceInfoTimeStamp
|
||||
,@orderChannelQuantity
|
||||
,@unitPurchaseCost
|
||||
,@unitMinPriceProfit
|
||||
,@unitMinPriceCost
|
||||
,@unitMinPriceDestory
|
||||
,@inventoryAgeMin
|
||||
,@inventoryAgeMax
|
||||
,@skuPriceTypeID
|
||||
,@competitivePrice
|
||||
,@minPrice
|
||||
,@maxPrice
|
||||
,@repriceIncrement
|
||||
,@reviewRequired
|
||||
);";
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@skuNumber", newInfo[i].SkuNumber);
|
||||
cmd.Parameters.AddWithValue("@orderChannel", newInfo[i].OrderChannel);
|
||||
cmd.Parameters.AddWithValue("@priceInfoTimeStamp", newInfo[i].PriceInfoTimeStamp);
|
||||
cmd.Parameters.AddWithValue("@orderChannelQuantity", newInfo[i].OrderChannelQuantity);
|
||||
cmd.Parameters.AddWithValue("@unitPurchaseCost", newInfo[i].UnitPurchaseCost);
|
||||
cmd.Parameters.AddWithValue("@unitMinPriceProfit", newInfo[i].UnitMinPriceProfit);
|
||||
cmd.Parameters.AddWithValue("@unitMinPriceCost", newInfo[i].UnitMinPriceCost);
|
||||
cmd.Parameters.AddWithValue("@unitMinPriceDestory", newInfo[i].UnitMinPriceDestory);
|
||||
cmd.Parameters.AddWithValue("@inventoryAgeMin", newInfo[i].InventoryAgeMin);
|
||||
cmd.Parameters.AddWithValue("@inventoryAgeMax", newInfo[i].InventoryAgeMax);
|
||||
cmd.Parameters.AddWithValue("@skuPriceTypeID", newInfo[i].PriceTypeId);
|
||||
cmd.Parameters.AddWithValue("@competitivePrice", newInfo[i].CompetitivePrice);
|
||||
cmd.Parameters.AddWithValue("@minPrice", newInfo[i].MinPrice);
|
||||
cmd.Parameters.AddWithValue("@maxPrice", newInfo[i].MaxPrice);
|
||||
cmd.Parameters.AddWithValue("@repriceIncrement", newInfo[i].RepriceIncrement);
|
||||
cmd.Parameters.AddWithValue("@reviewRequired", newInfo[i].ReviewRequired);
|
||||
|
||||
int j = cmd.ExecuteNonQuery();
|
||||
|
||||
if (j < 1)
|
||||
{
|
||||
throw new Exception("Failed database insert statement");
|
||||
}
|
||||
}
|
||||
}
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class ReadParameter : Connection
|
||||
{
|
||||
public ReadParameter(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<Model.Sku.Price.SkuPriceParameter> Execute()
|
||||
{
|
||||
string stringSql = @"
|
||||
SELECT
|
||||
b.SkuID AS SkuId
|
||||
,b.SkuTotalQuantity AS TotalQuantity
|
||||
,b.SkuTotalCost AS TotalCost
|
||||
,b.SkuAvgUnitCost AS UnitCostAverage
|
||||
,tblSku.skuSkuNumber AS SkuNumber
|
||||
,tblSku.skuProductID AS ProductId
|
||||
,tblSku.skuSkuConditionID AS ConditionId
|
||||
,tblSku.AccountTaxCodeID AS TaxCodeId
|
||||
,tblProductCategory.ProfitMinPercent AS ProfitMargin
|
||||
,tblProductCategory.ProfitMinAmount AS PriceMinProfit
|
||||
,(tblAmazonFeeEstimate.ReferralFee / tblAmazonFeeEstimate.PriceToEstimateFeeListingPrice) As AgentFeeMargin
|
||||
,(tblAmazonFeeEstimate.VariableClosingFee + tblAmazonFeeEstimate.PerItemFee + tblAmazonFeeEstimate.FBAFee + tblAmazonFeeEstimate.OtherFee_Exception) AS AgentFeeFixed
|
||||
,tblAccountTaxCode.TaxRateMultiplierGross AS VatMargin
|
||||
,tblAccountTaxCode.TaxRateName AS TaxRateName
|
||||
,tblSkuCondition.IsFixedPrice AS IsFixedPrice
|
||||
,tblSkuCondition.CompetitivePriceMultiplierNew
|
||||
FROM
|
||||
(((((
|
||||
SELECT
|
||||
a.SkuID,
|
||||
Sum(a.SumOfQuantity) AS SkuTotalQuantity,
|
||||
Sum(a.QuanityTimesUnitCost) AS SkuTotalCost,
|
||||
Sum(a.QuanityTimesUnitCost)/Sum(a.SumOfQuantity) AS SkuAvgUnitCost
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
tblStock.SkuID,
|
||||
Sum(tblStockJournalPost.Quantity) AS SumOfQuantity,
|
||||
tblStockJournal.StockID, tblAccountStockCost.AmountUnit,
|
||||
Sum([tblStockJournalPost].[Quantity])*[tblAccountStockCost].[AmountUnit] AS QuanityTimesUnitCost
|
||||
FROM
|
||||
(((tblStockJournalPost
|
||||
INNER JOIN tblStockStatus
|
||||
ON tblStockJournalPost.StockStatusID = tblStockStatus.StockStatusID)
|
||||
INNER JOIN tblStockJournal ON tblStockJournalPost.StockJournalID = tblStockJournal.StockJournalID)
|
||||
INNER JOIN tblAccountStockCost ON tblStockJournal.StockID = tblAccountStockCost.StockID)
|
||||
INNER JOIN tblStock ON tblAccountStockCost.StockID = tblStock.StockID
|
||||
WHERE
|
||||
tblStockStatus.StockStatusTypeID=3
|
||||
OR tblStockStatus.StockStatusTypeID=4
|
||||
GROUP BY
|
||||
tblStockJournal.StockID,
|
||||
tblAccountStockCost.AmountUnit,
|
||||
tblStock.SkuID
|
||||
HAVING
|
||||
Sum(tblStockJournalPost.Quantity)>0
|
||||
) a
|
||||
GROUP BY
|
||||
a.SkuID
|
||||
) b
|
||||
INNER JOIN tblSku ON b.SkuID = tblSku.skuSkuID)
|
||||
INNER JOIN tblProduct ON tblSku.skuProductID = tblProduct.prdProductID)
|
||||
LEFT JOIN tblAmazonFeeEstimate ON tblProduct.prdProductID = tblAmazonFeeEstimate.ProductIdentifier )
|
||||
INNER JOIN tblProductCategory ON tblProduct.ProductCategoryID = tblProductCategory.ProductCategoryID)
|
||||
INNER JOIN tblAccountTaxCode ON tblSku.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID
|
||||
INNER JOIN tblSkuCondition ON tblSku.skuSkuConditionID = tblSkuCondition.scnSkuConditionID
|
||||
";
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
var invPricing = conn.Query<Model.Sku.Price.SkuPriceParameter>(stringSql).ToList();
|
||||
|
||||
if (invPricing != null || invPricing.Any())
|
||||
{
|
||||
return invPricing;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class ReadPricingDetail : Connection
|
||||
{
|
||||
public ReadPricingDetail(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
public Dictionary<string, Model.Sku.Price.PriceInfo> ReadDictionary(List<string> skuNumberList, string orderChannel)
|
||||
{
|
||||
var dic = new Dictionary<string, Model.Sku.Price.PriceInfo>();
|
||||
var list = Read(skuNumberList, orderChannel);
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
dic.Add(list[i].SkuNumber, list[i]);
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
|
||||
public List<Model.Sku.Price.PriceInfo> Read(List<string> skuNumberList, string orderChannel)
|
||||
{
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
string sql = @"
|
||||
SELECT tblSku.skuSkuNumber AS SkuNumber
|
||||
,tblOrderChannel.OrderChannel
|
||||
,tblSkuPrice.PriceInfoTimeStamp
|
||||
,tblSkuPrice.OrderChannelQuantity
|
||||
,tblSkuPrice.UnitPurchaseCost
|
||||
,tblSkuPrice.UnitMinPriceProfit
|
||||
,tblSkuPrice.UnitMinPriceCost
|
||||
,tblSkuPrice.UnitMinPriceDestory
|
||||
,tblSkuPrice.InventoryAgeMin
|
||||
,tblSkuPrice.InventoryAgeMax
|
||||
,tblSkuPrice.CompetitivePrice
|
||||
,tblSkuPrice.MinPrice
|
||||
,tblSkuPrice.MaxPrice
|
||||
,tblSkuPrice.RepriceIncrement
|
||||
,tblSkuPrice.ReviewRequired
|
||||
,tblSkuPriceType.SkuPriceTypeID
|
||||
,tblSkuPriceType.TypeTitle
|
||||
FROM tblSkuPrice
|
||||
INNER JOIN tblSkuPriceType ON tblSkuPrice.SkuPriceTypeID = tblSkuPriceType.SkuPriceTypeID
|
||||
INNER JOIN tblSku ON tblSkuPrice.SkuID = tblSku.skuSkuID
|
||||
INNER JOIN tblOrderChannel ON tblSkuPrice.OrderChannelID = tblOrderChannel.OrderChannelID
|
||||
WHERE tblSku.skuSkuNumber IN @skuNumber
|
||||
AND (tblOrderChannel.OrderChannel = @orderChannel);";
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
parameters.Add("@skuNumber", skuNumberList);
|
||||
parameters.Add("@orderChannel", orderChannel);
|
||||
|
||||
return conn.Query<Model.Sku.Price.PriceInfo>(sql, parameters).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class ReadSkuConditionInfo : Connection
|
||||
{
|
||||
public ReadSkuConditionInfo(string sqlConnectionString): base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<Model.Sku.SkuConditionInfo> Read(List<int> conditionIdList)
|
||||
{
|
||||
string sql = @"
|
||||
SELECT scnSkuConditionID AS SkuConditionId
|
||||
,scnTitleShort AS TitleShort
|
||||
,scnSkuNumberSuffix AS SkuConditionNumber
|
||||
,BaseType AS AmazonBaseType
|
||||
,IsFixedPrice
|
||||
,CompetitivePriceMultiplierNew AS CompetitivePriceMultiplier
|
||||
,scnRepricerStrategy AS RepricerStrategy
|
||||
,scnAmazonIdentifier AS AmazonIdentifier
|
||||
,scnConditionNoteDefault AS ConditionNoteDefault
|
||||
,scnDescription AS Description
|
||||
FROM tblSkuCondition";
|
||||
|
||||
if (conditionIdList != null || !conditionIdList.Any())
|
||||
{
|
||||
sql += @"
|
||||
WHERE scnSkuConditionID IN @conditionIdList
|
||||
";
|
||||
}
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
var paramter = new DynamicParameters();
|
||||
paramter.Add("@conditionIdList", conditionIdList);
|
||||
|
||||
return conn.Query<Model.Sku.SkuConditionInfo>(sql, paramter).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user