Feature repricing min max (#10)

amazon settlement import/export improvements
This commit is contained in:
2020-05-01 09:08:23 +01:00
committed by GitHub
parent 56647c7648
commit 43d61c2ef8
118 changed files with 7930 additions and 3021 deletions

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class GetAccountCodeInfo
{
private string sqlConnectionString;
private Data.Database.Account.ReadAccountCode readAccountCode;
private Dictionary<int, Model.Account.AccountCode> cache;
public GetAccountCodeInfo(string sqlConnectionString)
{
this.sqlConnectionString = sqlConnectionString;
readAccountCode = new Data.Database.Account.ReadAccountCode(sqlConnectionString);
cache = new Dictionary<int, Model.Account.AccountCode>();
}
public void CacheClear()
{
cache.Clear();
}
public void CacheFill()
{
CacheClear();
var resultList = readAccountCode.All();
foreach (var result in resultList)
{
cache.Add(result.AccountCodeId, result);
}
}
public void CacheFill(List<int> accountCodeList, bool forceDbRead = false)
{
if (accountCodeList == null || !accountCodeList.Any())
{
return;
}
var accountCodeQueryList = new List<int>();
foreach (var code in accountCodeList.Distinct().ToList())
{
if (forceDbRead)
{
cache.Remove(code);
accountCodeQueryList.Add(code);
}
else if (!cache.ContainsKey(code))
{
accountCodeQueryList.Add(code);
}
}
// get db list
var dbList = readAccountCode.ByAccountCode(accountCodeQueryList);
// add to cache
foreach (var item in dbList)
{
cache.Add(item.AccountCodeId, item);
}
}
public Model.Account.AccountCode ByAccountCode(int accountCode, bool forceDbRead = false)
{
CacheFill(new List<int> { accountCode }, forceDbRead);
if (cache.ContainsKey(accountCode))
{
return cache[accountCode];
}
else
{
return null;
}
}
}
}

View File

@@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class GetInvoiceLineItem
{
string sqlConnectionString;
private Dictionary<string, Model.Account.InvoiceLineItem> cache;
private Data.Database.Account.ReadInvoiceLineItem dbRead;
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
private Logic.Account.GetTaxCodeInfo getTaxCode;
private Logic.Account.GetAccountCodeInfo getAccountCode;
public GetInvoiceLineItem(string sqlConnectionString)
{
this.sqlConnectionString = sqlConnectionString;
CacheInnit();
dbRead = new Data.Database.Account.ReadInvoiceLineItem(sqlConnectionString);
getAccountCode = new GetAccountCodeInfo(sqlConnectionString);
getTaxCode = new GetTaxCodeInfo(sqlConnectionString);
}
/// <summary>
/// Create new 'default' line item code when a requested item code is not found.
/// </summary>
public bool InsertNewOnNoMatch { get; set; } = false;
public void CacheInnit()
{
cache = new Dictionary<string, Model.Account.InvoiceLineItem>();
}
/// <summary>
/// Prefill cache in one SQL call, saves multiple SQL calls.
/// </summary>
/// <param name="itemCodeList">List of item codes to lookup from database</param>
/// <param name="forceDbRead">Forces a database read (does not read cache)</param>
public void CacheFill(List<string> itemCodeList, bool forceDbRead = false)
{
if (itemCodeList == null || !itemCodeList.Any())
{
return;
}
var itemCodeQueryList = new List<string>();
foreach (var itemCode in itemCodeList)
{
if (forceDbRead)
{
cache.Remove(itemCode);
itemCodeQueryList.Add(itemCode);
}
else if (!cache.ContainsKey(itemCode))
{
itemCodeQueryList.Add(itemCode);
}
}
// query database
var resultList = dbRead.ByItemCode(itemCodeQueryList);
// fill account & tax codes cache
getAccountCode.CacheFill(dbRead.AccountCodeList.Values.ToList(), forceDbRead);
getTaxCode.CacheFill(dbRead.TaxCodeList.Values.ToList(), forceDbRead);
// build final itemcode object and add to cache
foreach (var result in resultList.Values)
{
if (dbRead.AccountCodeList.ContainsKey(result.ItemCode))
{
result.DefaultAccountCode = getAccountCode.ByAccountCode(dbRead.AccountCodeList[result.ItemCode]);
}
if (dbRead.TaxCodeList.ContainsKey(result.ItemCode))
{
result.DefaultTaxCode = getTaxCode.GetByTaxCode(dbRead.TaxCodeList[result.ItemCode]);
}
cache.Add(result.ItemCode, result);
}
}
/// <summary>
/// Creates new 'default' item code entry. The item code and title are set the same and will require updating.
/// </summary>
/// <param name="itemCode">Item code string</param>
/// <returns></returns>
public Model.Account.InvoiceLineItem CreateDefault(string itemCode)
{
new Data.Database.Account.CreateInvoiceLineItem(sqlConnectionString).CreateDefault(itemCode);
var item = dbRead.ByItemCode(itemCode);
cache.Add(item.ItemCode, item);
return item;
}
public Model.Account.InvoiceLineItem ByItemCode(string itemCode, bool forceDbRead = false)
{
if (string.IsNullOrWhiteSpace(itemCode))
{
return null;
}
CacheFill(new List<string> { itemCode }, forceDbRead);
Model.Account.InvoiceLineItem item = null;
if (cache.ContainsKey(itemCode))
{
item = cache[itemCode];
// check title
if (!item.IsNewReviewRequired && item.Name == item.ItemCode)
{
throw new Exception
("ItemCode found with the incomplete title. Update title and then try again.");
}
return item;
}
if (!InsertNewOnNoMatch)
{
return null;
}
else
{
return CreateDefault(itemCode);
}
}
/// <summary>
/// Tests if ItemCode has Invoice line entry enabled
/// </summary>
/// <param name="itemCode">Item code</param>
/// <param name="forceDbRead">Forces a database read (does not read cache)</param>
/// <returns></returns>
public bool InvoiceLineEntryEnabled(string itemCode, bool forceDbRead = false)
{
var item = ByItemCode(itemCode, forceDbRead);
if (item == null)
throw new Exception("Invalid item code");
return item.InvoiceLineEntryEnabled;
}
/// <summary>
/// Tests if ItemCode is new (default) and a review id required
/// </summary>
/// <param name="itemCode">Item code</param>
/// <param name="forceDbRead">Forces a database read (does not read cache)</param>
/// <returns></returns>
public bool IsNewReviewRequired(string itemCode, bool forceDbRead = false)
{
var item = ByItemCode(itemCode, forceDbRead);
if (item == null)
{
throw new Exception("Invalid item code");
}
return item.IsNewReviewRequired;
}
}
}

View 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();
}
}
}

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class TaxCalculation
{
public decimal GetGrossAmount(decimal netAmount, decimal taxPercent)
{
return netAmount * (1 + (taxPercent / 100));
}
public decimal GetGrossAmount(decimal netAmount, Model.Account.TaxCodeInfo taxCodeInfo)
{
return GetGrossAmount(netAmount, taxCodeInfo.TaxRate);
}
public decimal GetNetAmount(decimal grossAmount, decimal taxPercent)
{
return grossAmount / (1 + (taxPercent / 100));
}
public decimal GetNetAmount(decimal grossAmount, Model.Account.TaxCodeInfo taxCodeInfo)
{
return GetNetAmount(grossAmount, taxCodeInfo.TaxRate);
}
public decimal GetTaxAmount(decimal amount, bool amountIsTaxInclusive, decimal taxPercent)
{
if (amountIsTaxInclusive)
{
return amount - GetNetAmount(amount, taxPercent);
}
else
{
return amount * (taxPercent / 100);
}
}
public decimal GetTaxAmount(decimal amount, bool amountIsTaxInclusive, Model.Account.TaxCodeInfo taxCodeInfo)
{
return GetTaxAmount(amount, amountIsTaxInclusive, taxCodeInfo.TaxRate);
}
public decimal GetMarginTaxRate(DateTime transactionDate)
{
decimal vatRate = 0;
if (transactionDate >= new DateTime(2011, 01, 04))
{
vatRate = 20;
}
else
{
// more coding required
throw new Exception("Transaction is outside the current margin scheme date scope");
}
return vatRate;
}
public decimal GetMarginTaxAmount(decimal marginAmount, DateTime transactionDate)
{
decimal vatRate = GetMarginTaxRate(transactionDate);
return GetTaxAmount(marginAmount, true, vatRate);
}
public decimal GetMarginTaxAmount(decimal purchasePrice, decimal salePrice, DateTime transactionDate)
{
return GetMarginTaxAmount(salePrice - purchasePrice, transactionDate);
}
/// <summary>
/// Returns a value to multiply margin (sale - purchase price) by to find margin scheme tax amount
/// </summary>
/// <param name="transactionDate">Date of transaction</param>
/// <returns>Value between 0 and 1</returns>
public decimal GetMarginMultiplier(DateTime transactionDate)
{
decimal vatRate = GetMarginTaxRate(transactionDate);
return vatRate / (vatRate + 100);
}
}
}

View File

@@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class ValidateAccountCode : Validate
{
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
public new void Innit()
{
base.Innit();
stringCheck = new Logic.Utilities.StringCheck();
}
public bool IsValidAccountCodeId(int accountCode)
{
if (accountCode >=0)
{ return true; }
else
{
ErrorListAdd("Invalid account code.");
return false;
}
}
public bool IsValidTitle(string title)
{
if (stringCheck.MaxLength(title, 150))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList);
return false;
}
}
public bool IsValidDescription(string description)
{
if (stringCheck.MaxLength(description, 500))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList);
return false;
}
}
public bool IsValidType(string type)
{
if (stringCheck.MaxLength(type, 50))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList);
return false;
}
}
public bool IsValidBasicType(string basicType)
{
if (stringCheck.MaxLength(basicType, 50))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList);
return false;
}
}
}
}

View File

@@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class ValidateCurrencyCode : Validate
{
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
public new void Innit()
{
base.Innit();
stringCheck = new Logic.Utilities.StringCheck();
}
public bool IsValidCurrencyCode(string currencyCode)
{
if (stringCheck.Length(currencyCode, 3) && stringCheck.IsAlpha(currencyCode, true))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList);
return false;
}
}
}
}

View File

@@ -1,267 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public abstract class ValidateInvoice : Validate
{
protected Account.ValidateAccountCode validateAccountCode = new Account.ValidateAccountCode();
protected Account.ValidateCurrencyCode validateCurrencyCode = new Account.ValidateCurrencyCode();
protected Account.ValidateTaxCode validateTaxCode = new ValidateTaxCode();
protected Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
public bool InvoiceNumberIsRequired { get; set; } = true;
public bool InvoiceLineDescriptionIsRequired { get; set; } = true;
public new void Innit()
{
base.Innit();
validateAccountCode.Innit();
validateCurrencyCode.Innit();
validateTaxCode.Innit();
stringCheck.Innit();
}
protected bool IsValidInvoice(Model.Account.IInvoice invoice)
{
return IsValidInvoice(new List<Model.Account.IInvoice> { invoice });
}
protected bool IsValidInvoice(List<Model.Account.IInvoice> invoiceList)
{
Innit();
if (invoiceList == null || !invoiceList.Any())
{
ErrorListAdd("Invoice list is null or empty.");
return false;
}
var tempErrorList = new List<string>();
for (int i = 0; i < invoiceList.Count(); i++)
{
Innit();
// check header info
if (invoiceList[i].ContactNameIsSet) { IsValidInvoiceContact(invoiceList[i].ContactName); }
else { ErrorListAdd("'Contact Name' is a required value"); }
if (invoiceList[i].InvoiceAmountIsSet)
{
if (!invoiceList[i].IsCreditNoteIsSet)
{ ErrorListAdd("'Is Credit Note' is a required value"); }
else
{
if (invoiceList[i].IsCreditNote && invoiceList[i].InvoiceAmount > 0)
{ ErrorListAdd("Credit Note amount cannot be greater than zero"); }
else if (!invoiceList[i].IsCreditNote && invoiceList[i].InvoiceAmount < 0)
{ ErrorListAdd("Invoice amount cannot be less than zero"); }
}
}
else { ErrorListAdd("'Invoice Amount' is a required value"); }
if (invoiceList[i].InvoiceCurrencyCodeIsSet) { IsValidInvoiceCurrency(invoiceList[i].InvoiceCurrencyCode); }
else { ErrorListAdd("'Invoice Currency Code' is a required value"); }
if (invoiceList[i].InvoiceDateIsSet) { IsValidInvoiceDate(invoiceList[i].InvoiceDate); }
else { ErrorListAdd("'Invoice Date' is a required value"); }
if (!invoiceList[i].InvoiceDateKindIsSet) { ErrorListAdd("'Invoice Date Kind' is a required value"); }
if (invoiceList[i].InvoiceDueDateIsSet) { IsValidInvoiceDueDate(invoiceList[i].InvoiceDueDate); }
if (invoiceList[i].InvoiceNumberIsSet)
{ IsValidInvoiceNumber(invoiceList[i].InvoiceNumber); }
else
{
if (InvoiceNumberIsRequired) { ErrorListAdd("'Invoice Number' is a required value"); }
}
if (invoiceList[i].InvoiceReferenceIsSet) { IsValidInvoiceReference(invoiceList[i].InvoiceReference); }
else { ErrorListAdd("'Invoice Reference' is a required value"); }
if (!invoiceList[i].IsCreditNoteIsSet) { ErrorListAdd("'Invoice Reference' is a required value"); }
// loop though lines and check and sum totals
if (!invoiceList[i].InvoiceLineListIsSet)
{ ErrorListAdd("Invoice is required to have lines."); }
else
{
decimal lineTotal = 0;
for (int j = 0; j < invoiceList[i].InvoiceLineList.Count(); j++)
{
if (!invoiceList[i].InvoiceLineList[j].AccountCodeIsSet) { ErrorListAdd("Line 'Account Code' is a required value"); }
else { IsValidInvoiceLineAccount(invoiceList[i].InvoiceLineList[j].AccountCode); }
if (!invoiceList[i].InvoiceLineList[j].DescriptionIsSet)
{
if (InvoiceLineDescriptionIsRequired) { ErrorListAdd("Line 'Description' is a required value"); }
}
else { IsValidInvoiceLineDescription(invoiceList[i].InvoiceLineList[j].Description); }
if (!invoiceList[i].InvoiceLineList[j].GrossTotalAmountIsSet) { ErrorListAdd("Line 'Gross Total Amount' is a required value"); }
if (!invoiceList[i].InvoiceLineList[j].ItemCodeIsSet) { ErrorListAdd("Line 'Item Code' is a required value"); }
else { IsValidLineItemCode(invoiceList[i].InvoiceLineList[j].ItemCode); }
if (!invoiceList[i].InvoiceLineList[j].QuantityIsSet) { ErrorListAdd("Line 'Quantity' is a required value"); }
if (!invoiceList[i].InvoiceLineList[j].TaxAmountIsSet) { ErrorListAdd("Line 'Tax Amount' is a required value"); }
if (!invoiceList[i].InvoiceLineList[j].TaxCodeIsSet) { ErrorListAdd("Line 'Tax Code' is a required value"); }
else { IsValidLineTaxCode(invoiceList[i].InvoiceLineList[j].TaxCode); }
if (!invoiceList[i].InvoiceLineList[j].TotalNetAmountIsSet) { ErrorListAdd("Line 'Total Net Amount' is a required value"); }
if ((invoiceList[i].InvoiceLineList[j].TaxAmount
+ invoiceList[i].InvoiceLineList[j].TaxAmountAdjust
+ invoiceList[i].InvoiceLineList[j].TotalNetAmount) != invoiceList[i].InvoiceLineList[j].GrossTotalAmount)
{ ErrorListAdd("Incorrect invoice line total (gross) amount."); }
lineTotal = lineTotal + invoiceList[i].InvoiceLineList[j].GrossTotalAmount;
}
// check totals
if (invoiceList[i].InvoiceAmountIsSet && (invoiceList[i].InvoiceAmount != lineTotal))
{ ErrorListAdd("Invoice line total does not match invoice total amount."); }
}
tempErrorList.AddRange(ErrorList.Select(x => "[Inv" + i + "] " + x).ToList());
}
Innit();
ErrorListAdd(tempErrorList);
if (ErrorListIsSet) { return false; }
else { return true; }
}
protected bool IsValidInvoiceLineAccount(int accountCode)
{
validateAccountCode.Innit();
if (!validateAccountCode.IsValidAccountCodeId(accountCode))
{
ErrorListAdd(validateAccountCode.ErrorList.Select(x => "Invalid invoice line account code: " + x).ToList());
return false;
}
else
{ return true; }
}
protected bool IsValidInvoiceLineDescription(string lineDescription)
{
int maxLength = 150;
stringCheck.Innit();
if (!stringCheck.MaxLength(lineDescription, maxLength))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid invoice line description: " + x).ToList());
return false;
}
return true;
}
protected bool IsValidInvoiceContact(string contactName)
{
int maxlength = 150;
stringCheck.Innit();
if (!stringCheck.MaxLength(contactName, maxlength))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid invoice nontact name: " + x).ToList());
return false;
}
return true;
}
protected bool IsValidInvoiceDate(DateTime invoiceDate)
{
if (invoiceDate.Kind != DateTimeKind.Utc)
{
ErrorListAdd(@"Invalid date/time, UTC kind required.");
return false;
}
else if (invoiceDate == default(DateTime))
{
ErrorListAdd("Date and time is default value.");
return false;
}
return true;
}
protected bool IsValidInvoiceDueDate(DateTime invoiceDueDate)
{
if (invoiceDueDate.Kind != DateTimeKind.Utc)
{
ErrorListAdd(@"Invalid date/time, UTC kind required.");
return false;
}
else if (invoiceDueDate == default(DateTime))
{
ErrorListAdd("Date and time is default value.");
return false;
}
return true;
}
protected bool IsValidInvoiceCurrency(string currencyCode)
{
validateCurrencyCode.Innit();
if (!validateCurrencyCode.IsValidCurrencyCode(currencyCode))
{
ErrorListAdd(validateCurrencyCode.ErrorList.Select(x => "Invalid invoice currency code: " + x).ToList());
return false;
}
else { return true; }
}
protected bool IsValidInvoiceNumber(string invoiceNumber)
{
int maxlength = 64;
stringCheck.Innit();
if (!stringCheck.MaxLength(invoiceNumber, maxlength))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid invoice number: " + x).ToList());
return false;
}
return true;
}
protected bool IsValidInvoiceReference(string invoiceReference)
{
int maxlength = 50;
stringCheck.Innit();
if (!stringCheck.MaxLength(invoiceReference, maxlength))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid invoice reference: " + x).ToList());
return false;
}
return true;
}
protected bool IsValidLineItemCode(string itemCode)
{
int maxlength = 250;
stringCheck.Innit();
if (!stringCheck.MaxLength(itemCode, maxlength))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid invoice line item code: " + x).ToList());
return false;
}
return true;
}
protected bool IsValidLineTaxCode(string taxCode)
{
validateTaxCode.Innit();
if (validateTaxCode.IsValidTaxCodeId(taxCode))
{ return true; }
else
{
ErrorListAdd(validateTaxCode.ErrorList.Select(x => "Invalid invoice line " + x).ToList());
return false;
}
}
}
}

View File

@@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class ValidateSalesInvoice : ValidateInvoice
{
public ValidateSalesInvoice()
{
int propertyCount = new Model.Account.SalesInvoice().GetType().GetProperties().Count();
if (propertyCount != 20)
{ throw new Exception("Model.Account.SalesInvoice property count has altered. Validate class requires an update."); }
propertyCount = new Model.Account.SalesInvoice.InvoiceLine().GetType().GetProperties().Count();
if (propertyCount != 18)
{ throw new Exception("Model.Account.SalesInvoice property count has altered. Validate class requires an update."); }
}
public bool IsValidInvoice(Model.Account.SalesInvoice invoice)
{
return IsValidInvoice(new List<Model.Account.SalesInvoice> { invoice });
}
public bool IsValidInvoice(List<Model.Account.SalesInvoice> invoiceList)
{
var interfaceList = invoiceList.Cast<Model.Account.IInvoice>().ToList();
return IsValidInvoice(interfaceList);
}
}
}

View File

@@ -1,145 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Logic.Account
{
public class ValidateTaxCode : Validate
{
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
public new void Innit()
{
base.Innit();
stringCheck.Innit();
}
public bool IsValidGrossAmountMultiplier(decimal multiplier)
{
if (multiplier >= 0 && multiplier <= 1)
{
return true;
}
else
{
ErrorListAdd( "Gross multiplier must be equal to, or between, 0 and 1.");
return false;
}
}
public bool IsValidNetAmountMultiplier(decimal multiplier)
{
if (multiplier >= 0 && multiplier <= 1)
{
return true;
}
else
{
ErrorListAdd("Net multiplier must not be less than 0 or greater than 1.");
return false;
}
}
public bool IsValidOnExpense(Model.Account.TaxCode taxInfo)
{
if (taxInfo.IsValidOnExpense || taxInfo.IsSetIsValidOnIncome)
{
if (taxInfo.IsSetIsValidOnExpense)
{
return true;
}
else
{
ErrorListAdd("Is Valid On Expense has not been set.");
return false;
}
}
else
{
ErrorListAdd("Either 'IsValidOnExpense' or 'IsSetIsValidOnSale' must be set to true.");
return false;
}
}
public bool IsValidOnIncome(Model.Account.TaxCode taxInfo)
{
if (taxInfo.IsValidOnExpense || taxInfo.IsSetIsValidOnIncome)
{
if (taxInfo.IsSetIsValidOnIncome)
{
return true;
}
else
{
ErrorListAdd("Is Valid On Income has not been set.");
return false;
}
}
else
{
ErrorListAdd("Either 'IsValidOnPurchase' or 'IsSetIsValidOnSale' must be set to true.");
return false;
}
}
public bool IsValidTaxCodeId(string taxCodeId)
{
if (!stringCheck.IsAlphaNumeric(taxCodeId, true))
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid Tax Code: " + x).ToList());
return false;
}
if (taxCodeId.Length != 4)
{
ErrorListAdd("Invalid Tax Code: Length does not equal 4 charaters.");
return false;
}
return true;
}
public bool IsValidTaxRateDescription(string description)
{
if (stringCheck.MaxLength(description, 250, true))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid Tax Rate Description: " + x).ToList());
return false;
}
}
public bool IsValidTaxRateTitle(string title)
{
if (stringCheck.MaxLength(title, 50, false))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid Tax Rate Title: " + x).ToList());
return false;
}
}
public bool IsValidTaxRateTitleShort(string title)
{
if (stringCheck.MaxLength(title, 50, false))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid Tax Rate Title Short: " + x).ToList());
return false;
}
}
public bool IsValidTaxType(string taxType)
{
if (stringCheck.MaxLength(taxType, 50, false))
{
return true;
}
else
{
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid Tax Rate Type: " + x).ToList());
return false;
}
}
}
}