mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
Fix amazon settlement period and other updates
This commit is contained in:
@@ -15,10 +15,14 @@ namespace bnhtrade.Core.Data.Database.Account
|
|||||||
cacheLineItemByTablePk = new Dictionary<int, Model.Account.InvoiceLineItem>();
|
cacheLineItemByTablePk = new Dictionary<int, Model.Account.InvoiceLineItem>();
|
||||||
cacheTablePkByItemCode = new Dictionary<string, int>();
|
cacheTablePkByItemCode = new Dictionary<string, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<int, Model.Account.InvoiceLineItem> cacheLineItemByTablePk;
|
private Dictionary<int, Model.Account.InvoiceLineItem> cacheLineItemByTablePk;
|
||||||
private Dictionary<string, int> cacheTablePkByItemCode;
|
private Dictionary<string, int> cacheTablePkByItemCode;
|
||||||
|
|
||||||
public bool InsertNewOnNoMatch { get; set; } = false;
|
public bool InsertNewOnNoMatch { get; set; } = false;
|
||||||
|
|
||||||
|
public string NewTypeTitle { get; } = "NEW TYPE";
|
||||||
|
|
||||||
public void CacheClear()
|
public void CacheClear()
|
||||||
{
|
{
|
||||||
cacheLineItemByTablePk.Clear();
|
cacheLineItemByTablePk.Clear();
|
||||||
@@ -111,7 +115,7 @@ namespace bnhtrade.Core.Data.Database.Account
|
|||||||
if (InsertNewOnNoMatch)
|
if (InsertNewOnNoMatch)
|
||||||
{
|
{
|
||||||
int tablePk = 0;
|
int tablePk = 0;
|
||||||
returnObject.Title = "NEW TYPE";
|
returnObject.Title = NewTypeTitle;
|
||||||
returnObject.ItemCode = itemCode;
|
returnObject.ItemCode = itemCode;
|
||||||
returnObject.IsNewReviewRequired = true;
|
returnObject.IsNewReviewRequired = true;
|
||||||
|
|
||||||
|
|||||||
@@ -9,38 +9,90 @@ namespace bnhtrade.Core.Data.Database.Consistency
|
|||||||
{
|
{
|
||||||
public class ImportAmazonSettlement : Connection
|
public class ImportAmazonSettlement : Connection
|
||||||
{
|
{
|
||||||
public string ErrorMessage { get; set; }
|
|
||||||
public ImportAmazonSettlement(string sqlConnectionString) : base(sqlConnectionString)
|
public ImportAmazonSettlement(string sqlConnectionString) : base(sqlConnectionString)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public bool RunCheck()
|
|
||||||
|
public List<string> ErrorMessage { get; private set; }
|
||||||
|
|
||||||
|
public bool ErrorMessageIsSet
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (ErrorMessage == null || !ErrorMessage.Any()) { return false; }
|
||||||
|
else { return true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PeriodDateGaps()
|
||||||
{
|
{
|
||||||
ErrorMessage = null;
|
ErrorMessage = null;
|
||||||
|
|
||||||
using (var sqlConn = new SqlConnection())
|
using (var sqlConn = new SqlConnection(sqlConnectionString))
|
||||||
{
|
{
|
||||||
|
var log = new Logic.Log.LogEvent();
|
||||||
sqlConn.Open();
|
sqlConn.Open();
|
||||||
|
|
||||||
|
// get list of marketplace names
|
||||||
|
var marketplaces = new List<string>();
|
||||||
using (SqlCommand cmd = new SqlCommand(@"
|
using (SqlCommand cmd = new SqlCommand(@"
|
||||||
SELECT Count(tblImportAmazonSettlementReportLine.ImportAmazonSettlementReportLineID) AS CountOfID
|
SELECT DISTINCT tblImportAmazonSettlementReport.ImportAmazonSettlementReportID
|
||||||
FROM tblImportAmazonSettlementReportLine
|
,tblImportAmazonSettlementReport.[marketplace-name]
|
||||||
INNER JOIN tblImportAmazonSettlementReport ON tblImportAmazonSettlementReportLine.ImportAmazonSettlementReportID = tblImportAmazonSettlementReport.ImportAmazonSettlementReportID
|
,tblImportAmazonSettlementReport.[settlement-start-date]
|
||||||
WHERE (
|
,tblImportAmazonSettlementReport.[settlement-end-date]
|
||||||
((tblImportAmazonSettlementReport.IsProcessed) = 0)
|
FROM tblImportAmazonSettlementReport
|
||||||
AND ((tblImportAmazonSettlementReportLine.AccountTransactionID) IS NOT NULL)
|
ORDER BY tblImportAmazonSettlementReport.[marketplace-name]
|
||||||
)
|
,tblImportAmazonSettlementReport.[settlement-start-date]
|
||||||
OR (
|
,tblImportAmazonSettlementReport.[settlement-end-date];
|
||||||
((tblImportAmazonSettlementReport.IsProcessed) = 0)
|
|
||||||
AND ((tblImportAmazonSettlementReportLine.IsProcessed) = 1)
|
|
||||||
);
|
|
||||||
", sqlConn))
|
", sqlConn))
|
||||||
{
|
{
|
||||||
int count = Convert.ToInt32(cmd.ExecuteScalar());
|
using(var reader = cmd.ExecuteReader())
|
||||||
if (count != 0)
|
|
||||||
{
|
{
|
||||||
ErrorMessage = "Error, " + count + " settlement report lines have transactionId/IsProcessed set on an unprocessed settlement";
|
if (!reader.HasRows)
|
||||||
return false;
|
{
|
||||||
|
ErrorMessage.Add("No data found. Is the table empty?");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
string marketplace = "some-random-string-7posadlnvl2oaweoh3amol5o5irv8nl2aoqefl";
|
||||||
|
DateTime endDate = DateTime.SpecifyKind(default(DateTime), DateTimeKind.Utc);
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if (reader.IsDBNull(1))
|
||||||
|
{
|
||||||
|
log.LogError(
|
||||||
|
"Action required: Enter market place name for settlelment report id " + reader.GetInt32(0) + "."
|
||||||
|
, "Unable to process settlement data from one settlement report '" + reader.GetInt32(0) +
|
||||||
|
"'. Report header table requires a market place name, which is not supplied in original " +
|
||||||
|
"report from Amazon. This is useually inferred from settlement lines. " +
|
||||||
|
"However, in this case, it was not not possible. Manual edit/entry for database table required."
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newMarketPlace = reader.GetString(1);
|
||||||
|
DateTime startDate = DateTime.SpecifyKind( reader.GetDateTime(2), DateTimeKind.Utc);
|
||||||
|
|
||||||
|
if (marketplace != newMarketPlace)
|
||||||
|
{
|
||||||
|
marketplace = newMarketPlace;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0 && startDate != endDate)
|
||||||
|
{
|
||||||
|
log.LogError("Inconsistancy in DB data found, break in settlement period dates.",
|
||||||
|
marketplace + " at ID=" + reader.GetInt32(0) + " start-date is not the same as the previous period end-date."
|
||||||
|
+ Environment.NewLine + "If it's a missing settlement report and it's over 90 days ago, you may need to go to"
|
||||||
|
+ " 'Seller Central' > 'Payments' > 'All Statements' and manually 'Request Report' for each missing settlement.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
endDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,24 +25,46 @@ namespace bnhtrade.Core.Data.Database.Export
|
|||||||
var readItemCode = new Data.Database.Account.ReadInvoiceLineItemCode(sqlConnectionString);
|
var readItemCode = new Data.Database.Account.ReadInvoiceLineItemCode(sqlConnectionString);
|
||||||
readItemCode.InsertNewOnNoMatch = true;
|
readItemCode.InsertNewOnNoMatch = true;
|
||||||
bool newTypeFound = false;
|
bool newTypeFound = false;
|
||||||
|
bool newTypeTitleFound = false;
|
||||||
for (int i = 0; i < invoiceList.Count(); i++)
|
for (int i = 0; i < invoiceList.Count(); i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < invoiceList[i].InvoiceLineList.Count(); j++)
|
for (int j = 0; j < invoiceList[i].InvoiceLineList.Count(); j++)
|
||||||
{
|
{
|
||||||
var itemCodeInfo = readItemCode.ByItemCode(invoiceList[i].InvoiceLineList[j].ItemCode);
|
var itemCodeInfo = readItemCode.ByItemCode(invoiceList[i].InvoiceLineList[j].ItemCode);
|
||||||
if (itemCodeInfo.IsNewReviewRequired)
|
if (itemCodeInfo.InvoiceLineEntryEnabled == false)
|
||||||
{ newTypeFound = true; }
|
{
|
||||||
|
invoiceList[i].InvoiceAmount = invoiceList[i].InvoiceAmount - invoiceList[i].InvoiceLineList[j].GrossTotalAmount;
|
||||||
|
invoiceList[i].InvoiceLineList.RemoveAt(j);
|
||||||
|
j = j - 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (itemCodeInfo.IsNewReviewRequired)
|
||||||
|
{
|
||||||
|
newTypeFound = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
invoiceList[i].InvoiceLineList[j].AccountCode = itemCodeInfo.DefaultAccountCode;
|
if (itemCodeInfo.Title == readItemCode.NewTypeTitle)
|
||||||
invoiceList[i].InvoiceLineList[j].TaxCode = itemCodeInfo.DefaultTaxCode;
|
{ newTypeTitleFound = true; }
|
||||||
invoiceList[i].InvoiceLineList[j].Description = itemCodeInfo.Description;
|
else
|
||||||
|
{
|
||||||
|
invoiceList[i].InvoiceLineList[j].AccountCode = itemCodeInfo.DefaultAccountCode;
|
||||||
|
invoiceList[i].InvoiceLineList[j].TaxCode = itemCodeInfo.DefaultTaxCode;
|
||||||
|
invoiceList[i].InvoiceLineList[j].Description = itemCodeInfo.Title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newTypeFound)
|
if (newTypeFound || newTypeTitleFound)
|
||||||
{
|
{
|
||||||
log.LogError("New line ItemCode created while processing Amazon settlements. Update table to complete.");
|
if (newTypeFound)
|
||||||
|
{
|
||||||
|
log.LogError("New line ItemCode found. Add item code default values and then try again.");
|
||||||
|
}
|
||||||
|
if (newTypeTitleFound)
|
||||||
|
{
|
||||||
|
log.LogError("ItemCode found with the incomplete title '" + readItemCode.NewTypeTitle + "'. Update title and then try again.");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,27 @@ using System.Transactions;
|
|||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Export
|
namespace bnhtrade.Core.Logic.Export
|
||||||
{
|
{
|
||||||
public class AmazonSettlementData
|
public class AmazonSettlement
|
||||||
{
|
{
|
||||||
private string sqlConnectionString;
|
private string sqlConnectionString;
|
||||||
private Dictionary<string, Model.Account.TaxCode> taxCodeBySkuNumer;
|
private Dictionary<string, Model.Account.TaxCode> taxCodeBySkuNumer;
|
||||||
|
|
||||||
public AmazonSettlementData(string sqlConnectionString)
|
public AmazonSettlement(string sqlConnectionString)
|
||||||
{
|
{
|
||||||
this.sqlConnectionString = sqlConnectionString;
|
this.sqlConnectionString = sqlConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToInvoice()
|
public void ToInvoice()
|
||||||
{
|
{
|
||||||
var console = new UI.Console.Update();
|
var console = new UI.Console.Update();
|
||||||
var log = new Logic.Log.LogEvent();
|
var log = new Logic.Log.LogEvent();
|
||||||
log.LogInformation("Starting processing of Amazon settlement data into export invoice table...");
|
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 )
|
||||||
|
{ return; }
|
||||||
|
|
||||||
// get list of unprocssed settlement reports to export
|
// get list of unprocssed settlement reports to export
|
||||||
var settlementData = new Data.Database.Import.ReadAmazonSettlement(sqlConnectionString);
|
var settlementData = new Data.Database.Import.ReadAmazonSettlement(sqlConnectionString);
|
||||||
var settlementList = settlementData.AllUnprocessed();
|
var settlementList = settlementData.AllUnprocessed();
|
||||||
@@ -234,12 +240,13 @@ namespace bnhtrade.Core.Logic.Export
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
scope.Dispose();
|
||||||
log.LogError(ex.Message);
|
log.LogError(ex.Message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.Write("\r");
|
Console.Write("\r");
|
||||||
log.LogInformation("Finished 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(string skuNumber, string transactionType, string amountType, string amountDescription)
|
||||||
@@ -8057,12 +8057,12 @@ namespace bnhtrade.Core
|
|||||||
TypeList reportList = new TypeList();
|
TypeList reportList = new TypeList();
|
||||||
reportList.Type.Add(mwsReportEnum);
|
reportList.Type.Add(mwsReportEnum);
|
||||||
GetReportListRequest requestList = new GetReportListRequest();
|
GetReportListRequest requestList = new GetReportListRequest();
|
||||||
|
requestList.ReportTypeList = reportList;
|
||||||
requestList.Merchant = merchantId;
|
requestList.Merchant = merchantId;
|
||||||
requestList.MaxCount = 100;
|
requestList.MaxCount = 100;
|
||||||
requestList.ReportTypeList = reportList;
|
requestList.Acknowledged = false;
|
||||||
bool? returnAcknowledged = false;
|
//requestList.AvailableFromDate = new DateTime(2019, 7, 1); // default is 90 days
|
||||||
if (returnAcknowledged == true) { requestList.Acknowledged = true; }
|
//requestList.AvailableToDate = new DateTime(2020, 2, 1);
|
||||||
else if (returnAcknowledged == false) { requestList.Acknowledged = false; }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/ request, recive request, and then iterate through the list
|
/ request, recive request, and then iterate through the list
|
||||||
@@ -8085,15 +8085,12 @@ namespace bnhtrade.Core
|
|||||||
* Pass file path to function to parse into database
|
* Pass file path to function to parse into database
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool import = ImportReportSettlementData(sqlConnectionString, filePath);
|
bool importAck = ImportReportSettlementData(sqlConnectionString, filePath);
|
||||||
|
|
||||||
// if opertion succeded, set the acknowledged property
|
// if opertion succeded, set the acknowledged property
|
||||||
if (import & (returnAcknowledged == false | returnAcknowledged == null))
|
if (importAck)
|
||||||
{
|
{
|
||||||
SetMwsReportAcknowledgement(reportId, true);
|
SetMwsReportAcknowledgement(reportId, true);
|
||||||
}
|
|
||||||
if (import == true)
|
|
||||||
{
|
|
||||||
reportsImported = reportsImported + 1;
|
reportsImported = reportsImported + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8634,7 +8631,7 @@ namespace bnhtrade.Core
|
|||||||
{
|
{
|
||||||
if (newLine)
|
if (newLine)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + consoleText);
|
Console.WriteLine("\r[" + DateTime.Now.ToString("HH:mm:ss") + "] " + consoleText);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Test
|
|||||||
}
|
}
|
||||||
private void AmazonSettlement()
|
private void AmazonSettlement()
|
||||||
{
|
{
|
||||||
var instance = new Core.Logic.Export.AmazonSettlementData(sqlConnectionString);
|
var instance = new Core.Logic.Export.AmazonSettlement(sqlConnectionString);
|
||||||
instance.ToInvoice();
|
instance.ToInvoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Test.Logic
|
|||||||
}
|
}
|
||||||
public void UpdateXeroWithAmzonSettlementData()
|
public void UpdateXeroWithAmzonSettlementData()
|
||||||
{
|
{
|
||||||
var instance = new bnhtrade.Core.Logic.Export.AmazonSettlementData(sqlConnectionString);
|
var instance = new bnhtrade.Core.Logic.Export.AmazonSettlement(sqlConnectionString);
|
||||||
instance.ToInvoice();
|
instance.ToInvoice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace bnhtrade.Core.UI.Console
|
|||||||
{
|
{
|
||||||
if (newLine)
|
if (newLine)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + consoleText);
|
System.Console.WriteLine("\r[" + DateTime.Now.ToString("HH:mm:ss") + "] " + consoleText);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ namespace bnhtrade.Core.UI.Console
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
System.Console.Write("\r[--------] " + consoleMessage, string.Format("{0:00}", waitSeconds));
|
System.Console.Write("\r[--------] " + consoleMessage, string. Format("{0:00}", waitSeconds));
|
||||||
System.Threading.Thread.Sleep(1000);
|
System.Threading.Thread.Sleep(1000);
|
||||||
waitSeconds = waitSeconds - 1;
|
waitSeconds = waitSeconds - 1;
|
||||||
} while (waitSeconds > 0);
|
} while (waitSeconds > 0);
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
<Compile Include="Logic\AmazonFBAInbound\UpdateDatabaseShipmentInfo.cs" />
|
<Compile Include="Logic\AmazonFBAInbound\UpdateDatabaseShipmentInfo.cs" />
|
||||||
<Compile Include="Data\Database\Export\CreateSalesInvoice.cs" />
|
<Compile Include="Data\Database\Export\CreateSalesInvoice.cs" />
|
||||||
<Compile Include="Logic\Export\ValidateSalesInvoice.cs" />
|
<Compile Include="Logic\Export\ValidateSalesInvoice.cs" />
|
||||||
<Compile Include="Logic\Export\AmazonSettlementData.cs" />
|
<Compile Include="Logic\Export\AmazonSettlement.cs" />
|
||||||
<Compile Include="Logic\Import\ValidateAmazonSettlement.cs" />
|
<Compile Include="Logic\Import\ValidateAmazonSettlement.cs" />
|
||||||
<Compile Include="Logic\Validate.cs" />
|
<Compile Include="Logic\Validate.cs" />
|
||||||
<Compile Include="Logic\Log\LogEvent.cs" />
|
<Compile Include="Logic\Log\LogEvent.cs" />
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace bnhtradeScheduledTasks
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
var task = new AmazonReport();
|
var task = new AmazonReport();
|
||||||
var task2 = new bnhtrade.Core.Logic.Export.AmazonSettlementData(sqlConnectionString);
|
var task2 = new bnhtrade.Core.Logic.Export.AmazonSettlement(sqlConnectionString);
|
||||||
task.UpdateAmazonSettlementData(sqlConnectionString);
|
task.UpdateAmazonSettlementData(sqlConnectionString);
|
||||||
task2.ToInvoice();
|
task2.ToInvoice();
|
||||||
Console.WriteLine("Complete, press any key to continue...");
|
Console.WriteLine("Complete, press any key to continue...");
|
||||||
@@ -469,7 +469,7 @@ namespace bnhtradeScheduledTasks
|
|||||||
|
|
||||||
var account = new AmazonReport();
|
var account = new AmazonReport();
|
||||||
var stock = new StockReconciliation();
|
var stock = new StockReconciliation();
|
||||||
var export = new bnhtrade.Core.Logic.Export.AmazonSettlementData(sqlConnectionString);
|
var export = new bnhtrade.Core.Logic.Export.AmazonSettlement(sqlConnectionString);
|
||||||
|
|
||||||
bool accountUpdate = false;
|
bool accountUpdate = false;
|
||||||
bool stockUpdate = false;
|
bool stockUpdate = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user