mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 23:37:16 +00:00
500 lines
16 KiB
C#
500 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core.Logic.Import
|
|
{
|
|
public class ValidateAmazonSettlement : Validate
|
|
{
|
|
protected Utilities.StringCheck stringCheck = new Utilities.StringCheck();
|
|
protected Utilities.DateTimeCheck timeCheck = new Utilities.DateTimeCheck();
|
|
protected Account.ValidateCurrencyCode currencyCheck = new Account.ValidateCurrencyCode();
|
|
protected Utilities.DecimalCheck decimalCheck = new Utilities.DecimalCheck();
|
|
|
|
public ValidateAmazonSettlement() : base()
|
|
{
|
|
|
|
}
|
|
|
|
public bool ValidateMarketPlaceName { get; set; } = true;
|
|
|
|
public new void Innit()
|
|
{
|
|
base.Innit();
|
|
timeCheck.Innit();
|
|
stringCheck.Innit();
|
|
currencyCheck.Innit();
|
|
decimalCheck.Innit();
|
|
}
|
|
|
|
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) { ErrorListAdd("CurrencyCode is a required value."); }
|
|
else { IsValidCurrencyCode(settlementList[i].CurrencyCode); }
|
|
|
|
if (!settlementList[i].DepositDateIsSet) { ErrorListAdd("DepositDate is a required value."); }
|
|
else { IsValidDepositDate(settlementList[i].DepositDate); }
|
|
|
|
if (!settlementList[i].EndDateIsSet) { ErrorListAdd("EndDate is a required value."); }
|
|
else { IsValidEndDate(settlementList[i].EndDate); }
|
|
|
|
if (!settlementList[i].IsProcessedIsSet) { ErrorListAdd("IsProcessed is a required value."); }
|
|
else { IsValidIsProcessed(settlementList[i].IsProcessed); }
|
|
|
|
if (!settlementList[i].MarketPlaceNameIsSet)
|
|
{
|
|
if (ValidateMarketPlaceName) { ErrorListAdd("MarketPlaceName is a required value."); }
|
|
}
|
|
else { IsValidMarketPlaceName(settlementList[i].MarketPlaceName); }
|
|
|
|
if (!settlementList[i].SettlementIdIsSet) { ErrorListAdd("SettlementId is a required value."); }
|
|
else { IsValidSettlementId(settlementList[i].SettlementId); }
|
|
|
|
if (!settlementList[i].StartDateIsSet) { ErrorListAdd("StartDate is a required value."); }
|
|
else { IsValidStartDate(settlementList[i].StartDate); }
|
|
|
|
if (!settlementList[i].TotalAmountIsSet) { ErrorListAdd("TotalAmount is a required value."); }
|
|
else { IsValidTotalAmount(settlementList[i].TotalAmount); }
|
|
|
|
|
|
// check line list
|
|
if (!settlementList[i].SettlementLineListIsSet)
|
|
{
|
|
ErrorListAdd("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)
|
|
{
|
|
ErrorListAdd("Settlement header total (" + settlementList[i].TotalAmount +
|
|
") does not match line total (" + lineSum + ")");
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ErrorListIsSet) { return false; }
|
|
else { return true; }
|
|
}
|
|
|
|
public bool IsValid(Model.Import.AmazonSettlement.SettlementLine settlementLine)
|
|
{
|
|
if (settlementLine.AdjustmentIdIsSet)
|
|
{
|
|
if (!IsValidAdjustmentId(settlementLine.AdjustmentId)) { }
|
|
}
|
|
|
|
if (settlementLine.AmountIsSet)
|
|
{
|
|
if (!IsValidAmount(settlementLine.Amount)) { }
|
|
}
|
|
else
|
|
{
|
|
ErrorListAdd("Amount is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.AmountDescriptionIsSet)
|
|
{
|
|
if (!IsValidAmountDescription(settlementLine.AmountDescription)) { }
|
|
}
|
|
else
|
|
{
|
|
ErrorListAdd("Amount Description is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.AmountTypeIsSet)
|
|
{
|
|
if (!IsValidAmountType(settlementLine.AmountType)) { }
|
|
}
|
|
else
|
|
{
|
|
ErrorListAdd("Amount Type is a required value.");
|
|
}
|
|
|
|
|
|
if (settlementLine.CurrenyCodeIsSet)
|
|
{
|
|
if (!IsValidCurrenyCode(settlementLine.CurrenyCode)) { }
|
|
}
|
|
else
|
|
{
|
|
ErrorListAdd("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
|
|
{
|
|
ErrorListAdd("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
|
|
{
|
|
ErrorListAdd("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
|
|
{
|
|
ErrorListAdd("Transaction Type is a required value.");
|
|
}
|
|
|
|
if (ErrorListIsSet) { return false; }
|
|
else { return true; }
|
|
}
|
|
|
|
public bool IsValidSettlementId(string settlementId)
|
|
{
|
|
if (!stringCheck.IsNumeric(settlementId))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid settlement Id: " + x).ToList());
|
|
return false;
|
|
}
|
|
if (!stringCheck.MaxLength(settlementId, 50))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.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))
|
|
{
|
|
ErrorListAdd("Invalid market place name.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidStartDate(DateTime startDate)
|
|
{
|
|
if (!timeCheck.IsUtc(startDate))
|
|
{
|
|
ErrorListAdd(timeCheck.ErrorList.Select(x => "Invalid StartDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidEndDate(DateTime endDate)
|
|
{
|
|
if (!timeCheck.IsUtc(endDate))
|
|
{
|
|
ErrorListAdd(timeCheck.ErrorList.Select(x => "Invalid EndDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidDepositDate(DateTime depositDate)
|
|
{
|
|
if (!timeCheck.IsUtc(depositDate))
|
|
{
|
|
ErrorListAdd(timeCheck.ErrorList.Select(x => "Invalid DepositDate: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidTotalAmount(decimal totalAmount)
|
|
{
|
|
if (!decimalCheck.SqlLength92(totalAmount))
|
|
{
|
|
ErrorListAdd(decimalCheck.ErrorList.Select(x => "Total Amount Invalid: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsValidCurrencyCode(string currencyCode)
|
|
{
|
|
if (!currencyCheck.IsValidCurrencyCode(currencyCode))
|
|
{
|
|
ErrorListAdd(currencyCheck.ErrorList.Select(x => "Total Amount CurrencyCode: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsValidTransactionType(string transactionType)
|
|
{
|
|
if (!stringCheck.MaxLength(transactionType, 50))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid transaction type: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidOrderId(string orderId)
|
|
{
|
|
if (!stringCheck.MaxLength(orderId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid order id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantOrderId(string merchantOrderId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantOrderId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid merchant order id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAdjustmentId(string adjustmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(adjustmentId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid adjustment id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidShipmentId(string shipmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(shipmentId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid shipment id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmountType(string amountType)
|
|
{
|
|
if (!stringCheck.MaxLength(amountType, 50))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid amount type: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmountDescription(string amountDescription)
|
|
{
|
|
if (!stringCheck.MaxLength(amountDescription, 100))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid amount description: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidAmount(decimal amount)
|
|
{
|
|
if (!decimalCheck.SqlLength92(amount))
|
|
{
|
|
ErrorListAdd(decimalCheck.ErrorList.Select(x => "Invalid amount: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidCurrenyCode(string currenyCode)
|
|
{
|
|
if (!currencyCheck.IsValidCurrencyCode(currenyCode))
|
|
{
|
|
ErrorListAdd(currencyCheck.ErrorList.Select(x => "Invalid curreny code: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidFulfillmentId(string fulfillmentId)
|
|
{
|
|
if (!stringCheck.MaxLength(fulfillmentId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.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))
|
|
{
|
|
ErrorListAdd(@"Invalid post date/time, not set to UTC kind.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidOrderItemCode(string orderItemCode)
|
|
{
|
|
if (!stringCheck.MaxLength(orderItemCode, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid order item code: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantOrderItemId(string merchantOrderItemId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantOrderItemId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid merchant order item id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidMerchantAdjustmentItemId(string merchantAdjustmentItemId)
|
|
{
|
|
if (!stringCheck.MaxLength(merchantAdjustmentItemId, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid merchant adjustment item id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidSku(string skuNumber)
|
|
{
|
|
if (!stringCheck.MaxLength(skuNumber, 50, true))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.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))
|
|
{
|
|
ErrorListAdd(stringCheck.ErrorList.Select(x => "Invalid promotion id: " + x).ToList());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsValidExportAccountInvoiceLineId(int exportAccountInvoiceLineId)
|
|
{
|
|
if (exportAccountInvoiceLineId > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ErrorListAdd("Export account invoice line id cannot be less than 1");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|