説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Address.js 12KB

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