From 98d8d2f31b4c07a2fd5e204791ed9861da9e18ec Mon Sep 17 00:00:00 2001 From: anion0278 Date: Fri, 12 Nov 2021 14:05:04 +0100 Subject: [PATCH] fix: tax calculation --- .../InvoiceConverter.cs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Mapp.BusinessLogic.Invoices/InvoiceConverter.cs b/Mapp.BusinessLogic.Invoices/InvoiceConverter.cs index f07124b..c4f0e66 100644 --- a/Mapp.BusinessLogic.Invoices/InvoiceConverter.cs +++ b/Mapp.BusinessLogic.Invoices/InvoiceConverter.cs @@ -162,7 +162,7 @@ private Invoice ProcessInvoiceLine(IReadOnlyDictionary valuesFro var invoiceItemShipping = FillInvoiceItem( new InvoiceItemGeneral(invoice, InvoiceItemType.Shipping), - GetSavedShippingType(sku, invoice.Classification), + GetSavedShippingType(sku, invoice.ClientInfo, invoice.Classification), decimal.Parse(valuesFromAmazon["shipping-price"]), decimal.Parse(valuesFromAmazon["shipping-tax"]), 1); @@ -183,15 +183,22 @@ private Invoice ProcessInvoiceLine(IReadOnlyDictionary valuesFro // TODO fix if (valuesFromAmazon.TryGetValue("gift-wrap-price", out var giftWrapPrice) // columns are not always available in the amazon invoice && valuesFromAmazon.TryGetValue("gift-wrap-tax", out var giftWrapTax) - && decimal.TryParse(giftWrapPrice, out var giftWrapPriceV) - && giftWrapPriceV != 0) + && decimal.TryParse(giftWrapPrice, out var giftWrapPriceValue) + && giftWrapPriceValue != 0) { + decimal giftWrapTaxVal = 0; + + if (decimal.TryParse(giftWrapTax, out var valueTax)) + { + giftWrapTaxVal = valueTax; + } + string giftWrapType = "Gift wrap " + valuesFromAmazon["gift-wrap-type"]; var invoiceItemGiftWrap = FillInvoiceItem( new InvoiceItemGeneral(invoice, InvoiceItemType.GiftWrap), giftWrapType, - decimal.Parse(giftWrapPrice), - decimal.Parse(giftWrapTax), + giftWrapPriceValue, + giftWrapTaxVal, 1); invoiceItems.Add(invoiceItemGiftWrap); } @@ -205,12 +212,13 @@ private Invoice ProcessInvoiceLine(IReadOnlyDictionary valuesFro } - private InvoiceItemBase FillInvoiceItem(InvoiceItemBase invoiceItem, string name, decimal price, decimal tax, decimal quantity) + private InvoiceItemBase FillInvoiceItem(InvoiceItemBase invoiceItem, string name, decimal priceIncludingTax, decimal tax, decimal quantity) { invoiceItem.Name = name; invoiceItem.Quantity = quantity; invoiceItem.TotalPriceWithTax = new CommonServices.Currency( - price * (1 - invoiceItem.ParentInvoice.CountryVat.ReversePercentage), + priceIncludingTax, // There is no need to manually calculate tax (ReverseTaxValue) and subtract it since its value is available in amazon report + // and recalculation logic is included into InvoiceBase Item invoiceItem.ParentInvoice.TotalPrice.ForeignCurrencyName, _rates); @@ -247,15 +255,22 @@ private string GetCustomsDeclarationBySkuOnlyForNonEu(string sku, InvoiceVatClas return string.Empty; } - private string GetSavedShippingType(string sku, InvoiceVatClassification classification) + private string GetSavedShippingType(string sku, ClientInfo clientInfo, InvoiceVatClassification classification) { string defaultShippingName = "Shipping"; + + if (_autocompleteData.DefaultShippingByPartnerCountry.TryGetValue(clientInfo.Address.Country, out string countryDefaultShipping)) + { + defaultShippingName = countryDefaultShipping; + } + if (classification != InvoiceVatClassification.UDA5 && classification != InvoiceVatClassification.RDzasEU) { return defaultShippingName; } - return GetAutocompleteOrEmpty( + // only for non-EU + return GetAutocompleteOrEmpty( // TODO ПРОБЛЕМА в том что при агригации шипиногов их названия будут стираться _autocompleteData.ShippingNameBySku, sku, defaultShippingName);