Method Of Calculating a Cart Total (MOCCT)
Technical highlight: Introducing strong typing DecimalNumberNot used in course of maturation
Description
Step 1 - Standard Price and impact price
It exists 4 types of products
To calculate the price of a product before the discount
It would help if you calculated exactly with the price you are offering the product.
If you want to calculate with fractional cents, then this needs to be able to be reproduced by the customer. So you need to show more precision on the product price, invoice positions and then round the final invoice to something that actually could be transferred.
You calculate either with tax-exclusive or tax-inclusive prices. If you want to display both prices, the other price would only be informative and imprecise and MUST not be used for any calculation.
1) Product A without combination
2) Product B without a combination
3) Product C without combination
4) Product D without combination
For Products with combination :
If you are in a B to B display mode use the following data for chart calculation
Price_of_product_tax_excluded_step1 = Retail price (tax excl.) and impact price (tax excl).
If you are in a B to C display mode use the following data for chart calculation
Price_of_product_tax_included_step1 = Retail price (tax incl.) + impact price (tax incl).
For the other products
If you are in a B to B display mode use the following data
Price_of_product_tax_excluded_step1 = Retail price (tax excl.)
If you are in a B to C display mode use the following data
Price_of_product_tax_included_step1 = Retail price (tax incl.)
Output data from this step
If B to C
For each product (Price_of_product_tax_included_step1;Rate of the product)
If B to B
For each product (Price_of_product_tax_excluded_step1;Rate of the product)
Example Output data for products A,B,C,D
If B to B
Product A : (5.221;20%)
Product B : (2.506;10%)
Product C : (6.22;20%)
Product D : (3.515;10%)
If B to C
Product A : (6.2652;20%)
Product B : (2.7566;10%)
Product C : (7.464;20%)
Product D : (3.8665;10%)
The data from this step to the following are sent with the most precision possible because the data displayed in the FO, so rounded, are this one after step 4 "Discount Customer Group" (or step 3 if step 4 is decided to be merged with step 3)
Step 2 - Discount Specific price for now consider no discount
This step will be calculated only if it exists some specific prices.
Output data from this step
If B to C
Price_of_product_tax_included_step2
Rate of the product
If B to B
Price_of_product_tax_excluded_step2
Rate of the product
The data from this step to the following are sent with the most of precision possible because the data displayed in the FO is this one after step 4 "Discount Customer Group" or step 3 if step 4 is decided to be merged with step 3.
Step 3 - Discount Catalog Price Rules for now consider no discount
This step will be calculated only if it exists some Catalog Price Rules.
To know if the prioritary between specific price and catalog price rules look at the diagram below
Output data from this step
If B to C
Price_of_product_tax_included_step3
Rate of the product
If B to B
Price_of_product_tax_excluded_step3
Rate of the product
The data from this step to the following are sent with the most of precision possible because the data displayed in the FO is this one after step 4 "Discount Customer Group" or step 3 if step 4 is decided to be merged with step 3.
Step 4 - Discount - Customer Group (maybe included in catalog price rules) for now consider no discount
This step will be calculated only if it exists some Catalog Price Rules.
Output data from this step
If B to C
Price_of_product_tax_included_step4
Rate of the product
If B to B
Price_of_product_tax_excluded_step4
Rate of the product
The data from this step to the following are sent with the most of precision possible because the data displayed in the FO is this one after step 4 "Discount Customer Group" or step 3 if step 4 is decided to be merged with step 3.
After each cart rules you have to apply rounding because each discount is displayed
Rounding 1 for display price
Each price displayed in the BO (list of products) and the FO is rounded according to the Decimals defined in currencies.
Products in BO :
Products in FO in the details page or in the catalog :
Display_price_rounding_1 = Price of the product after the discounts (step 3) on which will be applied round mode* taking into account the number of decimals as follows :
Configuration in the BO
WARNING: We have to disting data displayed to data used for the following calculations.
Output data from this step
For each product (Display_price_rounding_1, rate)
Example Output data for products A,B, C,D considering
round mode: Round up away from zero, when it is half way there (recommended) which is the round merchant
Product A : (5.22;20%)
Product B : (2.51;10%)
Product C : (6.22;20%)
Product D : (3.52;10%)
If B to C
Product A : (6.27;20%)
Product B : (2.76;10%)
Product C : (7.46;20%)
Product D : (3.87;10%)
Rounding 1 for calculation
We are going to set the Rounding thanks to a toggle button depending on :
either by the number of decimals in the currencies [case 1 -like rounding 1 for display price] or
the number of digits after coma in the tab pricing of product (case 2).
Why the second option is interesting?
Case of gas station for fuel. The price is calculated with three digits after coma even if the payment is with two digits in the case of euros for instance. So for the calculation, the rounding has to be done with three digits not depending on currency. Only the result will be rounded ate the end.
Case 1 : Rounding depending on the number of currency decimals used in the context of the FO and configured in the BO.
In this case, rounding for calculation in the next step is the same as that used for displayed prices.
Calculation_price_rounding_1 = Price of the product after the catalog discounts (step 4) on which will be applied round mode* taking into account the number of decimals as follows :
Configuration in the BO
Contextual currency in FO
Contextual currency in BO for order
Case 2 : Rounding depending on the number of digits after coma in the tab pricing of product (case 2).
Calculation_price_rounding_1 = Price of the product after the catalog discounts (step 4) on which will be applied round mode* taking into account the number of decimals as follows :
If B to C check the number of digits for retail price (tax excl.)
If B to B check the number of digits for retail price (tax incl.)
Case 1 : Output data from this step
For each product (Calculation_price_rounding_1, rate)
Example Output data for products A,B,C,D considering
round mode: Round up away from zero, when it is half way there (recommended) which is the round merchant
Case 1 if B to B
Product A : (5.22;20%)
Product B : (2.51;10%)
Product C : (6.22;20%)
Product D : (3.52;10%)
Case 1 If B to C
Product A : (6.27;20%)
Product B : (2.76;10%)
Product C : (7.46;20%)
Product D : (3.87;10%)
Todo case 2
Case 2 : Output data from this step
For each product (Calculation_price_rounding_1, rate)
*Round mode
Round up away form zero, when it is half way there (recommended)
Round down towards zero when it is half way there
Round towards the next even value
Round towards the next odd value
Round up to the nearest value
Round down to the nearest value
Step 5 - Discount- Cart Rules for now consider no discount
Output data from this step
If B to C
Price_of_product_tax_included_step5 (price after cart rules n)
Amount_of_the_discount_tax_included_step5
Rate of the product
If B to B
Price_of_product_tax_excluded_step5 (price after cart rules n)
Amount_of_the_discount_tax_excluded_step5
Rate of the product
Rounding 2 for display price for now consider no discount
The amount of the discount in the chart in the FO is rounded according to the Decimals defined in currencies.
Display_amount_discount_n_rounding_2 = Price of the product after the previous cart rule (step 5) on which will be applied round mode* taking into account the number of decimals as follows :
1 - Display_amount_discount_1_rounding_2
2-Display_amount_discount_2_rounding_2
Configuration in the BO
We have to disting data displayed to data used for the following calculations.
Output data from this step
Display_amount_discount_n_rounding_2
Rounding 2 for calculation for now consider no discount
Thanks to a toggle button either by the number of decimals in the currencies (case 1] or depending on the number of digits after coma in the tab pricing of product (case 2).
Why the second option is interesting ?
Case of gas station for fuel. The price is displayed with three digits after coma event if the payment is with two digits in the case of euros. So for the calculation, the rounding has to be done with three digits.
Case 1 : Rounding depends on the number of currency decimals used in the context of the FO and configured in the BO.
In this case, rounding for calculation in the next step is the same as the rounding used for displayed prices.
Calculation_amount_rounding_2 = Price of the product after the previous cart rule (step 5) on which will be applied round mode* taking into account the number of decimals as follows
Configuration in the BO
Contextual currency in FO
Contextual currency in BO for order
Case 2 : Rounding depending on the number of digits after coma in the tab pricing of product (case 2).
Calculation_amount_rounding_2 = Price of product before the discounts (value calculated in step 5) on which will be applied round mode* taking into account the number of decimals as follows
If B to C check the number of digits for retail price (tax excl.)
If B to B check the number of digits for retail price (tax incl.)
Output data from this step
Calculation_price_rounding_2
If you have another discount Go back to step 5 else go on calculation of VATthe
Step 6 - Total price excluded/included of products
B to B
a product A quantity 4 in the chart
a product B quantity 2 in the chart
a product C quantity 3 in the chart
a product D quantity 1
a product A 5.22 euros taxes excluded at rate 20%, quantity 4
a product B 2.51 taxes excluded 10%, quantity 2
a product C 6.22 taxes excluded at 20%, quantity 3
a product D 3.52 taxes excluded 10%, quantity 1
Total_cost_excluded_productA = 5.22 * 4 = 20.88
Total_cost_excluded_productB = 2.51 * 2 = 5.02
Total_cost_excluded_productC = 6.22 * 3 = 18.66
Total_cost_excluded_productD = 3.52 * 1 = 3.52
Total_cost_excluded_products = Total_cost_excluded_productA + Total_cost_excluded_productB + Total_cost_excluded_productC + Total_cost_excluded_productD = 20.88 + 5.02 + 18.66 + 3.52 = 48.08
Output data from this step
Total_cost_excluded_productA
Total_cost_excluded_productB
Total_cost_excluded_productC
Total_cost_excluded_productD
Total_cost_excluded_products
B to C
a product A quantity 4 in the chart
a product B quantity 2 in the chart
a product C quantity 3 in the chart
a product D quantity 1
a product A 6.27 euros taxes included at rate 20%, quantity 4
a product C 7.46 euros taxes included at rate 20%, quantity 3
a product B 2.76 euros taxes included at rate 10%, quantity 2
a product 3.87 euros taxes included at rate10%, quantity 1
Total_cost_included_productA = 6.27 * 4 = 25.08
Total_cost_included_productB = 2.76 * 2 = 5.52
Total_cost_included_productC = 7.46 * 3 = 22.38
Total_cost_included_productD = 3.87 * 1 = 3.87
Total_cost_included_products = Total_cost_included_productA + Total_cost_included_productB + Total_cost_included_productC + Total_cost_included_productD = 25.08 + 5.52 + 22.38 + 3.87 = 56.85
Output data from this step
Total_cost_included_productA
Total_cost_included_productB
Total_cost_included_productC
Total_cost_included_productD
Total_cost_included_products
Step 7 - Calculation of VAT
B to B
Taxes: Sum of rounding of VAT :
To calculate a unique VAT
1) VAT of products
First group the excluded tax costs by VAT value, round each one and then add them together. Consider Let's take the products A,B,C,D like rounded step 1
We combine products taxed at 20% and those taxed at 10%, as follows
a product A 5.22 euros taxes excluded at rate 20%, quantity 4
a product C 6.22 taxes excluded at 20%, quantity 3
a product B 2.51 taxes excluded 10%, quantity 2
a product D 3.52 taxes excluded 10%, quantity 1
We calculate the prices tax excluded of products with rate 20% rounded (let's use line rounding for the example):
Sum them cost of product tax excluded of product with rate 20%
Total_cost_excluded_ rate20 =Total_cost_excluded_productA +Total_cost_excluded_productC = 20.88 + 18.66 = 39,54
VAT of products with rate 20%
VAT_rate_20 = 20%*Total_cost_excluded_rate20 =0.20 * 39.54 = 7.908
We calculate the prices tax excluded of products with rate 10% rounded (let's use line rounding for the example):
Sum them cost of product tax excluded of product with rate 10%
Total_cost_excluded_ rate10 =Total_cost_excluded_productB +Total_cost_excluded_productD = 5.02 + 3.52 = 8,54
VAT of products with rate 10%
VAT_rate_10 = 10%*Total_cost_excluded_rate10 = 0.1 * 8.54 = 0.854
B to C
Let's now imagine the same product in B to C
and the parameter of rounding is fixing with this one of the currency so two decimals after coma
We combine products taxed at 20% and those taxed at 10%, as follows
a product A 6.27 euros taxes included at rate 20%, quantity 4
a product C 7.46 euros taxes included at rate 20%, quantity 3
a product B 2.76 euros taxes included at rate 10%, quantity 2
a product 3.87 euros taxes included at rate10%, quantity 1
We calculate the prices tax included of products with rate 20% rounded (let's use line rounding for the example):
Sum them cost of product tax included of product with rate 20%
Total_cost_included_ rate20 =Total_cost_included_productA +Total_cost_included_productC = 25.08 + 22.38
47.46/1.2 = 39.55 Price tax excluded of product with rate 20%
VAT of products with rate 20%
VAT_rate_20 = 47.46-39.55 = 7.91
We calculate the prices tax included of products with rate 10% rounded (let's use line rounding for the example):
Sum them cost of product tax included of product with rate 10%
Total_cost_included_ rate10 =Total_cost_included_productB +Total_cost_included_productD =
5.52 + 3.87 = 9.39 Price tax included of products with rate 10%
9.39/1.1 = 8.536363.. Price tax excluded of product with rate 10%
VAT of products with rate 10%
VAT_rate_10 = 9.39-(9.39/1.1) = 0.853636
Output data from this step
VAT_rate_20
VAT_rate_10
VAT_rate_X
Total_cost_excluded_products
Total_cost_included_products
2) To calculate multi VAT : TODO
Rounding 3 for display price
The amount of the discounts in the chart in the FO is rounded according to the Decimals defined in currencies.
The display mode is used for invoice and chart
Display_VAT_rate_20_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Display_VAT_rate_10_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Display_VAT_rate_X_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Display_Total_VAT_rounding_3 = Total_VAT_rounding_3 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Configuration in the BO
B to B : example
Display_VAT_rate_20_rounding_3 = 7.91 (rounded up of VAT_rate_20 = 7.908)
Display_VAT_rate_10_rounding_3 = 0.85 (rounded up of VAT_rate_10 = 0.854)
VAT total of products :
Display_Total_VAT_rounding_3 = Display_VAT_rate_20_rounding + Display_VAT_rate_10_rounding = 7.91 + 0.85 = 8.76
B to C : example
Display_VAT_rate_20_rounding_3 = 7.91 (rounded up of VAT_rate_20 = 7.91)
Display_VAT_rate_10_rounding_3 = 0.85 (rounded up of VAT_rate_10 = 0.853636)
VAT total of products
Display_Total_VAT_rounding_3 = Display_VAT_rate_20_rounding + Display_VAT_rate_10_rounding = 7.91 + 0.85 = 8.76
We have to disting data displayed to data used for the following calculations.
Output data from this step
Display_VAT_rate_20_rounding_3
Display_VAT_rate_10_rounding_3
Display_VAT_rate_X_rounding_3
Display_Total_VAT_rounding_3
Step Rounding 3 for calculation
Thanks to a toggle button either by the number of decimals in the currencies (case 1] or depending on the number of digits after coma in the tab pricing of product (case 2).
Why the second option is interesting ?
Case of gas station for fuel. The price is displayed with three digits after coma event if the payment is with two digits in the case of euros. So for the calculation, the rounding has to be done with three digits.
Case 1 : Rounding depending on the number of currency decimals used in the context of the FO and configured in the BO.
In this case, rounding for calculation in the next step is the same as the rounding used for displayed prices.
Calculation_VAT_rate_20_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Calculation_VAT_rate_10_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Calculation_VAT_rate_X_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Calculation_Total_VAT_rounding_3 = Total_VAT_rounding_3 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Configuration in the BO
Contextual currency in FO
Contextual currency in BO for order
Calculation_VAT_rate_20_rounding_3 = Display_VAT_rate_20_rounding_3
Calculation_VAT_rate_10_rounding_3 = Display_VAT_rate_10_rounding_3
Calculation_VAT_rate_X_rounding_3 = Display_VAT_rate_X_rounding_3
Calculation_Total_VAT_rounding_3 = Display_Total_VAT_rounding_3
Case 2 : Rounding depending on the number of digits after coma in the tab pricing of product (case 2).
TODO : an example
Calculation_VAT_rate_20_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows Calc_VAT_rate_10_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Calculation_VAT_rate_X_rounding_3 = VAT_rate_20 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
Calculation_Total_VAT_rounding_3 = Total_VAT_rounding_3 (step 6) on which will be applied round mode* taking into account the number of decimals as follows
If B to C check the number of digits for retail price (tax excl.)
If B to B check the number of digits for retail price (tax incl.)
Output data from this step
Calculation_VAT_rate_20_rounding_3
Calculation_VAT_rate_X_rounding_3
Calculation_Total_VAT_rounding_3
Step 8 - Retrieve cost of Shipping
Today, we consider only mono-shipping.
You have to determine if the shipping is free or not.
1) Shipping could be free :
1.1) If defined like this for the carrier
1.2) If a cart rule in the chart mentions free shipping and filled conditions of the cart rules
1.3) Shipping to 0 by range is like free or could be integrated to shipping not free = 0 and the result will be 0.
Range and cost are tax excluded: cf 1- and 2- image below
1.4) Free shipping starts at in Shipping>Preference (is tax included)
2) In case of shipping not free
Three things to retrieve : Carrier's tax, Cost tax excluded of shipping, handling charges if add handling costs is "Yes"
2.1) In Shipping>Carriers
1- Carrier's_tax
2- Cost_of_ shipping_tax_excluded
2.2) In Shipping>Preferences
3- Handling_charges_tax_excluded
VAT of shipping
The shipping and handling tax is added
Consider :
Cost_of_carrier_tax_excluded = 20 euros and Carrier's_tax = 10 %
Handling_charges_tax_excluded = 2 euros
Shipping_cost_tax_excluded = Cost_of_carrier_tax_excluded + Handling_charges_tax_excluded = 20 + 2 = 22
We calculate the shipping VAT: Carrier_VAT = Cost_of_carrier_tax_excluded * Carrier's_tax = 0,1 * 20 = 2
We calculate the handling VAT: Handling_VAT = Handling_charges_tax_excluded * Carrier's_tax = 0,1 * 2 = 0,2
For a total tax of :
Total_Shipping_VAT = Carrier_VAT + Handling_VAT
2 + 0,2 = 2.2
Output data from this step
Shipping_cost_tax_excluded
Total_Shipping_VAT
Rounding 4 for display
The amount of the discounts in the chart in the FO is rounded according to the Decimals defined in currencies.
Display_Shipping_cost_tax_excluded_rounding_4 = Shipping_cost_tax_excluded (step 7) on which will be applied round mode* taking into account the number of decimals as follows
Display_Total_Shipping_VAT_rounding_4 = Total_Shipping_VAT (step 7) on which will be applied round mode* taking into account the number of decimals as follows
Configuration in the BO
Output data from this step
Display_Shipping_cost_tax_excluded_rounding_4
Display_Total_Shipping_VAT_rounding_4
Rounding 4 for calculation
Step 9 - Display of the chart
B to B
2 - Display_price_rounding_1
3 - Total_cost_excluded_productX (step 6)
4 - Total_cost_included_products (step 6)
5 - Shipping_cost_tax_excluded (step 7)
6 - Total_tax_excluded = Total_cost_excluded_products (step 6) + Shipping_cost_tax_excluded (step 7)
9 - Taxes = Display_Total_VAT_rounding_3 + Total_Shipping_VAT_rounding_4 = 8.76 + 2.2 = 10.96 (stepXXX)
10 - Total = Total_tax_excluded + Taxes
B to C
2 - Price_of_product_tax_included_step1
3 - Total_cost_excluded_productX (step 6)
4 - Total_cost_included_products (step 6)
7 - Shipping_cost_tax_included : Shipping_cost_tax_excluded (step 7) + Total_Shipping_VAT (step 7)
8- Total_tax_included = Total_cost_included_products (step 6) + Shipping_cost_tax_included (step 10)
9 - Taxes = Display_Total_VAT_rounding_3 + Total_Shipping_VAT_rounding_4 = 8.76 + 2.2 = 10.96 (stepXXX)
Step 10 - Display of invoices
B to B
Dans la partie Base price changer les valeurs avec le prix included
1 - Rate of the product (step 1)
2 - Display_price_rounding_1
3 - Total_cost_excluded_productX (step 6)
4 - Total_cost_included_products (step 6)
5 - Shipping_cost_tax_excluded (step 7)
6 - Total_tax_excluded = Total_cost_excluded_products (step 6) + Shipping_cost_tax_excluded (step 7)
7 - VAT_rate_X
8 - Total_Shipping_VAT (step7)
9 - Taxes (step 9)
10 - Total (step 9)
B to C
1 - Rate of the product (step 1)
2 - Price_of_product_tax_included_step1
3 - Total_cost_included_productX (step 6)
4 - Total_cost_included_products (step 6)
5 - VAT_rate_X
6 - Total_Shipping_VAT (step7)
7 - Shipping_cost_tax_included : Shipping_cost_tax_excluded (step 7) + Total_Shipping_VAT (step 7)
8- Total_tax_included = Total_cost_included_products (step 6) + Shipping_cost_tax_included (step 10)
9 - Taxes (step 9)
Round (to move at another place)
Round on each line
Round on each item
Round on the total
Rules of calculation for cart rules
During the process of pricing you have to check Edit or add Cart Rule for following rules
MR_Pricing_calc_001 : If field Code in cart rules is blank, the rule will automatically be applied to benefiting customers. (MOCCT-008)
MR_Pricing_calc_002 : If field Code in cart rules is filled, the discount will be apply only if the code has been added in the chart.(MOCCT-008)
MR_Pricing_calc_003 : Status. Apply the cart rules if Status is "Yes".If Status is "No" the cart Rule is not applied (MOCCT-009)
MR_Pricing_calc_004 : Priority behavior (MOCCT-011)
MR_Pricing_calc_005 : Partial use The price of an item after prorata discount for an amount could not be lower than 0.
Amount of the second voucher :
If the amount discount is included : sum of product prices taxes included before discount - Sum of products prices taxes included after discount.
If the amount discount is excluded : sum of product prices taxes excluded before discount - Sum of products prices taxes excluded after discount.
Last updated