var app = angular.module("app", []); app.filter('suma', function () {return function (data) { var sum = 0.0; //var i=1; angular.forEach(data,function(value){ if(!angular.isUndefined(value['c'])) sum = sum + parseFloat(value['c']) * parseFloat(value['p'].precio); }); return sum; }; }); app.controller('vetjgctrl', ['$rootScope', '$http', '$filter', function($rootScope, $http, $filter) { $rootScope.quebusco=""; $rootScope.p=new Object(); $rootScope.carrito=new Object(); $rootScope.tmp1=""; $rootScope.tmp2=""; $rootScope.escliente=0; $rootScope.carritosanteriores=new Object(); $rootScope.lineacarrito=new Object(); $rootScope.compraok=0; /* $rootScope.departamentos=new Object(); $http.get('http://mimascota.info/js/departamentos.php').then(function(response) { $rootScope.departamentos=response.data; }); */ $rootScope.analisis=function(t,o,p) { $http.get('http://mimascota.info/js/origen.php?t='+t+'&o='+o+'&p='+p); } $rootScope.carritobbdd=function(p,c) { var t=''; $http.get('http://mimascota.info/js/carrito.php?t='+t+'&p='+p+'&c='+c); } $rootScope.recargacarrito=function(telefono) { $http.get('http://mimascota.info/js/cargacarrito.php?t='+telefono).then(function(response) { angular.forEach(response.data,function(value){ $rootScope.add($filter('filter')($rootScope.productos, {id:value.idproducto})[0]),parseInt(value.cantidad); console.log(response.status); }); }); } $rootScope.recargadatos=function(telefono) { $http.get('http://mimascota.info/js/productos.php?t='+telefono).then(function(response) { $rootScope.productos=response.data; //Ahora recargo el carrito $rootScope.recargacarrito(''); //console.log($rootScope.productos); }); $http.get('http://mimascota.info/js/telefono.php?t='+telefono).then(function(response) { $rootScope.escliente=parseInt(response.data); }); } $rootScope.filtro=function(filtro) { $rootScope.analisis('','vm','hago filtro en: '+filtro); $rootScope.quebusco=filtro } $rootScope.vermas=function(producto) { if(!$rootScope.productos){ setTimeout(function(){ $rootScope.p=($filter('filter')($rootScope.productos, {id:producto})[0]); }, 3000); setTimeout(function(){ $("#datosproducto").modal('toggle'); }, 500); } else { $rootScope.p=($filter('filter')($rootScope.productos, {id:producto})[0]); //console.log($filter('filter')($rootScope.productos, {id:producto})[0]); $("#datosproducto").modal('toggle'); } $rootScope.analisis('','vm','hacerclickvermas: '+producto); } $rootScope.vercarritos=function() { $http.get('http://mimascota.info/js/comprasanteriores.php?t=').then(function(response) { $rootScope.carritosanteriores=response.data; console.log('http://mimascota.info/js/comprasanteriores.php?t='); }); $rootScope.analisis('','vm','ver sus carritos'); } $rootScope.pagarTPV=function(cantidad) { var d = new Date(); var idtpv=Math.round(d.getTime() / 1000); //Quito las comas por si acaso cantidad=cantidad.replace(",",""); cantidad=Math.round(cantidad*100); $rootScope.analisis('','TPV','hago click en pagar: '+cantidad); //var carrito=[]; $http.get('http://mimascota.info/js/recibircarrito.php?t=&idtpv='+idtpv); window.open("http://tpv.vetjg.es/nuevo/anadirapagina.php?p="+cantidad+"&id="+idtpv); } $rootScope.add=function(producto, cantidad) { console.log(producto); var prodlocal=[]; //Verifico si ese producto está definido en el carrito //Esto hay que revisarlo if($rootScope.carrito[producto]) { cantidad=($rootScope.carrito[producto])+cantidad; } $rootScope.carrito[producto]=cantidad; //$rootScope.analisis('','añadir','añado producto al carro: '+producto.pro+" y cantidad: "+cantidad); //$rootScope.carrito[producto]=prodlocal; //$rootScope.carritobbdd(producto.id,prodlocal.c); console.log($rootScope.carrito); } $rootScope.guarda1=function(tel){ $rootScope.tmp1=tel; $('#telefono').val(""); $('#segundoboton').hide(); } $rootScope.guarda2=function(tel, pru){ $rootScope.tmp2=tel; if($rootScope.tmp1 == $rootScope.tmp2 && pru==4) { alert("ahora mismo recibira un SMS para poder comprar"); $http.get('http://mimascota.info/js/registrousuario.php?t='+$.base64('encode',tel)); } else alert("ERROR. VUELVA A INTENTARLO"); //Ahora borro todo $rootScope.tmp1=""; $rootScope.tmp2=""; $('#telefono').val(""); $('#prueba').val(""); $('#login').modal('toggle'); } $rootScope.cargacarritosanteriores=function(id){ $http.get('http://mimascota.info/js/lineascarrito.php?id='+id).then(function(response) { $rootScope.lineacarrito=response.data; }); } $rootScope.muestrasegundoboton=function(){ $('#segundoboton').show(); } $rootScope.analisis('','','Entrada 1 vez'); $rootScope.recargadatos(''); switch($rootScope.compraok) { case 0: break; case 1: $rootScope.titulo="Compra efectuada correctamente (titulo)"; $rootScope.subtitulo="Compra efectuada correctamente (subtitulo)"; $rootScope.eltexto="Compra efectuada correctamente"; $rootScope.foto="login"; break; case 2: $rootScope.titulo="Bienvenido (titulo)"; $rootScope.subtitulo="Bienvenido (subtitulo)"; $rootScope.eltexto="Vengo de numero 2"; $rootScope.foto="adjunto2"; break; case 3: $rootScope.eltexto="Vengo de numero 3"; break; case 5: $rootScope.titulo="Bienvenido"; $rootScope.subtitulo="Deseas participar en la peña de la loteria del club de compras JG"; $rootScope.eltexto="Escribe tu numero de telefono. Guarda el SMS que recibas para poder canjear tu premio en nuestro supermercado.\n Si participas aceptas que te enviemos ofertas de nuestros productos el día 1 de cada mes. Puedes darte de baja en cualquier momento respondiendo BAJA"; $rootScope.foto="loteria"; break; default: $rootScope.vermas($rootScope.compraok); break; $('#compraok').modal('toggle'); } }]);