string standalone.test_Ali_Docu_Sign()
{
try
{
// ================= FETCH DEAL & VALIDATE ==================
Deal_id = 5971686000063835007;
get_Details = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/Deals/" + Deal_id
type :GET
connection:"newzohocrm"
];
data = get_Details.get("data");
for each rec in data
{
existing_envelope_id = rec.get("Envelope_ID");
if(existing_envelope_id != null && existing_envelope_id != "")
{
return "Document already sent for this reservation";
}
unit_map = rec.get("Unit");
unit_name = "";
if(unit_map != null)
{
unit_name = ifnull(unit_map.get("name"),"");
}
//info unit_name;
customer_id = rec.get("Contact_Name").get("id");
contact_Details = zoho.crm.getRecordById("Contacts",customer_id);
single_buyer_email = ifnull(contact_Details.get("Email"),"");
single_buyer_name = ifnull(contact_Details.get("Full_Name"),"");
refined_countryandcode = standalone.Refine_phone_number_and_country_code(customer_id);
info refined_countryandcode;
single_buyer_phone = ifnull(contact_Details.get("Mobile"),"");
single_buyer_country_code = ifnull(contact_Details.get("Country_Code"),"");
// use Mobile for OTP
Joint_buyer_details = ifnull(rec.get("Joint_buyer_name"),null);
if(Joint_buyer_details != null)
{
Joint_buyer_id = Joint_buyer_details.get("id");
Joint_Buyer_contact_details = zoho.crm.getRecordById("Contacts",Joint_buyer_id);
Joint_Buyer_email = ifnull(Joint_Buyer_contact_details.get("Email"),"");
Joint_Buyer_name = ifnull(Joint_Buyer_contact_details.get("Full_Name"),"");
Joint_Buyer_Mobile = ifnull(Joint_Buyer_contact_details.get("Mobile"),"");
Joint_Buyer_country_code = ifnull(Joint_Buyer_contact_details.get("Country_Code"),"");
info "Join Buyer Mobile: " + Joint_Buyer_Mobile;
}
Reservation_File_Upload = rec.get("Reservation_File_Upload");
for each file_data in Reservation_File_Upload
{
file_id = file_data.get("File_Id__s");
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/files?id=" + file_id
type :GET
connection:"newzohocrm"
];
}
}
// ================= CONVERT TO BASE64 ==================
base64_pdf = zoho.encryption.base64Encode(response);
doc = Map();
doc.put("documentBase64",base64_pdf);
doc.put("name","Sale Purchase Agreement");
doc.put("fileExtension","docx");
doc.put("documentId","1");
// ================= SIGNERS ==================
sign_here_buyer = List();
sign_here_buyer.add({"anchorString":"Signed by Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"168","anchorYOffset":"32","required":true});
sign_here_buyer.add({"anchorString":"Signed for and on behalf of the Purchaser","anchorUnits":"pixels","anchorXOffset":"172","anchorYOffset":"4","required":true});
date_signed_buyer = List();
date_signed_buyer.add({"anchorString":"IN WITNESS WHEREOF the Parties have executed this Agreement.","anchorUnits":"pixels","anchorXOffset":"175","anchorYOffset":"115","required":false});
date_signed_buyer.add({"anchorString":"I/We acknowledge that in the event there is a Constitution, I/we agree to comply with the provisions","anchorUnits":"pixels","anchorXOffset":"155","anchorYOffset":"215","required":false});
date_signed_buyer.add({"anchorString":"Signed for and on behalf of the Purchaser","anchorUnits":"pixels","anchorXOffset":"167","anchorYOffset":"63","required":false});
initials_buyer = List();
initials_buyer.add({"anchorString":"Purchaser’s initials","anchorUnits":"pixels","anchorXOffset":"120","anchorYOffset":"16","required":true});
tabs_buyer = Map();
tabs_buyer.put("signHereTabs",sign_here_buyer);
tabs_buyer.put("dateSignedTabs",date_signed_buyer);
tabs_buyer.put("initialHereTabs",initials_buyer);
signer1 = Map();
signer1.put("email",single_buyer_email);
signer1.put("name",single_buyer_name);
signer1.put("recipientId","1");
signer1.put("routingOrder","2");
signer1.put("tabs",tabs_buyer);
// ---- Phone OTP Identity Verification ----
if(single_buyer_phone != "")
{
identity_verification = Map();
identity_verification.put("workflowId","c368e411-1592-4001-a3df-dca94ac539ae");
input_option = Map();
input_option.put("name","phone_number_list");
input_option.put("valueType","PhoneNumberList");
phone_list = List();
phone_item = Map();
phone_item.put("countryCode",single_buyer_country_code);
phone_item.put("number",single_buyer_phone);
phone_list.add(phone_item);
input_option.put("phoneNumberList",phone_list);
identity_verification.put("inputOptions",{input_option});
signer1.put("identityVerification",identity_verification);
}
signers_list = List();
signers_list.add(signer1);
// ---- Witness for Signer 1 ----
sign_here_witness = List();
sign_here_witness.add({"anchorString":"IN WITNESS WHEREOF the Parties have executed this Agreement","anchorUnits":"pixels","anchorXOffset":"168","anchorYOffset":"168","required":true});
sign_here_witness.add({"anchorString":"Signed for and on behalf of the Purchaser","anchorUnits":"pixels","anchorXOffset":"172","anchorYOffset":"90","required":true});
text_tabs_witness = List();
text_tabs_witness.add({"anchorString":"IN WITNESS WHEREOF the Parties have executed this Agreement","anchorUnits":"pixels","anchorXOffset":"160","anchorYOffset":"190","tabLabel":"witness1_name","value":"","locked":false,"required":true});
text_tabs_witness.add({"anchorString":"IN WITNESS WHEREOF the Parties have executed this Agreement","anchorUnits":"pixels","anchorXOffset":"160","anchorYOffset":"218","tabLabel":"witness1_address","value":"","locked":false,"required":true});
text_tabs_witness.add({"anchorString":"IN WITNESS WHEREOF the Parties have executed this Agreement","anchorUnits":"pixels","anchorXOffset":"160","anchorYOffset":"243","tabLabel":"witness1_occupation","value":"","locked":false,"required":true});
text_tabs_witness.add({"anchorString":"Signed for and on behalf of the Purchaser","anchorUnits":"pixels","anchorXOffset":"160","anchorYOffset":"110","tabLabel":"witness2_name","value":"","locked":false,"required":true});
text_tabs_witness.add({"anchorString":"Signed for and on behalf of the Purchaser","anchorUnits":"pixels","anchorXOffset":"160","anchorYOffset":"135","tabLabel":"witness2_address","value":"","locked":false,"required":true});
tabs_witness = Map();
tabs_witness.put("signHereTabs",sign_here_witness);
tabs_witness.put("textTabs",text_tabs_witness);
witness1 = Map();
witness1.put("witnessFor","1");
witness1.put("recipientId","2");
witness1.put("routingOrder","3");
witness1.put("email","");
witness1.put("name","");
witness1.put("tabs",tabs_witness);
// ---- Signer 2 (Joint Buyer) ----
if(Joint_Buyer_Mobile != "")
{
joint_identity_verification = Map();
joint_identity_verification.put("workflowId","c368e411-1592-4001-a3df-dca94ac539ae");
joint_input_option = Map();
joint_input_option.put("name","phone_number_list");
joint_input_option.put("valueType","PhoneNumberList");
joint_phone_list = List();
joint_phone_item = Map();
joint_phone_item.put("countryCode",Joint_Buyer_country_code);
joint_phone_item.put("number",Joint_Buyer_Mobile);
joint_phone_list.add(joint_phone_item);
joint_input_option.put("phoneNumberList",joint_phone_list);
joint_identity_verification.put("inputOptions",{joint_input_option});
}
if(Joint_buyer_details != null)
{
sign_here_joint = List();
sign_here_joint.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"172","anchorYOffset":"28","required":true});
sign_here_joint.add({"anchorString":"Signed by joint Purchaser","anchorUnits":"pixels","anchorXOffset":"172","anchorYOffset":"29","required":true});
sign_here_joint.add({"anchorString":"Signed for and on behalf of the Joint Purchaser","anchorUnits":"pixels","anchorXOffset":"175","anchorYOffset":"5","required":true});
date_signed_joint = List();
date_signed_joint.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"173","anchorYOffset":"79","required":false});
date_signed_joint.add({"anchorString":"Signed by joint Purchaser","anchorUnits":"pixels","anchorXOffset":"182","anchorYOffset":"80","required":false});
date_signed_joint.add({"anchorString":"Signed for and on behalf of the Joint Purchaser","anchorUnits":"pixels","anchorXOffset":"174","anchorYOffset":"65","required":false});
/////////
/////////////////
initials_buyer2 = List();
initials_buyer2.add({"anchorString":"Purchaser’s initials","anchorUnits":"pixels","anchorXOffset":"200","anchorYOffset":"16","required":true});
tabs_joint = Map();
tabs_joint.put("signHereTabs",sign_here_joint);
tabs_joint.put("dateSignedTabs",date_signed_joint);
tabs_joint.put("initialHereTabs",initials_buyer2);
signer2 = Map();
signer2.put("email",Joint_Buyer_email);
signer2.put("name",Joint_Buyer_name);
signer2.put("identityVerification",joint_identity_verification);
signer2.put("recipientId","3");
signer2.put("routingOrder","4");
signer2.put("tabs",tabs_joint);
signers_list.add(signer2);
// ---- Witness for Signer 2 (Joint Buyer) ----
sign_here_witness2 = List();
sign_here_witness2.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"173","anchorYOffset":"140","required":true});
//////Changed
sign_here_witness2.add({"anchorString":"Signed for and on behalf of the Joint Purchaser","anchorUnits":"pixels","anchorXOffset":"174","anchorYOffset":"103","required":true});
//////Changed
//////////////////////
/////////////////////////////
text_tabs_witness2 = List();
text_tabs_witness2.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"173","anchorYOffset":"160","tabLabel":"witness3_name","value":"","locked":false,"required":true});
//////Changed
text_tabs_witness2.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"173","anchorYOffset":"185","tabLabel":"witness3_address","value":"","locked":false,"required":true});
///changed
text_tabs_witness2.add({"anchorString":"Signed by Joint Individual Purchaser","anchorUnits":"pixels","anchorXOffset":"173","anchorYOffset":"210","tabLabel":"witness3_occupation","value":"","locked":false,"required":true});
///changed
////////////
///////////////////////////
text_tabs_witness2.add({"anchorString":"Signed for and on behalf of the Joint Purchaser","anchorUnits":"pixels","anchorXOffset":"174","anchorYOffset":"118","tabLabel":"witness4_name","value":"","locked":false,"required":true});
///chnages
text_tabs_witness2.add({"anchorString":"Signed for and on behalf of the Joint Purchaser","anchorUnits":"pixels","anchorXOffset":"170","anchorYOffset":"145","tabLabel":"witness4_address","value":"","locked":false,"required":true});
///changed
witness2_tabs = Map();
witness2_tabs.put("signHereTabs",sign_here_witness2);
witness2_tabs.put("textTabs",text_tabs_witness2);
witness2 = Map();
witness2.put("witnessFor","3");
witness2.put("recipientId","4");
witness2.put("routingOrder","5");
witness2.put("email","");
witness2.put("name","");
witness2.put("tabs",witness2_tabs);
}
// ---- Manager Final Signer (Lani Alipio) ----
sign_here_manager = List();
sign_here_manager.add({"documentId":"1","pageNumber":"2","xPosition":"100","yPosition":"600"});
tabs_manager = Map();
tabs_manager.put("signHereTabs",sign_here_manager);
manager_signer = Map();
manager_signer.put("email","muhammad.kaleem@leosops.com");
///
manager_signer.put("name","Lani Alipio");
manager_signer.put("recipientId","11");
if(Joint_buyer_details != null)
{
manager_signer.put("routingOrder","6");
}
else
{
manager_signer.put("routingOrder","5");
}
manager_signer.put("tabs",tabs_manager);
signers_list.add(manager_signer);
// ---- CC LIST (Mark + Lani) ----
cc_list = List();
cc_mark = Map();
cc_mark.put("email","m.awais@leosuk.com");
//
cc_mark.put("name","Mark");
cc_mark.put("recipientId","12");
cc_mark.put("routingOrder","1");
cc_list.add(cc_mark);
cc_noor = Map();
cc_noor.put("email","muhammad.usman@leosops.com");
///
cc_noor.put("name","Lani Alipio");
cc_noor.put("recipientId","13");
cc_noor.put("routingOrder","1");
cc_list.add(cc_noor);
/////////////
//////
cc_salesadmin = Map();
cc_salesadmin.put("email","syed.ali@leosuk.com");
cc_salesadmin.put("name","Syed");
cc_salesadmin.put("recipientId","15");
cc_salesadmin.put("routingOrder","1");
cc_list.add(cc_salesadmin);
///////////
//////////////
//////////////////
// cc_awais = Map();
// cc_awais.put("email","m.awais@leosuk.com");
// cc_awais.put("name","Awais khan");
// cc_awais.put("recipientId","16");
// cc_awais.put("routingOrder","1");
// cc_list.add(cc_awais);
////
////
// cc_ana = Map();
// cc_ana.put("email","anamay@leosuk.com");
// //////
// cc_ana.put("name","Ana May S. Zamora");
// cc_ana.put("recipientId","14");
// cc_ana.put("routingOrder","1");
// cc_list.add(cc_ana);
// ================= RECIPIENTS MAP ==================
recipients = Map();
recipients.put("signers",signers_list);
if(Joint_buyer_details != null)
{
recipients.put("witnesses",{witness1,witness2});
}
else
{
recipients.put("witnesses",{witness1});
}
recipients.put("carbonCopies",cc_list);
envelope = Map();
envelope.put("documents",{doc});
envelope.put("emailSubject","SPA for Signature - " + unit_name + " Final");
envelope.put("emailBlurb","Greetings!<br><br>" + "I hope you are doing well.<br><br>" + "Please your are requested to select the \"Draw\" option when signing the Sales and Purchase Agreement (SPA) via DocuSign, this is an important step to ensure compliance with the Dubai Land Department (DLD) requirements. The DLD mandates that electronic signatures on official documents, such as the SPA, must match the signature in the individual's passport. Using the \"Draw\" option in DocuSign allows you to replicate your handwritten signature, which is essential for this compliance.<br><br>" + "Steps to Draw Your Signature in DocuSign:<br><br>" + "Open the Document: Click on the link provided in the DocuSign email to access the SPA.<br><br>" + "Select the Signature Field: Click on the designated area where your signature is required.<br><br>" + "Choose the \"Draw\" Option: When prompted to choose a signature style, select the \"Draw\" option.<br><br>" + "Draw Your Signature: Use your mouse, stylus, or finger (on a touchscreen device) to draw your signature in the provided space.<br><br>" + "Confirm the Signature: Once satisfied with your drawn signature, confirm it to apply it to the document.<br><br>" + "This method ensures that your electronic signature closely matches your passport signature, meeting the DLD's requirements.<br><br>" + "Regarding the Selection of a Witness:<br><br>" + "We appreciate your involvement in selecting a witness for the SPA. Please provide the name and contact details of your chosen witness at your earliest convenience. Your witness will receive an invitation to sign the SPA via DocuSign once their details are confirmed.<br><br>" + "Next Steps:<br><br>" + "Sign the SPA: Please sign the SPA using the \"Draw\" option as outlined above.<br><br>" + "Select a Witness: Provide the name, Address and Occupation of your chosen witness.<br><br>" + "Witness Signs: Once your witness is added, they will receive an invitation to sign the SPA.<br><br>" + "If you have any questions or need further assistance during this process, please don't hesitate to reach out. We're here to help and ensure a smooth and compliant signing experience.<br><br>" + "Welcome once again to the Leo's Development family!");
envelope.put("status","sent");
envelope.put("recipients",recipients);
// ================= FETCH DOCUSIGN ACCESS TOKEN ==================
access_token_response = invokeurl
[
url :"https://www.zohoapis.com/crm/v6/settings/variables/5971686000102746225"
type :GET
connection:"newzohocrm"
];
access_token = access_token_response.get("variables").get(0).get("value");
headers = Map();
headers.put("Authorization","Bearer " + access_token);
headers.put("Content-Type","application/json");
response = invokeurl
[
url :"https://eu.docusign.net/restapi/v2.1/accounts/2a0daa7d-a770-4979-8208-9543d21f12e5/envelopes"
type :POST
parameters:envelope.toString()
headers:headers
];
info response;
if(response.get("status") == "sent")
{
envelopeId = response.get("envelopeId");
update_map = Map();
update_map.put("Envelope_ID",envelopeId);
update_map.put("Next_Status_Sync_Time",zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss","Asia/Dubai"));
update_map.put("Docu_Sign_Status","Sent");
Update_Rec = zoho.crm.updateRecord("Deals",Deal_id,update_map);
return "Document has been successfully sent to all recipients.";
}
else
{
return "Failed to send the document. Please verify that the customer details, including phone number and country code, are correct.";
}
}
catch (e)
{
sendmail
[
from :zoho.loginuserid
to :"zoho.failure@leosinternational.zohodesk.com"
subject :"[DocuSign Error | Deal " + Deal_id + "]"
message :"An error occurred while sending the document via DocuSign.\n\nDeal ID: " + Deal_id + "\nError Details: " + e.toString()
]
return "Error occurred: " + e.toString();
}
return "";
}