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:
Bobbie Hodgetts
2024-05-07 08:24:00 +01:00
committed by GitHub
parent 2f919d7b5a
commit 91ef9acc78
1272 changed files with 4944 additions and 2773311 deletions

View File

@@ -0,0 +1,36 @@
using System;
using System.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Logic.Sku
{
public class GetSkuId
{
/// <summary>
/// Used for retriving an SKU ID by parameters. If no match, can create a new SKU if required.
/// </summary>
/// <param name="productId">The product Id for the SKU</param>
/// <param name="conditionId">The condition Id for the SKU</param>
/// <param name="accountTaxCodeId">The tax code Id for the SKU</param>
/// <param name="noMatchCreateNew">When set to true, if no match is made, function will create a new sku and return the id for that</param>
/// <returns>Return the id for the new or existing sku or, dependant on set parameters, 0 if not found</returns>
/// <exception cref="Exception"></exception>
public int Request(int productId, int conditionId, int accountTaxCodeId, bool noMatchCreateNew)
{
using (TransactionScope scope = new TransactionScope())
{
int? skuId = new Data.Database.Sku.GetSkuId().ByParameters(productId, conditionId, accountTaxCodeId);
if (skuId != null)
{
return (int)skuId;
}
else if (noMatchCreateNew == false)
{
return 0;
}
return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId);
}
}
}
}

View File

@@ -1,121 +0,0 @@
using System;
using System.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Logic.Sku
{
class GetSkuIdByType
{
// used for retriving SKU that matched parameters, creates new if required, returns 0 if not found
public static int Request(string sqlConnectionString, int productId, int conditionId, int accountTaxCodeId, bool noMatchInsertNew)
{
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// look for existing entry
using (SqlCommand cmd = new SqlCommand(@"
SELECT
tblSku.skuSkuID
FROM
tblSku
WHERE
(((tblSku.skuProductID)=@productId) AND ((tblSku.skuSkuConditionID)=@conditionId) AND ((tblSku.AccountTaxCodeID)=@accountTaxCodeId));
", conn))
{
cmd.Parameters.AddWithValue("@productId", productId);
cmd.Parameters.AddWithValue("@conditionId", conditionId);
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
object obj = cmd.ExecuteScalar();
if (obj != null)
{
return (int)obj;
}
}
// value check insert bool
if (noMatchInsertNew == false)
{
return 0;
}
else
{
// get this far, check tax code id is a valid for SKU
using (SqlCommand cmd = new SqlCommand(@"
SELECT tblAccountTaxCode.InvoiceSales
FROM tblAccountTaxCode
WHERE (((tblAccountTaxCode.AccountTaxCodeID)=@accountTaxCodeId));
", conn))
{
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
object obj = cmd.ExecuteScalar();
if (obj == null)
{
throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " doesn't exist!");
}
else
{
bool result = (bool)obj;
if (result == 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;
}
}
}
}
}

View File

@@ -25,7 +25,7 @@ namespace bnhtrade.Core.Logic.Sku.Price
private Logic.Account.TaxCalculation taxCalc;
private decimal marginSchemeMargin;
public FbaPricing(string sqlConnectionString)
public FbaPricing()
{
// was part of a fba repricing feature, that, for now, is being abandoned
throw new NotImplementedException();