mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
wip
This commit is contained in:
@@ -86,6 +86,25 @@ namespace bnhtrade.Core.Data.Amazon.Report
|
|||||||
ReportProcessingStatus = ProcessingStatus.NULL;
|
ReportProcessingStatus = ProcessingStatus.NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a list of report that are currently available filtered parameters set in class
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>report list</returns>
|
||||||
|
protected IList<FikaAmazonAPI.AmazonSpApiSDK.Models.Reports.Report> ListAvailableReports()
|
||||||
|
{
|
||||||
|
var parameters = new ParameterReportList();
|
||||||
|
parameters.reportTypes = new List<ReportTypes>() { reportType };
|
||||||
|
parameters.marketplaceIds.Add(amznConn.GetCurrentMarketplace.ID);
|
||||||
|
|
||||||
|
// request from amazon
|
||||||
|
return amznConn.Reports.GetReports(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For reports that require a start and end period to report over.
|
/// For reports that require a start and end period to report over.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -169,6 +188,22 @@ namespace bnhtrade.Core.Data.Amazon.Report
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DownloadReport(reportId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void DownloadByReportId(string reportId)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
DownloadReport(reportId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DownloadReport(string reportId)
|
||||||
|
{
|
||||||
|
if (report == null)
|
||||||
|
{
|
||||||
|
WaitWhileProcessing(reportId);
|
||||||
|
}
|
||||||
|
|
||||||
// test for processing status
|
// test for processing status
|
||||||
if (report.ProcessingStatus == FikaAmazonAPI.AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.DONE)
|
if (report.ProcessingStatus == FikaAmazonAPI.AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.DONE)
|
||||||
{
|
{
|
||||||
@@ -246,12 +281,19 @@ namespace bnhtrade.Core.Data.Amazon.Report
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save to file
|
// save to file
|
||||||
string reportFilePath = Config.GetTempFileDirectoryPath() + @"\SP-API-Reports\ " + report.ReportType.ToString() + " reportId_" + reportId + ".txt";
|
string dirPath = Config.GetTempFileDirectoryPath() + @"\SP-API-Reports\";
|
||||||
|
System.IO.Directory.CreateDirectory(dirPath);
|
||||||
|
string reportFilePath = dirPath + report.ReportType.ToString() + " reportId_" + reportId + ".txt";
|
||||||
System.IO.File.WriteAllText(reportFilePath, reportString);
|
System.IO.File.WriteAllText(reportFilePath, reportString);
|
||||||
log.LogInformation("Amazon report #" + reportId + " sucessfully saved to disk.");
|
log.LogInformation("Amazon report #" + reportId + " sucessfully saved to disk.");
|
||||||
this.ReportFilePath = reportFilePath;
|
this.ReportFilePath = reportFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If a duplicate report has been recently requested, Amazon may return 'FATAL'. This method tests for, and attempts to retrive the duplicate report that is causing the error.
|
/// If a duplicate report has been recently requested, Amazon may return 'FATAL'. This method tests for, and attempts to retrive the duplicate report that is causing the error.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using bnhtrade.Core.Data.Amazon.SellingPartnerAPI;
|
using bnhtrade.Core.Data.Amazon.SellingPartnerAPI;
|
||||||
using FikaAmazonAPI;
|
using FikaAmazonAPI;
|
||||||
using FikaAmazonAPI.Parameter.Report;
|
using FikaAmazonAPI.Parameter.Report;
|
||||||
|
using FikaAmazonAPI.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,11 +11,9 @@ using static FikaAmazonAPI.Utils.Constants;
|
|||||||
|
|
||||||
namespace bnhtrade.Core.Data.Amazon.Report
|
namespace bnhtrade.Core.Data.Amazon.Report
|
||||||
{
|
{
|
||||||
public class SettlementReport
|
public class SettlementReport : ReportLogic
|
||||||
{
|
{
|
||||||
private AmazonConnection amznConn = new SpApiConnection().Connection;
|
public SettlementReport () : base(ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2)
|
||||||
|
|
||||||
public SettlementReport ()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,28 +24,22 @@ namespace bnhtrade.Core.Data.Amazon.Report
|
|||||||
public List<string> ListAvaliableReports()
|
public List<string> ListAvaliableReports()
|
||||||
{
|
{
|
||||||
UI.Console.WriteLine("Requesting list of avaliable settlement reports form Amazon SP-API");
|
UI.Console.WriteLine("Requesting list of avaliable settlement reports form Amazon SP-API");
|
||||||
|
var reportList = ListAvailableReports();
|
||||||
|
|
||||||
// set parameters
|
var reportIdList = new List<string>();
|
||||||
var parameters = new ParameterReportList();
|
foreach (var report in reportList)
|
||||||
parameters.reportTypes = new List<ReportTypes>() { ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2};
|
|
||||||
parameters.marketplaceIds.Add(amznConn.GetCurrentMarketplace.ID);
|
|
||||||
|
|
||||||
// request from amazon
|
|
||||||
var result = amznConn.Reports.GetReports(parameters);
|
|
||||||
|
|
||||||
var returnList = new List<string>();
|
|
||||||
foreach (var report in result)
|
|
||||||
{
|
{
|
||||||
returnList.Add(report.ReportId);
|
reportIdList.Add(report.ReportId);
|
||||||
}
|
}
|
||||||
|
|
||||||
UI.Console.WriteLine("{0} Settlement reports avaible on Amazon SP-API");
|
UI.Console.WriteLine("{0} Settlement reports avaible on Amazon SP-API");
|
||||||
return returnList;
|
return reportIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFile(string reportId)
|
public string GetReportFile(string reportId)
|
||||||
{
|
{
|
||||||
return amznConn.Reports.GetReportFile(reportId);
|
DownloadByReportId(reportId);
|
||||||
|
return ReportFilePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace bnhtrade.Core.Data.Database.Export
|
|||||||
cmd.Parameters.AddWithValue("@invoiceID", invoiceId);
|
cmd.Parameters.AddWithValue("@invoiceID", invoiceId);
|
||||||
cmd.Parameters.AddWithValue("@itemCode", invoiceList[i].InvoiceLineList[j].ItemCode);
|
cmd.Parameters.AddWithValue("@itemCode", invoiceList[i].InvoiceLineList[j].ItemCode);
|
||||||
cmd.Parameters.AddWithValue("@netAmount", invoiceList[i].InvoiceLineList[j].UnitAmount);
|
cmd.Parameters.AddWithValue("@netAmount", invoiceList[i].InvoiceLineList[j].UnitAmount);
|
||||||
cmd.Parameters.AddWithValue("@accountCode", invoiceList[i].InvoiceLineList[j].AccountCode.AccountCode);
|
cmd.Parameters.AddWithValue("@accountCode", (int)invoiceList[i].InvoiceLineList[j].AccountCode.AccountCode);
|
||||||
cmd.Parameters.AddWithValue("@taxAmount", invoiceList[i].InvoiceLineList[j].TaxAmount);
|
cmd.Parameters.AddWithValue("@taxAmount", invoiceList[i].InvoiceLineList[j].TaxAmount);
|
||||||
cmd.Parameters.AddWithValue("@taxCode", invoiceList[i].InvoiceLineList[j].TaxCode.TaxCode);
|
cmd.Parameters.AddWithValue("@taxCode", invoiceList[i].InvoiceLineList[j].TaxCode.TaxCode);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using bnhtrade.Core.Data.Amazon.Report;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Import
|
namespace bnhtrade.Core.Logic.Import
|
||||||
{
|
{
|
||||||
@@ -10,6 +11,7 @@ namespace bnhtrade.Core.Logic.Import
|
|||||||
|
|
||||||
public AmazonSettlement()
|
public AmazonSettlement()
|
||||||
{
|
{
|
||||||
|
amazonReport = new Data.Amazon.Report.SettlementReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SyncDatabase()
|
public void SyncDatabase()
|
||||||
@@ -53,12 +55,12 @@ namespace bnhtrade.Core.Logic.Import
|
|||||||
}
|
}
|
||||||
|
|
||||||
// import into database
|
// import into database
|
||||||
var dbImport = new Data.Database.Import.AmazonSettlementInsert();
|
var dbInsert = new Data.Database.Import.AmazonSettlementInsert();
|
||||||
for (int i = 0; i < spapiReportIdList.Count(); i++)
|
for (int i = 0; i < spapiReportIdList.Count(); i++)
|
||||||
{
|
{
|
||||||
UI.Console.WriteLine("Importing settlement report " + (i + 1) + " of " + spapiReportIdList.Count() + " (ReportID:" + spapiReportIdList[i] + ").");
|
UI.Console.WriteLine("Importing settlement report " + (i + 1) + " of " + spapiReportIdList.Count() + " (ReportID:" + spapiReportIdList[i] + ").");
|
||||||
var filePath = amazonReport.GetFile(spapiReportIdList[i]);
|
var filePath = amazonReport.GetReportFile(spapiReportIdList[i]);
|
||||||
bool ack = dbImport.ByFlatFile(filePath, spapiReportIdList[i]);
|
bool ack = dbInsert.ByFlatFile(filePath, spapiReportIdList[i]);
|
||||||
log.LogInformation("Settlment Report imported (ReportID:" + spapiReportIdList[i] + ").");
|
log.LogInformation("Settlment Report imported (ReportID:" + spapiReportIdList[i] + ").");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user