暫無描述
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 9.9KB

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