Create Customer in Books

PHOTO EMBED

Tue Jan 07 2025 15:00:43 GMT+0000 (Coordinated Universal Time)

Saved by @Pooja

void Books.Create_Cust_in_books(int cust)
{
	//Getting authtoken and organisation id
	books_access = thisapp.Books.Get_Books_Access();
	conn_tok = books_access.get("connection");
	org_id = books_access.get("organisation_id");
	//-------------------------------------------------------------------------
	fet_cust = Customers[ID == input.cust];
	cust_des = Destination[ID == fet_cust.Place_of_Supply];
	cust_gst_trm = GST_Treatment[ID == fet_cust.GST_Treatment];
	curr_code = Currency_Code[ID == fet_cust.Currency_Code];
	web_cnvt = fet_cust.Web.toString();
	web_suff = web_cnvt.getprefix("</a>");
	web_final = web_suff.getsuffix(">");
	custmap = Map();
	custmap.put("contact_type","customer");
	custmap.put("contact_name",fet_cust.Customer_Name);
	custmap.put("company_name",fet_cust.Customer_Name);
	//custmap.put("email",fet_cust.Email_ID);
	custmap.put("mobile",fet_cust.Contact_Number);
	custmap.put("phone",fet_cust.Phone_Number1);
	custmap.put("pan_no",fet_cust.PAN_No);
	custmap.put("gst_no",fet_cust.GST_No);
	custmap.put("website",web_final);
	custmap.put("place_of_contact",cust_des.Short_Name);
	custmap.put("gst_treatment",cust_gst_trm.Link_name);
	custmap.put("currency_id",curr_code.Zoho_Books_ID);
	custmap.put("currency_code",curr_code.Currency_Code);
	cont_list = List();
	primary_cont_pers = Map();
	primary_cont_pers.put("first_name",fet_cust.Customer_Name);
	primary_cont_pers.put("phone",fet_cust.Contact_Number);
	primary_cont_pers.put("email",fet_cust.Email_ID);
	cont_list.add(primary_cont_pers);
	//secndary Contact persons updated.
	if(fet_cust.Contact_Person_Details != null)
	{
		for each  contacts_val in fet_cust.Contact_Person_Details
		{
			cont_pers = Map();
			cont_pers.put("first_name",contacts_val.Contact_Person_Name);
			cont_pers.put("phone",contacts_val.Phone_Number);
			cont_pers.put("email",contacts_val.Email);
			cont_list.add(cont_pers);
		}
	}
	custmap.put("contact_persons",cont_list);
	bill_add = Map();
	shipp_add = Map();
	bill_add.put("address",fet_cust.Billing_Address.address_line_1);
	bill_add.put("street2",fet_cust.Billing_Address.address_line_2);
	bill_add.put("city",fet_cust.Billing_Address.district_city);
	bill_add.put("state",fet_cust.Billing_Address.state_province);
	bill_add.put("zip",fet_cust.Billing_Address.postal_Code);
	bill_add.put("country",fet_cust.Billing_Address.country);
	custmap.put("billing_address",bill_add);
	shipp_add.put("address",fet_cust.Shipping_Address.address_line_1);
	shipp_add.put("street2",fet_cust.Shipping_Address.address_line_2);
	shipp_add.put("city",fet_cust.Shipping_Address.district_city);
	shipp_add.put("state",fet_cust.Shipping_Address.state_province);
	shipp_add.put("zip",fet_cust.Shipping_Address.postal_Code);
	shipp_add.put("country",fet_cust.Shipping_Address.country);
	custmap.put("shipping_address",shipp_add);
	custmap.put("status","active");
	custmap.put("cf_customer_code",fet_cust.Customer_Code);
	//resp = zoho.books.createRecord("contacts",org_id,custmap,conn_tok);
	resp = zoho.books.createRecord("contacts",org_id,custmap);
	info resp;
	res_code = resp.get("code").toLong();
	if(res_code == 0)
	{
		books_id = resp.toMap().get("contact").toMap().get("contact_id");
		fet_cust.Customer_Books_ID=books_id;
		contact_person_list = List();
		contact_person_list = resp.toMap().get("contact").toMap().get("contact_persons").toList();
		for each  contacts_1 in contact_person_list
		{
			contact_rec = contacts_1.toMap();
			contact_Email = contact_rec.get("email");
			contact_person_id = contact_rec.get("contact_person_id");
			if(fet_cust.Email_ID == contact_Email)
			{
				fet_cust.contactPerson_Books_ID=contact_person_id;
			}
			else
			{
				updateContactPersonID = Contact_Person_Subform[Customer_Exis_ID == input.cust && Email == contact_Email];
				if(updateContactPersonID.count() > 0)
				{
					updateContactPersonID.Contact_Person_Books_ID=contact_person_id;
				}
			}
		}
	}
	//Insert into Log Details Report
	// 	ins_log = insert into Log_Files
	// 	[
	// 		Added_User=zoho.loginuser
	// 		Module_Name="Books"
	// 		Form_Name="Customer"
	// 		Log_Details=resp
	// 	];
}
content_copyCOPY