app.controller('facturaCtrl', function ($scope, $http, $window, notify,$location) { $scope.cero=true; $scope.total=0; var user = $location.search().user; if (user == undefined) user=""; $scope.update = function() { $http.get('back/cliente/' + user).success(function(data) { $scope.userdata = data; }); $http.get('back/productos/' + user).success(function(data) { $scope.listaproductos = data; }); }; $scope.fin = function () { var factura = {}; if ($scope.productos.length==0){ notify({message:"No hay productos",classes:"alert alert-danger"}); return; } $http.post('back/pedido', { factura: factura } ) .success(function(data, status, headers, config) { notify("Guardada correctamente"); }) .error(function(data, status, headers, config) { notify({classes:"alert alert-danger", message:"Error: "+ data.err}); }); } $scope.filterCero = function(criteria) { return function(item) { if ($scope.cero) return true; return item.cantidad > 0; }; }; $scope.updateTotal = function() { var total=0; total=$scope.listaproductos.reduce( function(acc,cur) { return acc+(cur.cantidad*cur.precio) },0); $scope.total=total; }; $scope.reset = function() { $scope.update(); }; $scope.ok = function () { }; $scope.reset(); });