SP-API stock reconciliation

Amazon had depreciated a number of reports that were used for stock reconciliation. Application now uses the new fba ledger report to reconcile. It is currently untested, as this requires data from Amazon. Methods that require testing will return a 'NotImplementedException'.

Also, removed the depreciated ILMerge and replaced with ILRepack.

Plus much more tidying up, and improvements.
This commit is contained in:
Bobbie Hodgetts
2024-05-07 08:24:00 +01:00
committed by GitHub
parent 2f919d7b5a
commit 91ef9acc78
1272 changed files with 4944 additions and 2773311 deletions

View File

@@ -10,6 +10,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaCustomerReturn : Connection
{
Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaCustomerReturn()
{
@@ -62,9 +64,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -183,18 +184,17 @@ namespace bnhtrade.Core.Data.Database.Import
}
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
log.LogInformation((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogWarning(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1,
log.LogError("Error running FbaInventoryReceiptReportImport, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -219,8 +219,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2015-08-25T00:00:00Z"); //this before first return
// no need to specific timezone, etc, as "Z" already specifis UTC
lastRecordDate = lastRecordDate = Constants.GetBusinessStartUtc();
}
else
{
@@ -234,8 +233,7 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaReturnsReport, no records were commited",
1,
log.LogError("Error running GetFbaReturnsReport, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);

View File

@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaInventoryAdjustment : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaInventoryAdjustment()
{
@@ -59,9 +57,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -185,18 +182,17 @@ namespace bnhtrade.Core.Data.Database.Import
}
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
log.LogInformation((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaAdustmentReport method, no records were commited",
1,
log.LogError("Error running ImportFbaAdustmentReport method, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -221,8 +217,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2014-09-01T00:00:00Z");
// no need to specific timezone, etc, as "Z" already specifis UTC
lastRecordDate = lastRecordDate = Constants.GetBusinessStartUtc();
}
else
{
@@ -236,8 +231,7 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaAdustmentData, no records were commited",
1,
log.LogError("Error running GetFbaAdustmentData, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);

View File

@@ -12,6 +12,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaInventoryAgeData : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaInventoryAgeData()
{
@@ -100,9 +102,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -276,12 +277,12 @@ namespace bnhtrade.Core.Data.Database.Import
}
}
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert(
log.LogInformation(
"Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, "
+ lineNoStockSkip + " 'No Stock' records were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
@@ -290,7 +291,7 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString());
log.LogError("Something went wrong during import, check details for more.", ex.ToString());
Console.WriteLine(ex.ToString());
}
}

View File

@@ -11,10 +11,10 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaInventoryData : Connection
{
Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaInventoryData()
{
}
public void InsertByFlatFile(string filePath)
@@ -78,9 +78,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -174,12 +173,12 @@ namespace bnhtrade.Core.Data.Database.Import
}
}
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert(
log.LogInformation(
"Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, "
+ lineNoStockSkip + " 'No Stock' records were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
@@ -188,7 +187,7 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString());
log.LogError("Something went wrong during import, check details for more.", ex.ToString());
Console.WriteLine(ex.ToString());
}
}

View File

@@ -0,0 +1,256 @@
using Amazon.Runtime.Internal.Transform;
using bnhtrade.Core.Logic.Amazon.Fba;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.IO;
using System.Linq;
namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaInventoryLedgerDetail : Connection
{
public AmazonFbaInventoryLedgerDetail()
{
}
public Dictionary<int, Model.Import.AmazonFbaInventoryLedgerDetail> Insert(List<Model.Import.AmazonFbaInventoryLedgerDetail> insertList)
{
var returnDict = new Dictionary<int, Model.Import.AmazonFbaInventoryLedgerDetail>();
if (insertList == null || insertList.Any() == false)
return returnDict;
SqlConnection conn;
SqlTransaction trans;
using (conn = new SqlConnection(SqlConnectionString))
{
conn.Open();
using (trans = conn.BeginTransaction())
{
foreach (var item in insertList)
{
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO tblImportFbaInventoryLedgerDetail (
FNSKU
,ASIN
,MSKU
,Title
,[Event Type]
,[Reference ID]
,Quantity
,[Fulfillment Center]
,Disposition
,Reason
,Country
,[Reconciled Quantity]
,[Unreconciled Quantity]
,[Date and Time]
)
OUTPUT INSERTED.ImportFbaInventoryLedgerDetailID
VALUES (
@fnsku
,@asin
,@msku
,@title
,@eventType
,@referenceid
,@quantity
,@fulfillmentCenter
,@disposition
,@reason
,@country
,@reconciledQuantity
,@unreconciledQuantity
,@dateAndTime
)
", conn, trans))
{
cmd.Parameters.AddWithValue("@fnsku", item.Fnsku);
cmd.Parameters.AddWithValue("@asin", item.Asin);
cmd.Parameters.AddWithValue("@msku", item.Msku);
cmd.Parameters.AddWithValue("@title", item.Title);
cmd.Parameters.AddWithValue("@eventType", item.EventType);
cmd.Parameters.AddWithValue("@referenceid", item.ReferenceId);
cmd.Parameters.AddWithValue("@quantity", item.Quantity);
cmd.Parameters.AddWithValue("@fulfillmentCenter", item.FulfillmentCenter);
cmd.Parameters.AddWithValue("@disposition", item.Disposition);
cmd.Parameters.AddWithValue("@reason", item.Reason);
cmd.Parameters.AddWithValue("@country", item.Country);
if (item.ReconciledQuantity == null) { cmd.Parameters.AddWithValue("@reconciledQuantity", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@reconciledQuantity", item.ReconciledQuantity); }
if (item.UnreconciledQuantity == null) { cmd.Parameters.AddWithValue("@unreconciledQuantity", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@unreconciledQuantity", item.UnreconciledQuantity); }
cmd.Parameters.AddWithValue("@dateAndTime", item.DateAndTime);
object obj = cmd.ExecuteScalar();
if (obj == null || obj == DBNull.Value)
{
throw new Exception("Error inserting new defalt invoice line item into database");
}
returnDict.Add((int)obj, item);
}
}
if (insertList.Count != returnDict.Count)
throw new Exception("AmazonFbaInventoryLedgerDetail db insert failed, not all records could be commmitted. Transaction rolled back");
trans.Commit();
return returnDict;
}
}
}
/// <summary>
/// Retrives the AmazonFbaInventoryLedgerDetail object from the database
/// </summary>
/// <param name="utcFrom">date time filter</param>
/// <param name="utcTo">date time filter</param>
/// <param name="isProcessed">isprocessed filter</param>
/// <returns>dictionary key=AmazonFbaInventoryLedgerDetailIs, value=AmazonFbaInventoryLedgerDetail object</returns>
public Dictionary<int, Model.Import.AmazonFbaInventoryLedgerDetail> Read(DateTime? utcFrom = null, DateTime? utcTo = null, bool? isProcessed = null)
{
var resultList = new Dictionary<int, Model.Import.AmazonFbaInventoryLedgerDetail>();
string sql = @"
SELECT TOP (1000) [ImportFbaInventoryLedgerDetailId]
,[FNSKU]
,[ASIN]
,[MSKU]
,[Title]
,[Event Type]
,[Reference ID]
,[Quantity]
,[Fulfillment Center]
,[Disposition]
,[Reason]
,[Country]
,[Reconciled Quantity]
,[Unreconciled Quantity]
,[Date and Time]
,[IsProcessed]
,[StockSkuTransactionID]
FROM [e2A].[dbo].[tblImportFbaInventoryLedgerDetail]
WHERE 1=1";
if (utcFrom != null)
sql = sql + " AND [Date and Time] >= @utcFrom";
if (utcTo != null)
sql = sql + " AND [Date and Time] <= @utcFrom";
if (isProcessed != null)
sql = sql + " AND [IsProcessed] = @isProcessed";
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
if (utcFrom != null)
cmd.Parameters.AddWithValue("@utcFrom", utcFrom);
if (utcTo != null)
cmd.Parameters.AddWithValue("@utcFrom", utcTo);
if (isProcessed != null)
cmd.Parameters.AddWithValue("@isProcessed", isProcessed);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
var result = new Model.Import.AmazonFbaInventoryLedgerDetail();
result.Fnsku = reader.GetString(1);
result.Asin = reader.GetString(2);
result.Msku = reader.GetString(3);
result.Title = reader.GetString(4);
result.EventType = reader.GetString(5);
if (!reader.IsDBNull(6))
result.ReferenceId = reader.GetString(6);
result.Quantity = reader.GetInt32(7);
result.FulfillmentCenter = reader.GetString(8);
result.Disposition = reader.GetString(9);
if (!reader.IsDBNull(10))
result.Reason = reader.GetString(10);
result.Country = reader.GetString(11);
if (!reader.IsDBNull(12))
result.ReconciledQuantity = reader.GetInt32(12);
if (!reader.IsDBNull(13))
result.UnreconciledQuantity = reader.GetInt32(13);
result.DateAndTime = DateTime.SpecifyKind(reader.GetDateTime(14), DateTimeKind.Utc);
resultList.Add(reader.GetInt32(0), result);
}
}
return resultList;
}
}
}
}
/// <summary>
/// Set the record as processed, where no entry has been made into the stock sku transaction table
/// </summary>
public void UpdateIsProcessed(int fbaInventoryLedgerDetailId, bool isProcessed)
{
UpdateIsProcessed(fbaInventoryLedgerDetailId, isProcessed, null);
}
/// <summary>
/// Set the record as processed, and an entry has been made into the stock sku transaction table
/// </summary>
public void UpdateIsProcessed(int fbaInventoryLedgerDetailId, int stockSkuTransactionId)
{
UpdateIsProcessed(fbaInventoryLedgerDetailId, true, stockSkuTransactionId);
}
/// <summary>
/// Use of the two methods above ensures that the transactionId can not be set when the isProcessed is false
/// </summary>
private void UpdateIsProcessed(int fbaInventoryLedgerDetailId, bool? isProcessed, int? stockSkuTransactionId)
{
string sql = @"
UPDATE
tblImportFbaInventoryLedgerDetail
SET
IsProcessed = @isProcessed
, StockSkuTransactionID = @stockSkuTransactionId
WHERE
(ImportFbaInventoryLedgerDetailID = @fbaInventoryLedgerDetailId)";
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
if (isProcessed == null) { cmd.Parameters.AddWithValue("@isProcessed", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@isProcessed", isProcessed); }
if (stockSkuTransactionId == null) { cmd.Parameters.AddWithValue("@stockSkuTransactionId", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@stockSkuTransactionId", stockSkuTransactionId); }
cmd.Parameters.AddWithValue("@fbaInventoryLedgerDetailId", fbaInventoryLedgerDetailId);
int i = cmd.ExecuteNonQuery();
if (i < 1)
throw new Exception("No row were effected by the update operation");
if (i > 1)
throw new Exception("Multiple rows were effected by the update operation");
}
}
}
}
}

View File

@@ -11,6 +11,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaInventoryReceipt : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaInventoryReceipt()
{
@@ -42,9 +44,9 @@ namespace bnhtrade.Core.Data.Database.Import
// create notification if amazon add extra headers
if (columnCount > 7)
{
new Logic.Log.LogEvent().EventLogInsert(
"Amazon have added a new column to their 'Fba Inventory Receipt' report, you may want to check this out.",
2);
log.LogWarning(
"Amazon have added a new column to their 'Fba Inventory Receipt' report, you may want to check this out."
);
}
int indexOfReceivedDate = Array.IndexOf(headers, "received-date");
@@ -66,9 +68,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -142,18 +143,17 @@ namespace bnhtrade.Core.Data.Database.Import
// only commit if records all complete with no errors -- ommiting duplcates relies on all records from one day being committed together
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineOutsideScope)) + " total report items inserted into db, " + lineOutsideScope + " item(s) outside of requested time scope where skipped.");
log.LogInformation((lineNumber - (1 + lineErrorSkip + lineOutsideScope)) + " total report items inserted into db, " + lineOutsideScope + " item(s) outside of requested time scope where skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1,
log.LogError("Error running FbaInventoryReceiptReportImport, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -178,8 +178,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2014-09-01T00:00:00Z");
// no need to specific timezone, etc, as "Z" already specifis UTC
lastRecordDate = lastRecordDate = Constants.GetBusinessStartUtc();
}
else
{
@@ -193,8 +192,7 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1,
log.LogError("Error running FbaInventoryReceiptReportImport, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);

View File

@@ -1,15 +1,24 @@
using System;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Finances;
using FikaAmazonAPI.ConstructFeed.Messages;
using NUnit.Framework.Constraints;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaReimbursement : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaReimbursement()
{
@@ -66,9 +75,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -228,18 +236,17 @@ namespace bnhtrade.Core.Data.Database.Import
}
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
log.LogInformation((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaReimbursementReport method, no records were commited",
1,
log.LogError("Error running ImportFbaReimbursementReport method, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -264,8 +271,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2014-09-01T00:00:00Z");
// no need to specific timezone, etc, as "Z" already specifis UTC
lastRecordDate = lastRecordDate = Constants.GetBusinessStartUtc();
}
else
{
@@ -279,13 +285,124 @@ namespace bnhtrade.Core.Data.Database.Import
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaReimbursementData, no records were commited",
1,
log.LogError("Error running GetFbaReimbursementData, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
throw ex;
}
}
public List<Model.Import.FbaReimbursementReport> Read(bool? isProcessed = null)
{
var returnList = new List<Model.Import.FbaReimbursementReport>();
string sql = @"
SELECT
[ImportFbaReimbursementReportID]
,[approval-date]
,[reimbursement-id]
,[case-id]
,[amazon-order-id]
,[reason]
,[sku]
,[fnsku]
,[asin]
,[condition]
,[currency-unit]
,[amount-per-unit]
,[amount-total]
,[quantity-reimbursed-cash]
,[quantity-reimbursed-inventory]
,[quantity-reimbursed-total]
,[IsProcessed]
,[StockSkuTransactionID]
FROM [tblImportFbaReimbursementReport]
where (1=1) ";
if (isProcessed.HasValue)
{
if (isProcessed == true)
{
sql = sql + " AND (IsProcessed = 1) ";
}
else
{
sql = sql + " AND (IsProcessed = 0) ";
}
}
SqlConnection sqlConn;
using (sqlConn = new SqlConnection(SqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(sql, sqlConn))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var item = new Model.Import.FbaReimbursementReport();
item.FbaReimbursementReportID = reader.GetInt32(0);
item.ApprovalDate = DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
item.ReimbursementId = reader.GetString(2);
if (!reader.IsDBNull(3)) { item.CaseId = reader.GetString(3); }
if (!reader.IsDBNull(4)) { item.AmazonOrderId = reader.GetString(4); }
item.Reason = reader.GetString(5);
item.Sku = reader.GetString(6);
item.Fnsku = reader.GetString(7);
item.Asin = reader.GetString(8);
item.Condition = reader.GetString(9);
item.CurrencyUnit = reader.GetString(10);
item.AmountPerUnit = reader.GetInt32(11);
item.AmountTotal = reader.GetInt32(12);
item.QuantityReimbursedCash = reader.GetInt32(13);
item.QuantityReimbursedInventory = reader.GetInt32(14);
item.QuantityReimbursedTotal = reader.GetInt32(15);
item.IsProcessed = reader.GetBoolean(16);
if (!reader.IsDBNull(17)) { item.StockSkuTransactionID = reader.GetInt32(17); }
returnList.Add(item);
}
}
}
}
return returnList;
}
public void UpdateIsProcessed(int fbaReimbursementReportID, bool isProcessed, int? stockSkuTransactionId)
{
// consistancy checks
if (isProcessed == false && stockSkuTransactionId.HasValue)
{
throw new ArgumentException("Consistancy check error, incorrect argument combination passed to function");
}
string sql = @"
UPDATE
tblImportFbaReimbursementReport
SET
IsProcessed=@isProcessed
, StockSkuTransactionID=@transactionId
WHERE
ImportFbaReimbursementReportID=@importTableId;
";
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@importTableId", fbaReimbursementReportID);
cmd.Parameters.AddWithValue("@isProcessed", isProcessed);
if (stockSkuTransactionId.HasValue) { cmd.Parameters.AddWithValue("@transactionId", stockSkuTransactionId); }
else { cmd.Parameters.AddWithValue("@transactionId", DBNull.Value); }
cmd.ExecuteNonQuery();
}
}
}
}
}

View File

@@ -10,6 +10,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaRemovalOrder : Connection
{
Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaRemovalOrder()
{
@@ -66,9 +68,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -175,18 +176,17 @@ namespace bnhtrade.Core.Data.Database.Import
}
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert("ImportFbaRemovalOrderReport() " + (lineNumber - (1 + lineErrorSkip + lineUpdate)) + " records created, " + lineUpdate + " records updated.");
log.LogInformation("ImportFbaRemovalOrderReport() " + (lineNumber - (1 + lineErrorSkip + lineUpdate)) + " records created, " + lineUpdate + " records updated.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogInformation(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaRemovalOrderReport method, no records were commited",
1,
log.LogError("Error running ImportFbaRemovalOrderReport method, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -194,47 +194,5 @@ namespace bnhtrade.Core.Data.Database.Import
}
return true;
}
public DateTime ReadRecentDate()
{
DateTime lastRecordDate;
SqlConnection sqlConn;
try
{
using (sqlConn = new SqlConnection(SqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(
"SELECT Max([request-date]) AS MaxDate FROM tblImportFbaRemovalOrderReport;"
, sqlConn))
{
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2015-09-15T00:00:00Z");
// no need to specific timezone, etc, as "Z" already specifis UTC
}
else
{
lastRecordDate = ((DateTime)cmd.ExecuteScalar());
lastRecordDate = DateTime.SpecifyKind(lastRecordDate, DateTimeKind.Utc);
lastRecordDate = lastRecordDate.AddDays(-30); // yes, that's right -30 days
//startTime = DateTime.Parse("2015-05-01T00:00:00Z");
}
return lastRecordDate;
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaRemovalOrderReport, no records were commited",
1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
throw ex;
}
}
}
}

View File

@@ -11,6 +11,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonFbaSaleShipment : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonFbaSaleShipment()
{
@@ -96,9 +98,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineErrorSkip = lineErrorSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -280,18 +281,17 @@ namespace bnhtrade.Core.Data.Database.Import
}
trans.Commit();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
log.LogInformation((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1,
log.LogError("Error running FbaInventoryReceiptReportImport, no records were commited",
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
@@ -585,48 +585,6 @@ namespace bnhtrade.Core.Data.Database.Import
return returnList;
}
public DateTime ReadRecentDate()
{
DateTime lastRecordDate;
SqlConnection sqlConn;
try
{
using (sqlConn = new SqlConnection(SqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(
"SELECT Max([shipment-date]) AS MaxDate FROM tblImportFbaSaleShipment;"
, sqlConn))
{
if (cmd.ExecuteScalar() == DBNull.Value)
{
// use first month started selling on Amazon
lastRecordDate = DateTime.Parse("2014-09-01T00:00:00Z");
// no need to specific timezone, etc, as "Z" already specifis UTC
lastRecordDate = DateTime.Parse("2016-02-01T00:00:00Z");
// fba sale shipments for previous 18 months only
}
else
{
lastRecordDate = ((DateTime)cmd.ExecuteScalar());
lastRecordDate = DateTime.SpecifyKind(lastRecordDate, DateTimeKind.Utc);
}
return lastRecordDate;
}
}
}
catch (Exception ex)
{
new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
);
throw ex;
}
}
public Dictionary<string, int> ReadSaleCount(List<string> skuNumber, DateTime periodStart, DateTime periodEnd)
{
var returnList = new Dictionary<string, int>();

View File

@@ -11,6 +11,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
public class AmazonSettlementInsert : Connection
{
Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public AmazonSettlementInsert ()
{
@@ -84,9 +86,8 @@ namespace bnhtrade.Core.Data.Database.Import
{
// skip line
lineSkip = lineSkip + 1;
new Logic.Log.LogEvent().EventLogInsert(
log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
2,
filePath
);
}
@@ -102,7 +103,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (recordCount > 0)
{
UpdateSpapiReportId(items[indexSettlementId], reportId);
new Logic.Log.LogEvent().EventLogInsert("Settlement report already imported, skipping...");
log.LogInformation("Settlement report already imported, skipping...");
scope.Complete();
return true;
}
@@ -285,18 +286,18 @@ namespace bnhtrade.Core.Data.Database.Import
if (sumOfAmount != settlementAmount)
{
new Logic.Log.LogEvent().EventLogInsert("Error importing settlement id'" + settlementRef + "'. Sum of inserted settlement lines (" + sumOfAmount +
") does not match settlement amount (" + settlementAmount + ").", 1);
log.LogError("Error importing settlement id'" + settlementRef + "'. Sum of inserted settlement lines (" + sumOfAmount +
") does not match settlement amount (" + settlementAmount + ").");
return false;
}
}
scope.Complete();
Console.Write("\r");
new Logic.Log.LogEvent().EventLogInsert((lineNumber - (2 + lineSkip)) + " total settlement items inserted");
log.LogInformation((lineNumber - (2 + lineSkip)) + " total settlement items inserted");
if (lineSkip > 0)
{
new Logic.Log.LogEvent().EventLogInsert(lineSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
log.LogError(lineSkip + " total line(s) where skipped due to insufficent number of cells on row");
}
}
}