Brak opisu
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.

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