controller.js 3.93 KB
angular.module('focaOrdenCarga')
    .controller('focaOrdenCargaController', [
        '$scope',
        '$uibModal',
        '$location',
        '$filter',
        '$timeout',
        'focaOrdenCargaService',
        'focaBotoneraLateralService',
        'focaModalService',
        'notaPedidoBusinessService',
        '$rootScope',
        'focaSeguimientoService',
        'APP',
        'focaLoginService',
        '$localStorage',
        function (
            $scope, $uibModal, $location, $filter, $timeout, focaOrdenCargaService,
            focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
            $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) {
            config();

            function config() {
                // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
                $scope.tmpCantidad = Number;
                $scope.tmpPrecio = Number;
                $scope.isNumber = angular.isNumber;
                $scope.datepickerAbierto = false;
                $scope.show = false;
                $scope.cargando = true;
                $scope.cabeceras = [];
                $scope.botonera = focaOrdenCargaService.getBotonera();
                $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
                $scope.comprobante = $filter('rellenarDigitos')(0, 8);
                $scope.dateOptions = {
                    maxDate: new Date(),
                    minDate: new Date(2010, 0, 1)
                };

                //SETEO BOTONERA LATERAL
                $timeout(function () {
                    focaBotoneraLateralService.showSalir(false);
                    focaBotoneraLateralService.showPausar(true);
                    focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
                    focaBotoneraLateralService.addCustomButton('Salir', salir);
                });

                init();

            }

            function init() {
                $scope.ordenCarga = {
                    id: 0,
                    cliente: {},
                    proveedor: {},
                    domicilio: { dom: '' },
                    vendedor: {},
                    fechaCarga: new Date(),
                    cotizacion: {},
                    articulosNotaPedido: [],
                    notaPedidoPlazo: [],
                    notaPedidoPuntoDescarga: []
                };

            }

            $scope.$watch('ordenCarga', function (newValue) {
                focaBotoneraLateralService.setPausarData({
                    label: 'ordenCarga',
                    val: newValue
                });
            }, true);

            $scope.$watch('ordenCarga', function (newValue) {
                focaBotoneraLateralService.setPausarData({
                    label: 'ordenCarga',
                    val: newValue
                });
                focaBotoneraLateralService.setRutasPausadas({
                    label: 'rutas',
                    val: 'orden-carga'
                });
            }, true);

            $scope.crearOrdenCarga = function () {

                focaBotoneraLateralService.startGuardar();
                $scope.saveLoading = true;

            }

            $scope.salir = function () {
                $location.path('/');
            };

            function salir() {
                var confirmacion = false;

                if (!angular.equals($scope.ordenCarga, $scope.inicial)) {
                    confirmacion = true;
                }

                if (confirmacion) {
                    focaModalService.confirm(
                        '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
                    ).then(function (data) {
                        if (data) {
                            $location.path('/');
                        }
                    });
                } else {
                    $location.path('/');
                }
            }
        }]);