Items to Books
Wed Feb 26 2025 12:21:21 GMT+0000 (Coordinated Universal Time)
Saved by @Pooja
map Books.Create_Items_in_Books(int item) { //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_itm = Materials[ID == input.item]; if(fet_itm.Material_Item_Type.Material_Type == "Services") { mattype = "service"; } else { mattype = "goods"; } //info fet_itm.Status; itmmap = Map(); itmmap.put("name",fet_itm.Part_Description); //itmmap.put("cf_part_no",fet_itm.Part_No); //info fet_itm.Part_No; itmmap.put("rate",ifnull(fet_itm.Selling_Price,0.00)); itmmap.put("description",fet_itm.Specification); itmmap.put("purchase_description",fet_itm.Specification); itmmap.put("hsn_or_sac",fet_itm.HSN_SAC); if(fet_itm.Material_Item_Type.Material_Type == "CWPL Produts") { itmmap.put("is_returnable",true); } //if the Tracking item is enabled in the zoho books and edit the item is not allowing. issue no.157 if(isblank(fet_itm.Zoho_Books_ID)) { itmmap.put("item_type","sales_and_purchases"); } info itmmap; itmmap.put("product_type",mattype); itmmap.put("purchase_rate",ifnull(fet_itm.Purchase_Price,0.00)); itmmap.put("unit",fet_itm.Primary_UoM.UOM); itmmap.put("sku",fet_itm.Part_No); itmmap.put("cf_mafr_part_no",fet_itm.Mfr_Part_No); //itmmap.put("cf_manufacturer_name",fet_itm.Manufacturer_Name.Manufacturer_Name); itmmap.put("cf_brand_name",fet_itm.Brand_Name.Brand_Name); itmmap.put("status",fet_itm.Status.toLowerCase()); itmmap.put("account_id",ifnull(fet_itm.Sales_Account.Account_ID.toLong(),"")); itmmap.put("purchase_account_id",ifnull(fet_itm.Purchase_Account.Account_ID.toLong(),"")); //Tax Prefrence item_map_inter = Map(); item_map_inter.put("tax_specification","inter"); item_map_inter.put("tax_type",0); item_map_inter.put("tax_name",fet_itm.IGST_Details.Tax_Name); item_map_inter.put("tax_percentage",fet_itm.IGST_Details.Total_Rate); item_map_inter.put("tax_id",fet_itm.IGST_Details.Zoho_Books_ID); //Intra Map item_map_intra = Map(); item_map_intra.put("tax_specification","intra"); item_map_intra.put("tax_type",0); item_map_intra.put("tax_name",fet_itm.GST_Details.Tax_Name); item_map_intra.put("tax_percentage",fet_itm.GST_Details.Total_Rate); item_map_intra.put("tax_id",fet_itm.GST_Details.Zoho_Books_ID); item_prefer_s = List(); item_prefer_s.add(item_map_inter); item_prefer_s.add(item_map_intra); itmmap.put("item_tax_preferences",item_prefer_s); //Custom Fields cf_list = List(); cf_map = Map(); cat_mast = Category[ID == fet_itm.Category]; sub_cat_mast = Sub_Category[ID == fet_itm.Sub_Category]; //manu_name = Manufacturer_Master[ID == fet_itm.Manufacturer_Name]; brand_dt = Brand_Master[ID == fet_itm.Brand_Name]; //cf_list = {{"api_name":"cf_material_type","value":fet_itm.Material_Item_Type.Material_Type},{"api_name":"cf_sub_category","value":sub_cat_mast.Sub_Category},{"api_name":"cf_part_no","value":fet_itm.Part_No},{"api_name":"cf_category","value":cat_mast.Category},{"api_name":"cf_mfr_part_no","value":ifnull(fet_itm.Mfr_Part_No,"")}}; cf_list = {{"api_name":"cf_material_type","value":fet_itm.Material_Item_Type.Material_Type},{"api_name":"cf_sub_category","value":sub_cat_mast.Sub_Category},{"api_name":"cf_category","value":cat_mast.Category},{"api_name":"cf_mfr_part_no","value":ifnull(fet_itm.Mfr_Part_No,"")},{"api_name":"cf_classification","value":ifnull(fet_itm.Classification,"")},{"api_name":"cf_link_to_erp","value":"https://creatorapp.zoho.in/carrierwheels/erp/#Report:All_Materials?ID=" + fet_itm.ID}}; itmmap.put("custom_fields",cf_list); js_map = Map(); js_map.put("JSONString",itmmap.toString()); getzbid = fet_itm.Zoho_Books_ID.tostring(); //info "getzbid" + getzbid; if(isBlank(getzbid) || isnull(getzbid)) { resp = zoho.books.createRecord("items",org_id,itmmap,conn_tok); rescode = resp.get("code").toLong(); } else { resp_get = zoho.books.updateRecord("items",org_id,getzbid,itmmap,conn_tok); //info "resp_get " + resp_get; rescode = resp_get.get("code").toLong(); rescode_get = resp_get.get("code").toLong(); if(rescode != 0) { resp = zoho.books.createRecord("items",org_id,itmmap,conn_tok); } else { resp = zoho.books.updateRecord("items",org_id,getzbid,itmmap,conn_tok); } } //info "rescode " + rescode; resp_Map = Map(); log_type = "Failure"; if(rescode == 0) { log_type = "Success"; resp_Map.put("Resp","Success"); resp_Map.put("log_msg",resp); books_id = resp.toMap().get("item").toMap().get("item_id"); fet_itm.Zoho_Books_ID=books_id; fet_itm.Books_Sync="Yes"; } // else // { // fet_itm.Books_Sync="No"; // } //info "resp" + resp; //info log_type; //Insert into Log Details Report ins_log = insert into Log_Files [ Added_User=zoho.loginuser Module_Name="Books" Form_Name="Item" Reference_NO=fet_itm.Part_No + " - " + fet_itm.Part_Description Log_Details=resp Log_Type=log_type ]; //sending error log message if(log_type == "Failure") { resp_Map.put("Resp","Failure"); resp_Map.put("log_msg",resp.get("message")); //thisapp.Books.sendErrorLog("Item",fet_itm.Item,resp); } log = resp_Map.get("log_msg").toString(); return resp_Map; }
Comments