mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
141
src/bnhtrade.Core/Logic/Account/GetTaxCodeInfo.cs
Normal file
141
src/bnhtrade.Core/Logic/Account/GetTaxCodeInfo.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Account
|
||||
{
|
||||
public class GetTaxCodeInfo
|
||||
{
|
||||
string sqlConnectionString;
|
||||
private bool allRetrived;
|
||||
private Dictionary<string, Model.Account.TaxCodeInfo> cache;
|
||||
private Dictionary<string, Model.Account.TaxCodeInfo> cacheInvoiceItem;
|
||||
private Data.Database.Account.ReadTaxCode dbRead;
|
||||
|
||||
public GetTaxCodeInfo(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
allRetrived = false;
|
||||
CacheClear();
|
||||
dbRead = new Data.Database.Account.ReadTaxCode(sqlConnectionString);
|
||||
}
|
||||
|
||||
private void CacheClear()
|
||||
{
|
||||
cache = new Dictionary<string, Model.Account.TaxCodeInfo>();
|
||||
cacheInvoiceItem = new Dictionary<string, Model.Account.TaxCodeInfo>();
|
||||
}
|
||||
|
||||
public void CacheFill()
|
||||
{
|
||||
CacheClear();
|
||||
|
||||
var list = dbRead.GetAllActive();
|
||||
foreach (var item in list)
|
||||
{
|
||||
cache.Add(item.TaxCode, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheFill(List<string> taxCodeList, bool forceDbRead = false)
|
||||
{
|
||||
if (taxCodeList == null || !taxCodeList.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var taxCodeQueryList = new List<string>();
|
||||
foreach (var code in taxCodeList.Distinct().ToList())
|
||||
{
|
||||
if (forceDbRead)
|
||||
{
|
||||
cache.Remove(code);
|
||||
taxCodeQueryList.Add(code);
|
||||
}
|
||||
else if (!cache.ContainsKey(code))
|
||||
{
|
||||
taxCodeQueryList.Add(code);
|
||||
}
|
||||
}
|
||||
|
||||
// get db list
|
||||
var dbList = dbRead.GetByTaxCode(taxCodeQueryList);
|
||||
|
||||
// add to cache
|
||||
foreach (var item in dbList)
|
||||
{
|
||||
cache.Add(item.TaxCode, item);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Model.Account.TaxCodeInfo> GetAllActive()
|
||||
{
|
||||
CacheFill();
|
||||
return cache.Values.ToList();
|
||||
}
|
||||
|
||||
public Model.Account.TaxCodeInfo GetByTaxCode(string taxCode, bool forceDbRead = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(taxCode))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
CacheFill(new List<string> { taxCode }, forceDbRead);
|
||||
|
||||
if (cache.ContainsKey(taxCode))
|
||||
{
|
||||
return cache[taxCode];
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// remove any duplicates
|
||||
var cleanSkuList = skuNumberList.Distinct().ToList();
|
||||
|
||||
// get db list
|
||||
var dbList = dbRead.GetTaxCodeBySkuNumber(skuNumberList);
|
||||
|
||||
if (!dbList.Any()) { return returnList; }
|
||||
|
||||
// charge the cache
|
||||
dbRead.GetAllActive();
|
||||
|
||||
// build dictionary
|
||||
foreach (var item in dbList)
|
||||
{
|
||||
var taxInfo = GetByTaxCode(item.Value);
|
||||
if (taxInfo != null)
|
||||
{
|
||||
returnList.Add(item.Key, taxInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public Dictionary<string, Model.Account.TaxCodeInfo> Get(List<Model.Account.InvoiceLineItem> invoiceLineList)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user