diff --git a/src/js/controller.js b/src/js/controller.js index 9208a64..a1fd248 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -574,58 +574,69 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } }; + function abrirModal() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Precio Condición', + templateUrl: 'modal-precio-condicion.html', + controller: 'focaModalPrecioCondicionController', + size: 'lg', + resolve: { + idListaPrecio: function() { + return $scope.notaPedido.cliente.MOD || null; + } + } + } + ); + + modalInstance.result.then( + function(precioCondicion) { + var cabecera = ''; + var plazosConcat = ''; + if (!Array.isArray(precioCondicion)) { + $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; + $scope.notaPedido.precioCondicion = precioCondicion; + $scope.notaPedido.idPrecioCondicion = precioCondicion.id; + $scope.idLista = precioCondicion.idListaPrecio; + for (var i = 0; i < precioCondicion.plazoPago.length; i++) { + plazosConcat += precioCondicion.plazoPago[i].dias + ' '; + } + cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + + ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); + } else { //Cuando se ingresan los plazos manualmente + $scope.notaPedido.idPrecioCondicion = 0; + //-1, el modal productos busca todos los productos + $scope.idLista = -1; + $scope.notaPedido.notaPedidoPlazo = precioCondicion; + for (var j = 0; j < precioCondicion.length; j++) { + plazosConcat += precioCondicion[j].dias + ' '; + } + cabecera = 'Ingreso manual ' + plazosConcat.trim(); + } + $scope.notaPedido.articulosNotaPedido = []; + $scope.$broadcast('addCabecera', { + label: 'Precios y condiciones:', + valor: cabecera + }); + }, function() { + + } + ); + } + $scope.seleccionarPreciosYCondiciones = function() { if (!$scope.notaPedido.cliente.COD) { focaModalService.alert('Primero seleccione un cliente'); return; } - if (validarNotaRemitada()) { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Precio Condición', - templateUrl: 'modal-precio-condicion.html', - controller: 'focaModalPrecioCondicionController', - size: 'lg', - resolve: { - idListaPrecio: function() { - return $scope.notaPedido.cliente.MOD || null; - } - } - } - ); - modalInstance.result.then( - function(precioCondicion) { - var cabecera = ''; - var plazosConcat = ''; - if (!Array.isArray(precioCondicion)) { - $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; - $scope.notaPedido.precioCondicion = precioCondicion; - $scope.notaPedido.idPrecioCondicion = precioCondicion.id; - $scope.idLista = precioCondicion.idListaPrecio; - for (var i = 0; i < precioCondicion.plazoPago.length; i++) { - plazosConcat += precioCondicion.plazoPago[i].dias + ' '; - } - cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + - ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); - } else { //Cuando se ingresan los plazos manualmente - $scope.notaPedido.idPrecioCondicion = 0; - //-1, el modal productos busca todos los productos - $scope.idLista = -1; - $scope.notaPedido.notaPedidoPlazo = precioCondicion; - for (var j = 0; j < precioCondicion.length; j++) { - plazosConcat += precioCondicion[j].dias + ' '; - } - cabecera = 'Ingreso manual ' + plazosConcat.trim(); + if ($scope.notaPedido.articulosNotaPedido.length !== 0) { + focaModalService.confirm('Se perderan los datos ingresados').then(function(data) { + if (data) { + abrirModal(); } - $scope.notaPedido.articulosNotaPedido = []; - $scope.$broadcast('addCabecera', { - label: 'Precios y condiciones:', - valor: cabecera - }); - }, function() { - - } - ); + }); + } else if (validarNotaRemitada()) { + abrirModal(); } }; @@ -901,8 +912,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', notaPedido.numeroNotaPedido, 8 ); - if (notaPedido.notaPedidoPuntoDescarga) { - var puntosDescarga = notaPedido.notaPedidoPuntoDescarga + if (notaPedido.notaPedidoPuntoDescarga) { + var puntosDescarga = notaPedido.notaPedidoPuntoDescarga; cabeceras.push({ label: 'Puntos de descarga: ', valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))