Commit 40026917 by lizefeng

优化结算表解析

parent a4ed804b
......@@ -576,6 +576,33 @@ namespace AutoTurnOver.Services
var refundDbData = ApiRefundDataMapDbData(pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData, refundItem);
feeDatas.AddRange(refundDbData);
}
if (settlementData.AmazonEnvelope.Message.SettlementReport.SellerDealPayment != null)
{
foreach (var sellerDealPaymentItem in settlementData.AmazonEnvelope.Message.SettlementReport.SellerDealPayment)
{
var adFee = sellerDealPaymentItem;
var adItemData = ApiOtherTransactionDataMapDbData(adFee.MarketplaceName, pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
(adFee.DealID ?? "").Replace("\n", ""), adFee.PostedDate,
adFee.DealFee.Amount.Text ?? 0, "Deal Fee", adFee.DealFee.Amount.Currency, "other fee");
feeDatas.Add(adItemData);
}
}
if (settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment != null)
{
foreach (var sellerCouponPaymentItem in settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment)
{
var adFee = sellerCouponPaymentItem;
var adItemData = ApiOtherTransactionDataMapDbData(adFee.MarketplaceName, pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
(adFee.CouponID ?? "").Replace("\n", ""), adFee.PostedDate,
adFee.CouponFee.Amount.Text ?? 0, adFee.CouponFee.Type, adFee.CouponFee.Amount.Currency, "other fee");
feeDatas.Add(adItemData);
}
}
var marketplaceName = "";
//精准读取系统站点
......@@ -598,7 +625,7 @@ namespace AutoTurnOver.Services
{
var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName,pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
otherTransactionItem.TransactionID, otherTransactionItem.PostedDate,
otherTransactionItemFee.Amount.Text ?? 0, otherTransactionItemFee.Type, otherTransactionItemFee.Amount.Currency);
otherTransactionItemFee.Amount.Text ?? 0, otherTransactionItemFee.Type, otherTransactionItemFee.Amount.Currency,"other", otherTransactionItem.AmazonOrderID);
feeDatas.Add(otherTransactionItemData);
}
}
......@@ -606,7 +633,7 @@ namespace AutoTurnOver.Services
{
var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName,pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
otherTransactionItem.TransactionID, otherTransactionItem.PostedDate,
otherTransactionItem.Amount.Text ?? 0, otherTransactionItem.TransactionType, otherTransactionItem.Amount.Currency);
otherTransactionItem.Amount.Text ?? 0, otherTransactionItem.TransactionType, otherTransactionItem.Amount.Currency, "other" ,otherTransactionItem.AmazonOrderID);
feeDatas.Add(otherTransactionItemData);
}
......@@ -619,12 +646,14 @@ namespace AutoTurnOver.Services
var adFee = advertisingTransactionDetailsItem;
var adItemData = ApiOtherTransactionDataMapDbData(marketplaceName, pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
adFee.InvoiceId, adFee.PostedDate,
adFee.TransactionAmount.Text ?? 0, advertisingTransactionDetailsItem.TransactionType, adFee.TransactionAmount.Currency);
adFee.TransactionAmount.Text ?? 0, advertisingTransactionDetailsItem.TransactionType, adFee.TransactionAmount.Currency, "other fee");
feeDatas.Add(adItemData);
}
}
dc_base_amazon_settlement settlementDbData = new dc_base_amazon_settlement
{
amount = settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData.TotalAmount.Text ?? 0,
......@@ -877,16 +906,12 @@ namespace AutoTurnOver.Services
feeShipmentEvent.gift_wrap_credits = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.gift_wrap_credits_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales = item.ItemPrice.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
var marketplace_withheld = item.ItemPrice.Component.Where(s => s.Type.Contains("VAT")).ToList();
var marketplace_withheld = item.ItemPrice.Component.Where(s => s.Type.Contains("MarketplaceFacilitator")).ToList();
if (marketplace_withheld != null && marketplace_withheld.Count >= 1)
{
feeShipmentEvent.marketplace_withheld_tax = marketplace_withheld.Sum(s => s.Amount.Text ?? 0);
var marketplace_withheld_type = marketplace_withheld.FirstOrDefault().Type;
if (!string.IsNullOrWhiteSpace(marketplace_withheld_type))
{
feeShipmentEvent.tax_collection_model = marketplace_withheld_type.Substring(0, marketplace_withheld_type.IndexOf("VAT"));
}
var marketplace_withheld_type = "MarketplaceFacilitator";
feeShipmentEvent.tax_collection_model = marketplace_withheld_type;
}
}
......@@ -901,8 +926,12 @@ namespace AutoTurnOver.Services
if (item.Promotion != null && item.Promotion.Any(s=>s.Amount.Text != 0))
{
feeShipmentEvent.promotional_rebates = feeShipmentEvent.postage_credits;
feeShipmentEvent.promotional_rebates_tax = feeShipmentEvent.shipping_credits_tax;
feeShipmentEvent.promotional_rebates = item.Promotion.Sum(s => s.Amount.Text ?? 0);
// 美国站统一没有这个
if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName))
{
feeShipmentEvent.promotional_rebates_tax = 0 - feeShipmentEvent.shipping_credits_tax;
}
}
feeShipmentEvent.total =
......@@ -977,16 +1006,12 @@ namespace AutoTurnOver.Services
feeShipmentEvent.gift_wrap_credits = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.gift_wrap_credits_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
var marketplace_withheld = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Contains("VAT")).ToList();
var marketplace_withheld = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Contains("MarketplaceFacilitator")).ToList();
if (marketplace_withheld != null && marketplace_withheld.Count >= 1)
{
feeShipmentEvent.marketplace_withheld_tax = marketplace_withheld.Sum(s => s.Amount.Text ?? 0);
var marketplace_withheld_type = marketplace_withheld.FirstOrDefault().Type;
if (!string.IsNullOrWhiteSpace(marketplace_withheld_type))
{
feeShipmentEvent.tax_collection_model = marketplace_withheld_type.Substring(0, marketplace_withheld_type.IndexOf("VAT"));
}
var marketplace_withheld_type = "MarketplaceFacilitator";
feeShipmentEvent.tax_collection_model = marketplace_withheld_type;
}
}
......@@ -1001,8 +1026,13 @@ namespace AutoTurnOver.Services
if (itemFeeAdjustment.PromotionAdjustment != null && itemFeeAdjustment.PromotionAdjustment.Any(s=>s.Amount.Text != 0))
{
feeShipmentEvent.promotional_rebates = 0-feeShipmentEvent.postage_credits;
feeShipmentEvent.promotional_rebates_tax = 0-feeShipmentEvent.shipping_credits_tax;
feeShipmentEvent.promotional_rebates = itemFeeAdjustment.PromotionAdjustment.Sum(s=>s.Amount.Text??0);
// 美国站统一没有这个
if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName))
{
feeShipmentEvent.promotional_rebates_tax = 0 - feeShipmentEvent.shipping_credits_tax;
}
}
feeShipmentEvent.total =
......@@ -1030,7 +1060,7 @@ namespace AutoTurnOver.Services
}
public dc_base_amazon_fee ApiOtherTransactionDataMapDbData(string marketplaceName,AmazonAccountDto account, ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SettlementDataDto xmlSettlementData,
string transactionID, DateTime? postedDate, decimal amount, string type, string currency_code)
string transactionID, DateTime? postedDate, decimal amount, string type, string currency_code,string source = "other",string amazonOrderID = null)
{
var fbaTypeDic = new Dictionary<string, string> { };
fbaTypeDic.Add("Storage Fee", "FBA Inventory Fee");
......@@ -1043,16 +1073,38 @@ namespace AutoTurnOver.Services
dc_base_amazon_fee feeShipmentEvent = new dc_base_amazon_fee { };
feeShipmentEvent.account = account.Account;
feeShipmentEvent.settlement_id = xmlSettlementData.AmazonSettlementID;
feeShipmentEvent.AmazonOrderId = transactionID;
if (!string.IsNullOrWhiteSpace(amazonOrderID))
{
feeShipmentEvent.AmazonOrderId = amazonOrderID;
}
else
{
feeShipmentEvent.AmazonOrderId = transactionID;
}
feeShipmentEvent.currency_code = currency_code;
feeShipmentEvent.MarketplaceName = marketplaceName;
feeShipmentEvent.description = type;
feeShipmentEvent.total = amount;
if (source == "other")
{
feeShipmentEvent.other = amount;
}
else if (source == "other fee")
{
feeShipmentEvent.other_transaction_fees = amount;
}
feeShipmentEvent.type = "Other";
if (fbaTypeDic.ContainsKey(type))
if (!string.IsNullOrWhiteSpace(type))
{
feeShipmentEvent.type = fbaTypeDic[type];
feeShipmentEvent.type = type;
if (fbaTypeDic.ContainsKey(type))
{
feeShipmentEvent.type = fbaTypeDic[type];
}
}
feeShipmentEvent.data_id = $"{account.Account}_OtherTransaction_{feeShipmentEvent.AmazonOrderId}_{ feeShipmentEvent.description}_{feeShipmentEvent.settlement_id}";
feeShipmentEvent.date = postedDate == null ? new DateTime(1991, 1, 1) : postedDate.Value;
return feeShipmentEvent;
......
......@@ -281,6 +281,34 @@ namespace AutoTurnOver.Services.Dto
public Amount BaseAmount { get; set; } = new Amount { };
public Amount TransactionAmount { get; set; } = new Amount { };
}
[JsonProperty("SellerDealPayment")]
[JsonConverter(typeof(SellerDealPaymentDataConverter))]
public List<SellerDealPaymentDto> SellerDealPayment { get; set; }
public class SellerDealPaymentDto
{
public DateTime? PostedDate { get; set; }
public string TransactionType { get; set; }
public string PaymentReason { get; set; }
public string DealDescription { get; set; }
public string DealID { get; set; }
public string MarketplaceName { get; set; }
public FeeDto DealFee { get; set; }
}
[JsonProperty("SellerCouponPayment")]
[JsonConverter(typeof(SellerCouponPaymentDataConverter))]
public List<SellerCouponPaymentDto> SellerCouponPayment { get; set; }
public class SellerCouponPaymentDto
{
public DateTime? PostedDate { get; set; }
public string TransactionType { get; set; }
public string PaymentReason { get; set; }
public string Count { get; set; }
public string CouponID { get; set; }
public string MarketplaceName { get; set; }
public FeeDto CouponFee { get; set; }
}
}
}
public class PromotionDto
......@@ -424,6 +452,66 @@ namespace AutoTurnOver.Services.Dto
serializer.Serialize(writer, value);
}
}
class SellerDealPaymentDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerDealPaymentDto));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
{
return token.ToObject<List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerDealPaymentDto>>();
}
if (token.Type == JTokenType.Object)
{
return new List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerDealPaymentDto> { token.ToObject<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerDealPaymentDto>() };
}
else
{
return new List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerDealPaymentDto> { };
}
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
class SellerCouponPaymentDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerCouponPaymentDto));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
{
return token.ToObject<List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerCouponPaymentDto>>();
}
if (token.Type == JTokenType.Object)
{
return new List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerCouponPaymentDto> { token.ToObject<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerCouponPaymentDto>() };
}
else
{
return new List<ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SellerCouponPaymentDto> { };
}
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
class ItemDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment