Files
bnhtrade/src/bnhtrade.Core/Logic/Account/GetTaxCodeInfo.cs
Bobbie Hodgetts 29f9fae508 Added invoice export function and started implementation of unitofwork pattern (#43)
* complete read invoices from db

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* updated nuget package spapi

* WIP

* wip, now test

* wip, jut need to fix tax inclusive line amounts not supported

* wip

* wip, before I f everything up

* no, it complies now, this is the one before I f everything up

* wip

* wip

* wip, logic ready for testing

* wip it builds!!!!

* wip tested, working, need to complete the gui section

* wip

* wip

* wip - created export invoice data delete, time for testing

* wip testing phase

* wip - delete function fully tested and working

* wip on to sorting out the issue with settlement invoices not tallying

* wip

* wip

* wip

* wip

* wip before I complete change the ReadInvoiceLineItem sections

* that appears to have worked, on with the main quest

* no it's doesn't work, saving before i remove the confusing cache system (just use a dictionary!!)

* wipping picadilli

* wip

* wip

* implemented uow on inovice export, now for testing

* wip

* wip all tested do invoice currency convertion fearure

* wip

* pretty much done so long as xero accepts the exported invoices

* Complete!
2025-06-26 23:29:22 +01:00

112 lines
3.2 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> 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=SkuNumber and value=TaxCodeInfo</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;
}
}
}