How to create a microflow to calculate Final Price with Discount, GST, and Other Charges (Decimal attributes)

0
Hi everyone, I am working on a pricing calculation in Mendix and need help creating a microflow. I have an entity Pricing with the following attributes (all are of type Decimal): BasePrice DiscountPercent DiscountValue FinalPrice Freight PackingForwarding IntegratedGST StateGST CentralGST InsuranceValue ThirdPartyInspectionCharge LegalAndDocCharge Requirement I want to calculate the FinalPrice using a microflow with the following logic: Calculate DiscountValue If DiscountPercent is provided:DiscountValue = BasePrice * DiscountPercent / 100 Otherwise, use the manually entered DiscountValue Calculate NetPrice   NetPrice = BasePrice - DiscountValue Add additional charges:   TotalCharges = Freight + PackingForwarding + InsuranceValue + ThirdPartyInspectionCharge + LegalAndDocCharge Calculate GST values (if applicable): IntegratedGST OR StateGST + CentralGST Calculate FinalPrice:   FinalPrice = NetPrice + TotalCharges + GST Questions What is the best microflow structure to implement this logic? Should I use Decision activities to handle DiscountPercent vs DiscountValue? How can I safely handle empty or null decimal values in calculations? Is it better to calculate GST before or after adding extra charges? Any screenshots or example microflow logic would be really helpful. Thanks in advance! 
asked
2 answers
0

Use a single “Recalculate Pricing” microflow. At the start of the flow, normalize all numeric fields by treating empty values as zero. Then calculate the discount, net price, additional charges, GST, and final price in separate activities to keep the logic clear and make debugging easier.

 

A Decision activity should be used to determine whether the discount is calculated from DiscountPercent or whether the manually entered DiscountValue is used.

 

Empty or null decimal values should always be handled by defaulting them to 0 before any arithmetic is performed, using variables or inline conditions.

 

In most scenarios, GST is best calculated after adding the applicable extra charges to the net price, unless specific business or tax rules require a different approach.

answered
0

Hello Priyanka,

  • Create a variable for calculation and map the values where it needed.
  • yes, you can use decisions  to handle DiscountPercent vs DiscountValue
  • Performing math on an empty (null) Decimal will result in an error or an empty result. To avoid this, use the if- then -else expression or a "Null Check" pattern for every attribute that isn't mandatory. for example: 
    (if $Pricing/Freight != empty then $Pricing/Freight else 0) + 
    (if $Pricing/PackingForwarding != empty then $Pricing/PackingForwarding else 0) +
    (if $Pricing/InsuranceValue != empty then $Pricing/InsuranceValue else 0)
    

     

  • And Yes, it better to add GST after the discounted value and total price calculated.

 

Additionally, For the calculation part you can create a sub microflow so that would easy to debug in future if any issue persist.

 

Regards,

Guna

 

answered