controller.js 2.33 KB
angular.module('focaAbmPlazoPago')
    .controller('focaAbmPlazosPagoController', [
        '$scope', 'focaAbmPlazoPagoService', '$location', 'focaModalService',
        function($scope, focaAbmPlazoPagoService, $location, focaModalService) {
            focaAbmPlazoPagoService.obtenerPlazosPago().then(function(datos) {
                $scope.plazosPago = datos.data;
            });
            $scope.editar = function(idPreciosCondiciones, id) {
                $location.path('/precio-condicion/' + idPreciosCondiciones + '/plazo-pago/' + id);
            };
            $scope.solicitarConfirmacion = function(plazoPago) {
                focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago '+
                plazoPago.item+' '+plazoPago.dias+' ?').then(
                    function(confirm) {
                        if(confirm){
                            focaAbmPlazoPagoService.borrarPlazoPago(plazoPago.id);
                            $scope.plazosPago.splice(
                            $scope.plazosPago.indexOf(plazoPago), 1
                        );
                        }
                    }
                );
            };
        }
    ])
    .controller('focaAbmPlazoPagoController', [
        '$scope', 'focaAbmPlazoPagoService',
        '$routeParams', '$location',
        function(
            $scope, focaAbmPlazoPagoService,
            $routeParams, $location
        ) {
            focaAbmPlazoPagoService.obtenerPlazoPago($routeParams.id)
                .then(function(datos) {
                    $scope.plazoPago = {
                        id: 0,
                        idPreciosCondiciones: $routeParams.idPreciosCondiciones,
                        item: '',
                        dias: ''
                    };
                    if(datos.data.id) {
                        $scope.plazoPago = datos.data;
                    }
                });
            $scope.cancelar = function() {
                $location.path('/precio-condicion/' + $routeParams.idPreciosCondiciones);
            };
            $scope.guardar = function(plazoPago) {
                focaAbmPlazoPagoService.guardarPlazoPago(plazoPago)
                    .then(function() {
                        $location.path('/precio-condicion/' + $routeParams.idPreciosCondiciones);
                    });
            };
        }
    ]);