Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Address.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. async function addressDetails() {
  2. // const user_addr_num =$("#Profile_Phone_num").val();
  3. getbillinginfoBind();
  4. let addr_phone = $('#phonenumber');
  5. let addr_addrline = $('#addressdes');
  6. let addr_zip = $('#zipcode');
  7. let stateArr = [];
  8. function getCustomDropDownHTML({ cityid, cityname, countryid }) {
  9. return ` <div class="bg-white stateoption px-2 border-bottom py-2 cursor-pointer" data-name="${cityname}" data-value="${cityid}">${cityname}</div>`;
  10. }
  11. function renderCustomStateDropdown(stateList) {
  12. let html = ``;
  13. let maxLen = stateList.length > 10 ? 10 : stateList.length
  14. for (let i = 0; i < maxLen; i++) {
  15. let currItem = stateList[i];
  16. html += getCustomDropDownHTML(currItem);
  17. }
  18. $('.stateBox').html(html);
  19. $('.stateoption').off().click(function (e) {
  20. const name = $(e.target).data('name');
  21. const id = $(e.target).data('value');
  22. $('#state').val(name);
  23. $('#state').attr('data-id', id);
  24. })
  25. }
  26. function loadDropdownStateEvents() {
  27. $('#state').off().focus(function () {
  28. $('.stateBox').removeClass('d-none');
  29. $(document).off('click').click(closeDrop);
  30. })
  31. $(document).off().click(closeDrop);
  32. function closeDrop(e) {
  33. let id = $(e.target).hasClass('stateoption');
  34. if ($(e.target).attr('id') === 'state') return;
  35. if (id) {
  36. $('.stateBox').addClass('d-none');
  37. $(document).off();
  38. } else {
  39. $('.stateBox').addClass('d-none');
  40. $(document).off();
  41. }
  42. }
  43. $('#state').keyup(debounce(function (event) {
  44. onChangeState(event)
  45. }));
  46. }
  47. function getbillinginfoBind() {
  48. return new Promise(async (resolve, reject) => {
  49. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  50. console.log(cookieRes);
  51. const { errorMsg, isError, response } =
  52. await API_SERVICES_ACTIONS.getAPIService(
  53. `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}`
  54. );
  55. let res = JSON.parse(response.result);
  56. console.log(res);
  57. res = res[res.length - 1];
  58. addr_phone.val(res?.phonenumber);
  59. $('#Profile_User_name').val(res?.organizationname)
  60. $('#Profile_Phone_num').val(res?.phonenumber)
  61. let Profileusername = $('#Profile_User_name').val()
  62. let Profileuserphone = $('#Profile_Phone_num').val()
  63. $('.overview_user_name').html(Profileusername);
  64. $('.overview_user_phone').html(Profileuserphone);
  65. if (res?.cityid == "0") {
  66. $(".profile_Address").html(
  67. `<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>`
  68. );
  69. $(".address_edit").hide();
  70. $(".create_address").on("click", function () {
  71. $(this).hide();
  72. $('.saveaddress').hide()
  73. $(".addresslist").show();
  74. $(".Createaddress").show();
  75. getCountryStateCurrency();
  76. });
  77. $('.Createaddress').off().on('click', async function () {
  78. if (addr_zip.val() == "" || addr_addrline.val() == "") {
  79. // toastr.error('Required Feilds are Empty!');
  80. // if(addr_phone.val() == '' || addr_phone.val().length <10){
  81. // addr_phone.addClass("is-invalid");
  82. // }
  83. // else{
  84. // addr_phone.removeClass("is-invalid");
  85. // }
  86. if (addr_zip.val() == '' || addr_zip.val().length < 6) {
  87. addr_zip.addClass("is-invalid");
  88. }
  89. else {
  90. addr_zip.removeClass("is-invalid");
  91. }
  92. if (addr_addrline.val() == '') {
  93. addr_addrline.addClass("is-invalid");
  94. } else {
  95. addr_addrline.removeClass("is-invalid");
  96. }
  97. }
  98. else {
  99. $(".addresslist").hide();
  100. $(".profile_Address").show();
  101. $(".address_edit").show();
  102. $(".address_edit_cancel").hide();
  103. await createBillingForm()
  104. await getbillinginfoBind();
  105. }
  106. })
  107. } else {
  108. $(".profile_Address").html(
  109. `<div class=User_address><address><p><strong class="">${res?.organizationname}</strong><p>${res?.addressline},${res?.cityname},${res?.zipcode}<p>Mobile: ${res?.phonenumber}</address></div>`
  110. );
  111. $('#state').val(res?.cityname)
  112. $('#state').attr('data-id',res?.cityid);
  113. $('#zipcode').val(res?.zipcode);
  114. $('#addressdes').val(res?.addressline);
  115. }
  116. resolve();
  117. });
  118. }
  119. $(".address_edit").on("click", function () {
  120. $(this).hide();
  121. $(".profile_Address").hide();
  122. $(".addresslist").show();
  123. $(".address_edit_cancel").show();
  124. getCountryStateCurrency();
  125. getbillinginfoBind()
  126. });
  127. $(".address_edit_cancel").on("click", function () {
  128. $(this).hide();
  129. $(".addresslist").hide();
  130. $(".profile_Address").show();
  131. $(".address_edit").show();
  132. });
  133. $(".saveaddress")
  134. .off("click")
  135. .click(async function () {
  136. if (addr_zip.val() == "" || addr_addrline.val() == "") {
  137. // toastr.error('Required Feilds are Empty!');
  138. // if(addr_phone.val() == '' || addr_phone.val().length <10){
  139. // addr_phone.addClass("is-invalid");
  140. // }
  141. // else{
  142. // addr_phone.removeClass("is-invalid");
  143. // }
  144. if (addr_zip.val() == '' || addr_zip.val().length < 6) {
  145. addr_zip.addClass("is-invalid");
  146. }
  147. else {
  148. addr_zip.removeClass("is-invalid");
  149. }
  150. if (addr_addrline.val() == '') {
  151. addr_addrline.addClass("is-invalid");
  152. } else {
  153. addr_addrline.removeClass("is-invalid");
  154. }
  155. }
  156. else {
  157. $(".addresslist").hide();
  158. $(".profile_Address").show();
  159. $(".address_edit").show();
  160. $(".address_edit_cancel").hide();
  161. $('.spinner-border').removeClass('d-none')
  162. $('.saveaddress').find('span').addClass('d-none')
  163. await AddresssaveForm();
  164. $('.spinner-border').addClass('d-none')
  165. $('.saveaddress').find('span').removeClass('d-none')
  166. await getbillinginfoBind();
  167. }
  168. });
  169. function onChangeState(e){
  170. let userItem = e.target.value.toLowerCase();
  171. let limit = 10;
  172. let results = [];
  173. let maxLen = stateArr.length > 10 ? 10 :stateArr.length;
  174. for(let i=0;i<stateArr.length;i++){
  175. let currItem = stateArr[i];
  176. let stateName = currItem.cityname.toLowerCase();
  177. if(stateName.includes(userItem)){
  178. results.push(currItem);
  179. if(results.length>=10) break;
  180. }
  181. }
  182. $('.stateBox').removeClass('d-none');
  183. renderCustomStateDropdown(results);
  184. loadDropdownStateEvents();
  185. }
  186. async function getCountryStateCurrency() {
  187. const countryRes = await API_SERVICES_ACTIONS.getAPIService(
  188. "apis/v4/bizgaze/integrations/anwiauth/getcountry"
  189. );
  190. if (countryRes.isError) {
  191. alert("something went wrong");
  192. console.log(countryRes);
  193. return;
  194. }
  195. let countryData = JSON.parse(countryRes.response.result);
  196. console.log(countryData, "country");
  197. for (let i = 0; i < countryData.length; i++) {
  198. if (countryData[i].countryname.toLowerCase() === "india") {
  199. countryID = countryData[i].countryid;
  200. countrynameData = countryData[i].countryname;
  201. break;
  202. }
  203. }
  204. const stateRes = await API_SERVICES_ACTIONS.getAPIService(
  205. `apis/v4/bizgaze/integrations/anwiauth/getcities/countryid/${countryID}`
  206. );
  207. if (stateRes.isError) {
  208. alert("something went wrong");
  209. console.log(stateRes, "state");
  210. return;
  211. }
  212. let stateData = JSON.parse(stateRes.response.result);
  213. console.log(stateData, "state");
  214. stateArr = stateData;
  215. renderCustomStateDropdown(stateArr);
  216. loadDropdownStateEvents();
  217. const currencyRes = await API_SERVICES_ACTIONS.getAPIService(
  218. "apis/v4/bizgaze/integrations/anwiauth/getcurrencies"
  219. );
  220. if (currencyRes.isError) {
  221. alert("something went wrong");
  222. console.log(currencyRes);
  223. return;
  224. }
  225. let currencyData = JSON.parse(currencyRes.response.result);
  226. console.log(currencyData, "currencyDatacurrencyDatacurrencyData");
  227. for (let i = 0; i < currencyData.length; i++) {
  228. const curr = currencyData[i];
  229. if (curr.currencyname.toLowerCase().includes("india")) {
  230. currencyid = curr.currencyid;
  231. }
  232. }
  233. }
  234. async function getCountryId() {
  235. const countryRes = await API_SERVICES_ACTIONS.getAPIService(
  236. "apis/v4/bizgaze/integrations/anwiauth/getcountry"
  237. );
  238. if (countryRes.isError) {
  239. alert("something went wrong");
  240. console.log(countryRes);
  241. return;
  242. }
  243. let ctyId = 0;
  244. let countryData = JSON.parse(countryRes.response.result);
  245. console.log(countryData);
  246. for (let i = 0; i < countryData.length; i++) {
  247. if (countryData[i].countryname.toLowerCase() === "india") {
  248. countryId = countryData[i].countryid;
  249. ctyId = countryId;
  250. countrynameData = countryData[i].countryname;
  251. break;
  252. }
  253. }
  254. return ctyId;
  255. }
  256. function createBillingForm() {
  257. return new Promise(async (resolve, reject) => {
  258. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  259. let { userId, name } = cookieRes;
  260. const ctyId = await getCountryId();
  261. let stateId = $("#state").data('id');
  262. let payload = {
  263. cityid: stateId,
  264. CityName: $(`[data-id="${stateId}"`).html(),
  265. addressline1: $("#addressdes").val(),
  266. OrganizationType: 2,
  267. organizationname: name,
  268. //"OrganizationId":,
  269. ContactName: name,
  270. ContactId: userId,
  271. countryname: "india",
  272. countryid: ctyId,
  273. statename: $(`[data-id="${stateId}"`).html(),
  274. phonenumber: $("#phonenumber").val(),
  275. OrganizationId: userId,
  276. currencyid: 2,
  277. taxno: "0",
  278. BillingInfoExists: false,
  279. lobid: 0,
  280. lobname: "IT Products",
  281. gstindetailid: 0,
  282. zipcode: $("#zipcode").val(),
  283. };
  284. const res = await API_SERVICES_ACTIONS.postAPIService(
  285. "apis/v4/bizgaze/crm/address/savebillinginfo",
  286. payload
  287. );
  288. // http://localhost:3088/apis/v4/bizgaze/crm/address/savebillinginfo
  289. console.log(res);
  290. resolve();
  291. });
  292. }
  293. async function AddresssaveForm() {
  294. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  295. let { userId, name } = cookieRes;
  296. const { errorMsg, isError, response } =
  297. await API_SERVICES_ACTIONS.getAPIService(
  298. `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}`
  299. );
  300. let resAnwi = JSON.parse(response.result);
  301. console.log(resAnwi, "befores");
  302. resAnwi = resAnwi[resAnwi.length - 1];
  303. let stateId = parseInt($("#state").data('id'));
  304. let payload = {
  305. ...resAnwi,
  306. phonenumber: $("#phonenumber").val(),
  307. addressline1: $("#addressdes").val(),
  308. zipcode: $("#zipcode").val(),
  309. cityid: stateId,
  310. CityName: $('#state').val(),
  311. cityname: $('#state').val(),
  312. };
  313. console.log(payload, "addresssaave");
  314. //
  315. const res = await API_SERVICES_ACTIONS.postAPIService(
  316. "apis/v4/bizgaze/crm/address/savebillinginfo",
  317. payload
  318. );
  319. return new Promise((reslove, reject) => {
  320. reslove(res);
  321. });
  322. }
  323. }