This commit is contained in:
Bobbie Hodgetts
2024-08-06 12:07:18 +01:00
parent 1c7ed5da93
commit a865abb788
3 changed files with 8 additions and 122 deletions

View File

@@ -9,7 +9,7 @@ using System.Transactions;
namespace bnhtrade.Core.Data.Database.Sku namespace bnhtrade.Core.Data.Database.Sku
{ {
public class InsertSku : Connection internal class InsertSku : Connection
{ {
public int InsertNew(int productId, int conditionId, int accountTaxCodeId) public int InsertNew(int productId, int conditionId, int accountTaxCodeId)
{ {

View File

@@ -28,9 +28,11 @@ namespace bnhtrade.Core.Logic.Sku
{ {
return 0; return 0;
} }
else
{
return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId); return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId);
} }
} }
} }
}
} }

View File

@@ -229,123 +229,6 @@ namespace bnhtrade.Core
} }
} }
namespace Sku
{
public class Sku
{
public static int GetSkuIdByType(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;
}
}
}
}
}
namespace Stock namespace Stock
{ {
public class StockCreate public class StockCreate
@@ -549,7 +432,7 @@ namespace bnhtrade.Core
} }
else else
{ {
throw new Exception("Manual delete of this stock type is not supported, use the moethod that created it!"); throw new Exception("Manual delete of this stock type is not supported, use the method that created it!");
} }
// check there is only one stock journal entry for stock item // check there is only one stock journal entry for stock item
@@ -879,6 +762,7 @@ namespace bnhtrade.Core
} }
// insert journal posts into database // insert journal posts into database
//new Data.Database.Stock
Core.Stock.StockJournal.StockJournalPostInsert(conn, stockId, stockJournalId, journalPosts, isNewStock); Core.Stock.StockJournal.StockJournalPostInsert(conn, stockId, stockJournalId, journalPosts, isNewStock);
// consistency check // consistency check