mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 14:37:16 +00:00
SP-API stock reconciliation
Amazon had depreciated a number of reports that were used for stock reconciliation. Application now uses the new fba ledger report to reconcile. It is currently untested, as this requires data from Amazon. Methods that require testing will return a 'NotImplementedException'. Also, removed the depreciated ILMerge and replaced with ILRepack. Plus much more tidying up, and improvements.
This commit is contained in:
85
src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs
Normal file
85
src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using FikaAmazonAPI.AmazonSpApiSDK.Models.ProductPricing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class InsertSku : Connection
|
||||
{
|
||||
public int InsertNew(int productId, int conditionId, int accountTaxCodeId)
|
||||
{
|
||||
using (TransactionScope scope = new TransactionScope())
|
||||
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
// check tax code id is a valid for SKU
|
||||
var dbTax = new Data.Database.Account.ReadTaxCode();
|
||||
var taxCodeList = dbTax.GetByTaxCodeId(new List<int> { accountTaxCodeId });
|
||||
|
||||
if (!taxCodeList.Any())
|
||||
{
|
||||
throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " doesn't exist!");
|
||||
}
|
||||
else if (taxCodeList[0].IsValidOnIncome == false)
|
||||
{
|
||||
throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " is not a valid type for an SKU.");
|
||||
}
|
||||
|
||||
// get info to create sku number
|
||||
int skuCount;
|
||||
int skuSuffix;
|
||||
using (SqlCommand cmd = new SqlCommand("SELECT NEXT VALUE FOR SkuCountSequence;", conn))
|
||||
{
|
||||
skuCount = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT tblSkuCondition.scnSkuNumberSuffix
|
||||
FROM tblSkuCondition
|
||||
WHERE (((tblSkuCondition.scnSkuConditionID)=@conditionId));
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@conditionId", conditionId);
|
||||
|
||||
try
|
||||
{
|
||||
skuSuffix = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Error retriving SKU number suffix for SkuConditionID=" + conditionId + "." +
|
||||
System.Environment.NewLine + "Error Message: " + ex.Message);
|
||||
}
|
||||
}
|
||||
string skuNumber = skuCount.ToString("D6") + "-" + skuSuffix.ToString("D2");
|
||||
|
||||
// insert new sku
|
||||
int skuId;
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
INSERT INTO tblSku
|
||||
(skuSkuNumber, skuProductID, skuSkuConditionID, AccountTaxCodeID)
|
||||
OUTPUT INSERTED.skuSkuID
|
||||
VALUES
|
||||
(@skuNumber, @productId, @conditionId, @accountTaxCodeId)
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@skuNumber", skuNumber);
|
||||
cmd.Parameters.AddWithValue("@productId", productId);
|
||||
cmd.Parameters.AddWithValue("@conditionId", conditionId);
|
||||
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
|
||||
|
||||
skuId = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
return skuId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user