controller.js 2.6 KB
angular.module('focaHojaRuta')
    .controller('listaHojaRutaCtrl',
        [
        '$scope', '$filter', '$uibModal', 'hojaRutaService',
        function($scope, $filter, $uibModal, hojaRutaService) {
            hojaRutaService.getHojasRuta().then(function(res) {
                $scope.hojasRuta = res.data;
            });
            $scope.cabecera = [];
            $scope.showCabecera = true;
            addCabecera('Transportista:', 'Andesmar');
            addCabecera('Chofer:', 'Carlos');
            addCabecera('Vehículo:', 'SCANIA');
            $scope.now = new Date();
            $scope.puntoVenta = '0000';
            $scope.comprobante = '00000000';

            $scope.verDetalle = function(hojaRuta) {
                var modalInstance = $uibModal.open(
                    {
                        ariaLabelledBy: 'Detalle hoja ruta',
                        templateUrl: 'modal-detalle-hoja-ruta.html',
                        controller: 'focaModalDetalleHojaRutaController',
                        resolve: {
                            parametrosDetalleHojaRuta: function(){
                                return {
                                    remito: '00001-00000001',
                                    cliente: 'Rubén Gomez',
                                    domicilio: 'Patricias Mendocinas 5050',
                                    producto: 'Super',
                                    litros: 20
                                };
                            }
                        },
                        size: 'lg'
                    }
                );
                modalInstance.result.then(function() {
                    
                })
            };

            function addCabecera(label, valor) {
                var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
                if(propiedad.length === 1) {
                    propiedad[0].valor = valor;
                } else {
                    $scope.cabecera.push({label: label, valor: valor});
                }
            }

            function removeCabecera(label) {
                var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
                if(propiedad.length === 1) {
                    $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
                }
            }

            function rellenar(relleno, longitud) {
                relleno = '' + relleno;
                while (relleno.length < longitud) {
                    relleno = '0' + relleno;
                }

                return relleno;
            }
        }
    ]);