Skip to content

Dynamic report encoding #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ Please see [here](https://github.com/abuzuhri/Amazon-SP-API-CSharp/blob/main/Sou
>>
>> ***This is not required and will operate normally without the ProxyAddress being set.***


### Configuration using Docker - Linux
You need to add windows-1252 encoding
```csharp
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
```


### Order List, For more orders sample please check [Here](https://github.com/abuzuhri/Amazon-SP-API-CSharp/blob/main/Source/FikaAmazonAPI.SampleCode/ReportsSample.cs).
```CSharp
ParameterOrderList serachOrderList = new ParameterOrderList();
Expand Down
4 changes: 2 additions & 2 deletions Source/FikaAmazonAPI/ReportGeneration/ProductsReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace FikaAmazonAPI.ReportGeneration
public class ProductsReport
{
public List<ProductsRow> Data { get; set; } = new List<ProductsRow>();
public ProductsReport(string path, Encoding encoding = default)
public ProductsReport(string path)
{
if (string.IsNullOrEmpty(path))
return;

var table = Table.ConvertFromCSV(path, encoding: encoding);
var table = Table.ConvertFromCSV(path);

List<ProductsRow> values = new List<ProductsRow>();
foreach (var row in table.Rows)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using FikaAmazonAPI.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace FikaAmazonAPI.ReportGeneration.ReportDataTable
{
Expand Down Expand Up @@ -48,13 +50,12 @@ public Table(params string[] header)
this.header = header;
}

public static Table ConvertFromCSV(string path, char separator = '\t', Encoding encoding = default)
public static Table ConvertFromCSV(string path, char separator = '\t')
{
var lines = File.ReadAllLines(path, encoding ?? Encoding.UTF8);
var lines = File.ReadAllLines(path, EncodingHelper.GetEncodingFromCulture(Thread.CurrentThread.CurrentCulture));

var table = new Table(lines.First().Split(separator));


lines.Skip(1).ToList().ForEach(a => ConvertFromCSVAddRow(table, a, separator));
return table;
}
Expand Down
34 changes: 34 additions & 0 deletions Source/FikaAmazonAPI/ReportGeneration/ReportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,40 @@ private async Task<string> GetOrderInvoicingDataAsync(AmazonConnection amazonCon

#endregion

#region VatInvoicing

public List<VatInvoicingReportRow> GetVATInvoicingData(DateTime fromDate, DateTime toDate,
List<MarketPlace> marketplaces = null) =>
Task.Run(() => GetVATInvoicingDataAsync(fromDate, toDate, marketplaces)).ConfigureAwait(false)
.GetAwaiter().GetResult();

public async Task<List<VatInvoicingReportRow>> GetVATInvoicingDataAsync(DateTime fromDate, DateTime toDate,
List<MarketPlace> marketplaces = null)
{
List<VatInvoicingReportRow> list = new List<VatInvoicingReportRow>();
var dateList = ReportDateRange.GetDateRange(fromDate, toDate, DAY_30);
foreach (var range in dateList)
{
var path = await GetVATInvoicingDataAsync(_amazonConnection, range.StartDate, range.EndDate,
marketplaces);
VatInvoicingReport report = new VatInvoicingReport(path, _amazonConnection.RefNumber);
list.AddRange(report.Data);
}

return list;
}

private async Task<string> GetVATInvoicingDataAsync(AmazonConnection amazonConnection, DateTime fromDate,
DateTime toDate, List<MarketPlace> marketplaces = null)
{
var options = new ReportOptions();
options.Add("ReportOption=All", "true");
return await amazonConnection.Reports.CreateReportAndDownloadFileAsync(
ReportTypes.GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT, fromDate, toDate, options, false, marketplaces);
}

#endregion

#region Settlement

public List<LedgerDetailReportRow> GetLedgerDetail(int days) =>
Expand Down
229 changes: 229 additions & 0 deletions Source/FikaAmazonAPI/ReportGeneration/VatInvoicingReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
using FikaAmazonAPI.ReportGeneration.ReportDataTable;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

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

var table = Table.ConvertFromCSV(path);

List<VatInvoicingReportRow> values = new List<VatInvoicingReportRow>();
foreach (var row in table.Rows)
{
values.Add(VatInvoicingReportRow.FromRow(row, refNumber));
}
Data = values;
}
}


public class VatInvoicingReportRow
{
public string MarketplaceId { get; set; }
public string AmazonOrderId { get; set; }
public string OrderItemId { get; set; }
public string ShippingId { get; set; }
public string TransactionId { get; set; }
public string TransactionType { get; set; }
public string InvoiceNumber { get; set; }
public string InvoiceStatus { get; set; }
public string InvoiceStatusDescription { get; set; }
public string IsAmazonInvoiced { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? ShipmentDate { get; set; }
public string BuyerVatNumber { get; set; }
public string SellerVatNumber { get; set; }
public string ASIN { get; set; }
public string SKU { get; set; }
public string ProductName { get; set; }
public decimal? QuantityPurchased { get; set; }
public string Currency { get; set; }
public decimal? ItemVatInclAmount { get; set; }
public decimal? ItemVatAmount { get; set; }
public decimal? ItemVatExclAmount { get; set; }
public decimal? ItemVatRate { get; set; }
public decimal? ItemPromoVatInclAmount { get; set; }
public decimal? ItemPromoVatExclAmount { get; set; }
public decimal? ItemPromoVatAmount { get; set; }
public decimal? ItemPromoVatRate { get; set; }
public string ItemPromotionId { get; set; }
public decimal? GiftWrapVatInclAmount { get; set; }
public decimal? GiftWrapVatAmount { get; set; }
public decimal? GiftWrapVatExclAmount { get; set; }
public decimal? GiftWrapVatRate { get; set; }
public decimal? GiftPromoVatInclAmount { get; set; }
public decimal? GiftPromoVatExclAmount { get; set; }
public decimal? GiftPromoVatAmount { get; set; }
public decimal? GiftPromoVatRate { get; set; }
public string GiftPromotionId { get; set; }
public decimal? ShippingVatInclAmount { get; set; }
public decimal? ShippingVatAmount { get; set; }
public decimal? ShippingVatExclAmount { get; set; }
public decimal? ShippingVatRate { get; set; }
public decimal? ShippingPromoVatInclAmount { get; set; }
public decimal? ShippingPromoVatExclAmount { get; set; }
public decimal? ShippingPromoVatAmount { get; set; }
public decimal? ShippingPromoVatRate { get; set; }
public string ShipPromotionId { get; set; }
public string IsBusinessOrder { get; set; }
public string PriceDesignation { get; set; }
public string PurchaseOrderNumber { get; set; }
public string RecipientName { get; set; }
public string ShipServiceLevel { get; set; }
public string FulfilledBy { get; set; }
public string ShipAddress1 { get; set; }
public string ShipAddress2 { get; set; }
public string ShipAddress3 { get; set; }
public string ShipCity { get; set; }
public string ShipState { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
public string ShipPhoneNumber { get; set; }
public string ShipFromCountry { get; set; }
public string ShipFromState { get; set; }
public string ShipFromCity { get; set; }
public string ShipFromPostalCode { get; set; }
public string BillingName { get; set; }
public string BillAddress1 { get; set; }
public string BillAddress2 { get; set; }
public string BillAddress3 { get; set; }
public string BillCity { get; set; }
public string BillState { get; set; }
public string BillPostalCode { get; set; }
public string BillCountry { get; set; }
public string BillingPhoneNumber { get; set; }
public string BuyerName { get; set; }
public string BuyerCompanyName { get; set; }
public string LegacyCustomerOrderItemId { get; set; }
public string RecommendedInvoiceFormat { get; set; }
public string BuyerTaxRegistrationType { get; set; }
public string BuyerEInvoiceAccountId { get; set; }
public string IsBuyerPhysicallyPresent { get; set; }
public string IsSellerPhysicallyPresent { get; set; }
public string CitationEs { get; set; }
public string CitationIt { get; set; }
public string CitationFr { get; set; }
public string CitationDe { get; set; }
public string CitationEn { get; set; }
public string ExportOutsideEu { get; set; }
public string IsInvoiceCorrected { get; set; }
public string OriginalVatInvoiceNumber { get; set; }
public string InvoiceCorrectionDetails { get; set; }

public string refNumber { get; set; }

public VatInvoicingReportRow()
{

}

public static VatInvoicingReportRow FromRow(TableRow rowData, string refNumber)
{
var row = new VatInvoicingReportRow();
row.MarketplaceId = rowData.GetString("marketplace-id");
row.AmazonOrderId = rowData.GetString("order-id");
row.OrderItemId = rowData.GetString("order-item-id");
row.ShippingId = rowData.GetString("shipping-id");
row.TransactionId = rowData.GetString("transaction-id");
row.TransactionType = rowData.GetString("transaction-type");
row.InvoiceNumber = rowData.GetString("invoice-number");
row.InvoiceStatus = rowData.GetString("invoice-status");
row.InvoiceStatusDescription = rowData.GetString("invoice-status-description");
row.IsAmazonInvoiced = rowData.GetString("is-amazon-invoiced");
row.OrderDate = DataConverter.GetDate(rowData.GetString("order-date"), DataConverter.DateTimeFormat.DATETIME_K_FORMAT);
row.ShipmentDate = DataConverter.GetDate(rowData.GetString("shipment-date"), DataConverter.DateTimeFormat.DATETIME_K_FORMAT);
row.BuyerVatNumber = rowData.GetString("buyer-vat-number");
row.SellerVatNumber = rowData.GetString("seller-vat-number");
row.ASIN = rowData.GetString("asin");
row.SKU = rowData.GetString("sku");
row.ProductName = rowData.GetString("product-name");
row.QuantityPurchased = rowData.GetDecimal("quantity-purchased");
row.Currency = rowData.GetString("currency");
row.ItemVatInclAmount = rowData.GetDecimal("item-vat-incl-amount");
row.ItemVatAmount = rowData.GetDecimal("item-vat-amount");
row.ItemVatExclAmount = rowData.GetDecimal("item-vat-excl-amount");
row.ItemVatRate = rowData.GetDecimal("item-vat-rate");
row.ItemPromoVatInclAmount = rowData.GetDecimal("item-promo-vat-incl-amount");
row.ItemPromoVatExclAmount = rowData.GetDecimal("item-promo-vat-excl-amount");
row.ItemPromoVatAmount = rowData.GetDecimal("item-promo-vat-amount");
row.ItemPromoVatRate = rowData.GetDecimal("item-promo-vat-rate");
row.ItemPromotionId = rowData.GetString("item-promotion-id");
row.GiftWrapVatInclAmount = rowData.GetDecimal("gift-wrap-vat-incl-amount");
row.GiftWrapVatAmount = rowData.GetDecimal("gift-wrap-vat-amount");
row.GiftWrapVatExclAmount = rowData.GetDecimal("gift-wrap-vat-excl-amount");
row.GiftWrapVatRate = rowData.GetDecimal("gift-wrap-vat-rate");
row.GiftPromoVatInclAmount = rowData.GetDecimal("gift-promo-vat-incl-amount");
row.GiftPromoVatExclAmount = rowData.GetDecimal("gift-promo-vat-excl-amount");
row.GiftPromoVatAmount = rowData.GetDecimal("gift-promo-vat-amount");
row.GiftPromoVatRate = rowData.GetDecimal("gift-promo-vat-rate");
row.GiftPromotionId = rowData.GetString("gift-promotion-id");
row.ShippingVatInclAmount = rowData.GetDecimal("shipping-vat-incl-amount");
row.ShippingVatAmount = rowData.GetDecimal("shipping-vat-amount");
row.ShippingVatExclAmount = rowData.GetDecimal("shipping-vat-excl-amount");
row.ShippingVatRate = rowData.GetDecimal("shipping-vat-rate");
row.ShippingPromoVatInclAmount = rowData.GetDecimal("shipping-promo-vat-incl-amount");
row.ShippingPromoVatExclAmount = rowData.GetDecimal("shipping-promo-vat-excl-amount");
row.ShippingPromoVatAmount = rowData.GetDecimal("shipping-promo-vat-amount");
row.ShippingPromoVatRate = rowData.GetDecimal("shipping-promo-vat-rate");
row.ShipPromotionId = rowData.GetString("ship-promotion-id");
row.IsBusinessOrder = rowData.GetString("is-business-order");
row.PriceDesignation = rowData.GetString("price-designation");
row.PurchaseOrderNumber = rowData.GetString("purchase-order-number");
row.RecipientName = rowData.GetString("recipient-name");
row.ShipServiceLevel = rowData.GetString("ship-service-level");
row.FulfilledBy = rowData.GetString("fulfilled-by");
row.ShipAddress1 = rowData.GetString("ship-address-1");
row.ShipAddress2 = rowData.GetString("ship-address-2");
row.ShipAddress3 = rowData.GetString("ship-address-3");
row.ShipCity = rowData.GetString("ship-city");
row.ShipState = rowData.GetString("ship-state");
row.ShipPostalCode = rowData.GetString("ship-postal-code");
row.ShipCountry = rowData.GetString("ship-country");
row.ShipPhoneNumber = rowData.GetString("ship-phone-number");
row.ShipFromCountry = rowData.GetString("ship-from-country");
row.ShipFromState = rowData.GetString("ship-from-state");
row.ShipFromCity = rowData.GetString("ship-from-city");
row.ShipFromPostalCode = rowData.GetString("ship-from-postal-code");
row.BillingName = rowData.GetString("billing-name");
row.BillAddress1 = rowData.GetString("bill-address-1");
row.BillAddress2 = rowData.GetString("bill-address-2");
row.BillAddress3 = rowData.GetString("bill-address-3");
row.BillCity = rowData.GetString("bill-city");
row.BillState = rowData.GetString("bill-state");
row.BillPostalCode = rowData.GetString("bill-postal-code");
row.BillCountry = rowData.GetString("bill-country");
row.BillingPhoneNumber = rowData.GetString("billing-phone-number");
row.BuyerName = rowData.GetString("buyer-name");
row.BuyerCompanyName = rowData.GetString("buyer-company-name");
row.LegacyCustomerOrderItemId = rowData.GetString("legacy-customer-order-item-id");
row.RecommendedInvoiceFormat = rowData.GetString("recommended-invoice-format");
row.BuyerTaxRegistrationType = rowData.GetString("buyer-tax-registration-type");
row.BuyerEInvoiceAccountId = rowData.GetString("buyer-e-invoice-account-id");
row.IsBuyerPhysicallyPresent = rowData.GetString("is-buyer-physically-present");
row.IsSellerPhysicallyPresent = rowData.GetString("is-seller-physically-present");
row.CitationEs = rowData.GetString("citation-es");
row.CitationIt = rowData.GetString("citation-it");
row.CitationFr = rowData.GetString("citation-fr");
row.CitationDe = rowData.GetString("citation-de");
row.CitationEn = rowData.GetString("citation-en");
row.ExportOutsideEu = rowData.GetString("export-outside-eu");
row.IsInvoiceCorrected = rowData.GetString("is-invoice-corrected");
row.OriginalVatInvoiceNumber = rowData.GetString("original-vat-invoice-number");
row.InvoiceCorrectionDetails = rowData.GetString("invoice-correction-details");

row.refNumber = refNumber;
return row;

return row;
}
}
}
2 changes: 2 additions & 0 deletions Source/FikaAmazonAPI/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ private async Task<string> GetFileAsync(ReportDocument reportDocument, Cancellat

cancellationToken.ThrowIfCancellationRequested();

FileTransform.SetFileEncoding(tempFilePath);

return tempFilePath;
}
catch (OperationCanceledException)
Expand Down
Loading
Loading