void Books.Create_Vendor_to_Books(int ven)
{
books_conn = "books_con14";
fetch_ven = Vendor[ID == input.ven];
info fetch_ven;
//fet_en = Zoho_Books_Entity[Entity == fetch_ven.Entity.Entity].Org_ID;
ven_des = Destination[ID == fetch_ven.Place_of_Supply];
ven_pay = Payment_Terms[ID == fetch_ven.Payment_Terms];
curr_code = Currency_Code[ID == fetch_ven.Currency_Code];
ven_gst_trm = GST_Treatment[ID == fetch_ven.GST_Treatment];
// Mapping
vendormap = Map();
vendormap.put("contact_name",fetch_ven.Vendor_Name);
vendormap.put("contact_type","vendor");
vendormap.put("company_name",fetch_ven.Vendor_Name);
vendormap.put("mobile",fetch_ven.Mobile);
vendormap.put("phone",fetch_ven.Phone_Number);
if(fetch_ven.Entity.Entity == "Marine Mechanics Pvt Ltd, India")
{
vendormap.put("pan_no",fetch_ven.PAN_No.trim());
vendormap.put("gst_no",fetch_ven.GST_No.trim());
vendormap.put("place_of_contact",ven_des.Short_Name);
vendormap.put("gst_treatment",ven_gst_trm.Link_name);
vendormap.put("payment_terms_label",ven_pay.Stages);
}
vendormap.put("currency_code",curr_code.Currency_Code);
cont_list = List();
primary_cont_pers = Map();
primary_cont_pers.put("first_name",fetch_ven.Vendor_Name);
primary_cont_pers.put("phone",fetch_ven.Phone_Number);
primary_cont_pers.put("email",fetch_ven.Email_ID1);
cont_list.add(primary_cont_pers);
//secndary Contact persons updated.
if(fetch_ven.Secondary_Contact_Person_s_Details != null)
{
for each contacts_val in fetch_ven.Secondary_Contact_Person_s_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);
}
}
vendormap.put("contact_persons",cont_list);
bill_add = Map();
bill_add.put("address",fetch_ven.Billing_Address.address_line_1);
bill_add.put("street2",fetch_ven.Billing_Address.address_line_2);
bill_add.put("city",fetch_ven.Billing_Address.district_city);
bill_add.put("state",fetch_ven.Billing_Address.state_province);
bill_add.put("zip",fetch_ven.Billing_Address.postal_Code);
bill_add.put("country",fetch_ven.Billing_Address.country);
vendormap.put("billing_address",bill_add);
shipp_add = Map();
shipp_add.put("address",fetch_ven.Shipping_Address.address_line_1);
shipp_add.put("street2",fetch_ven.Shipping_Address.address_line_2);
shipp_add.put("city",fetch_ven.Shipping_Address.district_city);
shipp_add.put("state",fetch_ven.Shipping_Address.state_province);
shipp_add.put("zip",fetch_ven.Shipping_Address.postal_Code);
shipp_add.put("country",fetch_ven.Shipping_Address.country);
vendormap.put("shipping_address",shipp_add);
vendormap.put("status",fetch_ven.Status);
for each rec in fetch_ven.Vendor_Entities
{
resp = zoho.books.createRecord("contacts",rec.Org_ID.Org_ID.toString(),vendormap,books_conn);
res_code = resp.get("code").toLong();
books_id = resp.toMap().get("contact").toMap().get("contact_id");
rec.Zoho_book_ID=books_id;
}
info resp;
res_code = resp.get("code").toLong();
if(res_code == 0)
{
books_id = resp.toMap().get("contact").toMap().get("contact_id");
fetch_ven.ZOHO_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(fetch_ven.Email_ID == contact_Email)
{
fetch_ven.contactPerson_Books_ID=contact_person_id;
}
else
{
updateContactPersonID = Contact_Person_Subform[Vendor_Exis_ID == input.ven && 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="Vendors"
Log_Details=resp
Reference_NO=fetch_ven.Vendor_ID
];
}