
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. |
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()}); |