123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- async function addressDetails() {
- debugger;
- 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/products/getbillinginfo/contactid/${cookieRes.userId}`
- );
- let res = JSON.parse(response.result);
- debugger;
- console.log(res);
- res = res[res.length - 1];
- debugger
- $('#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_phone.val() == "" || 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="text-capitalize">${res.organizationname}</strong><p>${res.addressline},${res.cityname}<br>${res.statename},${res.zipcode}<p>Mobile: ${res.phonenumber}</address></div>`
- );
- }
- resolve();
- });
- } debugger
-
-
- $(".address_edit").on("click", function () {
- $(this).hide();
- $(".profile_Address").hide();
- $(".addresslist").show();
- $(".address_edit_cancel").show();
- getCountryStateCurrency();
- });
-
- $(".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_phone.val() == "" || 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/products/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/products/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 += `<option value="${stateData[i].cityid}" data-id="${stateData[i].cityid}">${stateData[i].cityname}</option>`;
- }
-
- $("#state").append(html);
-
- $("#state").select2({
- placeholder: "Select a City",
- allowClear: true,
- });
-
- const currencyRes = await API_SERVICES_ACTIONS.getAPIService(
- "apis/v4/bizgaze/integrations/products/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/products/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/products/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);
- });
- }
- }
|