Skip to content

Commit 2f658f9

Browse files
authored
Merge pull request #202 from kevinvenclovas/main
added GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING report
2 parents 49963a6 + a62774a commit 2f658f9

File tree

5 files changed

+175
-33
lines changed

5 files changed

+175
-33
lines changed

Source/FikaAmazonAPI/ReportGeneration/DataConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace FikaAmazonAPI.ReportGeneration
45
{
@@ -27,15 +28,15 @@ public static class DateTimeFormate
2728
}
2829
public static decimal? GetDecimal(string str)
2930
{
30-
if (decimal.TryParse(str, out decimal value))
31+
if (decimal.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal value))
3132
{
3233
return value;
3334
}
3435
return null;
3536
}
3637
public static int? GetInt(string str)
3738
{
38-
if (int.TryParse(str, out int value))
39+
if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value))
3940
{
4041
return value;
4142
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using FikaAmazonAPI.ReportGeneration.ReportDataTable;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace FikaAmazonAPI.ReportGeneration
8+
{
9+
public class OrderInvoicingReport
10+
{
11+
public List<OrderInvoicingReportRow> Data { get; set; } = new List<OrderInvoicingReportRow>();
12+
public OrderInvoicingReport(string path, string refNumber)
13+
{
14+
if (string.IsNullOrEmpty(path))
15+
return;
16+
17+
var table = Table.ConvertFromCSV(path);
18+
19+
List<OrderInvoicingReportRow> values = new List<OrderInvoicingReportRow>();
20+
foreach (var row in table.Rows)
21+
{
22+
values.Add(OrderInvoicingReportRow.FromRow(row, refNumber));
23+
}
24+
Data = values;
25+
}
26+
}
27+
28+
29+
public class OrderInvoicingReportRow
30+
{
31+
public string AmazonOrderId { get; set; }
32+
public string OrderItemId { get; set; }
33+
public DateTime? PurchaseDate{ get; set; }
34+
public DateTime? PaymentDate { get; set; }
35+
public string BuyerEmail { get; set; }
36+
public string BuyerName { get; set; }
37+
public string PaymentMethodeDetails { get; set; }
38+
public string BuyerPhoneNumber { get; set; }
39+
public string SKU { get; set; }
40+
public string ProductName { get; set; }
41+
public decimal? Quantity { get; set; }
42+
public string Currency { get; set; }
43+
public decimal? ItemPrice { get; set; }
44+
public decimal? ItemTax { get; set; }
45+
public decimal? ShippingPrice { get; set; }
46+
public decimal? ShippingTax { get; set; }
47+
public string ShipServiceLevel { get; set; }
48+
public string RecipientName { get; set; }
49+
public string ShipAddress1 { get; set; }
50+
public string ShipAddress2 { get; set; }
51+
public string ShipAddress3 { get; set; }
52+
public string ShipCity { get; set; }
53+
public string ShipState { get; set; }
54+
public string ShipPostalCode { get; set; }
55+
public string ShipCountry { get; set; }
56+
public string ShipPhoneNumber { get; set; }
57+
public string BillAddress1 { get; set; }
58+
public string BillAddress2 { get; set; }
59+
public string BillAddress3 { get; set; }
60+
public string BillCity { get; set; }
61+
public string BillState { get; set; }
62+
public string BillPostalCode { get; set; }
63+
public string BillCountry { get; set; }
64+
public string DeliveryIndustructions { get; set; }
65+
public string SalesChannel { get; set; }
66+
public string BuyerCompany { get; set; }
67+
public string BuyerTaxRegistationId { get; set; }
68+
public string BuyerTaxRegistationCountry { get; set; }
69+
public string refNumber { get; set; }
70+
71+
public OrderInvoicingReportRow()
72+
{
73+
74+
}
75+
76+
public static OrderInvoicingReportRow FromRow(TableRow rowData, string refNumber)
77+
{
78+
var row = new OrderInvoicingReportRow();
79+
row.AmazonOrderId = rowData.GetString("order-id");
80+
row.OrderItemId = rowData.GetString("order-item-id");
81+
row.PurchaseDate = DataConverter.GetDate(rowData.GetString("purchase-date"), DataConverter.DateTimeFormate.DATETIME_K_FORMAT);
82+
row.PaymentDate = DataConverter.GetDate(rowData.GetString("payments-date"), DataConverter.DateTimeFormate.DATETIME_K_FORMAT);
83+
row.BuyerEmail = rowData.GetString("buyer-email");
84+
row.BuyerName = rowData.GetString("buyer-name");
85+
row.PaymentMethodeDetails = rowData.GetString("payment-method-details");
86+
row.BuyerPhoneNumber = rowData.GetString("buyer-phone-number");
87+
row.SKU = rowData.GetString("sku");
88+
row.ProductName = rowData.GetString("product-name");
89+
row.Quantity = rowData.GetDecimal("quantity-purchased");
90+
row.Currency = rowData.GetString("currency");
91+
row.ItemPrice = rowData.GetDecimal("item-price");
92+
row.ItemTax = rowData.GetDecimal("item-tax");
93+
row.ShippingPrice = rowData.GetDecimal("shipping-price");
94+
row.ShippingTax = rowData.GetDecimal("shipping-tax");
95+
row.ShipServiceLevel = rowData.GetString("ship-service-level");
96+
row.RecipientName = rowData.GetString("recipient-name");
97+
row.ShipAddress1 = rowData.GetString("ship-address-1");
98+
row.ShipAddress2 = rowData.GetString("ship-address-2");
99+
row.ShipAddress3 = rowData.GetString("ship-address-3");
100+
row.ShipCity = rowData.GetString("ship-city");
101+
row.ShipState = rowData.GetString("ship-state");
102+
row.ShipPostalCode = rowData.GetString("ship-postal-code");
103+
row.ShipCountry = rowData.GetString("ship-country");
104+
row.ShipPhoneNumber = rowData.GetString("ship-phone-number");
105+
row.BillAddress1 = rowData.GetString("bill-address-1");
106+
row.BillAddress2 = rowData.GetString("bill-address-2");
107+
row.BillAddress3 = rowData.GetString("bill-address-3");
108+
row.BillCity = rowData.GetString("bill-city");
109+
row.BillState = rowData.GetString("bill-state");
110+
row.BillPostalCode = rowData.GetString("bill-postal-code");
111+
row.BillCountry = rowData.GetString("bill-country");
112+
row.DeliveryIndustructions = rowData.GetString("delivery-Instructions");
113+
row.SalesChannel = rowData.GetString("sales-channel");
114+
row.BuyerCompany = rowData.GetString("buyer-company-name");
115+
row.BuyerTaxRegistationId = rowData.GetString("buyer-tax-registration-id");
116+
row.BuyerTaxRegistationCountry = rowData.GetString("buyer-tax-registration-country");
117+
row.refNumber = refNumber;
118+
119+
return row;
120+
}
121+
}
122+
}

Source/FikaAmazonAPI/ReportGeneration/ReportDataTable/RowExtensionMethods.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45

56
namespace FikaAmazonAPI.ReportGeneration.ReportDataTable
@@ -27,7 +28,7 @@ public static long GetInt64(this TableRow row, string id)
2728
public static decimal GetDecimal(this TableRow row, string id)
2829
{
2930
return AValueWithThisIdExists(row, id) && TheValueIsNotEmpty(row, id)
30-
? Convert.ToDecimal(row[id])
31+
? Convert.ToDecimal(row[id], CultureInfo.InvariantCulture)
3132
: decimal.MinValue;
3233
}
3334
public static DateTime GetDateTime(this TableRow row, string id)
@@ -145,7 +146,7 @@ public static Guid GetGuid(this TableRow row, string id)
145146
public static double GetDouble(this TableRow row, string id)
146147
{
147148
return AValueWithThisIdExists(row, id) && TheValueIsNotEmpty(row, id)
148-
? Convert.ToDouble(row[id])
149+
? Convert.ToDouble(row[id], CultureInfo.InvariantCulture)
149150
: double.MinValue;
150151
}
151152
private static bool AValueWithThisIdExists(IEnumerable<KeyValuePair<string, string>> row, string id)

Source/FikaAmazonAPI/ReportGeneration/ReportManager.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,27 @@ private async Task<string> GetOrdersByOrderDateAsync(AmazonConnection amazonConn
249249
{
250250
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL, fromDate, toDate);
251251
}
252+
253+
public List<OrderInvoicingReportRow> GetOrderInvoicingData(DateTime fromDate, DateTime toDate) =>
254+
Task.Run(() => GetOrderInvoicingDataAsync(fromDate, toDate)).ConfigureAwait(false).GetAwaiter().GetResult();
255+
public async Task<List<OrderInvoicingReportRow>> GetOrderInvoicingDataAsync(DateTime fromDate, DateTime toDate)
256+
{
257+
List<OrderInvoicingReportRow> list = new List<OrderInvoicingReportRow>();
258+
var dateList = ReportDateRange.GetDateRange(fromDate, toDate, DAY_30);
259+
foreach (var range in dateList)
260+
{
261+
var path = await GetOrderInvoicingDataAsync(_amazonConnection, range.StartDate, range.EndDate);
262+
OrderInvoicingReport report = new OrderInvoicingReport(path, _amazonConnection.RefNumber);
263+
list.AddRange(report.Data);
264+
}
265+
return list;
266+
}
267+
private async Task<string> GetOrderInvoicingDataAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate)
268+
{
269+
var options = new AmazonSpApiSDK.Models.Reports.ReportOptions();
270+
options.Add("ShowSalesChannel", "true");
271+
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING, fromDate, toDate, options, false);
272+
}
252273
#endregion
253274

254275

Source/FikaAmazonAPI/Services/NotificationService.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,43 @@ public async Task StartReceivingNotificationMessagesAsync(ParameterMessageReceiv
123123
var SQS_URL = param.SQS_URL;
124124
var Region = param.RegionEndpoint;
125125

126-
var amazonSQSClient = new AmazonSQSClient(awsAccessKeyId, awsSecretAccessKey, Region);
127-
128-
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(SQS_URL);
129-
receiveMessageRequest.MaxNumberOfMessages = 10;
130-
131-
132-
while (true)
126+
using (var amazonSQSClient = new AmazonSQSClient(awsAccessKeyId, awsSecretAccessKey, Region))
133127
{
134-
try
128+
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(SQS_URL);
129+
receiveMessageRequest.MaxNumberOfMessages = 10;
130+
131+
while (true)
135132
{
136-
var result = await amazonSQSClient.ReceiveMessageAsync(receiveMessageRequest);
137-
var Messages = result.Messages;
138-
if (Messages.Count > 0)
133+
try
139134
{
140-
foreach (var msg in Messages)
135+
var result = await amazonSQSClient.ReceiveMessageAsync(receiveMessageRequest);
136+
var Messages = result.Messages;
137+
if (Messages.Count > 0)
141138
{
142-
try
139+
foreach (var msg in Messages)
143140
{
144-
var data = DeserializeNotification(msg);
141+
try
142+
{
143+
var data = DeserializeNotification(msg);
144+
145+
messageReceiver.NewMessageRevicedTriger(data);
146+
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle);
147+
}
148+
catch (Exception ex)
149+
{
150+
messageReceiver.ErrorCatch(ex);
151+
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle);
152+
}
145153

146-
messageReceiver.NewMessageRevicedTriger(data);
147-
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle);
148154
}
149-
catch (Exception ex)
150-
{
151-
messageReceiver.ErrorCatch(ex);
152-
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle);
153-
}
154-
155155
}
156156
}
157-
}
158-
catch (Exception ex)
159-
{
160-
messageReceiver.ErrorCatch(ex);
157+
catch (Exception ex)
158+
{
159+
messageReceiver.ErrorCatch(ex);
160+
}
161161
}
162162
}
163-
164-
165-
166163
}
167164
private async Task DeleteMessageFromQueueAsync(AmazonSQSClient sqsClient, string QueueUrl, string ReceiptHandle)
168165
{

0 commit comments

Comments
 (0)