async function addressDetails() { debugger; // const user_addr_num =$("#Profile_Phone_num").val(); getbillinginfoBind(); let addr_phone=$('#phonenumber'); let addr_addrline =$('#addressdes'); let addr_zip =$('#zipcode'); function getbillinginfoBind() { return new Promise(async (resolve, reject) => { let cookieRes = COOKIE_HELPER_ACTIONS.getCookie(); console.log(cookieRes); const { errorMsg, isError, response } = await API_SERVICES_ACTIONS.getAPIService( `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}` ); let res = JSON.parse(response.result); debugger; console.log(res); res = res[res.length - 1]; debugger addr_phone.val(res.phonenumber); $('#Profile_User_name').val(res.organizationname) $('#Profile_Phone_num').val(res.phonenumber) let Profileusername =$('#Profile_User_name').val() let Profileuserphone=$('#Profile_Phone_num').val() $('.overview_user_name').html(Profileusername); $('.overview_user_phone').html(Profileuserphone); if (res.cityid == "0") { $(".profile_Address").html( `
` ); $(".address_edit").hide(); $(".create_address").on("click", function () { debugger $(this).hide(); $('.saveaddress').hide() $(".addresslist").show(); $(".Createaddress").show(); getCountryStateCurrency(); }); $('.Createaddress').on('click',async function(){ if( addr_zip.val() == "" || addr_addrline.val() == ""){ // toastr.error('Required Feilds are Empty!'); // if(addr_phone.val() == '' || addr_phone.val().length <10){ // addr_phone.addClass("is-invalid"); // } // else{ // addr_phone.removeClass("is-invalid"); // } if(addr_zip.val() == '' || addr_zip.val().length < 6){ addr_zip.addClass("is-invalid"); } else{ addr_zip.removeClass("is-invalid"); } if(addr_addrline.val() == ''){ addr_addrline.addClass("is-invalid"); } else{ addr_addrline.removeClass("is-invalid"); } } else{ $(".addresslist").hide(); $(".profile_Address").show(); $(".address_edit").show(); $(".address_edit_cancel").hide(); await createBillingForm() await getbillinginfoBind(); } }) } else { $(".profile_Address").html( `

${res.organizationname}

${res.addressline},${res.cityname}
${res.statename},${res.zipcode}

Mobile: ${res.phonenumber}

` ); } resolve(); }); } debugger $(".address_edit").on("click", function () { $(this).hide(); $(".profile_Address").hide(); $(".addresslist").show(); $(".address_edit_cancel").show(); getCountryStateCurrency(); getbillinginfoBind() }); $(".address_edit_cancel").on("click", function () { $(this).hide(); $(".addresslist").hide(); $(".profile_Address").show(); $(".address_edit").show(); }); $(".saveaddress") .off("click") .click(async function () { debugger if(addr_zip.val() == "" || addr_addrline.val() == ""){ // toastr.error('Required Feilds are Empty!'); // if(addr_phone.val() == '' || addr_phone.val().length <10){ // addr_phone.addClass("is-invalid"); // } // else{ // addr_phone.removeClass("is-invalid"); // } if(addr_zip.val() == '' || addr_zip.val().length < 6){ addr_zip.addClass("is-invalid"); } else{ addr_zip.removeClass("is-invalid"); } if(addr_addrline.val() == ''){ addr_addrline.addClass("is-invalid"); } else{ addr_addrline.removeClass("is-invalid"); } } else{ $(".addresslist").hide(); $(".profile_Address").show(); $(".address_edit").show(); $(".address_edit_cancel").hide(); $('.spinner-border').removeClass('d-none') $('.saveaddress').find('span').addClass('d-none') await AddresssaveForm(); $('.spinner-border').addClass('d-none') $('.saveaddress').find('span').removeClass('d-none') await getbillinginfoBind(); } }); async function getCountryStateCurrency() { const countryRes = await API_SERVICES_ACTIONS.getAPIService( "apis/v4/bizgaze/integrations/anwiauth/getcountry" ); if (countryRes.isError) { alert("something went wrong"); console.log(countryRes); return; } let countryData = JSON.parse(countryRes.response.result); console.log(countryData, "country"); for (let i = 0; i < countryData.length; i++) { if (countryData[i].countryname.toLowerCase() === "india") { countryID = countryData[i].countryid; countrynameData = countryData[i].countryname; break; } } const stateRes = await API_SERVICES_ACTIONS.getAPIService( `apis/v4/bizgaze/integrations/anwiauth/getcities/countryid/${countryID}` ); if (stateRes.isError) { alert("something went wrong"); console.log(stateRes, "state"); return; } let stateData = JSON.parse(stateRes.response.result); console.log(stateData, "state"); $("#state").html(""); console.log("start"); let html = ""; statesList = stateData; for (let i = 0; i < stateData.length; i++) { html += ``; } $("#state").append(html); $("#state").select2({ placeholder: "Select a City", allowClear: true, }); const currencyRes = await API_SERVICES_ACTIONS.getAPIService( "apis/v4/bizgaze/integrations/anwiauth/getcurrencies" ); if (currencyRes.isError) { alert("something went wrong"); console.log(currencyRes); return; } let currencyData = JSON.parse(currencyRes.response.result); console.log(currencyData, "currencyDatacurrencyDatacurrencyData"); for (let i = 0; i < currencyData.length; i++) { const curr = currencyData[i]; if (curr.currencyname.toLowerCase().includes("india")) { currencyid = curr.currencyid; } } } async function getCountryId() { const countryRes = await API_SERVICES_ACTIONS.getAPIService( "apis/v4/bizgaze/integrations/anwiauth/getcountry" ); if (countryRes.isError) { alert("something went wrong"); console.log(countryRes); return; } let ctyId = 0; let countryData = JSON.parse(countryRes.response.result); console.log(countryData); for (let i = 0; i < countryData.length; i++) { if (countryData[i].countryname.toLowerCase() === "india") { countryId = countryData[i].countryid; ctyId = countryId; countrynameData = countryData[i].countryname; break; } } return ctyId; } function createBillingForm() { debugger; return new Promise(async (resolve, reject) => { let cookieRes = COOKIE_HELPER_ACTIONS.getCookie(); let { userId, name } = cookieRes; const ctyId = await getCountryId(); let stateId = parseInt($("#state").val()); let payload = { cityid: stateId, CityName: $(`[data-id="${stateId}"`).html(), addressline1: $("#addressdes").val(), OrganizationType: 2, organizationname: name, //"OrganizationId":, ContactName: name, ContactId: userId, countryname: "india", countryid: ctyId, statename: $(`[data-id="${stateId}"`).html(), phonenumber: $("#phonenumber").val(), OrganizationId: userId, currencyid: 2, taxno: "0", BillingInfoExists: false, lobid: 0, lobname: "IT Products", gstindetailid: 0, zipcode: $("#zipcode").val(), }; const res = await API_SERVICES_ACTIONS.postAPIService( "apis/v4/bizgaze/crm/address/savebillinginfo", payload ); // http://localhost:3088/apis/v4/bizgaze/crm/address/savebillinginfo console.log(res); resolve(); }); } async function AddresssaveForm() { debugger; let cookieRes = COOKIE_HELPER_ACTIONS.getCookie(); let { userId, name } = cookieRes; const { errorMsg, isError, response } = await API_SERVICES_ACTIONS.getAPIService( `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}` ); let resAnwi = JSON.parse(response.result); console.log(resAnwi, "befores"); resAnwi = resAnwi[resAnwi.length - 1]; let stateId = parseInt($("#state").val()); let payload = { ...resAnwi, phonenumber: $("#phonenumber").val(), addressline1: $("#addressdes").val(), zipcode: $("#zipcode").val(), cityid: stateId, CityName: $(`[data-id="${stateId}"`).html(), }; console.log(payload, "addresssaave"); // const res = await API_SERVICES_ACTIONS.postAPIService( "apis/v4/bizgaze/crm/address/savebillinginfo", payload ); return new Promise((reslove, reject) => { reslove(res); }); } }