Skip to content

Commit aa3c6af

Browse files
committed
2 parents ed2a927 + 6170bb7 commit aa3c6af

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

Source/FikaAmazonAPI/ReportGeneration/ReportDateRange.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@ public class ReportDateRange
1010
public ReportDateRange(DateTime startDate, DateTime endDate) { StartDate = startDate; EndDate = endDate;}
1111

1212

13-
public static IList<ReportDateRange> GetDateRange(DateTime startDate,DateTime endDate,int MaxDays)
14-
{
15-
List<ReportDateRange> list=new List<ReportDateRange>();
13+
public static IList<ReportDateRange> GetDateRange(DateTime startDate, DateTime endDate, int MaxDays)
14+
{
15+
List<ReportDateRange> list = new List<ReportDateRange>();
16+
DateTime tempEnd = startDate;
17+
DateTime start = startDate;
1618

17-
double totalDays = (endDate - startDate).TotalDays;
18-
int range = (int)(totalDays / MaxDays);
19-
int remind = (int)(totalDays % MaxDays);
20-
if (remind > 0)
21-
range++;
19+
while (true)
20+
{
21+
tempEnd = tempEnd.AddDays(MaxDays);
22+
if (tempEnd > endDate)
23+
{
24+
tempEnd = endDate;
25+
list.Add(new ReportDateRange(start, tempEnd));
26+
break;
27+
}
28+
else
29+
{
30+
list.Add(new ReportDateRange(start, tempEnd));
31+
start = tempEnd.AddSeconds(1);
32+
}
2233

23-
for (int i = 0; i < range; i++)
24-
{
25-
var newStartDate = startDate.AddDays(i * MaxDays);
26-
var newEndDate = newStartDate.AddDays(MaxDays);
27-
if (i == range - 1)
28-
newEndDate = endDate;
34+
}
2935

30-
list.Add(new ReportDateRange(newStartDate, newEndDate));
31-
}
32-
33-
return list;
36+
return list;
3437
}
3538
}
3639
}

Source/FikaAmazonAPI/ReportGeneration/ReportManager.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using FikaAmazonAPI.Utils;
2+
using System;
23
using System.Collections.Generic;
34
using System.Threading.Tasks;
45
using static FikaAmazonAPI.Utils.Constants;
@@ -250,25 +251,26 @@ private async Task<string> GetOrdersByOrderDateAsync(AmazonConnection amazonConn
250251
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL, fromDate, toDate);
251252
}
252253

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)
254+
public List<OrderInvoicingReportRow> GetOrderInvoicingData(DateTime fromDate, DateTime toDate, List<MarketPlace> marketplaces = null) =>
255+
Task.Run(() => GetOrderInvoicingDataAsync(fromDate, toDate, marketplaces)).ConfigureAwait(false).GetAwaiter().GetResult();
256+
public async Task<List<OrderInvoicingReportRow>> GetOrderInvoicingDataAsync(DateTime fromDate, DateTime toDate, List<MarketPlace> marketplaces = null)
256257
{
257258
List<OrderInvoicingReportRow> list = new List<OrderInvoicingReportRow>();
258259
var dateList = ReportDateRange.GetDateRange(fromDate, toDate, DAY_30);
259260
foreach (var range in dateList)
260261
{
261-
var path = await GetOrderInvoicingDataAsync(_amazonConnection, range.StartDate, range.EndDate);
262+
var path = await GetOrderInvoicingDataAsync(_amazonConnection, range.StartDate, range.EndDate, marketplaces);
262263
OrderInvoicingReport report = new OrderInvoicingReport(path, _amazonConnection.RefNumber);
263264
list.AddRange(report.Data);
264265
}
265266
return list;
266267
}
267-
private async Task<string> GetOrderInvoicingDataAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate)
268+
269+
private async Task<string> GetOrderInvoicingDataAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate, List<MarketPlace> marketplaces = null)
268270
{
269271
var options = new AmazonSpApiSDK.Models.Reports.ReportOptions();
270272
options.Add("ShowSalesChannel", "true");
271-
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING, fromDate, toDate, options, false);
273+
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING, fromDate, toDate, options, false, marketplaces);
272274
}
273275
#endregion
274276

Source/FikaAmazonAPI/Services/ReportService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.IO;
10+
using System.Linq;
1011
using System.Threading.Tasks;
1112
using static FikaAmazonAPI.Utils.Constants;
1213

@@ -247,7 +248,7 @@ public async Task<bool> CancelReportScheduleAsync(string reportScheduleId)
247248

248249
public string CreateReportAndDownloadFile(ReportTypes reportType, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null, bool isRestrictedReport = false) =>
249250
Task.Run(() => CreateReportAndDownloadFileAsync(reportType, dataStartTime, dataEndTime, reportOptions, isRestrictedReport)).ConfigureAwait(false).GetAwaiter().GetResult();
250-
public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportType, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null, bool isRestrictedReport = false)
251+
public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportType, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null, bool isRestrictedReport = false, List<MarketPlace> marketplaces = null)
251252
{
252253
if (!isRestrictedReport && Enum.TryParse<RestrictedReportTypes>(reportType.ToString(), out _))
253254
{
@@ -259,7 +260,14 @@ public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportTyp
259260

260261
parameters.marketplaceIds = new MarketplaceIds();
261262

262-
parameters.marketplaceIds.Add(AmazonCredential.MarketPlace.ID);
263+
if (marketplaces == null)
264+
{
265+
parameters.marketplaceIds.Add(AmazonCredential.MarketPlace.ID);
266+
}
267+
else
268+
{
269+
parameters.marketplaceIds.AddRange(marketplaces.Select(x => x.ID).ToList());
270+
}
263271

264272
if (reportOptions != null)
265273
parameters.reportOptions = reportOptions;

0 commit comments

Comments
 (0)