From 4628f0848d6b500b6b9e7b8a2e4003fe41cceb34 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Mon, 22 Oct 2018 18:13:28 -0300 Subject: [PATCH] add to do's --- src/js/controller.js | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index b21db0f..da7f197 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -33,31 +33,37 @@ angular.module('focaCrearNotaPedido') $scope.articulosTabla = res.data; } ); + //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO + //(NO REQUERIDO EN ESTA VERSION) // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( // function(res) { // $scope.notaPedido.domicilio = res.data; // } // ); } else { - $scope.notaPedido.fechaCarga = new Date(); - // $scope.notaPedido.domicilio = [{ id: 0 }]; + $scope.notaPedido.fechaCarga = new Date(); $scope.notaPedido.bomba = '0'; $scope.notaPedido.flete = '0'; idLista = undefined; } - $scope.addNewDom = function() { - $scope.notaPedido.domicilio.push({ 'id': 0 }); - }; - $scope.removeNewChoice = function(choice) { - if ($scope.notaPedido.domicilio.length > 1) { - $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( - function(c) { - return c.$$hashKey === choice.$$hashKey; - } - ), 1); - } - }; + //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO + // $scope.addNewDom = function() { + // $scope.notaPedido.domicilio.push({ 'id': 0 }); + // }; + // $scope.removeNewChoice = function(choice) { + // if ($scope.notaPedido.domicilio.length > 1) { + // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( + // function(c) { + // return c.$$hashKey === choice.$$hashKey; + // } + // ), 1); + // } + // }; $scope.crearNotaPedido = function() { + if($scope.articulosTabla.length === 0) { + focaModalService.alert('Debe cargar almenos un articulo'); + return; + } if($scope.notaPedido.domicilio.id === undefined) { $scope.notaPedido.domicilio.id = 0; } @@ -77,15 +83,17 @@ angular.module('focaCrearNotaPedido') crearNotaPedidoService.crearNotaPedido(notaPedido).then( function(data) { focaModalService.alert('Nota pedido creada'); - var flete = { - idNotaPedido: data.data.id, - idTransportista: $scope.notaPedido.fleteId, - idChofer: $scope.notaPedido.chofer.id, - idVehiculo: $scope.notaPedido.vehiculo.id, - kilometros: $scope.notaPedido.kilometros, - costoKilometro: $scope.notaPedido.costoUnitarioKmFlete - }; - crearNotaPedidoService.crearFlete(flete); + if($scope.notaPedido.flete === 1) { + var flete = { + idNotaPedido: data.data.id, + idTransportista: $scope.notaPedido.fleteId, + idChofer: $scope.notaPedido.chofer.id, + idVehiculo: $scope.notaPedido.vehiculo.id, + kilometros: $scope.notaPedido.kilometros, + costoKilometro: $scope.notaPedido.costoUnitarioKmFlete + }; + crearNotaPedidoService.crearFlete(flete); + } var articulosNotaPedido = $scope.articulosTabla; for(var i = 0; i< articulosNotaPedido.length;i++) { delete articulosNotaPedido[i].edit; @@ -214,9 +222,9 @@ angular.module('focaCrearNotaPedido') }; $scope.getTotal = function() { var total = 0; - var array = $scope.articulosTabla; - for (var i = 0; i < array.length; i++) { - total += array[i].precio * array[i].cantidad; + var arrayTempArticulos = $scope.articulosTabla; + for (var i = 0; i < arrayTempArticulos.length; i++) { + total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; } return total.toFixed(2); }; -- 1.9.1