try { erroravailable = false; errormessage = ""; partRate = 0; travel_Amount = 0; final_Amount = 0; Amount = 0; Total_distance_travelled = 0; temp_hrs = 0; temp_min = 0; part_update_Map = Map(); part_update_Map1 = Map(); Time_Sheets_Resp = zoho.fsm.getRelatedRecords("Time_Sheets","Service_Appointments",service_appointment.get("id")); //info Time_Sheets_Resp; if(!Time_Sheets_Resp.isEmpty() && Time_Sheets_Resp != null) { Time_Sheets_List = Time_Sheets_Resp.get("data").toList(); serv_line_item_id = Time_Sheets_Resp.get("data").toMap().get("Timesheet_X_Services").toMap().get("Service_Line_Item").toMap().get("id"); for each Time_Sheets_data in Time_Sheets_List { time = Time_Sheets_data.toMap().get("Duration"); if(time != "" && time != null) { if(time.toNumber() >= 60) { temptime = time.toNumber() / 60; time = time.toNumber() - temptime.toNumber() * 60; temp_hrs = temp_hrs + temptime.toNumber(); temp_min = temp_min + time; } else { temp_min = temp_min + time.toNumber(); } } else { erroravailable = true; errormessage = "The time Sheet is yet be completed"; } } new_hrs = temp_min / 60; new_final_hrs = temp_hrs + new_hrs; new_final_hrs = new_final_hrs.round(2); //info new_final_hrs; app_resp = zoho.fsm.getRecordById("Service_Appointments",service_appointment.get("id")); app_list = app_resp.get("data").toMap().get("Appointments_X_Services").toList(); for each app_data in app_list { if(app_data.toMap().get("Service_Line_Item").toMap().get("id") == serv_line_item_id) { wo_id = app_data.toMap().get("Work_Order").toMap().get("id"); } } if(wo_id != null && wo_id != "") { wo_resp = zoho.fsm.getRecordById("Work_Orders",wo_id).toMap().get("data").toMap(); tax = wo_resp.get("Service_Line_Items").toMap().get("Tax"); taxRate = tax.get("Tax_Percentage"); } respTrips = zoho.fsm.getRelatedRecords("Trips","Service_Appointments",service_appointment.get("id")); if(!respTrips.isNull() && !respTrips.isEmpty()) { resp_data_list = respTrips.get("data").toList(); //info resp_data_list; for each resp_data in resp_data_list { appointment_name = resp_data.get("Appointment").toMap().get("name"); trip_name = resp_data.get("Name"); description = appointment_name + " " + trip_name; Distance_Travelled = resp_data.get("Distance_Travelled"); //info Distance_Travelled; if(!Distance_Travelled.isNull() && !Distance_Travelled.isEmpty()) { Total_distance_travelled = Total_distance_travelled + Distance_Travelled.get("value").toDecimal(); } } } info Total_distance_travelled; partsList = zoho.fsm.getRecords("Service_And_Parts").get("data").toList(); for each parts_data in partsList { //info parts_data; if(parts_data.get("Name") == "Distance Travelled for Trip") { if(Total_distance_travelled > 0) { partRate = parts_data.get("Unit_Price"); part_update_Map1.put("Part",parts_data.get("id")); part_update_Map1.put("Description",parts_data.get("Description")); part_update_Map1.put("Service_Line_Item",serv_line_item_id); part_update_Map1.put("Unit",parts_data.get("Unit")); part_update_Map1.put("List_Price",parts_data.get("Unit_Price")); part_update_Map1.put("Tax",tax); part_update_Map1.put("Quantity",Total_distance_travelled); } } if(parts_data.get("Name") == "Billable Hours") { part_update_Map.put("Part",parts_data.get("id")); part_update_Map.put("Description",parts_data.get("Description")); part_update_Map.put("Service_Line_Item",serv_line_item_id); part_update_Map.put("Quantity",new_final_hrs); part_update_Map.put("Unit",parts_data.get("Unit")); part_update_Map.put("List_Price",parts_data.get("Unit_Price")); part_update_Map.put("Tax",tax); } } Part_Line_Items_List = list(); Part_Line_Items_List.add(part_update_Map); if(!part_update_Map1.isNull() && !part_update_Map1.isEmpty() ) { Part_Line_Items_List.add(part_update_Map1); } serv_update_Map = Map(); serv_update_Map.put("id",serv_line_item_id); serv_update_Map.put("Part_Line_Items",Part_Line_Items_List); updateMapList = list(); updateMapList.add(serv_update_Map); updateMap = Map(); updateMap.put("Service_Line_Items",updateMapList); //info updateMap; } else { erroravailable = true; errormessage = "Time sheet is not created"; } if(erroravailable != true) { info updateMap; result = zoho.fsm.updateRecord("Work_Orders",wo_id,updateMap); info result; } else { info errormessage; /* sendmail [ from: zoho.adminuserid to: zoho.adminuserid subject: "Work Order is not updated" message: errormessage ] */ } } catch (e) { info e; /* sendmail [ from: zoho.adminuserid to: zoho.adminuserid subject: "Error in the function" message: e ] */ } |
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
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.
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.