Zoho FSM | Calculate Work Order Profit

Calculate Work Order Profit

Use case: Calculate the profit earned for a work order.
 
Profit = Grand Total of the work order - Total cost price of the work order

where,
Total cost price of the work order = Total cost price of the services used + Total cost price of the parts used
 
Total cost price of the services used = (Cost Price of the service1 X Quantity used) + (Cost Price of the service2 X Quantity used) +....+ (Cost Price of the serviceN X Quantity used)
 
Total cost price of the parts used = (Cost Price of the part1 X Quantity used) + (Cost Price of the part2 X Quantity used) +....+ (Cost Price of the partN X Quantity used)

Follow the steps below to implement this use case:

Step 1: Add custom fields 

Add the following custom fields:
 
Module
Field Name
Field Type
Description
Services And Parts (Services layout)
Cost Price
Decimal
For a service, enter the cost/purchase price of the service in this field.
Services And Parts (Parts layout)
Cost Price
Decimal
For a part, enter the cost/purchase price of the part in this field.
Work Orders
Total Cost Price
Decimal
Whenever the workflow is triggered, this field will be populated with the total cost price of the work order.
Work Orders
Total Profit
Decimal
Whenever the workflow is triggered, this field will be populated with the profit earned for the work order.
 
When you add a new field to the Services module, that field will automatically get added to the Unused Fields of the Parts module and vice versa. You can drag and drop the field from the Unused Fields section to the module layout.
 

Step 2: Create a custom function   

Create a custom function to calculate the Total Cost Price and Total Profit of a work order and to populate these values in the Total Cost Price, and Total Profit fields of a work order.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CalculateWOProfit
    2. Module: Work Order
    3. In the Deluge Script Editor, enter the following script:

serviceLineitems = work_order.get("Service_Line_Items");
//info serviceLineitems;
servicepricemap = Map();
totalPurchased = 0;
for each  sitem in serviceLineitems
{
 serviceId = sitem.get("Service").get("id");
 sitemquantity = sitem.get("Quantity");
 info sitemquantity;
 if(!servicepricemap.containKey(serviceId))
 {
  sinfo = zoho.fsm.getRecordById("Service_And_Parts",serviceId);
  //info sinfo;
  servicepurchased = sinfo.get("data").get(0).get("Cost_Price__C");
  //info servicepurchased;
  if(servicepurchased != null && servicepurchased != "")
  {
   servicepricemap.put(serviceId,servicepurchased);
  }
  else
  {
   servicepricemap.put(serviceId,sinfo.get("data").get(0).get("Unit_Price"));
  }
 }
 if(servicepricemap.get(serviceId) != null)
 {
  purchseval = servicepricemap.get(serviceId);
  totalPurchased = totalPurchased + sitemquantity * purchseval;
  //info "totalPurchased: " + totalPurchased;
 }
}
partlineitems = work_order.get("Part_Line_Items");
partmap = Map();
totalPartsPurchased = 0;
for each  pitem in partlineitems
{
 partId = pitem.get("Part").get("id");
 pitemquantity = pitem.get("Quantity");
 if(!partmap.containKey(partId))
 {
  pinfo = zoho.fsm.getRecordById("Service_And_Parts",partId);
  //info sinfo;
  partpurchased = pinfo.get("data").get(0).get("Cost_Price__C");
  if(partpurchased != null && partpurchased != "")
  {
   partmap.put(partId,partpurchased);
  }
  else
  {
   partmap.put(partId,pinfo.get("data").get(0).get("Unit_Price"));
  }
 }
 if(partmap.get(partId) != null)
 {
  partpurchaseVale = partmap.get(partId);
  totalPartsPurchased = totalPartsPurchased + pitemquantity * partpurchaseVale;
  //info "totalPartsPurchased: " + totalPartsPurchased;
 }
}
//info "totalPartsPurchased: " + totalPartsPurchased;
//info "totalPurchased: " + totalPurchased;
totalpurchasedWo = totalPartsPurchased + totalPurchased;
info "totalpurchasedWo: " + totalpurchasedWo.toDecimal();
wototal = work_order.get("Grand_Total");
info "wototal:" + wototal;
totalprofit = wototal - totalpurchasedWo;
info "Profit: " + totalprofit.toDecimal();
info zoho.fsm.updateRecord("Work_Orders",work_order.get("id"),{"Total_Cost_Price__C":totalpurchasedWo.toDecimal(),"Total_Profit__C":totalprofit.toDecimal()});

In the above code snippet, the API names of the custom fields used are highlighted in blue.  Replace these with the API names of the custom fields ypu have created. You can find the API names of the custom fields in the module builder (Setup > Customization > Module and Fields) of the respective modules.
 

Step 3: Create a workflow rule

Create a workflow rule in Zoho FSM that will update a work order with the Total Cost Price and Total Profit of the work order.
  1. Go to Setup > Automation > Workflow Rules and click Create Workflow.
  2. Enter the following details, then click Next:
    1. Module: Work Orders
    2. Rule Name: CalculateWOProfit
    3. Description: Calculate the profit earned for a work order



  3. Select the rule trigger as Created or Edited and click Next.
    Select the checkbox Repeat this workflow whenever a Work Order is edited.



  4. Select the rule criteria as To all Work Orders and click Next.



  5. Click +Action and select Function.



  6. Select Existing Functions and click Next.



  7. Select the custom function created in the previous step.



  8. Click Save.


Testing the use case

Provide the Cost Price for the Services and Parts.


 
Create or edit a work order. The Total Cost Price and Total Profit of the work order.will be populated.
 


    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now


            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION








                                You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                    Manage your brands on social media

                                      Zoho Desk Resources

                                      • Desk Community Learning Series


                                      • Digest


                                      • Functions


                                      • Meetups


                                      • Kbase


                                      • Resources


                                      • Glossary


                                      • Desk Marketplace


                                      • MVP Corner


                                      • Word of the Day


                                        Zoho Marketing Automation

                                          Zoho Sheet Resources

                                           

                                              Zoho Forms Resources


                                                Secure your business
                                                communication with Zoho Mail


                                                Mail on the move with
                                                Zoho Mail mobile application

                                                  Stay on top of your schedule
                                                  at all times


                                                  Carry your calendar with you
                                                  Anytime, anywhere




                                                        Zoho Sign Resources

                                                          Sign, Paperless!

                                                          Sign and send business documents on the go!

                                                          Get Started Now




                                                                  Zoho TeamInbox Resources



                                                                          Zoho DataPrep Resources



                                                                            Zoho DataPrep Demo

                                                                            Get a personalized demo or POC

                                                                            REGISTER NOW


                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now









                                                                                                  • Related Articles

                                                                                                  • Notify Changes in Work Order Status

                                                                                                    Usecase: Notify the customer by email each time the status of the work order changes. Also, notify the customer when the payment has been done for the work order. Follow the steps below to implement this use case: Step 1: Create a custom function ...
                                                                                                  • Create an Expense record for a Work Order

                                                                                                    Use case: In a work order, if the user adds service line items to record expenses, then create an Expense record in Zoho Expense for an amount equivalent to the sum of all such service Line Item Amount. A service called Expense will be used for this ...
                                                                                                  • Automate creating and sending Invoice on work order creation

                                                                                                    Usecase: When creating a work order, based on an user input, automatically create and send invoice for the work order. Follow the steps below to implement this usecase: Step 1: Create a custom field Step 2: Create a connection for Zoho FSM Step 3: ...
                                                                                                  • Copy Notes from Work Order to Service Appointment

                                                                                                    Use case: When a Service Appointment is created, copy the Notes from its parent Work Order. Follow the steps below to implement this use case: Step 1: Create a connection for Zoho FSM Step 2: Create a custom function Step 3: Create a workflow rule ...
                                                                                                  • Create a Work Order in Zoho FSM from a Sales Order in Zoho Books

                                                                                                    Use case: Whenever a Sales Order is created in Zoho Books, create a Work Order for it in Zoho FSM. Follow the steps below to implement this use case: Step 1: Create a connection for Zoho FSM in Zoho Books Step 2: Create a custom function in Zoho ...
                                                                                                    Wherever you are is as good as
                                                                                                    your workplace

                                                                                                      Resources

                                                                                                      Videos

                                                                                                      Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                      eBooks

                                                                                                      Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                      Webinars

                                                                                                      Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                      CRM Tips

                                                                                                      Make the most of Zoho CRM with these useful tips.



                                                                                                        Zoho Show Resources