var CreditViewModel = { creditInfo: ko.observable({ address: [], profile: { firstName: "", lastName: "" } }) }; $(document).ready(function () { if (document.getElementById('my-credits') != null) { ko.applyBindings(CreditViewModel, document.getElementById('my-credits')); } }); let host = ""; (location.href.includes("qacalypso")) ? host = "newqa" : host = "newpdn"; function getUser() { fetch('/no-cache/profileSystem/getProfile') .then(user => user.json()) .then(user => { if (user.IsUserDefined) { if (user.FirstName != null) { $('#nameUser').html(" " + user.FirstName + "!"); } fetch('https://' + host + '-calypsomiddleware.com/api/front/clients/email?email=' + user.Email) .then(response => response.json()) .then(response => { console.log(response); if (response.clientStatus && response.clientStatus !== "Activo") { Swal.fire({ title: 'Error al ingresar a tu cuenta', text: "Parece que tu cuenta esta desactivada, puedes terminar tu compra como cliente no empresarial", icon: 'error', showCancelButton: false, confirmButtonColor: '#BE2828', confirmButtonText: 'Confirmar' }) .then(value => { logout(); }); return; } var data = { f: 'email,priceTables,userId,clientCode,isCorporate', fq: 'email' + ':' + response.contacts[0].contact_email }; $.ajax({ url: 'https://' + host + '-calypsomiddleware.com/api/front/entity/', contentType: 'application/json; charset=utf-8', data: data, type: "GET" }) .done(function (data) { data = data.Documents[0]; console.log(data); if (data.isCorporate === false) { Swal.fire({ title: 'Cuenta no autorizada para acceso B2B', html: "
Lo sentimos, tu acceso como cliente empresarial ha sido denegado. Llámanos al 320 3336644 para mas información.
", icon: 'warning', showCancelButton: true, confirmButtonColor: '#2b2b2b', cancelButtonColor: '#be2828', confirmButtonText: 'Acceder como B2C', cancelButtonText: 'Cerrar' }) .then((result) => { console.log(result); if (!result.isConfirmed) { logout(); } }); //Si el acceso esta authorizado } else if (data.isCorporate === true) { if (!sessionStorage.getItem('acceso')) { Swal.fire({ position: 'center', icon: 'success', title: 'Acceso autorizado', html: "Felicitaciones, tu acceso ha sido autorizado, ya puedes realizar tus compras
", showConfirmButton: false, timer: 1500 }) .then(data => { sessionStorage.setItem('acceso', true); }); } } }); if (response.clientCode != null) { HeaderViewModel.addresses(response.address); console.log(HeaderViewModel); searchCredits(response.clientCode, user); $('.address-account').hide(); if (location.pathname == '/_secure/account') { $(document).on('click', '.vtex-account_menu-link', function () { $('.vtex-account').addClass('is-direction-section'); }); } if (location.hash == '#/addresses') { $('.vtex-account').addClass('is-direction-section'); } } else { $('.status-credit').hide(); } if (location.pathname == '/_secure/account') { $('.vtex-account_menu-link').each(function (e, i) { if (i.innerHTML == 'Mis Creditos') { $(i).hide(); } if (i.innerHTML == 'Tarjetas de crédito') { var allLinks = $('.vtex-account_menu-link'); $(allLinks[allLinks.length - 2]).after(i); } }); $('.myo-cancel-btn').remove(); } }); } }); } getUser(); function searchCredits(code, profile) { fetch('https://'+ host +'-calypsomiddleware.com/api/front/clients/email?email=' + profile.Email) .then(res => res.json()) .then(res => { if (res.clientStatus && res.clientStatus !== "Activo") { Swal.fire({ title: 'Error al ingresar a tu cuenta', text: "Parece que tu cuenta esta desactivada, puedes terminar tu compra como cliente no empresarial", icon: 'error', showCancelButton: false, confirmButtonColor: '#BE2828', confirmButtonText: 'Confirmar' }) .then(value => { logout(); }); return; } var data = { f: 'email,priceTables,userId,clientCode,isCorporate', fq: 'email' + ':' + res.contacts[0].contact_email }; $.ajax({ url: "https://"+ host +"-calypsomiddleware.com/api/front/entity/", contentType: 'application/json; charset=utf-8', data: data, type: "GET" }) .done(function (data) { data = data.Documents[0]; console.log(data); if (data.isCorporate === false) { Swal.fire({ title: 'Cuenta no autorizada para acceso B2B', text: "No tienes permisos para acceder como cliente empresarial", icon: 'warning', showCancelButton: true, confirmButtonColor: '#2b2b2b', cancelButtonColor: '#be2828', confirmButtonText: 'Acceder como B2C', cancelButtonText: 'Cerrar' }).then((result) => { console.log(result); if (!result.isConfirmed) { logout(); } }); //Si el acceso esta authorizado } else if (data.isCorporate === true) { if (!sessionStorage.getItem('acceso')) { Swal.fire({ position: 'center', icon: 'success', title: 'Acceso autorizado', text: "Felicitaciones, tu acceso ha sido autorizado, ya puedes realizar tus compras.", showConfirmButton: false, timer: 1500 }).then(data => { sessionStorage.setItem('acceso', true); }); } } }); res['profile'] = profile; $('.status-credit-value').html(cropPrice(currency(res.creditAvailable))); if (document.getElementById('my-credits') != null) { CreditViewModel.creditInfo(res); } }); } function dowloadExtract() { var pdf = new jsPDF('p', 'pt', 'a4'); pdf.addHTML(document.getElementById("my-credits"), function () { pdf.save('extracto-cliente.pdf'); }); }