facturaCtrl.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. app.controller('facturaCtrl', function ($scope, $http, $window, notify,$location) {
  2. $scope.cero=true;
  3. $scope.total=0;
  4. var user = $location.search().user;
  5. if (user == undefined)
  6. user="";
  7. $scope.update = function() {
  8. $http.get('back/cliente/' + user).success(function(data) {
  9. $scope.userdata = data;
  10. });
  11. $http.get('back/productos/' + user).success(function(data) {
  12. $scope.listaproductos = data;
  13. });
  14. };
  15. $scope.fin = function () {
  16. var factura = {};
  17. if ($scope.productos.length==0){
  18. notify({message:"No hay productos",classes:"alert alert-danger"});
  19. return;
  20. }
  21. $http.post('back/pedido', { factura: factura } )
  22. .success(function(data, status, headers, config) {
  23. notify("Guardada correctamente");
  24. })
  25. .error(function(data, status, headers, config) {
  26. notify({classes:"alert alert-danger", message:"Error: "+ data.err});
  27. });
  28. }
  29. $scope.filterCero = function(criteria) {
  30. return function(item) {
  31. if ($scope.cero)
  32. return true;
  33. return item.cantidad > 0;
  34. };
  35. };
  36. $scope.updateTotal = function() {
  37. var total=0;
  38. total=$scope.listaproductos.reduce(
  39. function(acc,cur) {
  40. return acc+(cur.cantidad*cur.precio)
  41. },0);
  42. $scope.total=total;
  43. };
  44. $scope.reset = function() {
  45. $scope.update();
  46. };
  47. $scope.ok = function () {
  48. };
  49. $scope.reset();
  50. });