![sql toolbelt discounts sql toolbelt discounts](https://azuredevopslabs.com/labs/vstsextend/redgate/images/viewdata.png)
In the above image, you can see how the right column displays the subtotal of the line item with respect to the discount and quantity. To use this field, all you need to do is add it to your views or Quote templates and it'll show the calculated value. Both cases then handle the quantity by multiplying the price less discount by the given quantity. It simply subtracts the $discount_amount from the $discount_price. The last part (lines 16-22) handles the calculation for the flat-rate discount. It calculates the percentage amount from the $discount_amount, then subtracts that amount from the $discount_price.
![sql toolbelt discounts sql toolbelt discounts](https://origin2.cdn.componentsource.com/sites/default/files/styles/image_large/public/images/product_description/red-gate/red-gate-sql-developer-suite/img_479056.png)
![sql toolbelt discounts sql toolbelt discounts](https://miro.medium.com/max/900/1*nFyq7oP7-kyaXCjsyYV-8g.png)
The middle part (lines 3-15) handles the calculation for the percentage based discount. If $discount_select is false, then the Product is using a flat-rate discount". It basically says "If $discount_select is true, then the Product is using a percentage-based discount. $discount_select is a checkbox field which evaluates to true (checked) or false (not checked) in SugarLogic, so I used it as the boolean to check against. To handle these two cases, I started things off with the ifElse function. Products on Quotes can be discounted two ways, by a specific amount or by a percentage. To break this down a bit, there are two primary things that need to be calculated: discount and quantity. To enable SugarLogic and Calculated Fields, all you need to do is check the 'Calculated Value' checkbox and click the 'Edit Formula' button to start writing your logic. To help better communicate each line item on the Quote, I created a new field on the Products module called 'subtotal_c' of type 'Currency'. Best of all, SugarLogic is a key feature of the much anticipated SugarCRM 7 so you can rest assured your customizations will last. SugarLogic a great way to add simple logic and calculations to module fields without dealing with messy logic hook hacks. If you haven't looked into adding SugarLogic to your custom SugarCRM development tool belt, you should definitely take some time to learn more about it. SugarLogic and Calculated Fields are the perfect tools for this use case. Last week as I was working on customizing Quotes for a client, and I wanted to display the subtotal for each individual line item on the quote taking into account the quantity and discount.