Hello everyone, and welcome back to our series!
In Zoho Books, the Item Amount in invoices is calculated by multiplying the Quantity and Rate fields. Previously, we shared a
function to include a custom field in this calculation. Today, we are taking it a step further to make it even more versatile for various business needs. Instead of just one custom field, you can include two custom fields to determine the Item Amount.
Item Amount = Custom Field 1 × Custom Field 2 × Rate × Quantity
Consider Mr. John Hector, who runs a steel production plant. He processes orders for steel sheets according to their dimensions. For accurate billing, he can utilize today's function. When creating the invoice, John can enter the length and width of each steel sheet into the custom fields and specify the number of sheets ordered, and the rate per square foot in the default fields. The function will automatically calculate the Item Amount using this formula:
Item Amount = Length × Width × Quantity × RatePrerequisites:
1. Create a Connection named "zbooks" to successfully execute the function. You can watch the GIF attached below to know how to create the connection.
2. Create the third (Length) and fourth (Width) variables as item-level custom fields (Decimal type) to be displayed in the sales transactions.
3. Similarly, create another custom field called " Unit Rate" to be displayed in the item table. The purpose of this custom field is to store the original sales rate of the line item.
Custom Function:
Navigate to Settings -> Automation -> Workflow Actions -> Custom Functions -> +New Custom Function -> Add the function code from this
GitHub link -> Save.
Workflow Rule:
Go to Settings -> Automation -> Workflow Rules -> +New Workflow Rule and set up the workflow rule as shown below:-
In the final step of this workflow rule, associate the custom function you created and then hit Save.
Here's how the function will work:
The custom function will be executed once the invoice is saved. Initially, it copies the original sales rate to the Unit Rate (Custom) field. Then, it multiplies Length × Width × Unit Rate and populates the result in the Rate (Default) field. Following this, Zoho Books calculates Rate (Default field) × Quantity and fills the result in the Amount field.
Note: If you wish to hide the "Rate" - default field at the template level, go to Settings > Customisation > PDF Templates > Invoices > Edit > Table > Disable the checkbox for Rate field > Save. Now, the Custom Field 1 (Length), Custom Field 2 (Width), Unit Rate (Custom Field), Quantity and the Amount field will be displayed on the invoices.
If you have to incorporate two extra values into your Item Amount calculation, this function is perfect for you. For further customization or assistance, please reach out to our Support team at
support[at]zohobooks[dot]com. We're here to help!
Regards,
Shireen Farhana
Zoho Cares