Skip to content

Commit a62774a

Browse files
author
KevinVenclovas
committed
convert report to new table mapping
1 parent 8b4d777 commit a62774a

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed
Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using FikaAmazonAPI.ReportGeneration.ReportDataTable;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -12,10 +13,14 @@ public OrderInvoicingReport(string path, string refNumber)
1213
{
1314
if (string.IsNullOrEmpty(path))
1415
return;
15-
var values = File.ReadAllLines(path)
16-
.Skip(1)
17-
.Select(v => OrderInvoicingReportRow.FromCsv(v, refNumber))
18-
.ToList();
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+
}
1924
Data = values;
2025
}
2126
}
@@ -61,60 +66,57 @@ public class OrderInvoicingReportRow
6166
public string BuyerCompany { get; set; }
6267
public string BuyerTaxRegistationId { get; set; }
6368
public string BuyerTaxRegistationCountry { get; set; }
69+
public string refNumber { get; set; }
6470

6571
public OrderInvoicingReportRow()
6672
{
6773

6874
}
6975

70-
public static OrderInvoicingReportRow FromCsv(string csvLine, string refNumber)
76+
public static OrderInvoicingReportRow FromRow(TableRow rowData, string refNumber)
7177
{
72-
string[] values = csvLine.Split('\t');
7378
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];
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+
112119
return row;
113120
}
114121
}
115-
116-
117-
118-
119-
120122
}

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)

0 commit comments

Comments
 (0)