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.
 


      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          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







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsRetailOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceForms for Solopreneurs
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit
                              Forms for Government
                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic FormsInsurance
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsWufoo alternativeEncrypted Forms
                              Accessible FormsTypeform alternativeSecure Forms

                              WCAG

                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now






                                                            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

                                                                  Use cases

                                                                  Make the most of Zoho Desk with the use cases.

                                                                   
                                                                    

                                                                  eBooks

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

                                                                   
                                                                    

                                                                  Videos

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

                                                                   
                                                                    

                                                                  Webinar

                                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                                   
                                                                    
                                                                  • Desk Community Learning Series


                                                                  • Meetups


                                                                  • Ask the Experts


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner



                                                                    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 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 ...
                                                                                                                            • Work Orders

                                                                                                                              A work order is a record created for executing a contact service request. Available in Editions: All Editions Create Work Orders Permission Required: Work Orders A Work Order can be created in one of the following ways: From Requests: Use the Convert ...
                                                                                                                            • 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: ...
                                                                                                                            • Can I create a Work Order directly from a Request in Zoho FSM?

                                                                                                                              Yes. Once a Request is created, you can convert it into a Work Order. To convert a request into a work order: From the Request details page, click Create Convert to Work Order. The Request information (such as Contact, Company, and Service Address) ...
                                                                                                                              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