mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 14:37:16 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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.Account
|
||||
{
|
||||
public class CreateInvoiceLineItem : Connection
|
||||
{
|
||||
public CreateInvoiceLineItem(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public int CreateDefault(string itemCode)
|
||||
{
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
INSERT INTO tblAccountInvoiceLineItem ( ItemName, ItemCode )
|
||||
OUTPUT INSERTED.AccountInvoiceLineItemID
|
||||
VALUES ( @itemName, @itemCode )
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@itemName", itemCode);
|
||||
cmd.Parameters.AddWithValue("@itemCode", itemCode);
|
||||
|
||||
object obj = cmd.ExecuteScalar();
|
||||
|
||||
if (obj == null || obj == DBNull.Value)
|
||||
{
|
||||
throw new Exception("Error inserting new defalt invoice line item into database");
|
||||
}
|
||||
|
||||
return (int)obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,62 +9,34 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
{
|
||||
public class ReadAccountCode : Connection
|
||||
{
|
||||
private bool allRetrived;
|
||||
private Dictionary<int, Model.Account.AccountCode> cache;
|
||||
protected ReadAccountCode(string sqlConnectionString) : base(sqlConnectionString)
|
||||
private Data.Database.WhereBuilder sqlWhere = new WhereBuilder();
|
||||
private List<Model.Account.AccountCode> resultList;
|
||||
|
||||
public ReadAccountCode(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
allRetrived = false;
|
||||
cache = new Dictionary<int, Model.Account.AccountCode>();
|
||||
}
|
||||
protected void ClearCache()
|
||||
|
||||
public List<Model.Account.AccountCode> All()
|
||||
{
|
||||
allRetrived = false;
|
||||
cache.Clear();
|
||||
Innit();
|
||||
return Execute(null, null);
|
||||
}
|
||||
public List<Model.Account.AccountCode> GetAll()
|
||||
|
||||
public List<Model.Account.AccountCode> ByAccountCode(List<int> accountCodeList)
|
||||
{
|
||||
if (allRetrived == false)
|
||||
Innit();
|
||||
|
||||
if (accountCodeList == null || !accountCodeList.Any())
|
||||
{
|
||||
UpdateCache(-1);
|
||||
allRetrived = true;
|
||||
return resultList;
|
||||
}
|
||||
|
||||
var returnList = new List<Model.Account.AccountCode>();
|
||||
foreach (var item in cache)
|
||||
{
|
||||
returnList.Add(item.Value);
|
||||
}
|
||||
|
||||
return returnList;
|
||||
sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE ");
|
||||
return Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList);
|
||||
}
|
||||
public Model.Account.AccountCode GetByAccountCode(int accountCode)
|
||||
{
|
||||
if (cache.ContainsKey(accountCode))
|
||||
{
|
||||
return cache[accountCode];
|
||||
}
|
||||
else if (allRetrived)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCache(accountCode);
|
||||
if (cache.ContainsKey(accountCode))
|
||||
{
|
||||
return cache[accountCode];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void UpdateCache(int accountCode = -1)
|
||||
{
|
||||
var dicCache = new Dictionary<int, Model.Account.AccountCode>();
|
||||
|
||||
bool whereClause = false;
|
||||
private List<Model.Account.AccountCode> Execute(string sqlWhere, Dictionary<string, object> parameters)
|
||||
{
|
||||
//build sql query
|
||||
string sqlString = @"
|
||||
SELECT tblAccountChartOf.AccountChartOfID
|
||||
@@ -74,13 +46,8 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
,tblAccountChartOfType.AccountChartOfType
|
||||
,tblAccountChartOfType.BasicType
|
||||
FROM tblAccountChartOf
|
||||
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID";
|
||||
if (accountCode > -1)
|
||||
{
|
||||
whereClause = true;
|
||||
sqlString = sqlString + @"
|
||||
WHERE (((tblAccountChartOf.AccountCode) = @accountCode))";
|
||||
}
|
||||
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID
|
||||
" + sqlWhere;
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
@@ -88,9 +55,12 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
||||
{
|
||||
if (whereClause)
|
||||
if (parameters != null)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@accountCode", accountCode);
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
|
||||
}
|
||||
}
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
@@ -108,30 +78,19 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
result.Type = reader.GetString(4);
|
||||
result.BasicType = reader.GetString(5);
|
||||
|
||||
if (whereClause)
|
||||
{
|
||||
if (cache.ContainsKey(result.AccountCodeId))
|
||||
{
|
||||
cache.Remove(result.AccountCodeId);
|
||||
}
|
||||
cache.Add(result.AccountCodeId, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dicCache.Add(result.AccountCodeId, result);
|
||||
}
|
||||
resultList.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
// update cache
|
||||
if (!whereClause)
|
||||
{
|
||||
cache.Clear();
|
||||
allRetrived = true;
|
||||
cache = dicCache;
|
||||
}
|
||||
}
|
||||
|
||||
private void Innit()
|
||||
{
|
||||
resultList = new List<Model.Account.AccountCode>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
113
src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs
Normal file
113
src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
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.Account
|
||||
{
|
||||
public class ReadInvoiceLineItem : Connection
|
||||
{
|
||||
public ReadInvoiceLineItem(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
Innit();
|
||||
}
|
||||
|
||||
public Dictionary<string, int> AccountCodeList { get; private set; }
|
||||
|
||||
public Dictionary<string, string> TaxCodeList { get; private set; }
|
||||
|
||||
private void Innit()
|
||||
{
|
||||
AccountCodeList = new Dictionary<string, int>();
|
||||
TaxCodeList = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public Model.Account.InvoiceLineItem ByItemCode(string itemCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemCode)) { return null; }
|
||||
|
||||
var result = ByItemCode(new List<string>{ itemCode });
|
||||
|
||||
if (!result.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result[itemCode];
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, Model.Account.InvoiceLineItem> ByItemCode(List<string> itemCodeList)
|
||||
{
|
||||
Innit();
|
||||
var resultList = new Dictionary<string, Model.Account.InvoiceLineItem>();
|
||||
|
||||
if (itemCodeList == null || !itemCodeList.Any())
|
||||
{ return resultList; }
|
||||
|
||||
string sql = @"
|
||||
SELECT tblAccountInvoiceLineItem.ItemCode
|
||||
,tblAccountInvoiceLineItem.ItemName
|
||||
,tblAccountInvoiceLineItem.ItemDescription
|
||||
,tblAccountInvoiceLineItem.IsNewReviewRequired
|
||||
,tblAccountInvoiceLineItem.InvoiceLineEntryEnable
|
||||
,tblAccountChartOf.AccountCode
|
||||
,tblAccountTaxCode.TaxCode
|
||||
FROM tblAccountInvoiceLineItem
|
||||
LEFT OUTER JOIN tblAccountTaxCode ON tblAccountInvoiceLineItem.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
|
||||
LEFT OUTER JOIN tblAccountChartOf ON tblAccountInvoiceLineItem.AccountChartOfID_Default = tblAccountChartOf.AccountChartOfID
|
||||
WHERE ";
|
||||
|
||||
var whereBuilder = new WhereBuilder();
|
||||
whereBuilder.In("tblAccountInvoiceLineItem.ItemCode", itemCodeList);
|
||||
sql += whereBuilder.SqlWhereString;
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
foreach (var param in whereBuilder.ParameterList)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(param.Key, param.Value);
|
||||
}
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var result = new Model.Account.InvoiceLineItem();
|
||||
|
||||
result.ItemCode = reader.GetString(0);
|
||||
result.Name = reader.GetString(1);
|
||||
if (!reader.IsDBNull(2)) { result.Description = reader.GetString(2); }
|
||||
result.IsNewReviewRequired = reader.GetBoolean(3);
|
||||
result.InvoiceLineEntryEnabled = reader.GetBoolean(4);
|
||||
|
||||
if (!reader.IsDBNull(5))
|
||||
{
|
||||
AccountCodeList.Add(result.ItemCode, reader.GetInt32(5));
|
||||
}
|
||||
if (!reader.IsDBNull(6))
|
||||
{
|
||||
TaxCodeList.Add(result.ItemCode, reader.GetString(6));
|
||||
}
|
||||
|
||||
resultList.Add(result.ItemCode, result);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
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.Account
|
||||
{
|
||||
public class ReadInvoiceLineItemCode : Connection
|
||||
{
|
||||
public ReadInvoiceLineItemCode(string sqlConnectionString) : base (sqlConnectionString)
|
||||
{
|
||||
cacheLineItemByTablePk = new Dictionary<int, Model.Account.InvoiceLineItem>();
|
||||
cacheTablePkByItemCode = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
private Dictionary<int, Model.Account.InvoiceLineItem> cacheLineItemByTablePk;
|
||||
private Dictionary<string, int> cacheTablePkByItemCode;
|
||||
|
||||
public bool InsertNewOnNoMatch { get; set; } = false;
|
||||
|
||||
public string NewTypeTitle { get; } = "NEW TYPE";
|
||||
|
||||
public void CacheClear()
|
||||
{
|
||||
cacheLineItemByTablePk.Clear();
|
||||
cacheTablePkByItemCode.Clear();
|
||||
}
|
||||
|
||||
private void CacheRemove(int tablePk)
|
||||
{
|
||||
if (cacheLineItemByTablePk.ContainsKey(tablePk))
|
||||
{
|
||||
string itemCode = cacheLineItemByTablePk[tablePk].ItemCode;
|
||||
cacheLineItemByTablePk.Remove(tablePk);
|
||||
cacheTablePkByItemCode.Remove(itemCode);
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheRemove(string itemCode)
|
||||
{
|
||||
if (cacheTablePkByItemCode.ContainsKey(itemCode))
|
||||
{
|
||||
CacheRemove(cacheTablePkByItemCode[itemCode]);
|
||||
}
|
||||
}
|
||||
|
||||
private void CacheUpdate(int tablePk, Model.Account.InvoiceLineItem lineItem)
|
||||
{
|
||||
if (cacheLineItemByTablePk.ContainsKey(tablePk))
|
||||
{
|
||||
CacheRemove(tablePk);
|
||||
}
|
||||
cacheLineItemByTablePk.Add(tablePk, lineItem);
|
||||
cacheTablePkByItemCode.Add(lineItem.ItemCode, tablePk);
|
||||
}
|
||||
|
||||
public Model.Account.InvoiceLineItem ByItemCode(string itemCode, bool forceCacheUpdate = false)
|
||||
{
|
||||
// check cache
|
||||
if (!forceCacheUpdate && cacheTablePkByItemCode.ContainsKey(itemCode))
|
||||
{
|
||||
return cacheLineItemByTablePk[cacheTablePkByItemCode[itemCode]];
|
||||
}
|
||||
|
||||
var returnObject = new Model.Account.InvoiceLineItem();
|
||||
returnObject.ItemCode = itemCode;
|
||||
|
||||
using (TransactionScope scopeSupress = new TransactionScope(TransactionScopeOption.Suppress))
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT tblExportAccountInvoiceLineType.ExportAccountInvoiceLineTypeID
|
||||
,tblExportAccountInvoiceLineType.TypeTitle
|
||||
,tblExportAccountInvoiceLineType.TypeDescription
|
||||
,tblExportAccountInvoiceLineType.IsNewReviewRequired
|
||||
,tblExportAccountInvoiceLineType.InvoiceLineEntryEnable
|
||||
,tblAccountChartOf.AccountCode
|
||||
,tblAccountTaxCode.TaxCode
|
||||
FROM (
|
||||
tblExportAccountInvoiceLineType LEFT JOIN tblAccountChartOf ON tblExportAccountInvoiceLineType.AccountChartOfID_Default = tblAccountChartOf.AccountChartOfID
|
||||
)
|
||||
LEFT JOIN tblAccountTaxCode ON tblExportAccountInvoiceLineType.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
|
||||
WHERE (((tblExportAccountInvoiceLineType.MatchString) = @matchString))
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@matchString", returnObject.ItemCode);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
int tablePk = reader.GetInt32(0);
|
||||
returnObject.Title = reader.GetString(1);
|
||||
if (!reader.IsDBNull(2)) { returnObject.Description = reader.GetString(2); }
|
||||
returnObject.IsNewReviewRequired = reader.GetBoolean(3);
|
||||
returnObject.InvoiceLineEntryEnabled = reader.GetBoolean(4);
|
||||
if (!reader.IsDBNull(5)) { returnObject.DefaultAccountCode = reader.GetInt32(5); }
|
||||
if (!reader.IsDBNull(6)) { returnObject.DefaultTaxCode = reader.GetString(6); }
|
||||
|
||||
// add to cache
|
||||
CacheUpdate(tablePk, returnObject);
|
||||
|
||||
// return object
|
||||
return returnObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// insert new and retrive new value, if required
|
||||
if (InsertNewOnNoMatch)
|
||||
{
|
||||
int tablePk = 0;
|
||||
returnObject.Title = NewTypeTitle;
|
||||
returnObject.ItemCode = itemCode;
|
||||
returnObject.IsNewReviewRequired = true;
|
||||
|
||||
using (SqlCommand insertCmd = new SqlCommand(@"
|
||||
INSERT INTO tblExportAccountInvoiceLineType ( TypeTitle, MatchString )
|
||||
OUTPUT INSERTED.ExportAccountInvoiceLineTypeID
|
||||
VALUES ( @typeTitle, @matchString )
|
||||
", conn))
|
||||
{
|
||||
insertCmd.Parameters.AddWithValue("@typeTitle", returnObject.Title);
|
||||
insertCmd.Parameters.AddWithValue("@matchString", returnObject.ItemCode);
|
||||
|
||||
tablePk = (int)insertCmd.ExecuteScalar();
|
||||
|
||||
scopeSupress.Complete();
|
||||
}
|
||||
// add to cache
|
||||
CacheUpdate(tablePk, returnObject);
|
||||
|
||||
// return object
|
||||
return returnObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,165 +9,32 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
{
|
||||
public class ReadTaxCode : Connection
|
||||
{
|
||||
private bool allRetrived;
|
||||
private Dictionary<string, Model.Account.TaxCode> cache;
|
||||
private Data.Database.WhereBuilder whereBuilder;
|
||||
|
||||
public ReadTaxCode(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
allRetrived = false;
|
||||
cache = new Dictionary<string, Model.Account.TaxCode>();
|
||||
whereBuilder = new WhereBuilder();
|
||||
}
|
||||
private void ClearCache()
|
||||
|
||||
private List<Model.Account.TaxCodeInfo> Execute(string sqlWhere, Dictionary<string, object> parameters)
|
||||
{
|
||||
allRetrived = false;
|
||||
cache.Clear();
|
||||
}
|
||||
public List<Model.Account.TaxCode> GetAll()
|
||||
{
|
||||
if (allRetrived == false)
|
||||
{
|
||||
UpdateCache(null);
|
||||
allRetrived = true;
|
||||
}
|
||||
var resultList = new List<Model.Account.TaxCodeInfo>();
|
||||
|
||||
var returnList = new List<Model.Account.TaxCode>();
|
||||
foreach (var item in cache)
|
||||
{
|
||||
returnList.Add(item.Value);
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
public Dictionary<string, Model.Account.TaxCode> BySkuNumber(List<string> skuNumberList)
|
||||
{
|
||||
// check input list for items
|
||||
if (skuNumberList == null || !skuNumberList.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// build SQL string
|
||||
string sqlString = @"
|
||||
SELECT
|
||||
tblSku.skuSkuNumber, tblAccountTaxCode.TaxCode
|
||||
FROM
|
||||
tblAccountTaxCode INNER JOIN tblSku ON tblAccountTaxCode.AccountTaxCodeID = tblSku.AccountTaxCodeID
|
||||
WHERE
|
||||
";
|
||||
|
||||
var parameterValueList = new List<Tuple<string, string>>();
|
||||
foreach (var item in skuNumberList)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(item))
|
||||
{
|
||||
int count = parameterValueList.Count;
|
||||
var parameterValue = new Tuple<string, string>("@parameter" + count, item);
|
||||
parameterValueList.Add(parameterValue);
|
||||
if (count == 0)
|
||||
{
|
||||
sqlString = sqlString + @"
|
||||
skuSkuNumber = " + parameterValue.Item1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlString = sqlString + @"
|
||||
OR skuSkuNumber = " + parameterValue.Item1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterValueList.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// execute query and build result list
|
||||
var skuTaxCodeList = new List<Tuple<string, string>>();
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
||||
{
|
||||
foreach (var item in parameterValueList)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(item.Item1, item.Item2);
|
||||
}
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
var skuTaxCode = new Tuple<string, string>(
|
||||
reader.GetString(0),
|
||||
reader.GetString(1)
|
||||
);
|
||||
skuTaxCodeList.Add(skuTaxCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// build dictionary of skuNumber to TaxCodeInfo
|
||||
var returnDictionary = new Dictionary<string, Model.Account.TaxCode>();
|
||||
foreach (var item in skuTaxCodeList)
|
||||
{
|
||||
returnDictionary.Add(item.Item1, GetByTaxCodeId(item.Item2));
|
||||
}
|
||||
|
||||
return returnDictionary;
|
||||
}
|
||||
}
|
||||
public Model.Account.TaxCode GetByTaxCodeId(string taxCode)
|
||||
{
|
||||
if (cache.ContainsKey(taxCode))
|
||||
{
|
||||
return cache[taxCode];
|
||||
}
|
||||
else if (allRetrived)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCache(taxCode);
|
||||
if (cache.ContainsKey(taxCode))
|
||||
{
|
||||
return cache[taxCode];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void UpdateCache(string taxCode)
|
||||
{
|
||||
var dicCache = new Dictionary<string, Model.Account.TaxCode>();
|
||||
|
||||
bool whereClause = false;
|
||||
//build sql query
|
||||
string sqlString = @"
|
||||
SELECT
|
||||
TaxCode
|
||||
,TaxRateName
|
||||
,TaxRateMultiplierNet
|
||||
,TaxRateMultiplierGross
|
||||
,TaxCodeName
|
||||
,TaxCodeDescription
|
||||
,TaxRatePercent
|
||||
,IsMarginScheme
|
||||
,IsValidOnExpense
|
||||
,IsVailidOnIncome
|
||||
,Description
|
||||
,IsActive
|
||||
,TaxType
|
||||
FROM tblAccountTaxCode";
|
||||
if (!string.IsNullOrWhiteSpace(taxCode))
|
||||
{
|
||||
whereClause = true;
|
||||
sqlString = sqlString + @"
|
||||
WHERE TaxCode = @taxCode";
|
||||
}
|
||||
|
||||
sqlString += sqlWhere;
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
@@ -175,9 +42,9 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
||||
{
|
||||
if (whereClause)
|
||||
foreach (var paramter in parameters)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@taxCode", taxCode);
|
||||
cmd.Parameters.AddWithValue(paramter.Key, paramter.Value);
|
||||
}
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
@@ -186,42 +53,160 @@ namespace bnhtrade.Core.Data.Database.Account
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var result = new Model.Account.TaxCode();
|
||||
string taxCodeId = reader.GetString(0);
|
||||
string name = reader.GetString(1);
|
||||
string description = null;
|
||||
if (!reader.IsDBNull(2)) { description = reader.GetString(2); }
|
||||
decimal rate = reader.GetDecimal(3);
|
||||
bool isMargin = reader.GetBoolean(4);
|
||||
bool isValidOnExpense = reader.GetBoolean(5);
|
||||
bool isValidOnIncome = reader.GetBoolean(6);
|
||||
bool isActive = reader.GetBoolean(7);
|
||||
string taxType = reader.GetString(8);
|
||||
|
||||
result.TaxCodeId = reader.GetString(0);
|
||||
result.TaxRateTitle = reader.GetString(1);
|
||||
result.NetAmountMultiplier = reader.GetDecimal(2);
|
||||
result.GrossAmountMultiplier = reader.GetDecimal(3);
|
||||
result.IsValidOnExpense = reader.GetBoolean(4);
|
||||
result.IsValidOnIncome = reader.GetBoolean(5);
|
||||
if (!reader.IsDBNull(6)) { result.TaxRateDescription = reader.GetString(6); }
|
||||
result.IsActive = reader.GetBoolean(7);
|
||||
result.TaxType = reader.GetString(8);
|
||||
var result = new Model.Account.TaxCodeInfo(
|
||||
taxCodeId,
|
||||
name,
|
||||
description,
|
||||
rate,
|
||||
isMargin,
|
||||
isValidOnExpense,
|
||||
isValidOnIncome,
|
||||
taxType,
|
||||
isActive);
|
||||
|
||||
if (whereClause)
|
||||
{
|
||||
if (cache.ContainsKey(result.TaxCodeId))
|
||||
{
|
||||
cache.Remove(result.TaxCodeId);
|
||||
}
|
||||
cache.Add(result.TaxCodeId, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dicCache.Add(result.TaxCodeId, result);
|
||||
}
|
||||
resultList.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// update cache
|
||||
if (!whereClause)
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public List<Model.Account.TaxCodeInfo> GetByTaxCode(List<string> taxcodeList)
|
||||
{
|
||||
var resultList = new List<Model.Account.TaxCodeInfo>();
|
||||
|
||||
if (taxcodeList == null || !taxcodeList.Any())
|
||||
{
|
||||
cache.Clear();
|
||||
allRetrived = true;
|
||||
cache = dicCache;
|
||||
return resultList;
|
||||
}
|
||||
|
||||
whereBuilder.Innit();
|
||||
whereBuilder.In("TaxCode", taxcodeList, "WHERE");
|
||||
|
||||
return Execute(whereBuilder.SqlWhereString, whereBuilder.ParameterList);
|
||||
}
|
||||
|
||||
public List<Model.Account.TaxCodeInfo> GetAllActive()
|
||||
{
|
||||
string sqlWhere = @"
|
||||
WHERE IsActive=@isActive;";
|
||||
var parameters = new Dictionary<string, object>();
|
||||
parameters.Add("@isActive", true);
|
||||
|
||||
return Execute(sqlWhere, parameters);
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetTaxCodeBySkuNumber(List<string> skuNumberList)
|
||||
{
|
||||
var resultList = new Dictionary<string, string>();
|
||||
|
||||
if (skuNumberList == null || !skuNumberList.Any())
|
||||
{
|
||||
return resultList;
|
||||
}
|
||||
|
||||
string sql = @"
|
||||
SELECT tblSku.skuSkuNumber
|
||||
,tblAccountTaxCode.TaxCode
|
||||
FROM tblSku
|
||||
INNER JOIN tblAccountTaxCode ON tblSku.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID ";
|
||||
|
||||
whereBuilder.Innit();
|
||||
whereBuilder.In("tblSku.skuSkuNumber", skuNumberList, "WHERE");
|
||||
|
||||
sql += whereBuilder.SqlWhereString;
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
foreach (var param in whereBuilder.ParameterList)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(param.Key, param.Value);
|
||||
}
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
return resultList;
|
||||
}
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
resultList.Add(reader.GetString(0), reader.GetString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetTaxCodeByInvoiceLineItemCode(List<string> lineItemCode)
|
||||
{
|
||||
var resultList = new Dictionary<string, string>();
|
||||
|
||||
if (lineItemCode == null || !lineItemCode.Any())
|
||||
{
|
||||
return resultList;
|
||||
}
|
||||
|
||||
string sql = @"
|
||||
SELECT tblAccountInvoiceLineItem.ItemCode
|
||||
,tblAccountTaxCode.TaxCode
|
||||
FROM tblAccountInvoiceLineItem
|
||||
LEFT OUTER JOIN tblAccountTaxCode ON tblAccountInvoiceLineItem.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
|
||||
";
|
||||
|
||||
whereBuilder.Innit();
|
||||
whereBuilder.In("tblAccountInvoiceLineItem.ItemCode", lineItemCode, "WHERE");
|
||||
|
||||
sql += whereBuilder.SqlWhereString;
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
foreach (var param in whereBuilder.ParameterList)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(param.Key, param.Value);
|
||||
}
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
return resultList;
|
||||
}
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.IsDBNull(1)) { resultList.Add(reader.GetString(0), null); }
|
||||
else { resultList.Add(reader.GetString(0), reader.GetString(1)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user