Skip to content

Commit ceb8452

Browse files
author
Markus Falk
committed
VAT calculation and rounding
1 parent f3b34af commit ceb8452

File tree

67 files changed

+73960
-926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+73960
-926
lines changed

src/Libraries/Nop.Core/Domain/Orders/Order.cs

+58-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public partial class Order : BaseEntity
2626

2727
#region Utilities
2828

29-
protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRatesStr)
29+
protected virtual SortedDictionary<decimal, TaxRateRec> ParseTaxRates(string taxRatesStr)
3030
{
31-
var taxRatesDictionary = new SortedDictionary<decimal, decimal>();
31+
//var taxRatesDictionary = new SortedDictionary<decimal, decimal>();
32+
var taxRatesDictionary = new SortedDictionary<decimal, TaxRateRec>();
3233
if (String.IsNullOrEmpty(taxRatesStr))
3334
return taxRatesDictionary;
3435

@@ -39,13 +40,20 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
3940
continue;
4041

4142
string[] taxes = line.Split(new [] { ':' });
42-
if (taxes.Length == 2)
43+
if (taxes.Length == 6)
4344
{
4445
try
4546
{
46-
decimal taxRate = decimal.Parse(taxes[0].Trim(), CultureInfo.InvariantCulture);
47-
decimal taxValue = decimal.Parse(taxes[1].Trim(), CultureInfo.InvariantCulture);
48-
taxRatesDictionary.Add(taxRate, taxValue);
47+
decimal rate = decimal.Parse(taxes[0].Trim(), CultureInfo.InvariantCulture);
48+
taxRatesDictionary.Add(rate, new TaxRateRec()
49+
{
50+
VatRate = rate,
51+
Amount = decimal.Parse(taxes[1].Trim(), CultureInfo.InvariantCulture),
52+
DiscountAmount = decimal.Parse(taxes[2].Trim(), CultureInfo.InvariantCulture),
53+
BaseAmount = decimal.Parse(taxes[3].Trim(), CultureInfo.InvariantCulture),
54+
VatAmount = decimal.Parse(taxes[4].Trim(), CultureInfo.InvariantCulture),
55+
AmountIncludingVAT = decimal.Parse(taxes[5].Trim(), CultureInfo.InvariantCulture)
56+
});
4957
}
5058
catch (Exception exc)
5159
{
@@ -56,7 +64,15 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
5664

5765
//add at least one tax rate (0%)
5866
if (!taxRatesDictionary.Any())
59-
taxRatesDictionary.Add(decimal.Zero, decimal.Zero);
67+
taxRatesDictionary.Add(decimal.Zero, new TaxRateRec()
68+
{
69+
VatRate = decimal.Zero,
70+
Amount = decimal.Zero,
71+
DiscountAmount = decimal.Zero,
72+
BaseAmount = decimal.Zero,
73+
VatAmount = decimal.Zero,
74+
AmountIncludingVAT = decimal.Zero
75+
});
6076

6177
return taxRatesDictionary;
6278
}
@@ -196,7 +212,7 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
196212
public decimal OrderDiscount { get; set; }
197213

198214
/// <summary>
199-
/// Gets or sets the order total
215+
/// Gets or sets the order total to pay
200216
/// </summary>
201217
public decimal OrderTotal { get; set; }
202218

@@ -209,7 +225,7 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
209225
/// Gets or sets the reward points history entry identifier when reward points were earned (gained) for placing this order
210226
/// </summary>
211227
public int? RewardPointsHistoryEntryId { get; set; }
212-
228+
213229
/// <summary>
214230
/// Gets or sets the checkout attribute description
215231
/// </summary>
@@ -309,7 +325,7 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
309325
/// Gets or sets the paid date and time
310326
/// </summary>
311327
public DateTime? PaidDateUtc { get; set; }
312-
328+
313329
/// <summary>
314330
/// Gets or sets the shipping method
315331
/// </summary>
@@ -335,6 +351,24 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
335351
/// </summary>
336352
public DateTime CreatedOnUtc { get; set; }
337353

354+
/// <summary>
355+
/// Gets or sets the invoice ID
356+
/// </summary>
357+
public string InvoiceId { get; set; }
358+
/// <summary>
359+
/// Gets or sets the invoice date UTC
360+
/// </summary>
361+
public DateTime? InvoiceDateUtc { get; set; }
362+
363+
/// <summary>
364+
/// Gets or sets the order total base amount excl. tax
365+
/// </summary>
366+
public decimal OrderAmount { get; set; } //MF 09.12.16
367+
368+
/// <summary>
369+
/// Gets or sets the order total amount incl. tax
370+
/// </summary>
371+
public decimal OrderAmountIncl { get; set; } //MF 09.12.16
338372
#endregion
339373

340374
#region Navigation properties
@@ -476,14 +510,26 @@ public TaxDisplayType CustomerTaxDisplayType
476510
/// <summary>
477511
/// Gets the applied tax rates
478512
/// </summary>
479-
public SortedDictionary<decimal, decimal> TaxRatesDictionary
513+
public SortedDictionary<decimal, TaxRateRec> TaxRatesDictionary
480514
{
481515
get
482516
{
483517
return ParseTaxRates(this.TaxRates);
484518
}
485519
}
486-
520+
487521
#endregion
488522
}
523+
524+
#region Nested classes
525+
public partial class TaxRateRec
526+
{
527+
public decimal VatRate { get; set; }
528+
public decimal Amount { get; set; }
529+
public decimal DiscountAmount { get; set; }
530+
public decimal BaseAmount { get; set; }
531+
public decimal VatAmount { get; set; }
532+
public decimal AmountIncludingVAT { get; set; }
533+
}
534+
#endregion
489535
}

src/Libraries/Nop.Core/Domain/Orders/OrderItem.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public partial class OrderItem : BaseEntity
7575
/// Gets or sets the product attributes in XML format
7676
/// </summary>
7777
public string AttributesXml { get; set; }
78-
78+
7979
/// <summary>
8080
/// Gets or sets the download count
8181
/// </summary>
@@ -125,5 +125,10 @@ public virtual ICollection<GiftCard> AssociatedGiftCards
125125
get { return _associatedGiftCards ?? (_associatedGiftCards = new List<GiftCard>()); }
126126
protected set { _associatedGiftCards = value; }
127127
}
128+
129+
/// <summary>
130+
/// VAT% of product
131+
/// </summary>
132+
public decimal VatRate { get; set; } //MF 25.11.16
128133
}
129134
}

src/Libraries/Nop.Core/Domain/Orders/OrderSettings.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public class OrderSettings : ISettings
120120
/// Gets or sets a value indicating whether an order status should be set to "Complete" only when its shipping status is "Delivered". Otherwise, "Shipped" status will be enough.
121121
/// </summary>
122122
public bool CompleteOrderWhenDelivered { get; set; }
123-
123+
/// <summary>
124+
/// Last issued Invoice Id
125+
/// </summary>
126+
public int InvoiceIdent { get; set; }
127+
/// <summary>
128+
/// Last issued Invoice Date
129+
/// </summary>
130+
public int InvoiceYear { get; set; }
124131
}
125132
}

src/Libraries/Nop.Core/Domain/Orders/ShoppingCartItem.cs

+16-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public partial class ShoppingCartItem : BaseEntity
4343
/// Gets or sets the quantity
4444
/// </summary>
4545
public int Quantity { get; set; }
46-
4746
/// <summary>
4847
/// Gets or sets the rental product start date (null if it's not a rental product)
4948
/// </summary>
@@ -63,7 +62,7 @@ public partial class ShoppingCartItem : BaseEntity
6362
/// Gets or sets the date and time of instance update
6463
/// </summary>
6564
public DateTime UpdatedOnUtc { get; set; }
66-
65+
6766
/// <summary>
6867
/// Gets the log type
6968
/// </summary>
@@ -119,7 +118,7 @@ public bool IsShipEnabled
119118

120119
/// <summary>
121120
/// Gets the additional shipping charge
122-
/// </summary>
121+
/// </summary>
123122
public decimal AdditionalShippingCharge
124123
{
125124
get
@@ -145,5 +144,19 @@ public bool IsTaxExempt
145144
return false;
146145
}
147146
}
147+
//fields for restored cart
148+
/// <summary>
149+
/// VatRate for restored cart. Only used by UpdateOrderTotal and can be null
150+
/// </summary>
151+
public decimal? VatRate { get; set; }
152+
/// <summary>
153+
/// Subtotal of item with tax
154+
/// </summary>
155+
public decimal? SubTotalInclTax { get; set; }
156+
157+
/// <summary>
158+
/// Subtotal of item without tax
159+
/// </summary>
160+
public decimal? SubTotalExclTax { get; set; }
148161
}
149162
}

src/Libraries/Nop.Data/Mapping/Orders/OrderItemMap.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public OrderItemMap()
1717
this.Property(orderItem => orderItem.DiscountAmountExclTax).HasPrecision(18, 4);
1818
this.Property(orderItem => orderItem.OriginalProductCost).HasPrecision(18, 4);
1919
this.Property(orderItem => orderItem.ItemWeight).HasPrecision(18, 4);
20+
this.Property(orderItem => orderItem.VatRate).HasPrecision(18, 4); //MF 25.11.16
2021

2122

2223
this.HasRequired(orderItem => orderItem.Order)

src/Libraries/Nop.Data/Mapping/Orders/OrderMap.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public OrderMap()
1919
this.Property(o => o.PaymentMethodAdditionalFeeExclTax).HasPrecision(18, 4);
2020
this.Property(o => o.OrderTax).HasPrecision(18, 4);
2121
this.Property(o => o.OrderDiscount).HasPrecision(18, 4);
22+
this.Property(o => o.OrderAmount).HasPrecision(18, 4); //MF 09.12.16
23+
this.Property(o => o.OrderAmountIncl).HasPrecision(18, 4); //MF 09.12.16
2224
this.Property(o => o.OrderTotal).HasPrecision(18, 4);
2325
this.Property(o => o.RefundedAmount).HasPrecision(18, 4);
2426

@@ -27,11 +29,11 @@ public OrderMap()
2729
this.Ignore(o => o.ShippingStatus);
2830
this.Ignore(o => o.CustomerTaxDisplayType);
2931
this.Ignore(o => o.TaxRatesDictionary);
30-
32+
3133
this.HasRequired(o => o.Customer)
3234
.WithMany()
3335
.HasForeignKey(o => o.CustomerId);
34-
36+
3537
//code below is commented because it causes some issues on big databases - http://www.nopcommerce.com/boards/t/11126/bug-version-20-command-confirm-takes-several-minutes-using-big-databases.aspx
3638
//this.HasRequired(o => o.BillingAddress).WithOptional().Map(x => x.MapKey("BillingAddressId")).WillCascadeOnDelete(false);
3739
//this.HasOptional(o => o.ShippingAddress).WithOptionalDependent().Map(x => x.MapKey("ShippingAddressId")).WillCascadeOnDelete(false);

src/Libraries/Nop.Data/Mapping/Orders/ShoppingCartItemMap.cs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public ShoppingCartItemMap()
1616
this.Ignore(sci => sci.IsShipEnabled);
1717
this.Ignore(sci => sci.AdditionalShippingCharge);
1818
this.Ignore(sci => sci.IsTaxExempt);
19+
this.Ignore(sci => sci.VatRate);
20+
this.Ignore(sci => sci.SubTotalExclTax);
21+
this.Ignore(sci => sci.SubTotalInclTax);
1922

2023
this.HasRequired(sci => sci.Customer)
2124
.WithMany(c => c.ShoppingCartItems)

src/Libraries/Nop.Services/Catalog/IPriceFormatter.cs

+28-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public partial interface IPriceFormatter
4343
/// <param name="showTax">A value indicating whether to show tax suffix</param>
4444
/// <param name="language">Language</param>
4545
/// <returns>Price</returns>
46-
string FormatPrice(decimal price, bool showCurrency,
46+
string FormatPrice(decimal price, bool showCurrency,
4747
string currencyCode, bool showTax, Language language);
4848

4949
/// <summary>
@@ -67,7 +67,7 @@ string FormatPrice(decimal price, bool showCurrency,
6767
/// <param name="language">Language</param>
6868
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
6969
/// <returns>Price</returns>
70-
string FormatPrice(decimal price, bool showCurrency,
70+
string FormatPrice(decimal price, bool showCurrency,
7171
Currency targetCurrency, Language language, bool priceIncludesTax);
7272

7373
/// <summary>
@@ -80,7 +80,7 @@ string FormatPrice(decimal price, bool showCurrency,
8080
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
8181
/// <param name="showTax">A value indicating whether to show tax suffix</param>
8282
/// <returns>Price</returns>
83-
string FormatPrice(decimal price, bool showCurrency,
83+
string FormatPrice(decimal price, bool showCurrency,
8484
Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax);
8585

8686
/// <summary>
@@ -110,7 +110,7 @@ string FormatPrice(decimal price, bool showCurrency,
110110
/// <param name="language">Language</param>
111111
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
112112
/// <returns>Price</returns>
113-
string FormatShippingPrice(decimal price, bool showCurrency,
113+
string FormatShippingPrice(decimal price, bool showCurrency,
114114
Currency targetCurrency, Language language, bool priceIncludesTax);
115115
/// <summary>
116116
/// Formats the shipping price
@@ -122,9 +122,9 @@ string FormatShippingPrice(decimal price, bool showCurrency,
122122
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
123123
/// <param name="showTax">A value indicating whether to show tax suffix</param>
124124
/// <returns>Price</returns>
125-
string FormatShippingPrice(decimal price, bool showCurrency,
125+
string FormatShippingPrice(decimal price, bool showCurrency,
126126
Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax);
127-
127+
128128
/// <summary>
129129
/// Formats the shipping price
130130
/// </summary>
@@ -134,7 +134,7 @@ string FormatShippingPrice(decimal price, bool showCurrency,
134134
/// <param name="language">Language</param>
135135
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
136136
/// <returns>Price</returns>
137-
string FormatShippingPrice(decimal price, bool showCurrency,
137+
string FormatShippingPrice(decimal price, bool showCurrency,
138138
string currencyCode, Language language, bool priceIncludesTax);
139139

140140

@@ -169,7 +169,7 @@ string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
169169
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
170170
/// <param name="showTax">A value indicating whether to show tax suffix</param>
171171
/// <returns>Price</returns>
172-
string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
172+
string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
173173
Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax);
174174

175175
/// <summary>
@@ -181,7 +181,7 @@ string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
181181
/// <param name="language">Language</param>
182182
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
183183
/// <returns>Price</returns>
184-
string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
184+
string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
185185
string currencyCode, Language language, bool priceIncludesTax);
186186

187187

@@ -192,5 +192,24 @@ string FormatPaymentMethodAdditionalFee(decimal price, bool showCurrency,
192192
/// <param name="taxRate">Tax rate</param>
193193
/// <returns>Formatted tax rate</returns>
194194
string FormatTaxRate(decimal taxRate);
195+
196+
/// <summary>
197+
/// Adds tax suffix to text
198+
/// </summary>
199+
/// <param name="text">Text to format</param>
200+
/// <param name="language">Language</param>
201+
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
202+
/// <returns></returns>
203+
string FormatTaxString(string text, Language language, bool priceIncludesTax);
204+
205+
/// <summary>
206+
/// Adds tax suffix to text
207+
/// </summary>
208+
/// <param name="text">Text to format</param>
209+
/// <param name="language">Language</param>
210+
/// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
211+
/// <param name="showTax">Optional. A value indicating whether to show tax suffix.</param>
212+
/// <returns></returns>
213+
string FormatTaxString(string text, Language language, bool priceIncludesTax, bool showTax);
195214
}
196215
}

0 commit comments

Comments
 (0)