Files
bnhtrade/src/bnhtrade.Core/Logic/Account/GetTaxCodeInfo.cs
2024-04-11 12:26:13 +01:00

117 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class GetTaxCodeInfo
{
private Data.Database.Account.ReadTaxCode dbRead;
public GetTaxCodeInfo()
{
dbRead = new Data.Database.Account.ReadTaxCode();
}
public List<Model.Account.TaxCodeInfo> GetAllActive()
{
return dbRead.GetAllActive();
}
public List<Model.Account.TaxCodeInfo> GetByTaxCode(List<string> taxCodeList)
{
return dbRead.GetByTaxCode(taxCodeList);
}
public Model.Account.TaxCodeInfo GetByTaxCode(string taxCode)
{
var temp = GetByTaxCode(new List<string> { taxCode });
if (temp.Any())
{
return temp[0];
}
else
{
return null;
}
}
/// <summary>
/// Gets list of Tax Code Info for a given list of Sku Numbers
/// </summary>
/// <param name="skuNumberList">List of SKU numbers</param>
/// <returns>Dictionary, key is SkuNumber and value is Tax Code Info</returns>
public Dictionary<string, Model.Account.TaxCodeInfo> GetBySkuNumber(List<string> skuNumberList)
{
var returnList = new Dictionary<string, Model.Account.TaxCodeInfo>();
if (skuNumberList == null || !skuNumberList.Any())
{
return returnList;
}
// get db list
var dbList = dbRead.GetTaxCodeBySkuNumber(skuNumberList);
// build dictionary
foreach (var item in dbList)
{
var taxInfo = GetByTaxCode(item.Value);
if (taxInfo != null)
{
returnList.Add(item.Key, taxInfo);
}
}
return returnList;
}
public bool AddToSkuInfo(List<Model.Sku.Sku> skuList)
{
bool missionSuccess = true;
if (skuList == null || !skuList.Any())
{
return true;
}
// get list of sku numbers to condition codes
var lookupDictionary = GetBySkuNumber(skuList.Select(x => x.SkuNumber).ToList());
for (int i = 0; i < skuList.Count; i++)
{
if (lookupDictionary.ContainsKey(skuList[i].SkuNumber))
{
skuList[i].TaxCodeInfo = lookupDictionary[skuList[i].SkuNumber];
}
else
{
missionSuccess = false;
}
}
return missionSuccess;
}
public Dictionary<string, Model.Account.TaxCodeInfo> ConvertToDictionary(List<Model.Account.TaxCodeInfo> taxCodeList)
{
var returnDict = new Dictionary<string, Model.Account.TaxCodeInfo>();
if (taxCodeList == null)
{
return returnDict;
}
foreach (var taxCode in taxCodeList)
{
if (!returnDict.ContainsKey(taxCode.TaxCode))
{
returnDict.Add(taxCode.TaxCode, taxCode);
}
}
return returnDict;
}
}
}