async function addressDetails() {
// const user_addr_num =$("#Profile_Phone_num").val();
getbillinginfoBind();
let addr_phone = $('#phonenumber');
let addr_addrline = $('#addressdes');
let addr_zip = $('#zipcode');
let stateArr = [];
function getCustomDropDownHTML({ cityid, cityname, countryid }) {
return `
${cityname}
`;
}
function renderCustomStateDropdown(stateList) {
let html = ``;
let maxLen = stateList.length > 10 ? 10 : stateList.length
for (let i = 0; i < maxLen; i++) {
let currItem = stateList[i];
html += getCustomDropDownHTML(currItem);
}
$('.stateBox').html(html);
$('.stateoption').off().click(function (e) {
const name = $(e.target).data('name');
const id = $(e.target).data('value');
$('#state').val(name);
$('#state').attr('data-id', id);
})
}
function loadDropdownStateEvents() {
$('#state').off().focus(function () {
$('.stateBox').removeClass('d-none');
$(document).off('click').click(closeDrop);
})
$(document).off().click(closeDrop);
function closeDrop(e) {
let id = $(e.target).hasClass('stateoption');
if ($(e.target).attr('id') === 'state') return;
if (id) {
$('.stateBox').addClass('d-none');
$(document).off();
} else {
$('.stateBox').addClass('d-none');
$(document).off();
}
}
$('#state').keyup(debounce(function (event) {
onChangeState(event)
}));
}
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);
console.log(res);
res = res[res.length - 1];
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 () {
$(this).hide();
$('.saveaddress').hide()
$(".addresslist").show();
$(".Createaddress").show();
getCountryStateCurrency();
});
$('.Createaddress').off().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?.zipcode}
Mobile: ${res?.phonenumber}
`
);
$('#state').val(res?.cityname)
$('#state').attr('data-id',res?.cityid);
$('#zipcode').val(res?.zipcode);
$('#addressdes').val(res?.addressline);
}
resolve();
});
}
$(".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 () {
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();
}
});
function onChangeState(e){
let userItem = e.target.value.toLowerCase();
let limit = 10;
let results = [];
let maxLen = stateArr.length > 10 ? 10 :stateArr.length;
for(let i=0;i=10) break;
}
}
$('.stateBox').removeClass('d-none');
renderCustomStateDropdown(results);
loadDropdownStateEvents();
}
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");
stateArr = stateData;
renderCustomStateDropdown(stateArr);
loadDropdownStateEvents();
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() {
return new Promise(async (resolve, reject) => {
let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
let { userId, name } = cookieRes;
const ctyId = await getCountryId();
let stateId = $("#state").data('id');
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() {
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").data('id'));
let payload = {
...resAnwi,
phonenumber: $("#phonenumber").val(),
addressline1: $("#addressdes").val(),
zipcode: $("#zipcode").val(),
cityid: stateId,
CityName: $('#state').val(),
cityname: $('#state').val(),
};
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);
});
}
}