function shoppingCart(){} shoppingCart.prototype = { removeTicket : function(proCodigo, carCodigo, message){ const element = document.getElementById(proCodigo); const itemData = element.getAttribute('data-ticket-item'); var thisObject = this; var modal = new Modal({ title: translate["shopping-cart-js-delete-confirmation"], body: '', confirm: function (){ ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/remove-ticket-shopping-cart', method: 'post', data: {pro_codigo: proCodigo, car_codigo: carCodigo}, dataType: 'json', error: function(json){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'OK' }); modal.show(); }, success: function(json) { ajaxLoader.ajaxStop(); modal.hide(); if(!json.status){ var modalError = new Modal({ title: json.title, body : '', buttonOK : false, }); modalError.show(); }else{ gtmActions.removeFromCart([JSON.parse(itemData)]); $('#'+proCodigo).remove(); if($('#resume-'+proCodigo).length > 0){ $('#resume-'+proCodigo).remove(); } $('#shoppingCartItems').text(json.total_cart); $('#shoppingCartItemsMobile').text(json.total_cart); thisObject.changeTotalBoxValues(json); setTimeout(function(){ window.location.reload(); }, 500); } }, }); }, }); modal.show(); }, removeAllTickets: function(message) { var thisObject = this; var modal = new Modal({ title: translate["shopping-cart-js-delete-confirmation"], body: '', confirm: function (){ ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/discard-shopping-cart', method: 'post', dataType: 'json', error: function(json){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'OK' }); modal.show(); }, success: function(json) { ajaxLoader.ajaxStop(); modal.hide(); if(!json.status){ var modalError = new Modal({ title: json.title, body : '', buttonOK : false, }); modalError.show(); }else{ window.location.reload(); } }, }); }, }); modal.show(); }, insertDiscount : function(proCodigo, carCodigo, dscCodigo, eveCodigo, rg, dob, nome, cupHash, cupCodigo, email){ var thisObject = this; ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/insert-discount', data: {pro_codigo: proCodigo, car_codigo: carCodigo, dsc_codigo: dscCodigo, eve_codigo: eveCodigo, rg: rg, dob: dob, nome: nome, cup_hash: cupHash, cup_codigo: cupCodigo, email: email}, method: 'post', dataType: 'json', success: function(json){ ajaxLoader.ajaxStop(); if(json.status){ if(cupCodigo != undefined){ location.reload(); return; } thisObject.changeTotalBoxValues(json); thisObject.changeTicketvalues(json, proCodigo); if(nome != null){ $('#'+proCodigo+' #halfTicketName').text(nome); $('#'+proCodigo+' #halfTicketName').css('display', 'block'); }else{ $('#'+proCodigo+' #halfTicketName').text(''); $('#'+proCodigo+' #halfTicketName').css('display', 'none'); } if(json.coupon){ location.reload(); } if(json.message != undefined){ var modalParams = { title: json.title, body : '', buttonOK : false, cancelText: 'OK', dismissButton : false }; if(json.buttons != undefined){ if(json.buttons.ok != undefined){ modalParams.buttonOK = true; modalParams.okText = json.buttons.ok; modalParams.confirm = 'self.close'; if( typeof json.buttons.okUrl === 'string' ) { modalParams.confirm = function(){window.location.href = json.buttons.okUrl}; } } if(json.buttons.cancel != undefined){ modalParams.cancelText = json.buttons.cancel; modalParams.cancel = function(){ $(".premmia-inteira option").each(function (){ if ($(this).val() === '0') { $('#ticketDiscount'+proCodigo).val('0'); $('#ticketDiscount'+proCodigo).change(); } else if ($(this).val() === 'T-2') { $('#ticketDiscount'+proCodigo).val('T-2'); $('#ticketDiscount'+proCodigo).change(); } }); }; } if( typeof json.buttons.cancelUrl === 'string' ) { modalParams.cancel = function(){window.location.href = json.buttons.cancelUrl}; } } var modal = new Modal(modalParams); modal.show(); } }else{ var modalParams = { title: json.title, body : '', buttonOK : false, cancelText: 'OK', dismissButton : false, cancel: function(){ $('#ticketDiscount'+proCodigo).val(json.current_discount); } }; if(json.buttons != undefined){ if(json.buttons.ok != undefined){ modalParams.buttonOK = true; modalParams.okText = json.buttons.ok; modalParams.confirm = function(){window.location.href = json.buttons.okUrl}; } if(json.buttons.cancel != undefined){ modalParams.cancelText = json.buttons.cancel; modalParams.cancel = function() { window.open(json.buttons.cancelUrl,'_blank'); $('#ticketDiscount'+proCodigo).val('T-2'); $('#ticketDiscount'+proCodigo).change(); }; if( typeof json.buttons.cancelUrl === 'string' ) { modalParams.cancel = function(){window.location.href = json.buttons.cancelUrl}; } } } var modal = new Modal(modalParams); modal.show(); } } }); }, applyDiscount : function(productId, cartId, eventId, callback, ing_codigo){ var thisObject = this; var discountId = $("#ticketDiscount"+productId).val(); if(discountId == 0){ // $('#modal').css('display', 'block'); // $('.modal-backdrop').css('display', 'block'); // $('#form-half-ticket').trigger("reset"); // // $('#modal').attr("data-pro", productId); // $('#modal').attr("data-car", cartId); // $('#modal').attr("data-eve", eventId); // $('#modal').attr("data-dsc", discountId); // $('#modal').modal('show'); } else if(discountId.charAt(0) == 'L'){ $('#modal').css('display', 'block'); $('.modal-backdrop').css('display', 'block'); $('#form-half-ticket').trigger("reset"); $('#modal').attr("data-pro", productId); $('#modal').attr("data-car", cartId); $('#modal').attr("data-eve", eventId); $('#modal').attr("data-dsc", discountId); if(callback) { callback(discountId, ing_codigo); } else { $('#modal').modal('show'); } } else if(discountId.charAt(0) == 'M'){ $('#modal-multiclubes').css('display', 'block'); $('.modal-backdrop').css('display', 'block'); $('#form-multiclubes').trigger("reset"); $('#modal-multiclubes').attr("data-pro", productId); $('#modal-multiclubes').attr("data-car", cartId); $('#modal-multiclubes').attr("data-eve", eventId); $('#modal-multiclubes').attr("data-dsc", discountId); $('#modal-multiclubes').modal('show'); } else if(discountId.charAt(0) == 'C'){ $('#modalCupom').css('display', 'block'); $('.modal-backdrop').css('display', 'block'); $('#form-cupom').trigger("reset"); $('#modalCupom').attr("data-pro", productId); $('#modalCupom').attr("data-car", cartId); $('#modalCupom').attr("data-eve", eventId); $('#modalCupom').attr("data-dsc", discountId); $('#modalCupom').modal('show'); }else{ thisObject.insertDiscount(productId, cartId, discountId, eventId); // fiz isso para quando tiver a troca de ingresso para meia novamente, fazer um reload na pagina para atualizar o preço setTimeout(function() { window.location.reload(); }, 1000); } }, changeTotalBoxValues : function(jsonData){ const feeTaxValue = parseFloat(jsonData.fee_tax.replace(",", ".")); const totalValue = parseFloat(jsonData.total.replace(",", ".")); const subTotal = parseFloat(jsonData.subtotal.replace(",", ".")); const subTotalFormatado = subTotal.toLocaleString('pt-br', {minimumFractionDigits: 2}) const total = jsonData.total; const totalFormatado = 'R$ ' +total.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }); $('.subtotal').html(jsonData.subtotal); $('.discount').html(jsonData.discount); $('.order_tax').html(jsonData.order_tax); $('.fee_tax').html(jsonData.fee_tax); $('.total').html(totalFormatado); }, changeTicketvalues : function(jsonData, proCodigo){ const price = parseFloat(jsonData.product_price.replace(',', '.')); const convenienceFee = parseFloat(jsonData.product_convenience_fee.replace(',', '.')); let product_price = price - convenienceFee; product_price = product_price.toLocaleString('pt-BR', { minimumFractionDigits: 2 }); $('#total_' + proCodigo).html(product_price); $('#discount_' + proCodigo).html(jsonData.product_discount); $('#convenience_fee_' + proCodigo).html(jsonData.product_convenience_fee); $('#total_' + proCodigo).html(product_price); }, pay : function(cartId, totalShoppingCart){ let controll = true; $(".premmia-inteira option:selected").each(function (){ if ($(this).val() == 0 || $(this).val() == null) { $(this).parent().css('border', '1px solid #b94a48').css('background-color', '#fee'); controll = false; } }); $(".premmia-inteira").each(function (){ if ($(this).val() == null) { $(this).parent().css('border', '1px solid #b94a48').css('background-color', '#fee'); $(this).val('0'); controll = false; } }); if (controll) { window.location.href = '/policy'; }else { var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); } }, btnCancel : function(){ $(".premmia-inteira option").each(function (){ if ($(this).val() === '0') { $('#ticketDiscount'+ $('#modal').attr('data-pro') ).val('0'); } else if ($(this).val() === 'T-2') { $('#ticketDiscount'+ $('#modal').attr('data-pro') ).val('T-2'); } }); }, btnCancelPremmia : function(){ $("td.td_select select").val('0'); }, orderGenerate : function(carCodigo, totalShoppingCart){ const element = document.getElementById("shopping-cart"); const value = document.getElementById("total"); const itemData = element.getAttribute('data-cart'); ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/order-generate', data: {car_codigo: carCodigo, total_shoppingcart: totalShoppingCart}, method: 'post', dataType: 'json', error: function(){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); }, success: function(json){ if(json.status){ gtmActions.beginCheckout(JSON.parse(itemData), value.innerText.replace("R$ ", "").replace(".", "").replace(",", ".")); setTimeout(function() { window.location.replace(json.url); }, 500); }else{ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'Fechar', cancel: function(){ window.scrollTo(0, 0); setTimeout(function() { window.location.reload(); }, 1000); } }); modal.show(); } } }); }, sendToInsurance : function(){ var isValid = true; $('.premmia-inteira').each(function(n, obj){ if($(obj).val() == '0'){ var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); isValid = false; } }); if(isValid){ $.ajax({ url: '/shopping-cart/validate-shopping-cart-documents', method: 'post', dataType: 'json', error: function(){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); }, success: function(json){ if(json.status){ window.location.replace('/ticket-insurance'); }else{ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'OK', cancel: function(){ } }); modal.show(); } } }); } }, insuranceGenerate : function(carCodigo, totalShoppingCart){ let ingressos = []; let ingressosSeguro = document.querySelectorAll('[data-seguro-ingresso]'); ingressosSeguro.forEach(ingresso => { if(ingresso.checked) ingressos.push(ingresso.getAttribute('data-seguro-ingresso'))}) ajaxLoader.ajaxStart(); var thisObject = this; $.ajax({ url: '/ticket-insurance/ticket-insurance', data: {ingressos_seguro: ingressos, cart: carCodigo}, method: 'post', dataType: 'json', error: function(){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); }, success: function(json){ console.log(json) if(json.status){ thisObject.orderGenerate(carCodigo, totalShoppingCart); }else{ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'OK', cancel: function(){ location.reload(); } }); modal.show(); } } }); }, insuranceSendName : function(){ let ingressos = []; let ingressosSeguro = document.querySelectorAll('[data-insurance-name]'); ingressosSeguro.forEach(ingresso => (ingressos.push({[ingresso.getAttribute('name')]: ingresso.value}))) ajaxLoader.ajaxStart(); $.ajax({ url: '/ticket-insurance/add-insurance-name', data: {ingressos_seguro_nomes: ingressos}, method: 'post', dataType: 'json', error: function(){ ajaxLoader.ajaxStop(); var modal = new Modal({ title: 'Erro', body : '', buttonOK : false, cancelText: 'OK', }); modal.show(); }, success: function(json){ if(json.status){ window.location.reload(); }else{ ajaxLoader.ajaxStop(); var modal = new Modal({ title: json.title, body : '', buttonOK : false, cancelText: 'OK', cancel: function(){ location.reload(); } }); modal.show(); } } }); }, halfTicketTypeTicket: function (member = null) { var thisObject = this; var nome = $('#user_nome').val().trim(); var rg = $('#user_rg').val().trim(); var dob = $('#user_dob').val().trim(); var email = $('#user_email').val()?.trim(); // opcional let mensagens = []; if (!nome) mensagens.push("O nome é obrigatório."); if (!rg) mensagens.push("O CPF ou Passaporte é obrigatório."); if (!dob) mensagens.push("A data de nascimento é obrigatória."); if(!member){ if (mensagens.length > 0) { var modal = new Modal({ title: 'Erro de preenchimento', body: '', buttonOK: false, cancelText: 'OK', }); modal.show(); return; } } // Se passou na validação, fecha modal e chama a função $('#modal').modal('hide'); thisObject.insertDiscount( $('#modal').attr('data-pro'), $('#modal').data('car'), $('#modal').attr('data-dsc'), $('#modal').data('eve'), rg, dob, nome, null, $('#modal').attr('data-cup'), email ); }, couponTicket : function(){ var thisObject = this; $('#modalCupom').modal('hide'); thisObject.insertDiscount($('#modalCupom').attr('data-pro'), $('#modalCupom').data('car'), $('#modalCupom').data('dsc'), $('#modalCupom').data('eve'),null,null,null, $('#cup_hash').val()); }, applyCoupon : function(eveCodigo){ var thisObject = this; var cupHash = $('#cupHash').val(); ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/apply-coupon', data: {cup_hash: cupHash, eve_codigo: eveCodigo}, dataType: 'json', method: 'post', success: function(json){ ajaxLoader.ajaxStop(); if(json.status){ location.reload(); }else{ if(json.show_document_modal){ $('#modal').css('display', 'block'); $('.modal-backdrop').css('display', 'block'); $('#form-half-ticket').trigger("reset"); $('#modal').attr("data-pro", json.product_id); $('#modal').attr("data-car", json.cart_id); $('#modal').attr("data-eve", eveCodigo); $('#modal').attr("data-dsc", 'L-' + json.discount_id); $('#modal').attr("data-cup", json.coupon_id); $('#modal').find('.titulo-interna').text('CADASTRO'); $('#modal').modal('show'); }else{ var modal = new Modal({ title: json.title, body : '', buttonOK : false, }); modal.show() } } } }); }, multiclubesTypeTicket : function(){ $('#modal-multiclubes').modal('hide'); this.insertDiscount($('#modal-multiclubes').attr('data-pro'), $('#modal-multiclubes').data('car'), $('#modal-multiclubes').data('dsc'), $('#modal-multiclubes').data('eve'), $('#title_code').val()); }, removeCoupon : function(proCodigo, carCodigo, cupCodigo){ ajaxLoader.ajaxStart(); $.ajax({ url: '/shopping-cart/remove-coupon', data: {pro_codigo: proCodigo, car_codigo: carCodigo, cup_codigo: cupCodigo}, dataType: 'json', method: 'post', success: function(json){ ajaxLoader.ajaxStop(); if(json.status){ location.reload(); }else{ var modal = new Modal({ title: json.title, body : '', buttonOK : false, }); modal.show(); } } }); }, expireCart: function (){ ajaxLoader.ajaxStart(); setTimeout(function(){ $.ajax({ url: '/shopping-cart/expire-cart', dataType: 'json', method: 'post', success: function(json){ ajaxLoader.ajaxStop(); if(json.status){ window.location.href = json.url; }else{ window.location.reload(); } } }); }, 3000); }, ticketAddDocument : function(callback){ if(!$('#modal-documento-ingresso').find('#ticket-document-check').prop('checked')){ var modal = new Modal({ title: "Ops!!", body : '', buttonOK : false, }); modal.show(); return; } ajaxLoader.ajaxStart(); var ticketId = $('#modal-documento-ingresso').find('#ticket-document-ticket-id').val(); var name = $('#modal-documento-ingresso').find('#ticket-document-name').val(); var document = $('#modal-documento-ingresso').find('#ticket-document-document').val(); var email = $('#modal-documento-ingresso').find('#ticket-document-email').val(); var phone = $('#modal-documento-ingresso').find('#ticket-document-phone').val(); var dob = $('#modal-documento-ingresso').find('#ticket-document-dob').val(); // fluxo para copa fla var uniformSize = $('#modal-documento-ingresso').find('#ticket_tamanho_uniforme').val(); var studentClub = $('#modal-documento-ingresso').find('#ticket_aluno_flamengo').val(); var unit = $('#modal-documento-ingresso').find('#ticket_unidade').val(); var position = $('#modal-documento-ingresso').find('#ticket_posicao').val(); $.ajax({ url: '/shopping-cart/ticket-add-document', data: {ticketId: ticketId, name: name, document: document, email: email, phone: phone, dob: dob, uniformSize: uniformSize, studentClub: studentClub, unit: unit, position: position}, dataType: 'json', method: 'post', success: function(json){ ajaxLoader.ajaxStop(); if(json.status){ $('#ticket-'+ticketId+'-document-name').text(name); $('#ticket-'+ticketId+'-document-name').attr('onclick', "$('#modal-documento-ingresso').find('#ticket-document-ticket-id').val("+ticketId+");" + "$('#modal-documento-ingresso').find('#ticket-document-name').val('"+name+"');" + "$('#modal-documento-ingresso').find('#ticket-document-document').val('"+document+"');" + "$('#modal-documento-ingresso').find('#ticket-document-email').val('"+email+"');" + "$('#modal-documento-ingresso').find('#ticket-document-phone').val('"+phone+"');" + "$('#modal-documento-ingresso').find('#ticket-document-dob').val('"+dob+"');" + "$('#modal-documento-ingresso').modal()" ); $('#modal-documento-ingresso').modal('hide'); if(callback) { callback(json); } if( json.message && json.title ) { let modalParams = { title: json.title, body: '', buttonOk: true, }; if(json.buttons != undefined){ if(json.buttons.ok != undefined){ modalParams.okText = json.buttons.ok; } if( json.buttons.okUrl ) { modalParams.confirm = function(){ window.location.href = json.buttons.okUrl; }; } if(json.buttons.cancel != undefined){ modalParams.cancelText = json.buttons.cancel; } if( typeof json.buttons.cancelUrl === 'string' ) { modalParams.cancel = function(){window.location.href = json.buttons.cancelUrl}; } } const modal = new Modal(modalParams); modal.show(); return; } else { window.location.reload(); } }else{ var modal = new Modal({ title: "Ops!!", body : '', buttonOK : false, }); modal.show(); } } }); }, responsibleCupFla: function(){ var nome = $('#user_nome_responsible').val().trim(); var rg = $('#user_rg_responsible').val().trim(); var dob = $('#user_dob_responsible').val().trim(); var email = $('#user_email_responsible').val().trim(); var endereco = $('#user_endereco_responsible').val().trim(); var telefone = $('#user_telefone_responsible').val().trim(); var socio = $('#user_socio_flamengo').val(); let mensagens = []; if (!nome) mensagens.push("O nome é obrigatório."); if (!rg) mensagens.push("O CPF ou Passaporte é obrigatório."); if (!dob) mensagens.push("A data de nascimento é obrigatória."); if (!email) mensagens.push("O email é obrigatório."); if (!endereco) mensagens.push("O endereço é obrigatório."); if (!telefone) mensagens.push("O telefone é obrigatório."); if (!socio) mensagens.push("Selecione a opção de sócio."); if (mensagens.length > 0) { var modal = new Modal({ title: 'Ops!', body: '', buttonOK: false, cancelText: 'OK', }); modal.show(); return; } $.ajax({ url: '/shopping-cart/add-responsible-cup', data: {nome, rg, dob, email, endereco, telefone, socio}, dataType: 'json', method: 'post', success: function(json){ ajaxLoader.ajaxStop(); if(!json.status){ var modalParams = { title: 'Ops!', body : '', buttonOK : false, cancelText: 'OK', dismissButton : false }; var modal = new Modal(modalParams); modal.show(); } else { $('#modal').modal('hide'); window.location.reload(); } } }); } }; var shoppingCart = new shoppingCart();