mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 09:07:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -11,7 +11,8 @@ namespace bnhtrade.Core.Logic.Export
|
||||
public class AmazonSettlement
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private Dictionary<string, Model.Account.TaxCode> taxCodeBySkuNumer;
|
||||
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
|
||||
private List<string> lineItemCodeList = new List<string>();
|
||||
|
||||
public AmazonSettlement(string sqlConnectionString)
|
||||
{
|
||||
@@ -21,12 +22,11 @@ namespace bnhtrade.Core.Logic.Export
|
||||
public void ToInvoice()
|
||||
{
|
||||
var console = new UI.Console.Update();
|
||||
var log = new Logic.Log.LogEvent();
|
||||
log.LogInformation("Starting processing of Amazon settlement data into export invoice table...");
|
||||
|
||||
// check settlement reports consistancy
|
||||
var consistencyCheck = new Data.Database.Consistency.ImportAmazonSettlement(sqlConnectionString).PeriodDateGaps();
|
||||
if (consistencyCheck == false )
|
||||
if (consistencyCheck == false)
|
||||
{ return; }
|
||||
|
||||
// get list of unprocssed settlement reports to export
|
||||
@@ -65,38 +65,34 @@ namespace bnhtrade.Core.Logic.Export
|
||||
}
|
||||
|
||||
// validate settlelments
|
||||
var validate = new Logic.Import.ValidateAmazonSettlement();
|
||||
var validate = new Logic.Validate.AmazonSettlement();
|
||||
for (int i = 0; i < settlementList.Count(); i++)
|
||||
{
|
||||
if (!validate.IsValid(settlementList[i]))
|
||||
{
|
||||
log.LogError("Error procesing Amazon Settlement data for export.", validate.ErrorListToString());
|
||||
log.LogError("Error procesing Amazon Settlement data for export.", validate.ValidationResultListToString());
|
||||
}
|
||||
}
|
||||
if (validate.ErrorListIsSet) { return; }
|
||||
if (validate.IsValidResult == false) { return; }
|
||||
|
||||
// get dictionary of sku-number to taxcodeId
|
||||
Console.Write("\rBuilding SKU list... ");
|
||||
var dicSkuNumberToTaxCodeId = new Dictionary<string, string>();
|
||||
for (int i = 0; i < settlementList.Count(); i++)
|
||||
var skuList = new List<string>();
|
||||
foreach (var settlement in settlementList)
|
||||
{
|
||||
if (settlementList[i].SettlementLineListIsSet)
|
||||
if (settlement.SettlementLineListIsSet)
|
||||
{
|
||||
for (int j = 0; j < settlementList[i].SettlementLineList.Count(); j++)
|
||||
foreach (var line in settlement.SettlementLineList)
|
||||
{
|
||||
if (settlementList[i].SettlementLineList[j].SkuIsSet
|
||||
&& !string.IsNullOrWhiteSpace(settlementList[i].SettlementLineList[j].Sku))
|
||||
if (line.SkuIsSet
|
||||
&& !string.IsNullOrWhiteSpace(line.Sku))
|
||||
{
|
||||
if (!dicSkuNumberToTaxCodeId.ContainsKey(settlementList[i].SettlementLineList[j].Sku))
|
||||
{
|
||||
dicSkuNumberToTaxCodeId.Add(settlementList[i].SettlementLineList[j].Sku, null);
|
||||
}
|
||||
skuList.Add(line.Sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var readTaxCode = new Data.Database.Account.ReadTaxCode(sqlConnectionString);
|
||||
taxCodeBySkuNumer = readTaxCode.BySkuNumber(dicSkuNumberToTaxCodeId.Keys.ToList());
|
||||
var taxCodeBySkuNumer = new Logic.Account.GetTaxCodeInfo(sqlConnectionString).GetBySkuNumber(skuList);
|
||||
|
||||
// loop through each settlement and build list of invoices to export
|
||||
Console.Write("\rBuilding invoices to export... ");
|
||||
@@ -117,7 +113,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
var itemCodeTotal = new Dictionary<string, decimal>();
|
||||
foreach (var line in month)
|
||||
{
|
||||
string itemCode = BuildLineItemCode(line.Sku, line.TransactionType, line.AmountType, line.AmountDescription);
|
||||
string itemCode = BuildLineItemCode(taxCodeBySkuNumer, line.Sku, line.TransactionType, line.AmountType, line.AmountDescription);
|
||||
if (itemCodeTotal.ContainsKey(itemCode))
|
||||
{
|
||||
itemCodeTotal[itemCode] += line.Amount;
|
||||
@@ -137,13 +133,12 @@ namespace bnhtrade.Core.Logic.Export
|
||||
decimal lineTaxTotal = 0m;
|
||||
foreach (var item in itemCodeTotal)
|
||||
{
|
||||
var line = new Model.Account.SalesInvoice.InvoiceLine();
|
||||
var line = new Model.Account.SalesInvoice.InvoiceLine(invoice.UnitAmountIsTaxExclusive);
|
||||
line.ItemCode = item.Key;
|
||||
line.TotalNetAmount = item.Value;
|
||||
lineNetTotal += item.Value;
|
||||
line.TaxAmount = 0;
|
||||
lineTaxTotal += 0;
|
||||
line.Quantity = 1;
|
||||
line.UnitAmount = item.Value;
|
||||
lineNetTotal += item.Value;
|
||||
lineTaxTotal += 0;
|
||||
invoice.InvoiceLineList.Add(line);
|
||||
}
|
||||
|
||||
@@ -153,11 +148,10 @@ namespace bnhtrade.Core.Logic.Export
|
||||
{ invoice.InvoiceDate = settlementList[i].EndDate; }
|
||||
else
|
||||
{ invoice.InvoiceDate = new DateTime(month.Key.Year, month.Key.Month, 1, 0, 0, 0, DateTimeKind.Utc).AddMonths(1).AddDays(-1); }
|
||||
invoice.InvoiceDateKind = DateTimeKind.Utc;
|
||||
invoice.InvoiceDueDate = settlementList[i].DepositDate;
|
||||
invoice.InvoiceReference = settlementList[i].SettlementId;
|
||||
invoice.InvoiceAmount = lineNetTotal + lineTaxTotal;
|
||||
if (invoice.InvoiceAmount < 0) { invoice.IsCreditNote = true; }
|
||||
invoice.InvoiceTotalAmount = lineNetTotal + lineTaxTotal;
|
||||
if (invoice.InvoiceTotalAmount < 0) { invoice.IsCreditNote = true; }
|
||||
else { invoice.IsCreditNote = false; }
|
||||
|
||||
// invoice complete, add to list
|
||||
@@ -174,11 +168,11 @@ namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
if (invoiceTotal.ContainsKey(invoiceList[i].InvoiceReference))
|
||||
{
|
||||
invoiceTotal[invoiceList[i].InvoiceReference] += invoiceList[i].InvoiceAmount;
|
||||
invoiceTotal[invoiceList[i].InvoiceReference] += invoiceList[i].InvoiceTotalAmount.GetValueOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
invoiceTotal.Add(invoiceList[i].InvoiceReference, invoiceList[i].InvoiceAmount);
|
||||
invoiceTotal.Add(invoiceList[i].InvoiceReference, invoiceList[i].InvoiceTotalAmount.GetValueOrDefault());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < settlementList.Count(); i++)
|
||||
@@ -194,8 +188,65 @@ namespace bnhtrade.Core.Logic.Export
|
||||
return;
|
||||
}
|
||||
|
||||
// postfix invoices spanning multiple months with -n
|
||||
if (invoiceList.Count() > 1)
|
||||
// add invoice item code data to lines
|
||||
// also clean invoices of any disabled lines (remove lines and possibly invoices)
|
||||
var getLineItemInfo = new Logic.Account.GetInvoiceLineItem(sqlConnectionString);
|
||||
getLineItemInfo.InsertNewOnNoMatch = true;
|
||||
getLineItemInfo.CacheFill(lineItemCodeList);
|
||||
bool newTypeFound = false;
|
||||
|
||||
for (int i = 0; i < invoiceList.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < invoiceList[i].InvoiceLineList.Count(); j++)
|
||||
{
|
||||
var itemCode = getLineItemInfo.ByItemCode(invoiceList[i].InvoiceLineList[j].ItemCode);
|
||||
// error! itemCode should never be null
|
||||
if (itemCode == null)
|
||||
{
|
||||
throw new Exception("Item code is null");
|
||||
}
|
||||
// flag new type and throw exception further on
|
||||
else if (itemCode.IsNewReviewRequired)
|
||||
{
|
||||
newTypeFound = true;
|
||||
}
|
||||
// clean invoices of any disabled lines (remove lines and possibly invoices)
|
||||
else if (itemCode.InvoiceLineEntryEnabled == false)
|
||||
{
|
||||
// remove line
|
||||
invoiceList[i].InvoiceTotalAmount = invoiceList[i].InvoiceTotalAmount - invoiceList[i].InvoiceLineList[j].LineTotalAmount;
|
||||
invoiceList[i].InvoiceLineList.RemoveAt(j);
|
||||
j = j - 1;
|
||||
|
||||
// remove invoice?
|
||||
if (invoiceList[i].InvoiceLineList.Count == 0)
|
||||
{
|
||||
invoiceList.RemoveAt(i);
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
// get here add info to lines
|
||||
else
|
||||
{
|
||||
invoiceList[i].InvoiceLineList[j].AccountCode = itemCode.DefaultAccountCode;
|
||||
invoiceList[i].InvoiceLineList[j].Description = itemCode.Name;
|
||||
invoiceList[i].InvoiceLineList[j].ItemCode = itemCode.ItemCode;
|
||||
invoiceList[i].InvoiceLineList[j].TaxCode = itemCode.DefaultTaxCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newTypeFound)
|
||||
{
|
||||
if (newTypeFound)
|
||||
{
|
||||
throw new Exception("New line ItemCode found. Add item code default values and then try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// postfix invoices references that span multiple months with -n
|
||||
if (invoiceList.Count > 1)
|
||||
{
|
||||
string lastRef = invoiceList[0].InvoiceReference;
|
||||
int countRef = 1;
|
||||
@@ -215,7 +266,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
if (countRef > 2)
|
||||
{
|
||||
log.LogError(
|
||||
countRef + " total numner of export invoices created from Amazon Settlement Id" + lastRef + "."
|
||||
countRef + " invoices where created from Amazon Settlement Id" + lastRef + "."
|
||||
, "Settlement period appears to span more 3 months or more. Whilst this is possible, it is unsual. Confirm his is correct.");
|
||||
}
|
||||
|
||||
@@ -230,8 +281,12 @@ namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
try
|
||||
{
|
||||
var saveInv = new Logic.Export.SalesInvoice(sqlConnectionString);
|
||||
// add temp invoice numbers
|
||||
saveInv.AddTempInvoiceNumber(invoiceList, true);
|
||||
|
||||
// write to the database (gets validated there)
|
||||
new Data.Database.Export.CreateSalesInvoice(sqlConnectionString).SaveInvoice(invoiceList);
|
||||
saveInv.SaveSalesInvoice(invoiceList);
|
||||
|
||||
// set settlements to isprocessed
|
||||
new Data.Database.Import.UpdateAmazonSettlement(sqlConnectionString).SetIsProcessedTrue(settlementIdList);
|
||||
@@ -241,15 +296,16 @@ namespace bnhtrade.Core.Logic.Export
|
||||
catch (Exception ex)
|
||||
{
|
||||
scope.Dispose();
|
||||
log.LogError(ex.Message);
|
||||
log.LogError("Exeception caught while writing Amazon settlement invoices to DB. Changes were rolled back."
|
||||
, ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Console.Write("\r");
|
||||
log.LogInformation("\rFinished processing of Amazon settlement data. " + invoiceList.Count() + " invoices created from "+ settlementIdList.Count() + " Amazon settlement reports.");
|
||||
log.LogInformation("\rFinished processing of Amazon settlement data. " + invoiceList.Count() + " invoices created from " + settlementIdList.Count() + " Amazon settlement reports.");
|
||||
}
|
||||
|
||||
private string BuildLineItemCode(string skuNumber, string transactionType, string amountType, string amountDescription)
|
||||
private string BuildLineItemCode(Dictionary<string, Model.Account.TaxCodeInfo> taxCodeBySkuNumer, string skuNumber, string transactionType, string amountType, string amountDescription)
|
||||
{
|
||||
// build the match string
|
||||
// NB special case for global accounting sale and refunds (also note Goodlwill is included) and sku's where tax is included
|
||||
@@ -264,13 +320,18 @@ namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
if (taxCodeBySkuNumer.ContainsKey(skuNumber))
|
||||
{
|
||||
matchString = matchString + "<TaxCode=" + taxCodeBySkuNumer[skuNumber].TaxCodeId + ">";
|
||||
matchString = matchString + "<TaxCode=" + taxCodeBySkuNumer[skuNumber].TaxCode + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Sku#" + skuNumber + " tax info not found in dictionary list.");
|
||||
}
|
||||
}
|
||||
|
||||
// add to list of generated line item codes
|
||||
lineItemCodeList.Add(matchString);
|
||||
|
||||
// return value
|
||||
return matchString;
|
||||
}
|
||||
}
|
||||
|
||||
124
src/bnhtrade.Core/Logic/Export/AmazonSubmitFile.cs
Normal file
124
src/bnhtrade.Core/Logic/Export/AmazonSubmitFile.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
public class AmazonSubmitFile
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
|
||||
private Log.LogEvent log = new Log.LogEvent();
|
||||
|
||||
public AmazonSubmitFile(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
}
|
||||
|
||||
public void SubmitInventoryLoader(MemoryStream stream)
|
||||
{
|
||||
Model.Export.AmazonFeedSubmission result;
|
||||
int queueId = QueueInventoryLoader(stream, out result);
|
||||
SubmitQueuedFeedSubmission(queueId, result);
|
||||
}
|
||||
|
||||
public void SubmitInventoryLoader(MemoryStream stream, out Model.Export.AmazonFeedSubmission result)
|
||||
{
|
||||
int queueId = QueueInventoryLoader(stream, out result);
|
||||
SubmitQueuedFeedSubmission(queueId, result);
|
||||
}
|
||||
|
||||
public int QueueInventoryLoader(MemoryStream stream)
|
||||
{
|
||||
Model.Export.AmazonFeedSubmission result;
|
||||
return QueueFeedSubbmission("_POST_FLAT_FILE_INVLOADER_DATA_", "txt", stream, out result);
|
||||
}
|
||||
|
||||
public int QueueInventoryLoader(MemoryStream stream, out Model.Export.AmazonFeedSubmission result)
|
||||
{
|
||||
// write file database
|
||||
return QueueFeedSubbmission("_POST_FLAT_FILE_INVLOADER_DATA_", "txt", stream, out result);
|
||||
}
|
||||
|
||||
private int QueueFeedSubbmission(string feedType, string fileExtention, MemoryStream stream, out Model.Export.AmazonFeedSubmission result)
|
||||
{
|
||||
// construct file object
|
||||
var fileInfo = new Model.Data.DatabaseFileStream();
|
||||
fileInfo.FileExtention = fileExtention;
|
||||
fileInfo.FileData = stream;
|
||||
fileInfo.FileMD5base64 = new Logic.Utilities.CalculateMD5().Base64(stream);
|
||||
|
||||
long longSize = stream.Length;
|
||||
if (longSize > 2147483647)
|
||||
throw new Exception("File size over 2.15 GB");
|
||||
fileInfo.FileSize = (int)longSize;
|
||||
|
||||
// save to database
|
||||
int queueId = 0;
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
queueId = new Data.Database.Export.CreateAmazonFeedSubmission(sqlConnectionString).Execute(feedType, fileInfo);
|
||||
|
||||
// validate the result
|
||||
var validateResults = new List<ValidationResult>();
|
||||
|
||||
bool isValid = Validator.TryValidateObject(
|
||||
fileInfo,
|
||||
new ValidationContext(fileInfo, null, null),
|
||||
validateResults);
|
||||
|
||||
if (isValid == false)
|
||||
{
|
||||
string error = "Create Database Amazon Feed Submission cancelled. Object validation failed.";
|
||||
new Log.LogEvent().LogError(error, string.Join(Environment.NewLine, validateResults));
|
||||
scope.Dispose();
|
||||
throw new Exception(error);
|
||||
}
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// create feed object
|
||||
result = new Model.Export.AmazonFeedSubmission();
|
||||
result.FeedType = feedType;
|
||||
result.File = fileInfo;
|
||||
|
||||
return queueId;
|
||||
}
|
||||
|
||||
// private, only to be used where you're sure feedSubmission matches DB and you don't want to call info from DB (large file)
|
||||
private void SubmitQueuedFeedSubmission(int queueId, Model.Export.AmazonFeedSubmission feedSubmission)
|
||||
{
|
||||
// upload to mws
|
||||
var feedSubmitt = new Data.AmazonMWS.Feeds.SubmitFeed(feedSubmission);
|
||||
|
||||
if (!feedSubmitt.FeedSubmissionRecived)
|
||||
{
|
||||
// failed do something here
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// set the amazon feed Id
|
||||
var dbUpdate = new Data.Database.Export.UpdateAmazonFeedSubmission(sqlConnectionString);
|
||||
dbUpdate.AddAmazonFeedId(queueId, feedSubmission.FeedSubmissionId);
|
||||
|
||||
// update progress info
|
||||
dbUpdate.UpdateStatusInfo(feedSubmission);
|
||||
}
|
||||
|
||||
private void SubmitQueuedFeedSubmission(int queueId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void SubmitQueuedFeedSubmission()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
src/bnhtrade.Core/Logic/Export/AmazonSubmitFileStatus.cs
Normal file
59
src/bnhtrade.Core/Logic/Export/AmazonSubmitFileStatus.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
public class AmazonSubmitFileStatus
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private bnhtrade.Core.Logic.Log.LogEvent log = new Log.LogEvent();
|
||||
|
||||
public AmazonSubmitFileStatus(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
}
|
||||
|
||||
public void UpdateStatusInfo()
|
||||
{
|
||||
var openList = new Data.Database.Export.ReadAmazonFeedSubmission(sqlConnectionString).GetOpenFeeds();
|
||||
if (openList.Count == 0)
|
||||
return;
|
||||
|
||||
var getStatus = new Data.AmazonMWS.Feeds.GetFeedSubmissions();
|
||||
getStatus.FeedSubmissionIdList = openList.Select(x => x.FeedSubmissionId).ToList();
|
||||
var currentStatus = getStatus.Invoke();
|
||||
|
||||
for (int i = 0; i < openList.Count; i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (int j = 0; j < currentStatus.Count; j++)
|
||||
{
|
||||
if (openList[i].FeedSubmissionId == currentStatus[j].FeedSubmissionId)
|
||||
{
|
||||
found = true;
|
||||
|
||||
openList[i].FeedProcessingStatus = currentStatus[j].FeedProcessingStatus;
|
||||
if (currentStatus[j].IsSetCompletedProcessingDate())
|
||||
openList[i].CompletedProcessingDate = currentStatus[j].CompletedProcessingDate;
|
||||
if (currentStatus[j].IsSetStartedProcessingDate())
|
||||
openList[i].StartedProcessingDate = currentStatus[j].StartedProcessingDate;
|
||||
if (currentStatus[j].IsSetSubmittedDate())
|
||||
openList[i].SubmittedDate = DateTime.Parse(currentStatus[j].SubmittedDate);
|
||||
}
|
||||
}
|
||||
if (found == false)
|
||||
{
|
||||
log.LogError("FeedSubmissionId '" + openList[i].FeedSubmissionId + "' exists in database but was not returned by Amazon MWS when queried.");
|
||||
openList.RemoveAt(i);
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// update the database
|
||||
new Data.Database.Export.UpdateAmazonFeedSubmission(sqlConnectionString).UpdateStatusInfo(openList);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/bnhtrade.Core/Logic/Export/SalesInvoice.cs
Normal file
53
src/bnhtrade.Core/Logic/Export/SalesInvoice.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
public class SalesInvoice
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private Logic.Log.LogEvent log = new Log.LogEvent();
|
||||
|
||||
public SalesInvoice(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
}
|
||||
|
||||
public string GetNextTempInvoiceNumber()
|
||||
{
|
||||
var sequence = new Data.Database.Programmability.Sequence(sqlConnectionString);
|
||||
return "_tmp" + sequence.GetNext("ExportTempInvoiceNumber").ToString("00000000");
|
||||
}
|
||||
|
||||
public void AddTempInvoiceNumber(IEnumerable<Model.Account.IInvoice> invoiceList, bool overwriteExisting)
|
||||
{
|
||||
for (int i = 0; i < invoiceList.Count(); i++)
|
||||
{
|
||||
if (invoiceList.ElementAt(i).InvoiceNumber != null && overwriteExisting == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
invoiceList.ElementAt(i).InvoiceNumber = GetNextTempInvoiceNumber();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSalesInvoice(List<Model.Account.SalesInvoice> invoiceList)
|
||||
{
|
||||
// validate the list of invoices
|
||||
var validateInvoice = new Logic.Validate.SalesInvoice();
|
||||
validateInvoice.IsValidExportInvoice(invoiceList);
|
||||
if (validateInvoice.IsValidResult == false)
|
||||
{
|
||||
log.LogError("Invalid Sales invoice(s) found. See extended info.", validateInvoice.ValidationResultListToString());
|
||||
return;
|
||||
}
|
||||
validateInvoice = null;
|
||||
|
||||
// save to database
|
||||
new Data.Database.Export.CreateSalesInvoice(sqlConnectionString).Execute(invoiceList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
class ValidateSalesInvoice : Logic.Account.ValidateInvoice
|
||||
{
|
||||
//public bool IsValidInvoice(Model.Export.SetSalesInvoice invoice)
|
||||
//{
|
||||
// ErrorMessage = null;
|
||||
|
||||
// var baseInvoice = CopyInvoiceToBase(invoice);
|
||||
// if (!base.IsValidInvoice(baseInvoice))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// // check each match string only appears once
|
||||
// var dicLookup = new Dictionary<string, string>();
|
||||
// foreach (var line in invoice.InvoiceLineList)
|
||||
// {
|
||||
// if (dicLookup.ContainsKey(line.LineTypeMatchString))
|
||||
// {
|
||||
// ErrorMessage = "'Line type match string' duplication.";
|
||||
// return false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dicLookup.Add(line.LineTypeMatchString, null);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return true;
|
||||
//}
|
||||
//public bool IsValidInvoiceHeader(Model.Export.SetSalesInvoice invoice)
|
||||
//{
|
||||
// ErrorMessage = null;
|
||||
|
||||
// var baseInvoice = CopyInvoiceHeaderToBase(invoice);
|
||||
// if (base.IsValidInvoiceHeader(baseInvoice))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
//public bool IsValidInvoiceLine(Model.Export.SetSalesInvoiceLine invoiceLine)
|
||||
//{
|
||||
// ErrorMessage = null;
|
||||
|
||||
// var baseLine = CopyInvoiceLineToBase(invoiceLine);
|
||||
// if (!IsValidLineTypeMatchString(invoiceLine.LineTypeMatchString)
|
||||
// || !base.IsValidInvoiceLine(baseLine))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
//}
|
||||
//public bool IsValidLineTypeMatchString(string matchString)
|
||||
//{
|
||||
// ErrorMessage = null;
|
||||
// var stringCheck = new Logic.Utilities.StringCheck();
|
||||
// if (!stringCheck.MaxLength(matchString, 250))
|
||||
// {
|
||||
// ErrorMessage = "Invalid Line Type Match String: " + stringCheck.ErrorMessage;
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//private Model.Account.SalesInvoice CopyInvoiceToBase(Model.Export.SetSalesInvoice invoice)
|
||||
//{
|
||||
// var baseInvoice = CopyInvoiceHeaderToBase(invoice);
|
||||
// if (invoice.IsSetInvoiceLineList)
|
||||
// {
|
||||
// var baseLineList = new List<Model.Account.SalesInvoiceLine>();
|
||||
// foreach (var line in invoice.InvoiceLineList)
|
||||
// {
|
||||
// baseLineList.Add(CopyInvoiceLineToBase(line));
|
||||
// }
|
||||
// baseInvoice.InvoiceLineList = baseLineList;
|
||||
// }
|
||||
// return baseInvoice;
|
||||
//}
|
||||
|
||||
//private Model.Account.SalesInvoice CopyInvoiceHeaderToBase(Model.Export.SetSalesInvoice invoice)
|
||||
//{
|
||||
// var baseInvoice = new Model.Account.SalesInvoice();
|
||||
|
||||
// if (invoice.IsSetContactName)
|
||||
// { baseInvoice.ContactName = invoice.ContactName; }
|
||||
// if (invoice.IsSetInvoiceAmount)
|
||||
// { baseInvoice.InvoiceAmount = invoice.InvoiceAmount; }
|
||||
// if (invoice.IsSetInvoiceCurrencyCode)
|
||||
// { baseInvoice.InvoiceCurrencyCode = invoice.InvoiceCurrencyCode; }
|
||||
// if (invoice.IsSetInvoiceDate)
|
||||
// { baseInvoice.InvoiceDate = invoice.InvoiceDate; }
|
||||
// if (invoice.IsSetInvoiceNumber)
|
||||
// { baseInvoice.InvoiceNumber = invoice.InvoiceNumber; }
|
||||
// if (invoice.IsSetInvoiceReference)
|
||||
// { baseInvoice.InvoiceReference = invoice.InvoiceReference; }
|
||||
// if (invoice.IsSetIsComplete)
|
||||
// { baseInvoice.IsComplete = invoice.IsComplete; }
|
||||
|
||||
// return baseInvoice;
|
||||
//}
|
||||
//private Model.Account.SalesInvoiceLine CopyInvoiceLineToBase(Model.Export.SetSalesInvoiceLine invoiceLine)
|
||||
//{
|
||||
// var baseLine = new Model.Account.SalesInvoiceLine();
|
||||
|
||||
// if (invoiceLine.IsSetAccountCode)
|
||||
// { baseLine.AccountCode = invoiceLine.AccountCode; }
|
||||
|
||||
// // something missing here ??????
|
||||
|
||||
// if (invoiceLine.IsSetDescription)
|
||||
// { baseLine.Description = invoiceLine.Description; }
|
||||
// if (invoiceLine.IsSetNetAmount)
|
||||
// { baseLine.TotalNetAmount = invoiceLine.NetAmount; }
|
||||
|
||||
// // tax adjustment to set ??????????
|
||||
|
||||
// if (invoiceLine.IsSetTaxCode)
|
||||
// { baseLine.TaxCode = invoiceLine.TaxCode; }
|
||||
|
||||
// return baseLine;
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user