Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Address.js 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. function getbillinginfoBind() {
  9. return new Promise(async (resolve, reject) => {
  10. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  11. console.log(cookieRes);
  12. const { errorMsg, isError, response } =
  13. await API_SERVICES_ACTIONS.getAPIService(
  14. `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}`
  15. );
  16. let res = JSON.parse(response.result);
  17. debugger;
  18. console.log(res);
  19. res = res[res.length - 1];
  20. debugger
  21. addr_phone.val(res.phonenumber);
  22. $('#Profile_User_name').val(res.organizationname)
  23. $('#Profile_Phone_num').val(res.phonenumber)
  24. let Profileusername =$('#Profile_User_name').val()
  25. let Profileuserphone=$('#Profile_Phone_num').val()
  26. $('.overview_user_name').html(Profileusername);
  27. $('.overview_user_phone').html(Profileuserphone);
  28. if (res.cityid == "0") {
  29. $(".profile_Address").html(
  30. `<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>`
  31. );
  32. $(".address_edit").hide();
  33. $(".create_address").on("click", function () {
  34. debugger
  35. $(this).hide();
  36. $('.saveaddress').hide()
  37. $(".addresslist").show();
  38. $(".Createaddress").show();
  39. getCountryStateCurrency();
  40. });
  41. $('.Createaddress').on('click',async function(){
  42. if( addr_zip.val() == "" || addr_addrline.val() == ""){
  43. // toastr.error('Required Feilds are Empty!');
  44. // if(addr_phone.val() == '' || addr_phone.val().length <10){
  45. // addr_phone.addClass("is-invalid");
  46. // }
  47. // else{
  48. // addr_phone.removeClass("is-invalid");
  49. // }
  50. if(addr_zip.val() == '' || addr_zip.val().length < 6){
  51. addr_zip.addClass("is-invalid");
  52. }
  53. else{
  54. addr_zip.removeClass("is-invalid");
  55. }
  56. if(addr_addrline.val() == ''){
  57. addr_addrline.addClass("is-invalid");
  58. } else{
  59. addr_addrline.removeClass("is-invalid");
  60. }
  61. }
  62. else{
  63. $(".addresslist").hide();
  64. $(".profile_Address").show();
  65. $(".address_edit").show();
  66. $(".address_edit_cancel").hide();
  67. await createBillingForm()
  68. await getbillinginfoBind();
  69. }
  70. })
  71. } else {
  72. $(".profile_Address").html(
  73. `<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>`
  74. );
  75. }
  76. resolve();
  77. });
  78. } debugger
  79. $(".address_edit").on("click", function () {
  80. $(this).hide();
  81. $(".profile_Address").hide();
  82. $(".addresslist").show();
  83. $(".address_edit_cancel").show();
  84. getCountryStateCurrency();
  85. getbillinginfoBind()
  86. });
  87. $(".address_edit_cancel").on("click", function () {
  88. $(this).hide();
  89. $(".addresslist").hide();
  90. $(".profile_Address").show();
  91. $(".address_edit").show();
  92. });
  93. $(".saveaddress")
  94. .off("click")
  95. .click(async function () {
  96. debugger
  97. if(addr_zip.val() == "" || addr_addrline.val() == ""){
  98. // toastr.error('Required Feilds are Empty!');
  99. // if(addr_phone.val() == '' || addr_phone.val().length <10){
  100. // addr_phone.addClass("is-invalid");
  101. // }
  102. // else{
  103. // addr_phone.removeClass("is-invalid");
  104. // }
  105. if(addr_zip.val() == '' || addr_zip.val().length < 6){
  106. addr_zip.addClass("is-invalid");
  107. }
  108. else{
  109. addr_zip.removeClass("is-invalid");
  110. }
  111. if(addr_addrline.val() == ''){
  112. addr_addrline.addClass("is-invalid");
  113. } else{
  114. addr_addrline.removeClass("is-invalid");
  115. }
  116. }
  117. else{
  118. $(".addresslist").hide();
  119. $(".profile_Address").show();
  120. $(".address_edit").show();
  121. $(".address_edit_cancel").hide();
  122. $('.spinner-border').removeClass('d-none')
  123. $('.saveaddress').find('span').addClass('d-none')
  124. await AddresssaveForm();
  125. $('.spinner-border').addClass('d-none')
  126. $('.saveaddress').find('span').removeClass('d-none')
  127. await getbillinginfoBind();
  128. }
  129. });
  130. async function getCountryStateCurrency() {
  131. const countryRes = await API_SERVICES_ACTIONS.getAPIService(
  132. "apis/v4/bizgaze/integrations/anwiauth/getcountry"
  133. );
  134. if (countryRes.isError) {
  135. alert("something went wrong");
  136. console.log(countryRes);
  137. return;
  138. }
  139. let countryData = JSON.parse(countryRes.response.result);
  140. console.log(countryData, "country");
  141. for (let i = 0; i < countryData.length; i++) {
  142. if (countryData[i].countryname.toLowerCase() === "india") {
  143. countryID = countryData[i].countryid;
  144. countrynameData = countryData[i].countryname;
  145. break;
  146. }
  147. }
  148. const stateRes = await API_SERVICES_ACTIONS.getAPIService(
  149. `apis/v4/bizgaze/integrations/anwiauth/getcities/countryid/${countryID}`
  150. );
  151. if (stateRes.isError) {
  152. alert("something went wrong");
  153. console.log(stateRes, "state");
  154. return;
  155. }
  156. let stateData = JSON.parse(stateRes.response.result);
  157. console.log(stateData, "state");
  158. $("#state").html("");
  159. console.log("start");
  160. let html = "";
  161. statesList = stateData;
  162. for (let i = 0; i < stateData.length; i++) {
  163. html += `<option value="${stateData[i].cityid}" data-id="${stateData[i].cityid}">${stateData[i].cityname}</option>`;
  164. }
  165. $("#state").append(html);
  166. $("#state").select2({
  167. placeholder: "Select a City",
  168. allowClear: true,
  169. });
  170. const currencyRes = await API_SERVICES_ACTIONS.getAPIService(
  171. "apis/v4/bizgaze/integrations/anwiauth/getcurrencies"
  172. );
  173. if (currencyRes.isError) {
  174. alert("something went wrong");
  175. console.log(currencyRes);
  176. return;
  177. }
  178. let currencyData = JSON.parse(currencyRes.response.result);
  179. console.log(currencyData, "currencyDatacurrencyDatacurrencyData");
  180. for (let i = 0; i < currencyData.length; i++) {
  181. const curr = currencyData[i];
  182. if (curr.currencyname.toLowerCase().includes("india")) {
  183. currencyid = curr.currencyid;
  184. }
  185. }
  186. }
  187. async function getCountryId() {
  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. console.log(countryRes);
  194. return;
  195. }
  196. let ctyId = 0;
  197. let countryData = JSON.parse(countryRes.response.result);
  198. console.log(countryData);
  199. for (let i = 0; i < countryData.length; i++) {
  200. if (countryData[i].countryname.toLowerCase() === "india") {
  201. countryId = countryData[i].countryid;
  202. ctyId = countryId;
  203. countrynameData = countryData[i].countryname;
  204. break;
  205. }
  206. }
  207. return ctyId;
  208. }
  209. function createBillingForm() {
  210. debugger;
  211. return new Promise(async (resolve, reject) => {
  212. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  213. let { userId, name } = cookieRes;
  214. const ctyId = await getCountryId();
  215. let stateId = parseInt($("#state").val());
  216. let payload = {
  217. cityid: stateId,
  218. CityName: $(`[data-id="${stateId}"`).html(),
  219. addressline1: $("#addressdes").val(),
  220. OrganizationType: 2,
  221. organizationname: name,
  222. //"OrganizationId":,
  223. ContactName: name,
  224. ContactId: userId,
  225. countryname: "india",
  226. countryid: ctyId,
  227. statename: $(`[data-id="${stateId}"`).html(),
  228. phonenumber: $("#phonenumber").val(),
  229. OrganizationId: userId,
  230. currencyid: 2,
  231. taxno: "0",
  232. BillingInfoExists: false,
  233. lobid: 0,
  234. lobname: "IT Products",
  235. gstindetailid: 0,
  236. zipcode: $("#zipcode").val(),
  237. };
  238. const res = await API_SERVICES_ACTIONS.postAPIService(
  239. "apis/v4/bizgaze/crm/address/savebillinginfo",
  240. payload
  241. );
  242. // http://localhost:3088/apis/v4/bizgaze/crm/address/savebillinginfo
  243. console.log(res);
  244. resolve();
  245. });
  246. }
  247. async function AddresssaveForm() {
  248. debugger;
  249. let cookieRes = COOKIE_HELPER_ACTIONS.getCookie();
  250. let { userId, name } = cookieRes;
  251. const { errorMsg, isError, response } =
  252. await API_SERVICES_ACTIONS.getAPIService(
  253. `apis/v4/bizgaze/integrations/anwiauth/getbillinginfo/contactid/${cookieRes.userId}`
  254. );
  255. let resAnwi = JSON.parse(response.result);
  256. console.log(resAnwi, "befores");
  257. resAnwi = resAnwi[resAnwi.length - 1];
  258. let stateId = parseInt($("#state").val());
  259. let payload = {
  260. ...resAnwi,
  261. phonenumber: $("#phonenumber").val(),
  262. addressline1: $("#addressdes").val(),
  263. zipcode: $("#zipcode").val(),
  264. cityid: stateId,
  265. CityName: $(`[data-id="${stateId}"`).html(),
  266. };
  267. console.log(payload, "addresssaave");
  268. //
  269. const res = await API_SERVICES_ACTIONS.postAPIService(
  270. "apis/v4/bizgaze/crm/address/savebillinginfo",
  271. payload
  272. );
  273. return new Promise((reslove, reject) => {
  274. reslove(res);
  275. });
  276. }
  277. }