|
|
@@ -13,20 +13,6 @@ app.controller('facturaCtrl', function ($scope, $http, $window, notify,$location
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- $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)
|
|
|
@@ -47,7 +33,31 @@ app.controller('facturaCtrl', function ($scope, $http, $window, notify,$location
|
|
|
$scope.update();
|
|
|
};
|
|
|
$scope.ok = function () {
|
|
|
+ var pedido = {};
|
|
|
+ var filtrados = $scope.listaproductos.filter(function(el) { return el.cantidad > 0; });
|
|
|
|
|
|
+ if (filtrados.length==0){
|
|
|
+ notify({message:"No hay productos",classes:"alert alert-danger"});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for(var f in $scope.listaproductos){
|
|
|
+ var prod = $scope.listaproductos[f];
|
|
|
+ if(isNaN(prod.cantidad)){
|
|
|
+ notify({message:prod.nombre+" tiene cantidad incorrecta",classes:"alert alert-danger"});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pedido.productos = filtrados;
|
|
|
+ pedido.cliente = $scope.userdata;
|
|
|
+
|
|
|
+ $http.post('back/pedido', { pedido: pedido } )
|
|
|
+ .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.reset();
|