6 Commits

64 changed files with 224 additions and 213 deletions
+15 -1
View File
@@ -12,7 +12,21 @@ namespace bnhtrade.Core
{
public string GetAppDataPath()
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\bnhtrade\";
string path = null;
if (OperatingSystem.IsWindows())
{
path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
+ @"\bnhtrade\";
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
+ "/.bnhtrade/";
}
else
{
throw new PlatformNotSupportedException("Unsupported operating system");
}
return path;
}
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
namespace bnhtrade.Core.Data.Database
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -1,5 +1,5 @@
using System;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
namespace bnhtrade.Core.Data.Database.Import
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -2,7 +2,7 @@
using bnhtrade.Core.Logic.Amazon.Fba;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.IO;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -3,7 +3,7 @@ using FikaAmazonAPI.ConstructFeed.Messages;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Runtime.ConstrainedExecution;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -1,7 +1,7 @@
using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -2,7 +2,6 @@
using bnhtrade.Core.Data.Database.Repository.Interface;
using bnhtrade.Core.Model.Amazon;
using Microsoft.Data.SqlClient;
using Microsoft.VisualBasic.Logging;
using System;
using System.Collections.Generic;
using System.Data;
@@ -369,7 +368,7 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
//
/// <summary>
/// Update the settlement report marketplace name by settlement Id (not table id)
/// Update the settlement report marketplace name by settlement Id (not row id)
/// </summary>
/// <param name="settlementId">Settlement id (not table/record id) of the settlement to update</param>
/// <param name="marketPlaceName">marketplace name</param>
@@ -433,13 +432,13 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
/// Takes a Settlement Report flat file from Amazon and imports it into the database.
/// </summary>
/// <param name="filePath">path to the Amazon report flat file</param>
/// <param name="reportId">The unique Amazon SP-API report id (not settlement id)</param>
/// <param name="spapiReportId">The unique Amazon SP-API report id (not settlement id)</param>
/// <returns></returns>
public bool CreateAmazonSettlements(string filePath, string reportId)
public bool CreateAmazonSettlements(string filePath, string spapiReportId)
{
int settlementReportId = 0;
string settlementRef = "";
bool marketPlaceUpdated = false;
string settlementRef = null;
string marketplaceName = null;
decimal settlementAmount = 0m;
int lineNumber = 2;
int lineSkip = 0;
@@ -479,17 +478,17 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
int indexQuantityPurchased = Array.IndexOf(headers, "quantity-purchased");
int indexPromotionId = Array.IndexOf(headers, "promotion-id");
string currency = "";
string currency = null;
string fileRow;
while ((fileRow = reader.ReadLine()) != null)
{
Console.Write("\rParsing record: " + lineNumber);
//split line into array
string[] items = fileRow.Split('\t');
if (items.Length != columnCount)
string[] rowArray = fileRow.Split('\t');
if (rowArray.Length != columnCount)
{
// skip line
// skip line, check settlement total at the end
lineSkip = lineSkip + 1;
_log.LogWarning(
"Line #" + lineNumber + " skipped due to no enough element in row.",
@@ -498,28 +497,25 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
}
else if (lineNumber == 2)
{
// check if settlement has already been imported
settlementRef = rowArray[indexSettlementId];
currency = rowArray[indexCurrency];
settlementAmount = decimal.Parse(rowArray[indexTotalAmount].Replace(",", "."));
// check if settlement has already been imported
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
{
cmd.CommandText = "SELECT COUNT(*) FROM tblImportAmazonSettlementReport WHERE [settlement-id]=@settlementId;";
cmd.Transaction = _transaction as SqlTransaction;
cmd.Parameters.AddWithValue("@settlementId", items[indexSettlementId]);
cmd.Parameters.AddWithValue("@settlementId", rowArray[indexSettlementId]);
int recordCount = (int)cmd.ExecuteScalar();
if (recordCount > 0)
{
SetSpapiReportId(items[indexSettlementId], reportId);
SetSpapiReportId(rowArray[indexSettlementId], spapiReportId);
_log.LogInformation("Settlement report already imported, skipping...");
return true;
}
}
//set currencyId
//currencyId = GeneralQueries.GetCurrencyId(items[5]);
//set currency
currency = items[indexCurrency];
settlementAmount = decimal.Parse(items[indexTotalAmount].Replace(",", "."));
// insert
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
@@ -543,61 +539,38 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
,@depositDate
,@settlementotalAmounttId
,@currency
,@reportId
,@spapiReportId
);";
// add parameters
if (indexSettlementId == -1 || items[indexSettlementId].Length == 0) { cmd.Parameters.AddWithValue("@settlementId", DBNull.Value); }
else
{
settlementRef = items[indexSettlementId];
cmd.Parameters.AddWithValue("@settlementId", settlementRef);
}
var parseDateTime = new Core.Logic.Utilities.DateTime();
if (indexSettlementStartDate == -1 || items[indexSettlementStartDate].Length == 0) { cmd.Parameters.AddWithValue("@settlementStartDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementStartDate])); }
if (indexSettlementEndDate == -1 || items[indexSettlementEndDate].Length == 0) { cmd.Parameters.AddWithValue("@settlementEndDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementEndDate])); }
if (indexDepositDate == -1 || items[indexDepositDate].Length == 0) { cmd.Parameters.AddWithValue("@depositDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@depositDate", parseDateTime.ParseIsoDateTimeString(items[indexDepositDate])); }
if (indexTotalAmount == -1 || items[indexTotalAmount].Length == 0) { cmd.Parameters.AddWithValue("@totalAmount", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@settlementotalAmounttId", settlementAmount); }
if (string.IsNullOrWhiteSpace(reportId)) { cmd.Parameters.AddWithValue("@reportId", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@reportId", reportId); }
// add parameters
cmd.Parameters.AddWithValue("@settlementId", rowArray[indexSettlementId]);
cmd.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexSettlementStartDate]));
cmd.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexSettlementEndDate]));
cmd.Parameters.AddWithValue("@depositDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexDepositDate]));
cmd.Parameters.AddWithValue("@settlementotalAmounttId", settlementAmount);
if (string.IsNullOrWhiteSpace(spapiReportId)) { cmd.Parameters.AddWithValue("@spapiReportId", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@spapiReportId", spapiReportId); }
cmd.Parameters.AddWithValue("@currency", currency);
//if (currencyId == -1) { sqlCommand.Parameters.AddWithValue("@currencyId", DBNull.Value); }
//else { sqlCommand.Parameters.AddWithValue("@currencyId", currencyId); }
//execute and retrive id
settlementReportId = (int)cmd.ExecuteScalar();
}
}
else
{
//update market place name in main table, if required
if (marketPlaceUpdated == false && settlementReportId > 0 && items[indexMarketplaceName].Length > 1)
// attempt to retrieve marketplace name for header table
if (rowArray[indexMarketplaceName].Length > 1 && settlementReportId > 0)
{
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
if (marketplaceName == null)
{
cmd.Transaction = _transaction as SqlTransaction;
cmd.CommandText = @"
UPDATE tblImportAmazonSettlementReport
SET [marketplace-name]=@MarketplaceName
WHERE ImportAmazonSettlementReportID=@ImportAmazonSettlementReportID;";
cmd.Parameters.AddWithValue("@MarketplaceName", items[indexMarketplaceName]);
cmd.Parameters.AddWithValue("@ImportAmazonSettlementReportID", settlementReportId);
cmd.ExecuteNonQuery();
marketPlaceUpdated = true;
marketplaceName = rowArray[indexMarketplaceName];
}
else if (marketplaceName != rowArray[indexMarketplaceName])
{
_log.LogError("Marketplace name '" + rowArray[indexMarketplaceName] + "' on line " + lineNumber +
" is different from marketplace name '" + marketplaceName + "' on previous line. This shouldn't be possible!");
}
}
@@ -620,67 +593,95 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
cmd.Parameters.AddWithValue("@currency", currency);
if (indexTransactionType == -1 || items[indexTransactionType].Length == 0) { cmd.Parameters.AddWithValue("@TransactionType", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@TransactionType", items[indexTransactionType]); }
if (indexTransactionType == -1 || rowArray[indexTransactionType].Length == 0) { cmd.Parameters.AddWithValue("@TransactionType", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@TransactionType", rowArray[indexTransactionType]); }
if (indexOrderId == -1 || items[indexOrderId].Length == 0) { cmd.Parameters.AddWithValue("@orderRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@orderRef", items[indexOrderId]); }
if (indexOrderId == -1 || rowArray[indexOrderId].Length == 0) { cmd.Parameters.AddWithValue("@orderRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@orderRef", rowArray[indexOrderId]); }
if (indexMerchantOrderId == -1 || items[indexMerchantOrderId].Length == 0) { cmd.Parameters.AddWithValue("@merchantOrderRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@merchantOrderRef", items[indexMerchantOrderId]); }
if (indexMerchantOrderId == -1 || rowArray[indexMerchantOrderId].Length == 0) { cmd.Parameters.AddWithValue("@merchantOrderRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@merchantOrderRef", rowArray[indexMerchantOrderId]); }
if (indexAdjustmentId == -1 || items[indexAdjustmentId].Length == 0) { cmd.Parameters.AddWithValue("@AdjustmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@AdjustmentRef", items[indexAdjustmentId]); }
if (indexAdjustmentId == -1 || rowArray[indexAdjustmentId].Length == 0) { cmd.Parameters.AddWithValue("@AdjustmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@AdjustmentRef", rowArray[indexAdjustmentId]); }
if (indexShipmentId == -1 || items[indexShipmentId].Length == 0) { cmd.Parameters.AddWithValue("@ShipmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@ShipmentRef", items[indexShipmentId]); }
if (indexShipmentId == -1 || rowArray[indexShipmentId].Length == 0) { cmd.Parameters.AddWithValue("@ShipmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@ShipmentRef", rowArray[indexShipmentId]); }
if (indexMarketplaceName == -1 || items[indexMarketplaceName].Length == 0) { cmd.Parameters.AddWithValue("@MarketplaceName", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MarketplaceName", items[indexMarketplaceName]); }
if (indexMarketplaceName == -1 || rowArray[indexMarketplaceName].Length == 0) { cmd.Parameters.AddWithValue("@MarketplaceName", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MarketplaceName", rowArray[indexMarketplaceName]); }
if (indexAmountType == -1 || items[indexAmountType].Length == 0) { cmd.Parameters.AddWithValue("@AmountType", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@AmountType", items[indexAmountType]); }
if (indexAmountType == -1 || rowArray[indexAmountType].Length == 0) { cmd.Parameters.AddWithValue("@AmountType", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@AmountType", rowArray[indexAmountType]); }
if (indexAmountDescription == -1 || items[indexAmountDescription].Length == 0) { cmd.Parameters.AddWithValue("@AmountDescription", DBNull.Value); }
if (indexAmountDescription == -1 || rowArray[indexAmountDescription].Length == 0) { cmd.Parameters.AddWithValue("@AmountDescription", DBNull.Value); }
else
{
string amountDescription = items[indexAmountDescription];
string amountDescription = rowArray[indexAmountDescription];
if (amountDescription.Length > 100) { amountDescription = amountDescription.Substring(0, 100); }
cmd.Parameters.AddWithValue("@AmountDescription", amountDescription);
}
if (indexAmount == -1 || items[indexAmount].Length == 0) { cmd.Parameters.AddWithValue("@Amount", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@Amount", decimal.Parse(items[indexAmount].Replace(",", "."))); }
if (indexAmount == -1 || rowArray[indexAmount].Length == 0) { cmd.Parameters.AddWithValue("@Amount", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@Amount", decimal.Parse(rowArray[indexAmount].Replace(",", "."))); }
if (indexFulfillmentId == -1 || items[indexFulfillmentId].Length == 0) { cmd.Parameters.AddWithValue("@FulfillmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@FulfillmentRef", items[indexFulfillmentId]); }
if (indexFulfillmentId == -1 || rowArray[indexFulfillmentId].Length == 0) { cmd.Parameters.AddWithValue("@FulfillmentRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@FulfillmentRef", rowArray[indexFulfillmentId]); }
if (indexPostedDateTime == -1 || items[indexPostedDateTime].Length == 0) { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTime().ParseIsoDateTimeString(items[indexPostedDateTime])); }
if (indexPostedDateTime == -1 || rowArray[indexPostedDateTime].Length == 0) { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTime().ParseIsoDateTimeString(rowArray[indexPostedDateTime])); }
if (indexOrderItemCode == -1 || items[indexOrderItemCode].Length == 0) { cmd.Parameters.AddWithValue("@OrderItemCode", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@OrderItemCode", long.Parse(items[indexOrderItemCode])); }
if (indexOrderItemCode == -1 || rowArray[indexOrderItemCode].Length == 0) { cmd.Parameters.AddWithValue("@OrderItemCode", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@OrderItemCode", long.Parse(rowArray[indexOrderItemCode])); }
if (indexMerchantOrderItemId == -1 || items[indexMerchantOrderItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", long.Parse(items[indexMerchantOrderItemId])); }
if (indexMerchantOrderItemId == -1 || rowArray[indexMerchantOrderItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", long.Parse(rowArray[indexMerchantOrderItemId])); }
if (indexMerchantAdjustmentItemId == -1 || items[indexMerchantAdjustmentItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", items[indexMerchantAdjustmentItemId]); }
if (indexMerchantAdjustmentItemId == -1 || rowArray[indexMerchantAdjustmentItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", rowArray[indexMerchantAdjustmentItemId]); }
if (indexSku == -1 || items[indexSku].Length == 0) { cmd.Parameters.AddWithValue("@SkuNumber", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@SkuNumber", items[indexSku]); }
if (indexSku == -1 || rowArray[indexSku].Length == 0) { cmd.Parameters.AddWithValue("@SkuNumber", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@SkuNumber", rowArray[indexSku]); }
if (indexQuantityPurchased == -1 || items[indexQuantityPurchased].Length == 0) { cmd.Parameters.AddWithValue("@QuantityPurchased", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@QuantityPurchased", int.Parse(items[indexQuantityPurchased])); }
if (indexQuantityPurchased == -1 || rowArray[indexQuantityPurchased].Length == 0) { cmd.Parameters.AddWithValue("@QuantityPurchased", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@QuantityPurchased", int.Parse(rowArray[indexQuantityPurchased])); }
if (indexPromotionId == -1 || items[indexPromotionId].Length == 0) { cmd.Parameters.AddWithValue("@PromotionRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@PromotionRef", items[indexPromotionId]); }
if (indexPromotionId == -1 || rowArray[indexPromotionId].Length == 0) { cmd.Parameters.AddWithValue("@PromotionRef", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@PromotionRef", rowArray[indexPromotionId]); }
cmd.ExecuteNonQuery();
}
}
lineNumber = lineNumber + 1;
}
// end of filestream reading
// if we haven't gotten the marketplace name from the line items, attempt to infer from currency
if (marketplaceName == null && settlementReportId > 0)
{
if (currency == "GBP")
{
marketplaceName = MarketPlaceEnum.AmazonUK.GetMarketplaceUrl();
marketplaceName = char.ToUpper(marketplaceName[0]) + marketplaceName.Substring(1);
}
}
// finally, if we have it, add marketplace name to main table
if (marketplaceName != null && settlementReportId > 0)
{
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
{
cmd.Transaction = _transaction as SqlTransaction;
cmd.CommandText = @"
UPDATE tblImportAmazonSettlementReport
SET [marketplace-name]=@MarketplaceName
WHERE ImportAmazonSettlementReportID=@ImportAmazonSettlementReportID;";
cmd.Parameters.AddWithValue("@MarketplaceName", marketplaceName);
cmd.Parameters.AddWithValue("@ImportAmazonSettlementReportID", settlementReportId);
cmd.ExecuteNonQuery();
}
}
}
//final check - settlement amount matches sum of inserted settlement lines
@@ -340,19 +340,19 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
WHERE 1 = 1 ";
// build the where statments
if (invoiceIdList != null || invoiceIdList.Any())
if (invoiceIdList != null && invoiceIdList.Any())
{
sqlBuilder.In("PurchaseID", invoiceLineIdList, "AND");
}
if (invoiceLineIdList != null || invoiceLineIdList.Any())
if (invoiceLineIdList != null && invoiceLineIdList.Any())
{
sqlBuilder.In("PurchaseLineID", invoiceLineIdList, "AND");
}
if (statusList != null || statusList.Any())
if (statusList != null && statusList.Any())
{
sqlBuilder.In("PurchaseLineStatus", invoiceLineIdList, "AND");
}
if (itemDescriptionList != null || itemDescriptionList.Any())
if (itemDescriptionList != null && itemDescriptionList.Any())
{
sqlBuilder.LikeAnd("ItemDescription", itemDescriptionList, "AND");
}
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Data.Database.Sku.Price
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,7 +1,7 @@
using bnhtrade.Core.Data.Database._BoilerPlate;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,5 +1,5 @@
using System;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Data.Database.Stock
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Configuration;
namespace bnhtrade.Core.Data.Database.UnitOfWork
@@ -1,7 +1,6 @@
using bnhtrade.Core.Test.Amazon.SP_API;
using CsvHelper;
using CsvHelper.Configuration.Attributes;
using Microsoft.VisualBasic.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@@ -4,7 +4,7 @@ using FikaAmazonAPI.ConstructFeed.Messages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
@@ -268,45 +268,6 @@ namespace bnhtrade.Core.Logic.Account
}
}
private DateTime GetHmrcMaxPeriodAvaible()
{
// HMRC monthly exchange rates are published on the penultimate Thursday of the month before
// For some leeeeeeeeway we'll use the penultimate Friday
// find penultimate Friday for current month
var ukTimeNow = new Logic.Utilities.DateTime().ConvertUtcToUk(DateTime.UtcNow);
var monthDayCount = DateTime.DaysInMonth(ukTimeNow.Year, ukTimeNow.Month);
var thisMonthPenultimateFriday = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, monthDayCount), DateTimeKind.Unspecified);
int count = 0;
int fridayCount = 0;
while (count != 15)
{
if (thisMonthPenultimateFriday.DayOfWeek == DayOfWeek.Friday)
{
fridayCount++;
if (fridayCount == 2)
{
break;
}
}
thisMonthPenultimateFriday = thisMonthPenultimateFriday.AddDays(-1);
count++;
}
if (count == 15)
{
throw new Exception("Something went wrong here ErrorID:ef7f5d8f-0f7b-4014-aa65-421ecd5d7367");
}
var mostRecentPeriodAvaible = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, 1), DateTimeKind.Unspecified); ;
if (ukTimeNow >= thisMonthPenultimateFriday)
{
mostRecentPeriodAvaible = mostRecentPeriodAvaible.AddMonths(1);
}
return mostRecentPeriodAvaible;
}
public void UpdateHmrcExchageRates()
{
Init();
@@ -381,16 +342,48 @@ namespace bnhtrade.Core.Logic.Account
}
// check if retrival from hmrc is required
var hmrcMaxMonthAvaible = GetHmrcMaxPeriodAvaible();
if (hmrcMonthToRetrive.Year == hmrcMaxMonthAvaible.Year && hmrcMonthToRetrive.Month > hmrcMaxMonthAvaible.Month)
// find penultimate Friday for current month
var ukTimeNow = new Logic.Utilities.DateTime().ConvertUtcToUk(DateTime.UtcNow);
var monthDayCount = DateTime.DaysInMonth(ukTimeNow.Year, ukTimeNow.Month);
var thisMonthPenultimateFriday = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, monthDayCount), DateTimeKind.Unspecified);
int dayCount = 0;
int fridayCount = 0;
while (dayCount < 15)
{
if (thisMonthPenultimateFriday.DayOfWeek == DayOfWeek.Friday)
{
fridayCount++;
if (fridayCount == 2)
{
break;
}
}
thisMonthPenultimateFriday = thisMonthPenultimateFriday.AddDays(-1);
dayCount++;
}
if (dayCount == 15)
{
throw new Exception("Something went wrong here ErrorID:ef7f5d8f-0f7b-4014-aa65-421ecd5d7367");
}
var mostRecentPeriodAvaible = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, 1), DateTimeKind.Unspecified); ;
if (ukTimeNow >= thisMonthPenultimateFriday)
{
mostRecentPeriodAvaible = mostRecentPeriodAvaible.AddMonths(1);
}
if (hmrcMonthToRetrive.Year >= mostRecentPeriodAvaible.Year && hmrcMonthToRetrive.Month > mostRecentPeriodAvaible.Month)
{
// nothing to retrive
_log.LogInformation("Exchange rates curretly up to date, exiting.");
int days = (thisMonthPenultimateFriday - DateTime.UtcNow).Days;
_log.LogInformation($"Exchange rates up to date, next HMRC update in {days} days for {hmrcMonthToRetrive.ToString("MMM yyyy")}.");
_log.LogInformation($"Stopping update database HMRC exchange rates.");
return;
}
// get info from hmrc and insert data in db
while (hmrcMonthToRetrive <= hmrcMaxMonthAvaible)
while (hmrcMonthToRetrive <= mostRecentPeriodAvaible)
{
count = 0;
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace bnhtrade.Core.Logic.Account
{
+1 -1
View File
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -173,10 +173,12 @@ namespace bnhtrade.Core.Logic.Export.AccountInvoice
null, new List<string> { settlementList[i].MarketPlace.GetMarketplaceUrl() }, true, true, 1);
if (completedSettlement.Any())
{
if (completedSettlement.FirstOrDefault().Value.EndDate != settlementList[i].StartDate)
var tempEndDate = completedSettlement.FirstOrDefault().Value.EndDate;
if (tempEndDate != settlementList[i].StartDate)
{
string error = (settlementList[i].StartDate - settlementList[i - 1].EndDate).Days + " day gap in "
+ settlementList[i].MarketPlace.GetMarketplaceUrl() + " settlement data (" + settlementList[i - 1].EndDate.ToString("dd MMM yyyy")
string error = (settlementList[i].StartDate - tempEndDate).Days + " day gap in "
+ settlementList[i].MarketPlace.GetMarketplaceUrl() + " settlement data (" + tempEndDate.ToString("dd MMM yyyy")
+ " to " + settlementList[i].StartDate.ToString("dd MMM yyyy") + "). Ensure all settlement reports have been imported.";
ErrorMessage = error;
_log.LogError("Cancelled processing of Amazon settlement data into invoice export queue: " + error);
@@ -1,7 +1,7 @@
using CsvHelper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Logic.Sku.Price
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Transactions;
using System.Windows.Forms;
namespace bnhtrade.Core.Logic.Sku
{
@@ -1,7 +1,7 @@
using bnhtrade.Core.Data.Database;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
@@ -3,7 +3,7 @@ using bnhtrade.Core.Model.Stock;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Restrictions;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -1,7 +1,7 @@
using bnhtrade.Core.Data.Database;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+1 -2
View File
@@ -1,5 +1,4 @@
using Microsoft.VisualBasic;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
@@ -28,7 +28,7 @@ namespace bnhtrade.Core.Model.Credentials
{
return "Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString()
+ ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString()
+ ";Connect Timeout=" + ConnectionTimeout + ";Encrypt=True;TrustServerCertificate=True";
+ ";Connect Timeout=" + ConnectionTimeout + ";Encrypt=True";
}
}
@@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.Design;
using System.Xml;
using System.Xml.Linq;
+2 -3
View File
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<!--Added the line below to copy all dll from .nuget folder to build output folder-->
<!--CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies-->
</PropertyGroup>
@@ -40,6 +38,7 @@
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.4" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>C:\Users\Bobbie\Desktop\bnhtrade</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
</Project>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>bnhtrade_Scheduled_Tasks</RootNamespace>
<AssemblyName>bnhtradeScheduledTasks</AssemblyName>