mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 17:17:15 +00:00
Migration from Amazon MWS to Selling Partner API
This commit is contained in:
@@ -21,16 +21,15 @@ namespace bnhtrade.Core.Logic.Export
|
||||
|
||||
public void ToInvoice()
|
||||
{
|
||||
var console = new UI.Console.Update();
|
||||
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();
|
||||
var consistencyCheck = new Data.Database.Consistency.ImportAmazonSettlement().PeriodDateGaps();
|
||||
if (consistencyCheck == false)
|
||||
{ return; }
|
||||
|
||||
// get list of unprocssed settlement reports to export
|
||||
var settlementData = new Data.Database.Import.ReadAmazonSettlement(sqlConnectionString);
|
||||
var settlementData = new Data.Database.Import.AmazonSettlementRead();
|
||||
var settlementList = settlementData.AllUnprocessed();
|
||||
settlementData = null;
|
||||
|
||||
@@ -92,7 +91,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
}
|
||||
}
|
||||
}
|
||||
var taxCodeBySkuNumer = new Logic.Account.GetTaxCodeInfo(sqlConnectionString).GetBySkuNumber(skuList);
|
||||
var taxCodeBySkuNumer = new Logic.Account.GetTaxCodeInfo().GetBySkuNumber(skuList);
|
||||
|
||||
// loop through each settlement and build list of invoices to export
|
||||
Console.Write("\rBuilding invoices to export... ");
|
||||
@@ -190,10 +189,11 @@ namespace bnhtrade.Core.Logic.Export
|
||||
|
||||
// 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);
|
||||
var getLineItemInfo = new Logic.Account.GetInvoiceLineItem();
|
||||
getLineItemInfo.InsertNewOnNoMatch = true;
|
||||
getLineItemInfo.CacheFill(lineItemCodeList);
|
||||
bool newTypeFound = false;
|
||||
string newTypeText = null;
|
||||
|
||||
for (int i = 0; i < invoiceList.Count(); i++)
|
||||
{
|
||||
@@ -209,6 +209,14 @@ namespace bnhtrade.Core.Logic.Export
|
||||
else if (itemCode.IsNewReviewRequired)
|
||||
{
|
||||
newTypeFound = true;
|
||||
if (string.IsNullOrWhiteSpace(itemCode.ItemCode))
|
||||
{
|
||||
newTypeText = itemCode.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
newTypeText = itemCode.ItemCode;
|
||||
}
|
||||
}
|
||||
// clean invoices of any disabled lines (remove lines and possibly invoices)
|
||||
else if (itemCode.InvoiceLineEntryEnabled == false)
|
||||
@@ -243,7 +251,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
if (newTypeFound)
|
||||
{
|
||||
throw new Exception("New line ItemCode found. Add item code default values and then try again.");
|
||||
throw new Exception("Parameters required for Invoice line item code '"+ newTypeText + "'. Set in tblAccountInvoiceLineItem.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -292,7 +300,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
saveInv.SaveSalesInvoice(invoiceList);
|
||||
|
||||
// set settlements to isprocessed
|
||||
new Data.Database.Import.UpdateAmazonSettlement(sqlConnectionString).SetIsProcessedTrue(settlementIdList);
|
||||
new Data.Database.Import.AmazonSettlementUpdate().SetIsProcessedTrue(settlementIdList);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
@@ -319,7 +327,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
|
||||
// add tax info if required
|
||||
if ((match01 == "Order" || match01 == "Refund")
|
||||
&& (match02 == "ItemPrice" || match02 == "Promotion"))
|
||||
&& (match02 == "ItemPrice" || match02 == "Promotion" || match02 == "ItemWithheldTax"))
|
||||
{
|
||||
if (taxCodeBySkuNumer.ContainsKey(skuNumber))
|
||||
{
|
||||
|
||||
@@ -24,29 +24,17 @@ namespace bnhtrade.Core.Logic.Export
|
||||
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);
|
||||
int queueId = QueueInventoryLoader(stream);
|
||||
SubmitQueuedFeedSubmission(queueId);
|
||||
}
|
||||
|
||||
public int QueueInventoryLoader(MemoryStream stream)
|
||||
{
|
||||
Model.Export.AmazonFeedSubmission result;
|
||||
return QueueFeedSubbmission("_POST_FLAT_FILE_INVLOADER_DATA_", "txt", stream, out result);
|
||||
return QueueFeedSubbmission("_POST_FLAT_FILE_INVLOADER_DATA_", "txt", stream);
|
||||
}
|
||||
|
||||
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)
|
||||
// adds the file(stream) to the database and returns the queue Id
|
||||
private int QueueFeedSubbmission(string feedType, string fileExtention, MemoryStream stream)
|
||||
{
|
||||
// construct file object
|
||||
var fileInfo = new Model.Data.DatabaseFileStream();
|
||||
@@ -63,7 +51,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
int queueId = 0;
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
queueId = new Data.Database.Export.CreateAmazonFeedSubmission(sqlConnectionString).Execute(feedType, fileInfo);
|
||||
queueId = new Data.Database.Export.CreateAmazonFeedSubmission().Execute(feedType, fileInfo);
|
||||
|
||||
// validate the result
|
||||
var validateResults = new List<ValidationResult>();
|
||||
@@ -83,11 +71,6 @@ namespace bnhtrade.Core.Logic.Export
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// create feed object
|
||||
result = new Model.Export.AmazonFeedSubmission();
|
||||
result.FeedType = feedType;
|
||||
result.File = fileInfo;
|
||||
|
||||
return queueId;
|
||||
}
|
||||
|
||||
@@ -95,7 +78,11 @@ namespace bnhtrade.Core.Logic.Export
|
||||
private void SubmitQueuedFeedSubmission(int queueId, Model.Export.AmazonFeedSubmission feedSubmission)
|
||||
{
|
||||
// upload to mws
|
||||
var feedSubmitt = new Data.AmazonMWS.Feeds.SubmitFeed(feedSubmission);
|
||||
//var feedSubmitt = new Data.AmazonMWS.Feeds.SubmitFeed(feedSubmission);
|
||||
|
||||
// upload to sp-api
|
||||
var feedSubmitt = new Data.Amazon.Feeds.SubmittFeed();
|
||||
feedSubmitt.SubmitFeed(feedSubmission);
|
||||
|
||||
if (!feedSubmitt.FeedSubmissionRecived)
|
||||
{
|
||||
@@ -104,7 +91,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
}
|
||||
|
||||
// set the amazon feed Id
|
||||
var dbUpdate = new Data.Database.Export.UpdateAmazonFeedSubmission(sqlConnectionString);
|
||||
var dbUpdate = new Data.Database.Export.UpdateAmazonFeedSubmission();
|
||||
dbUpdate.AddAmazonFeedId(queueId, feedSubmission.FeedSubmissionId);
|
||||
|
||||
// update progress info
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
|
||||
public string GetNextTempInvoiceNumber()
|
||||
{
|
||||
var sequence = new Data.Database.Programmability.Sequence(sqlConnectionString);
|
||||
var sequence = new Data.Database.Programmability.Sequence();
|
||||
return "_tmp" + sequence.GetNext("ExportTempInvoiceNumber").ToString("00000000");
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace bnhtrade.Core.Logic.Export
|
||||
validateInvoice = null;
|
||||
|
||||
// save to database
|
||||
new Data.Database.Export.CreateSalesInvoice(sqlConnectionString).Execute(invoiceList);
|
||||
new Data.Database.Export.CreateSalesInvoice().Execute(invoiceList);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user