Skip to content

Commit

Permalink
add new report to report manager GET_FBA_ESTIMATED_FBA_FEES_TXT_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
abuzuhri committed Mar 6, 2024
1 parent fcfd875 commit 966167e
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 4 deletions.
103 changes: 103 additions & 0 deletions Source/FikaAmazonAPI/ReportGeneration/FbaEstimateFeeReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using FikaAmazonAPI.ReportGeneration.ReportDataTable;
using System;
using System.Collections.Generic;

namespace FikaAmazonAPI.ReportGeneration
{
public class FbaEstimateFeeReport
{
public List<FbaEstimateFeeReportRow> Data { get; set; } = new List<FbaEstimateFeeReportRow>();
public FbaEstimateFeeReport(string path, string refNumber)
{
if (string.IsNullOrEmpty(path))
return;

var table = Table.ConvertFromCSV(path);

List<FbaEstimateFeeReportRow> values = new List<FbaEstimateFeeReportRow>();
foreach (var row in table.Rows)
{
values.Add(FbaEstimateFeeReportRow.FromRow(row, refNumber));
}
Data = values;
}
}
public class FbaEstimateFeeReportRow
{
public string sku { get; set; }
public string fnsku { get; set; }
public string asin { get; set; }
public string amazonStore { get; set; }
public string productName { get; set; }
public string productGroup { get; set; }
public string brand { get; set; }
public string fulfilledBy { get; set; }
public decimal? yourPrice { get; set; }
public decimal? salesPrice { get; set; }
public decimal? longestSide { get; set; }
public decimal? medianSide { get; set; }
public decimal? shortestSide { get; set; }
public decimal? lengthAndGirth { get; set; }
public decimal? itemPackageWeight { get; set; }
public decimal? estimatedFeeTotal { get; set; }
public decimal? estimatedReferralFeePerUnit { get; set; }
public decimal? estimatedPickPackFeePerUnit { get; set; }

public decimal? ReferralFeePercentage
{
get
{

try
{
decimal? price = estimatedReferralFeePerUnit * 100 / yourPrice;
return Math.Round(price.Value);
}
catch { return default(decimal?); }
}
}


public string unitOfDimension { get; set; }
public string unitOfWeight { get; set; }
public string currency { get; set; }
public string refNumber { get; set; }




public static FbaEstimateFeeReportRow FromRow(TableRow rowData, string refNumber)
{
var row = new FbaEstimateFeeReportRow();

row.sku = rowData.GetString("sku");
row.fnsku = rowData.GetString("fnsku");
row.asin = rowData.GetString("asin");
row.amazonStore = rowData.GetString("amazon-store");
row.productName = rowData.GetString("product-name");
row.productGroup = rowData.GetString("product-group");
row.brand = rowData.GetString("brand");
row.fulfilledBy = rowData.GetString("fulfilled-by");

row.yourPrice = DataConverter.GetDecimal(rowData.GetString("your-price"));
row.salesPrice = DataConverter.GetDecimal(rowData.GetString("sales-price"));
row.longestSide = DataConverter.GetDecimal(rowData.GetString("longest-side"));
row.medianSide = DataConverter.GetDecimal(rowData.GetString("median-side"));
row.shortestSide = DataConverter.GetDecimal(rowData.GetString("shortest-side"));
row.lengthAndGirth = DataConverter.GetDecimal(rowData.GetString("length-and-girth"));
row.lengthAndGirth = DataConverter.GetDecimal(rowData.GetString("length-and-girth"));
row.itemPackageWeight = DataConverter.GetDecimal(rowData.GetString("item-package-weight"));
row.estimatedFeeTotal = DataConverter.GetDecimal(rowData.GetString("estimated-fee-total"));
row.estimatedReferralFeePerUnit = DataConverter.GetDecimal(rowData.GetString("estimated-referral-fee-per-unit"));
row.estimatedPickPackFeePerUnit = DataConverter.GetDecimal(rowData.GetString("estimated-pick-pack-fee-per-unit"));

row.unitOfDimension = rowData.GetString("unit-of-dimension");
row.unitOfWeight = rowData.GetString("unit-of-weight");
row.currency = rowData.GetString("currency");

row.refNumber = refNumber;

return row;
}
}
}
28 changes: 24 additions & 4 deletions Source/FikaAmazonAPI/ReportGeneration/ReportManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using FikaAmazonAPI.Utils;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
using FikaAmazonAPI.Utils;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
using static FikaAmazonAPI.Utils.Constants;
using System.Threading;

namespace FikaAmazonAPI.ReportGeneration
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task<List<ReturnFBAOrderRow>> GetReturnFBAOrderAsync(DateTime fromD

private async Task<string> GetReturnFBAOrderAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate, List<MarketPlace> marketplaces = null, CancellationToken cancellationToken = default)
{
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA, fromDate, toDate, marketplaces: marketplaces, cancellationToken: cancellationToken);
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA, fromDate, toDate, marketplaces: marketplaces, cancellationToken: cancellationToken);
}


Expand Down Expand Up @@ -343,5 +343,25 @@ private async Task<string> GetInventoryPlanningDataAsync(AmazonConnection amazon
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FBA_INVENTORY_PLANNING_DATA);
}
#endregion

#region FbaEstimateFee
public List<FbaEstimateFeeReportRow> GetFbaEstimateFeeData(DateTime fromDate, DateTime toDate) =>
Task.Run(() => GetFbaEstimateFeeDataAsync(fromDate, toDate)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<List<FbaEstimateFeeReportRow>> GetFbaEstimateFeeDataAsync(DateTime fromDate, DateTime toDate)
{
List<FbaEstimateFeeReportRow> list = new List<FbaEstimateFeeReportRow>();

var path = await GetFbaEstimateFeeDataAsync(_amazonConnection, fromDate, toDate);
FbaEstimateFeeReport report = new FbaEstimateFeeReport(path, _amazonConnection.RefNumber);
list.AddRange(report.Data);

return list;
}
private async Task<string> GetFbaEstimateFeeDataAsync(AmazonConnection amazonConnection, DateTime fromDate, DateTime toDate)
{
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(ReportTypes.GET_FBA_ESTIMATED_FBA_FEES_TXT_DATA, fromDate, toDate);
}
#endregion

}
}

0 comments on commit 966167e

Please sign in to comment.