angular.module('focaAbmPreciosCondiciones') .controller('focaAbmPreciosCondicionesController', [ '$scope', 'focaAbmPreciosCondicionesService', '$location', '$uibModal', function($scope, focaAbmPreciosCondicionesService, $location, $uibModal) { focaAbmPreciosCondicionesService.obtenerPreciosCondiciones().then(function(datos) { $scope.preciosCondiciones = datos.data; }); $scope.editar = function(id) { $location.path('/precio-condicion/' + id); }; $scope.solicitarConfirmacion = function(precioCondicion) { $uibModal.open({ templateUrl: 'foca-abm-precios-condiciones-modal-confirmar.html', controller: 'focaAbmPreciosCondicionesModalConfirmarController', animation: false, backdrop: false, resolve: {precioCondicion: function(){return precioCondicion;}} }) .result.then(function(precioCondicion){ focaAbmPreciosCondicionesService.borrarPrecioCondicion(precioCondicion.id); $scope.preciosCondiciones.splice( $scope.preciosCondiciones.indexOf(precioCondicion), 1 ); }); }; } ]) .controller('focaAbmPrecioCondicionController', [ '$scope', 'focaAbmPreciosCondicionesService', 'focaAbmPlazoPagoService', '$routeParams', '$location', function( $scope, focaAbmPreciosCondicionesService, focaAbmPlazoPagoService, $routeParams, $location ) { focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) .then(function(datos) { $scope.precioCondicion = { id: 0, codigo: '', nombre: '', descripcion: '', idListaPrecio: 0, vigencia: new Date() }; if(datos.data.id) { $scope.precioCondicion = datos.data; focaAbmPlazoPagoService.obtenerPlazoPago(datos.data.id) .then(function(datos){ $scope.precioCondicion.plazos = datos.data; }); } }); $scope.cancelar = function() { $location.path('/precio-condicion'); }; $scope.guardar = function(precioCondicion) { focaAbmPreciosCondicionesService.guardarPrecioCondicion(precioCondicion) .then(function() { $location.path('/precio-condicion'); }); }; } ]) .controller('focaAbmPreciosCondicionesModalConfirmarController', [ '$uibModalInstance', '$scope', 'precioCondicion', function($uibModalInstance, $scope, precioCondicion) { $scope.precioCondicion = precioCondicion; $scope.cancelar = function() { $uibModalInstance.dismiss(); }; $scope.borrar = function() { $uibModalInstance.close(precioCondicion); }; } ]);