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. SugarLogic and Calculated Fields are the perfect tools for this use case. 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 a great way to add simple logic and calculations to module fields without dealing with messy logic hook hacks. Best of all, SugarLogic is a key feature of the much anticipated SugarCRM 7 so you can rest assured your customizations will last.
Without further ado, on to the code... 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'. 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. Here's the SugarLogic I came up with:
To break this down a bit, there are two primary things that need to be calculated: discount and quantity.
Products on Quotes can be discounted two ways, by a specific amount or by a percentage. To handle these two cases, I started things off with the ifElse function. $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. It basically says "If $discount_select is true, then the Product is using a percentage-based discount. If $discount_select is false, then the Product is using a flat-rate discount".
The middle part (lines 3-15) handles the calculation for the percentage based discount. It calculates the percentage amount from the $discount_amount, then subtracts that amount from the $discount_price. The last part (lines 16-22) handles the calculation for the flat-rate discount. It simply subtracts the $discount_amount from the $discount_price. Both cases then handle the quantity by multiplying the price less discount by the given 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. And that's it!
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.
There is one caveat. Due to how SugarLogic works, after adding the subtotal_c field, only newly create Quotes and Product line items will be given a calculated value. To get subtotal_c to show up for previously created items, you'll need to edit and save each product record so that the calculated field can be generated. You can do that with a simple script like this:
How have you used SugarLogic in the past? Have you ever made customizations like this in the past?
TapCRM - Mobile CRM App for SugarCRM
Best CRM Mobile App
Enable your teams to access the CRM data on the go through SugarCRM mobile app. Our Sugar CRM sales mobile app is created exclusively for SugarCRM and offers real time data availability to the users. It enables you to conduct systematized operations right from your mobile.
SugarCRM Survey Rocket
SugarCRM Survey Plugin
Create custom survey templates, online polls & more to trigger them using automation to get real-time feedback from your customers using Survey Rocket a sugarcrm survey builder. Moreover, use the CRM data using inward and outward piping mechanism.
Who reassigned this call? When was the status field adjusted? The SugarCRM Calls module doesn't allow Auditing the same way as other modules do. Fix that with this quick add-on.
- Show more addons