mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 22:47:15 +00:00
Export amazon settlement report fix
This commit is contained in:
77
src/bnhtrade.Core/Logic/Account/ValidateAccountCode.cs
Normal file
77
src/bnhtrade.Core/Logic/Account/ValidateAccountCode.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/bnhtrade.Core/Logic/Account/ValidateCurrencyCode.cs
Normal file
31
src/bnhtrade.Core/Logic/Account/ValidateCurrencyCode.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
267
src/bnhtrade.Core/Logic/Account/ValidateInvoice.cs
Normal file
267
src/bnhtrade.Core/Logic/Account/ValidateInvoice.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/bnhtrade.Core/Logic/Account/ValidateSalesInvoice.cs
Normal file
34
src/bnhtrade.Core/Logic/Account/ValidateSalesInvoice.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
145
src/bnhtrade.Core/Logic/Account/ValidateTaxCode.cs
Normal file
145
src/bnhtrade.Core/Logic/Account/ValidateTaxCode.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user