Skip to content

Commit 5a31f55

Browse files
author
KevinVenclovas
committed
added GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING report
1 parent 6c7872c commit 5a31f55

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace FikaAmazonAPI.ReportGeneration
7+
{
8+
public class OrderInvoicingReport
9+
{
10+
public List<OrderInvoicingReportRow> Data { get; set; } = new List<OrderInvoicingReportRow>();
11+
public OrderInvoicingReport(string path, string refNumber)
12+
{
13+
if (string.IsNullOrEmpty(path))
14+
return;
15+
var values = File.ReadAllLines(path)
16+
.Skip(1)
17+
.Select(v => OrderInvoicingReportRow.FromCsv(v, refNumber))
18+
.ToList();
19+
Data = values;
20+
}
21+
}
22+
23+
24+
public class OrderInvoicingReportRow
25+
{
26+
public string AmazonOrderId { get; set; }
27+
public string OrderItemId { get; set; }
28+
public DateTime? PurchaseDate{ get; set; }
29+
public DateTime? PaymentDate { get; set; }
30+
public string BuyerEmail { get; set; }
31+
public string BuyerName { get; set; }
32+
public string PaymentMethodeDetails { get; set; }
33+
public string BuyerPhoneNumber { get; set; }
34+
public string SKU { get; set; }
35+
public string ProductName { get; set; }
36+
public decimal? Quantity { get; set; }
37+
public string Currency { get; set; }
38+
public decimal? ItemPrice { get; set; }
39+
public decimal? ItemTax { get; set; }
40+
public decimal? ShippingPrice { get; set; }
41+
public decimal? ShippingTax { get; set; }
42+
public string ShipServiceLevel { get; set; }
43+
public string RecipientName { get; set; }
44+
public string ShipAddress1 { get; set; }
45+
public string ShipAddress2 { get; set; }
46+
public string ShipAddress3 { get; set; }
47+
public string ShipCity { get; set; }
48+
public string ShipState { get; set; }
49+
public string ShipPostalCode { get; set; }
50+
public string ShipCountry { get; set; }
51+
public string ShipPhoneNumber { get; set; }
52+
public string BillAddress1 { get; set; }
53+
public string BillAddress2 { get; set; }
54+
public string BillAddress3 { get; set; }
55+
public string BillCity { get; set; }
56+
public string BillState { get; set; }
57+
public string BillPostalCode { get; set; }
58+
public string BillCountry { get; set; }
59+
public string DeliveryIndustructions { get; set; }
60+
public string SalesChannel { get; set; }
61+
public string BuyerCompany { get; set; }
62+
public string BuyerTaxRegistationId { get; set; }
63+
public string BuyerTaxRegistationCountry { get; set; }
64+
65+
public OrderInvoicingReportRow()
66+
{
67+
68+
}
69+
70+
public static OrderInvoicingReportRow FromCsv(string csvLine, string refNumber)
71+
{
72+
string[] values = csvLine.Split('\t');
73+
var row = new OrderInvoicingReportRow();
74+
row.AmazonOrderId = values[0];
75+
row.OrderItemId = values[1];
76+
row.PurchaseDate = DataConverter.GetDate(values[2], DataConverter.DateTimeFormate.DATETIME_K_FORMAT);
77+
row.PaymentDate = DataConverter.GetDate(values[3], DataConverter.DateTimeFormate.DATETIME_K_FORMAT);
78+
row.BuyerEmail = values[4];
79+
row.BuyerName = values[5];
80+
row.PaymentMethodeDetails = values[6];
81+
row.BuyerPhoneNumber = values[7];
82+
row.SKU = values[8];
83+
row.ProductName = values[9];
84+
row.Quantity = DataConverter.GetInt(values[10]);
85+
row.Currency = values[11];
86+
row.ItemPrice = DataConverter.GetDecimal(values[12]);
87+
row.ItemTax = DataConverter.GetDecimal(values[13]);
88+
row.ShippingPrice = DataConverter.GetDecimal(values[14]);
89+
row.ShippingTax = DataConverter.GetDecimal(values[15]);
90+
row.ShipServiceLevel = values[16];
91+
row.RecipientName = values[17];
92+
row.ShipAddress1 = values[18];
93+
row.ShipAddress2 = values[19];
94+
row.ShipAddress3 = values[20];
95+
row.ShipCity = values[21];
96+
row.ShipState = values[22];
97+
row.ShipPostalCode = values[23];
98+
row.ShipCountry = values[24];
99+
row.ShipPhoneNumber = values[25];
100+
row.BillAddress1 = values[26];
101+
row.BillAddress2 = values[27];
102+
row.BillAddress3 = values[28];
103+
row.BillCity = values[29];
104+
row.BillState = values[30];
105+
row.BillPostalCode = values[31];
106+
row.BillCountry = values[32];
107+
row.DeliveryIndustructions = values[36];
108+
row.SalesChannel = values[37];
109+
row.BuyerCompany = values[50];
110+
row.BuyerTaxRegistationId = values[53];
111+
row.BuyerTaxRegistationCountry = values[54];
112+
return row;
113+
}
114+
}
115+
116+
117+
118+
119+
120+
}

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

0 commit comments

Comments
 (0)