Skip to content

Commit ed29e48

Browse files
committed
Add Referral Fee Report to report manager
1 parent d52898b commit ed29e48

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using FikaAmazonAPI.ReportGeneration.ReportDataTable;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace FikaAmazonAPI.ReportGeneration
6+
{
7+
public class ReferralFeeReport
8+
{
9+
public List<ReferralFeeReportRow> Data { get; set; } = new List<ReferralFeeReportRow>();
10+
public ReferralFeeReport(string path, string refNumber)
11+
{
12+
if (string.IsNullOrEmpty(path))
13+
return;
14+
15+
var table = Table.ConvertFromCSV(path);
16+
17+
List<ReferralFeeReportRow> values = new List<ReferralFeeReportRow>();
18+
foreach (var row in table.Rows)
19+
{
20+
values.Add(ReferralFeeReportRow.FromRow(row, refNumber));
21+
}
22+
Data = values;
23+
}
24+
}
25+
public class ReferralFeeReportRow
26+
{
27+
public string sellerSku { get; set; }
28+
public string asin { get; set; }
29+
public string itemName { get; set; }
30+
public decimal? price { get; set; }
31+
public decimal? estimatedReferralFeePerItem { get; set; }
32+
33+
public decimal? ReferralFeePercentage
34+
{
35+
get
36+
{
37+
38+
try
39+
{
40+
decimal? priceP = estimatedReferralFeePerItem * 100 / price;
41+
return Math.Round(priceP.Value);
42+
}
43+
catch { return default(decimal?); }
44+
}
45+
}
46+
47+
public string refNumber { get; set; }
48+
49+
50+
51+
52+
public static ReferralFeeReportRow FromRow(TableRow rowData, string refNumber)
53+
{
54+
var row = new ReferralFeeReportRow();
55+
56+
row.sellerSku = rowData.GetString("seller-sku");
57+
row.asin = rowData.GetString("asin");
58+
row.itemName = rowData.GetString("item-name");
59+
60+
row.price = DataConverter.GetDecimal(rowData.GetString("price"));
61+
row.estimatedReferralFeePerItem = DataConverter.GetDecimal(rowData.GetString("estimated-referral-fee-per-item"));
62+
63+
64+
row.refNumber = refNumber;
65+
66+
return row;
67+
}
68+
}
69+
}

Source/FikaAmazonAPI/ReportGeneration/ReportManager.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,24 @@ private async Task<string> GetFbaEstimateFeeDataAsync(AmazonConnection amazonCon
363363
}
364364
#endregion
365365

366+
367+
#region GetReferralFee
368+
public List<ReferralFeeReportRow> GetReferralFeeReportData(DateTime fromDate, DateTime toDate) =>
369+
Task.Run(() => GetReferralFeeReportDataAsync(fromDate, toDate)).ConfigureAwait(false).GetAwaiter().GetResult();
370+
public async Task<List<ReferralFeeReportRow>> GetReferralFeeReportDataAsync(DateTime fromDate, DateTime toDate)
371+
{
372+
List<ReferralFeeReportRow> list = new List<ReferralFeeReportRow>();
373+
374+
var path = await GetReferralFeeReportDataAsync(_amazonConnection, fromDate, toDate);
375+
ReferralFeeReport report = new ReferralFeeReport(path, _amazonConnection.RefNumber);
376+
list.AddRange(report.Data);
377+
378+
return list;
379+
}
380+
private async Task<string> GetReferralFeeReportDataAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate)
381+
{
382+
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_REFERRAL_FEE_PREVIEW_REPORT, fromDate, toDate);
383+
}
384+
#endregion
366385
}
367386
}

0 commit comments

Comments
 (0)