mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
29f9fae508
* 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!
482 lines
17 KiB
C#
482 lines
17 KiB
C#
using bnhtrade.Core.Model.Amazon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core.Logic.Validate
|
|
{
|
|
public class AmazonSettlement : Validate
|
|
{
|
|
protected Utilities.StringCheck stringCheck = new Utilities.StringCheck();
|
|
protected Utilities.DateTimeCheck timeCheck = new Utilities.DateTimeCheck();
|
|
protected Logic.Validate.CurrencyCode currencyCheck = new Logic.Validate.CurrencyCode();
|
|
protected Utilities.DecimalCheck decimalCheck = new Utilities.DecimalCheck();
|
|
|
|
public AmazonSettlement() : base()
|
|
{
|
|
|
|
}
|
|
|
|
public bool ValidateMarketPlaceName { get; set; } = true;
|
|
|
|
public new void Innit()
|
|
{
|
|
base.Init();
|
|
timeCheck.Init();
|
|
stringCheck.Init();
|
|
currencyCheck.Innit();
|
|
decimalCheck.Init();
|
|
}
|
|
|
|
public bool IsValid(Model.Import.AmazonSettlement settlement)
|
|
{
|
|
return IsValid(new List<Model.Import.AmazonSettlement> { settlement });
|
|
}
|
|
|
|
public bool IsValid(List<Model.Import.AmazonSettlement> settlementList)
|
|
{
|
|
Innit();
|
|
|
|
for (int i = 0; i < settlementList.Count; i++)
|
|
{
|
|
if (!settlementList[i].CurrencyCodeIsSet) { ValidationResultAdd("CurrencyCode is a required value."); }
|
|
else { IsValidCurrencyCode(settlementList[i].CurrencyCode); }
|
|
|
|
if (!settlementList[i].DepositDateIsSet) { ValidationResultAdd("DepositDate is a required value."); }
|
|
else { IsValidDepositDate(settlementList[i].DepositDate); }
|
|
|
|
if (!settlementList[i].EndDateIsSet) { ValidationResultAdd("EndDate is a required value."); }
|
|
else { IsValidEndDate(settlementList[i].EndDate); }
|
|
|
|
if (!settlementList[i].IsProcessedIsSet) { ValidationResultAdd("IsProcessed is a required value."); }
|
|
else { IsValidIsProcessed(settlementList[i].IsProcessed); }
|
|
|
|
if (!settlementList[i].MarketPlaceNameIsSet)
|
|
{
|
|
if (ValidateMarketPlaceName) { ValidationResultAdd("MarketPlaceName is a required value."); }
|
|
}
|
|
else { IsValidMarketPlaceName(settlementList[i].MarketPlace.GetMarketplaceUrl()); }
|
|
|
|
if (!settlementList[i].SettlementIdIsSet) { ValidationResultAdd("SettlementId is a required value."); }
|
|
else { IsValidSettlementId(settlementList[i].SettlementId); }
|
|
|
|
if (!settlementList[i].StartDateIsSet) { ValidationResultAdd("StartDate is a required value."); }
|
|
else { IsValidStartDate(settlementList[i].StartDate); }
|
|
|
|
if (!settlementList[i].TotalAmountIsSet) { ValidationResultAdd("TotalAmount is a required value."); }
|
|
else { IsValidTotalAmount(settlementList[i].TotalAmount); }
|
|
|
|
|
|
// check line list
|
|
if (!settlementList[i].SettlementLineListIsSet)
|
|
{
|
|
ValidationResultAdd("Settlement line list is null or empty");
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
// loop though lines and check
|
|
decimal lineSum = 0;
|
|
for (int j = 0; j < settlementList[i].SettlementLineList.Count(); j++)
|
|
{
|
|
IsValid(settlementList[i].SettlementLineList[j]);
|
|
if (settlementList[i].SettlementLineList[j].AmountIsSet)
|
|
{ lineSum += settlementList[i].SettlementLineList[j].Amount; }
|
|
}
|
|
|
|
// check totals
|
|
if (lineSum != settlementList[i].TotalAmount)
|
|
{
|
|
ValidationResultAdd("Settlement header total (" + settlementList[i].TotalAmount +
|
|
") does not match line total (" + lineSum + ")");
|
|
}
|
|
}
|
|
}
|
|
|
|
return IsValidResult;
|
|
}
|
|
|
|
public bool IsValid(Model.Import.AmazonSettlement.SettlementLine settlementLine)
|
|
{
|
|
if (settlementLine.AdjustmentIdIsSet)
|
|
{
|
|
if (!IsValidAdjustmentId(settlementLine.AdjustmentId)) { }
|
|
}
|
|
|
|
if (settlementLine.AmountIsSet)
|
|
{
|
|
if (!IsValidAmount(settlementLine.Amount)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Amount is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.AmountDescriptionIsSet)
|
|
{
|
|
if (!IsValidAmountDescription(settlementLine.AmountDescription)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Amount Description is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.AmountTypeIsSet)
|
|
{
|
|
if (!IsValidAmountType(settlementLine.AmountType)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Amount Type is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.CurrenyCodeIsSet)
|
|
{
|
|
if (!IsValidCurrenyCode(settlementLine.CurrenyCode)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Currency Code is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.ExportAccountInvoiceLineIdIsSet)
|
|
{
|
|
if (!IsValidExportAccountInvoiceLineId(settlementLine.ExportAccountInvoiceLineId)) { }
|
|
}
|
|
|
|
if (settlementLine.FulfillmentIdIsSet)
|
|
{
|
|
if (!IsValidFulfillmentId(settlementLine.FulfillmentId)) { }
|
|
}
|
|
|
|
if (settlementLine.IsProcessedIsSet)
|
|
{
|
|
if (!IsValidIsProcessed(settlementLine.IsProcessed)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Is Processed is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.MarketPlaceNameIsSet)
|
|
{
|
|
if (!IsValidMarketPlaceName(settlementLine.MarketPlaceName)) { }
|
|
}
|
|
|
|
if (settlementLine.MerchantAdjustmentItemIdIsSet)
|
|
{
|
|
if (!IsValidMerchantAdjustmentItemId(settlementLine.MerchantAdjustmentItemId)) { }
|
|
}
|
|
|
|
if (settlementLine.MerchantOrderIdIsSet)
|
|
{
|
|
if (!IsValidMerchantOrderId(settlementLine.MerchantOrderId)) { }
|
|
}
|
|
|
|
if (settlementLine.MerchantOrderItemIdIsSet)
|
|
{
|
|
if (!IsValidMerchantOrderItemId(settlementLine.MerchantOrderItemId)) { }
|
|
}
|
|
|
|
if (settlementLine.OrderIdIsSet)
|
|
{
|
|
if (!IsValidOrderId(settlementLine.OrderId)) { }
|
|
}
|
|
|
|
if (settlementLine.OrderItemCodeIsSet)
|
|
{
|
|
if (!IsValidOrderItemCode(settlementLine.OrderItemCode)) { }
|
|
}
|
|
|
|
if (settlementLine.PostDateTimeIsSet)
|
|
{
|
|
if (!IsValidPostDateTime(settlementLine.PostDateTime)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Posted DateTime is a required value.");
|
|
}
|
|
|
|
if (settlementLine.PromotionIdIsSet)
|
|
{
|
|
if (!IsValidPromotionId(settlementLine.PromotionId)) { }
|
|
}
|
|
|
|
if (settlementLine.QuantityPurchasedIsSet)
|
|
{
|
|
if (!IsValidQuantityPurchased(settlementLine.QuantityPurchased)) { }
|
|
}
|
|
|
|
if (settlementLine.ShipmentIdIsSet)
|
|
{
|
|
if (!IsValidShipmentId(settlementLine.ShipmentId)) { }
|
|
}
|
|
|
|
if (settlementLine.SkuIsSet)
|
|
{
|
|
if (!IsValidSku(settlementLine.Sku)) { }
|
|
}
|
|
|
|
if (settlementLine.TransactionTypeIsSet)
|
|
{
|
|
if (!IsValidTransactionType(settlementLine.TransactionType)) { }
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Transaction Type is a required value.");
|
|
}
|
|
|
|
return IsValidResult;
|
|
}
|
|
|
|
public bool IsValidSettlementId(string settlementId)
|
|
{
|
|
if (!stringCheck.IsNumeric(settlementId))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid settlement Id: " + x).ToList());
|
|
return false;
|
|
}
|
|
if (!stringCheck.MaxLength(settlementId, 50))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid settlement Id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidIsProcessed(bool isProcessed)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidMarketPlaceName(string marketPlaceName)
|
|
{
|
|
if (!stringCheck.MaxLength(marketPlaceName, 50, true))
|
|
{
|
|
ValidationResultAdd("Invalid market place name.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidStartDate(DateTime startDate)
|
|
{
|
|
if (!timeCheck.IsUtc(startDate))
|
|
{
|
|
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid StartDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidEndDate(DateTime endDate)
|
|
{
|
|
if (!timeCheck.IsUtc(endDate))
|
|
{
|
|
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid EndDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidDepositDate(DateTime depositDate)
|
|
{
|
|
if (!timeCheck.IsUtc(depositDate))
|
|
{
|
|
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid DepositDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidTotalAmount(decimal totalAmount)
|
|
{
|
|
if (!decimalCheck.SqlLength92(totalAmount))
|
|
{
|
|
ValidationResultAdd(decimalCheck.ValidationResult.Select(x => "Total Amount Invalid: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidCurrencyCode(string currencyCode)
|
|
{
|
|
if (!currencyCheck.IsValidCurrencyCode(currencyCode))
|
|
{
|
|
ValidationResultAdd(currencyCheck.ValidationResult.Select(x => "Total Amount CurrencyCode: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidTransactionType(string transactionType)
|
|
{
|
|
if (!stringCheck.MaxLength(transactionType, 50))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid transaction type: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidOrderId(string orderId)
|
|
{
|
|
if (!stringCheck.MaxLength(orderId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid order id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantOrderId(string merchantOrderId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantOrderId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant order id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAdjustmentId(string adjustmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(adjustmentId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid adjustment id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidShipmentId(string shipmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(shipmentId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid shipment id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmountType(string amountType)
|
|
{
|
|
if (!stringCheck.MaxLength(amountType, 50))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid amount type: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmountDescription(string amountDescription)
|
|
{
|
|
if (!stringCheck.MaxLength(amountDescription, 100))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid amount description: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmount(decimal amount)
|
|
{
|
|
if (!decimalCheck.SqlLength92(amount))
|
|
{
|
|
ValidationResultAdd(decimalCheck.ValidationResult.Select(x => "Invalid amount: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidCurrenyCode(string currenyCode)
|
|
{
|
|
if (!currencyCheck.IsValidCurrencyCode(currenyCode))
|
|
{
|
|
ValidationResultAdd(currencyCheck.ValidationResult.Select(x => "Invalid curreny code: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidFulfillmentId(string fulfillmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(fulfillmentId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid fulfillment Id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidPostDateTime(DateTime postDateTime)
|
|
{
|
|
var timeCheck = new Logic.Utilities.DateTimeCheck();
|
|
if (!timeCheck.IsUtc(postDateTime))
|
|
{
|
|
ValidationResultAdd(@"Invalid post date/time, not set to UTC kind.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidOrderItemCode(string orderItemCode)
|
|
{
|
|
if (!stringCheck.MaxLength(orderItemCode, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid order item code: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantOrderItemId(string merchantOrderItemId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantOrderItemId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant order item id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantAdjustmentItemId(string merchantAdjustmentItemId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantAdjustmentItemId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant adjustment item id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidSku(string skuNumber)
|
|
{
|
|
if (!stringCheck.MaxLength(skuNumber, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid sku number: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidQuantityPurchased(int quantityPurchased)
|
|
{
|
|
return true;
|
|
}
|
|
public bool IsValidPromotionId(string promotionId)
|
|
{
|
|
if (!stringCheck.MaxLength(promotionId, 50, true))
|
|
{
|
|
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid promotion id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidExportAccountInvoiceLineId(int exportAccountInvoiceLineId)
|
|
{
|
|
if (exportAccountInvoiceLineId > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ValidationResultAdd("Export account invoice line id cannot be less than 1");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|