123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- 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');
-
- let stateArr = [];
-
- function getCustomDropDownHTML({ cityid, cityname, countryid }) {
- return ` <div class="bg-white stateoption px-2 border-bottom py-2 cursor-pointer" data-name="${cityname}" data-value="${cityid}">${cityname}</div>`;
- }
-
- function renderCustomStateDropdown(stateList) {
- let html = ``;
- debugger;;
- 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) {
- debugger;
- 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);
- 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(
- `<div class=User_address><button class="btn btn-outline-primary create_address" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16"><path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/><path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/></svg> ADD NEW ADDRESS</button></div>`
- );
-
- $(".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(
- `<div class=User_address><address><p><strong class="">${res?.organizationname}</strong><p>${res?.addressline},${res?.cityname},${res?.zipcode}<p>Mobile: ${res?.phonenumber}</address></div>`
- );
- $('#state').val(res?.cityname)
- $('#state').attr('data-id',res?.cityid);
- $('#zipcode').val(res?.zipcode);
- $('#addressdes').val(res?.addressline);
- }
- 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();
- }
-
- });
-
- function onChangeState(e){
- let userItem = e.target.value.toLowerCase();
- let limit = 10;
- let results = [];
- let maxLen = stateArr.length > 10 ? 10 :stateArr.length;
- debugger
- for(let i=0;i<stateArr.length;i++){
- let currItem = stateArr[i];
- let stateName = currItem.cityname.toLowerCase();
- if(stateName.includes(userItem)){
- results.push(currItem);
- if(results.length>=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() {
- 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").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);
- });
- }
- }
|