Difference between revisions of "Calculate GST Function"
Line 2: | Line 2: | ||
You can automatically determine if GST should be calculated on an item and calculate the GST by using the following technique: | You can automatically determine if GST should be calculated on an item and calculate the GST by using the following technique: | ||
− | This example assumes you are adding this functionality to a [[UTA]] level and three existing [[Custom Fields|custom fields]] '''total''' - a text box to store the amount and '''GST''' - a select one combo box to indicate if the item should include '''GST'''. | + | This example assumes you are adding this functionality to a [[UTA]] level and three existing [[Custom Fields|custom fields]]: |
+ | '''total''' - a text box to store the amount and | ||
+ | '''GST''' - a select one combo box to indicate if the item should include '''GST'''. | ||
1. Create an additional [[Custom Fields|custom field]] - '''Calculate GST''' as '''Special - Browser Script''' type field. | 1. Create an additional [[Custom Fields|custom field]] - '''Calculate GST''' as '''Special - Browser Script''' type field. |
Revision as of 14:50, 13 May 2014
This feature uses JavaScript syntax |
You can automatically determine if GST should be calculated on an item and calculate the GST by using the following technique:
This example assumes you are adding this functionality to a UTA level and three existing custom fields: total - a text box to store the amount and GST - a select one combo box to indicate if the item should include GST.
1. Create an additional custom field - Calculate GST as Special - Browser Script type field.
2. Add the following expression to that field.
function calculategst(amount,gst) {if (gst=='Yes') return parseFloat(amount*0.06).toFixed(2); else return parseFloat(0).toFixed(2);}
This function - calculategst can be called from any field, but the Calculate GST field itself will not be displayed.
3. Create a calculated field to store the calculated value.
4. Add the following expression to that field.
calculategst([Total],[GST])
This expression is called the calculategst function and passes the total and the gst values. If GST is applicable, then the value is calculated and returned (to 2 places of decimal) else 0.00 is returned.