diff --git a/src/js/controller.js b/src/js/controller.js index fdefee4..4841c0d 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -5,7 +5,13 @@ angular.module('focaAbmPreciosCondiciones') function($scope, focaAbmPreciosCondicionesService, $location, focaModalService, focaBotoneraLateralService, $timeout) { focaAbmPreciosCondicionesService.obtenerPreciosCondiciones().then(function(datos) { + console.log(datos.data); $scope.preciosCondiciones = datos.data; + $scope.preciosCondiciones.forEach(function(precioCondicion) { + precioCondicion.plazoPago.sort(function(a, b) { + return a.dias- b.dias; + }); + }); }); $timeout(function() { @@ -37,12 +43,15 @@ angular.module('focaAbmPreciosCondiciones') ]) .controller('focaAbmPrecioCondicionController', [ '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', - '$routeParams', '$location', 'focaModalService', '$timeout', + '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', function( $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, - $routeParams, $location, focaModalService, $timeout + $routeParams, $location, focaModalService, $timeout, $uibModal, $window ) { + $scope.plazosAEliminar = []; $scope.mostrarPlazos = $routeParams.id > 0; + $scope.now = new Date(); + $scope.listaPrecioLabel = ''; focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) .then(function(datos) { $scope.precioCondicion = { @@ -53,11 +62,24 @@ angular.module('focaAbmPreciosCondiciones') idListaPrecio: 0, vigencia: new Date() }; - if (datos.data.id) { + if(datos.data.id) { $scope.precioCondicion = datos.data; + $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + + ' - ' + datos.data.listaPrecio.DES; + $scope.$broadcast('addCabecera', { + label: 'Precio y condición:', + valor: datos.data.nombre + }); focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) .then(function(datos) { $scope.precioCondicion.plazos = datos.data; + $scope.precioCondicion.plazos.sort(function(a, b) { + return a.dias- b.dias; + }); + $scope.plazoACargar = + { + item: datos.data.length + 1 + }; }); } }); @@ -72,17 +94,66 @@ angular.module('focaAbmPreciosCondiciones') $scope.cancelar = function() { $location.path('/precio-condicion'); }; - $scope.guardar = function(precioCondicion) { - focaAbmPreciosCondicionesService.guardarPrecioCondicion(precioCondicion) - .then(function() { - $location.path('/precio-condicion'); + $scope.guardar = function() { + var promises = []; + var precioCondicion = $scope.precioCondicion; + precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; + delete precioCondicion.listaPrecio; + if($scope.mostrarPlazos) { + promises.push( + focaAbmPreciosCondicionesService + .guardarPlazosPago($scope.precioCondicion.plazos) + ); + $scope.plazosAEliminar.forEach(function(id) { + promises.push( + focaAbmPreciosCondicionesService + .borrarPlazoPago(id) + ); }); - }; - $scope.editarPlazoPago = function(id) { - $location.path( - '/precio-condicion/' + $scope.precioCondicion.id + - '/plazo-pago/' + id + } + promises.push( + focaAbmPreciosCondicionesService + .guardarPrecioCondicion(precioCondicion) ); + + Promise.all(promises).then(function() { + $window.location.assign('/#!/precio-condicion'); + }, function(err){ + console.error(err); + }); + }; + + $scope.agregarPlazo = function(key) { + if(key === 13) { + if(!$scope.plazoACargar.dias) { + focaModalService.alert('Ingrese cantidad de días'); + return; + } + var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { + return a.dias === $scope.plazoACargar.dias; + }); + if(tieneEseDia.length > 0) { + focaModalService.alert('Ya ha ingresado un plazo con esos días'); + return; + } + $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; + $scope.plazoACargar.activo = true; + $scope.precioCondicion.plazos.push($scope.plazoACargar); + $scope.plazoACargar = + { + item: $scope.precioCondicion.plazos.length + 1 + }; + } + }; + $scope.quitarPlazo = function(key) { + if($scope.precioCondicion.plazos[key].id) + $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); + + $scope.precioCondicion.plazos.splice(key, 1); + $scope.plazoACargar = + { + item: $scope.precioCondicion.plazos.length + 1 + }; }; $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + @@ -97,5 +168,20 @@ angular.module('focaAbmPreciosCondiciones') } ); }; + + $scope.seleccionarListaPrecio = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Listas de precio', + templateUrl: 'modal-lista-precio.html', + controller: 'focaModalListaPrecioCtrl', + size: 'lg' + } + ); + modalInstance.result.then(function(listaPrecio) { + $scope.precioCondicion.listaPrecio = listaPrecio; + $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; + }); + }; } ]); diff --git a/src/js/service.js b/src/js/service.js index e6d14b8..8ec5eea 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -25,6 +25,12 @@ angular.module('focaAbmPreciosCondiciones') }, borrarPlazoPago: function(id) { return $http.delete(API_ENDPOINT.URL + '/plazo-pago/' + id); + }, + guardarPlazosPago: function(plazos){ + return $http.post( + API_ENDPOINT.URL + '/plazos-pago', + {plazosPago: plazos} + ); } }; } diff --git a/src/views/foca-abm-precios-condiciones-item.html b/src/views/foca-abm-precios-condiciones-item.html index 14812a9..bc7ac8b 100644 --- a/src/views/foca-abm-precios-condiciones-item.html +++ b/src/views/foca-abm-precios-condiciones-item.html @@ -1,37 +1,37 @@ -

Precios y Condiciones

-
- -
- -
- -
-
-
- -
- +
+ +
+
+ + +
+ + + +
-
-
- -
+
+
-
-
- -
- -
-
-
- -
- - - - - - - - - - - - - - - -
ItemDias - -
- - -
+
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+
+ + + + + + +
+ + +
+
-
- - + +
\ No newline at end of file diff --git a/src/views/foca-abm-precios-condiciones-listado.html b/src/views/foca-abm-precios-condiciones-listado.html index c15f6d6..93ba798 100644 --- a/src/views/foca-abm-precios-condiciones-listado.html +++ b/src/views/foca-abm-precios-condiciones-listado.html @@ -1,34 +1,52 @@ - + -
- - - - - - - - - - - - - - - -
CódigoNombre - -
- - -
+
+
+
+ + + + + + + + + + + + + + + + + +
NombreLista de precioPlazos + +
+ + +
+