mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 15:27:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
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.Import
|
||||
{
|
||||
public class ReadFbaInventoryAge : Connection
|
||||
{
|
||||
public ReadFbaInventoryAge(string sqlConnectionString): base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public (int MinAge, int MaxAge)? BySkuNumber(string skuNumber, string orderChannel)
|
||||
{
|
||||
int minAge = 0;
|
||||
int maxAge = 0;
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (var cmd03 = new SqlCommand(@"
|
||||
SELECT [snapshot-date]
|
||||
,[inv-age-0-to-90-days]
|
||||
,[inv-age-91-to-180-days]
|
||||
,[inv-age-181-to-270-days]
|
||||
,[inv-age-271-to-365-days]
|
||||
,[inv-age-365-plus-days]
|
||||
FROM tblImportFbaInventoryAgeReport
|
||||
WHERE sku = @skuNumber AND marketplace = @orderChannel
|
||||
", conn))
|
||||
{
|
||||
cmd03.Parameters.AddWithValue("@skuNumber", skuNumber);
|
||||
cmd03.Parameters.AddWithValue("@orderChannel", orderChannel);
|
||||
|
||||
using (var reader03 = cmd03.ExecuteReader())
|
||||
{
|
||||
if (reader03.Read())
|
||||
{
|
||||
// final min age
|
||||
if (reader03.GetInt32(1) > 0) { minAge = 1; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(2) > 0) { minAge = 91; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(3) > 0) { minAge = 181; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(4) > 0) { minAge = 271; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(5) > 0) { minAge = 366; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//find max age
|
||||
if (reader03.GetInt32(5) > 0) { maxAge = 2147483647; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(4) > 0) { maxAge = 365; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(3) > 0) { maxAge = 270; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(2) > 0) { maxAge = 180; }
|
||||
else
|
||||
{
|
||||
if (reader03.GetInt32(1) > 0) { maxAge = 90; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (minAge, maxAge);
|
||||
}
|
||||
}
|
||||
}
|
||||
117
src/bnhtrade.Core/Data/Database/Import/ReadFbaSaleShipment.cs
Normal file
117
src/bnhtrade.Core/Data/Database/Import/ReadFbaSaleShipment.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
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.Import
|
||||
{
|
||||
public class ReadFbaSaleShipment : Connection
|
||||
{
|
||||
public ReadFbaSaleShipment(string sqlConnectionString): base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<string, decimal> GetMaxSalePrice(List<string> skuNumber, int timePeriodDay)
|
||||
{
|
||||
var returnList = new Dictionary<string, decimal>();
|
||||
|
||||
if (skuNumber == null || !skuNumber.Any())
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
|
||||
string sql = @"
|
||||
SELECT sku
|
||||
,Max(ISNULL([tblImportFbaSaleShipment].[item-price], 0) + ISNULL([tblImportFbaSaleShipment].[item-tax], 0)) AS Expr1
|
||||
FROM tblImportFbaSaleShipment
|
||||
WHERE (
|
||||
(sku IN (";
|
||||
|
||||
for (int i = 0; i < skuNumber.Count; i++)
|
||||
{
|
||||
if (!(i + 1 == skuNumber.Count))
|
||||
{
|
||||
sql += "@skuNumber" + i + ", ";
|
||||
}
|
||||
else
|
||||
{
|
||||
sql += "@skuNumber" + i + "))";
|
||||
}
|
||||
}
|
||||
|
||||
sql += @"
|
||||
AND ((tblImportFbaSaleShipment.[shipment-date]) >= @shipDateFilter)
|
||||
)
|
||||
GROUP BY sku;";
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
for (int i = 0; i < skuNumber.Count; i++)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@skuNumber" + i, skuNumber[i]);
|
||||
}
|
||||
cmd.Parameters.AddWithValue("@shipDateFilter", DateTime.Today.AddDays(timePeriodDay * -1));
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
decimal price = reader.GetDecimal(1);
|
||||
if (price > 0)
|
||||
{
|
||||
returnList.Add(reader.GetString(0), price);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public Dictionary<string, int> GetSaleCount(List<string> skuNumber, DateTime periodStart, DateTime periodEnd)
|
||||
{
|
||||
var returnList = new Dictionary<string, int>();
|
||||
|
||||
if (skuNumber == null || !skuNumber.Any())
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
|
||||
string sql = @"
|
||||
SELECT sku
|
||||
,Count(1) AS CountOfSku
|
||||
FROM tblImportFbaSaleShipment
|
||||
WHERE (
|
||||
(sku IN @skuNumber)
|
||||
AND (
|
||||
(tblImportFbaSaleShipment.[shipment-date] >= @periodStart)
|
||||
AND tblImportFbaSaleShipment.[shipment-date] <= @periodEnd
|
||||
)
|
||||
)
|
||||
GROUP BY sku;";
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
var param = new DynamicParameters();
|
||||
param.Add("@skuNumber", skuNumber);
|
||||
param.Add("@periodStart", periodStart.ToUniversalTime());
|
||||
param.Add("@periodEnd", periodEnd.ToUniversalTime());
|
||||
|
||||
return conn.Query(sql, param).ToDictionary(
|
||||
row => (string)row.sku,
|
||||
row => (int)row.CountOfSku);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user