controller.js 4.67 KB
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',
        '$routeParams', '$location', '$uibModal',
        function(
            $scope, focaAbmPreciosCondicionesService,
            $routeParams, $location, $uibModal
        ) {
            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;
                        focaAbmPreciosCondicionesService.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');
                    });
            };
            $scope.editarPlazoPago = function(id) {
                $location.path(
                    '/precio-condicion/' + $scope.precioCondicion.id +
                    '/plazo-pago/' + id
                );
            };
            $scope.solicitarConfirmacionPlazoPago = function(plazoPago) {
                $uibModal.open({
                    templateUrl: 'foca-abm-plazos-pago-modal-confirmar.html',
                    controller: 'focaAbmPlazosPagosModalConfirmarController',
                    animation: false,
                    backdrop: false,
                    resolve: {plazoPago: function(){return plazoPago;}}
                })
                .result.then(function(plazoPago){
                    focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id);
                    $scope.precioCondicion.plazos.splice(
                        $scope.precioCondicion.plazos.indexOf(plazoPago), 1
                    );
                });
            }
        }
    ])
    .controller('focaAbmPreciosCondicionesModalConfirmarController', [
        '$uibModalInstance', '$scope', 'precioCondicion',
        function($uibModalInstance, $scope, precioCondicion) {
            $scope.precioCondicion = precioCondicion;
            $scope.cancelar = function() {
                $uibModalInstance.dismiss();
            };
            $scope.borrar = function() {
                $uibModalInstance.close(precioCondicion);
            };
        }
    ])
    .controller('focaAbmPlazosPagosModalConfirmarController', [
        '$uibModalInstance', '$scope', 'plazoPago',
        function($uibModalInstance, $scope, plazoPago) {
            $scope.plazoPago = plazoPago;
            $scope.cancelar = function() {
                $uibModalInstance.dismiss();
            };
            $scope.borrar = function() {
                $uibModalInstance.close(plazoPago);
            };
        }
    ]);