From b9513452f3ed3b72bbd0118ce5e2d035f3313ad4 Mon Sep 17 00:00:00 2001 From: mpuebla Date: Thu, 11 Jul 2019 16:34:46 -0300 Subject: [PATCH] Agregado modal para seleccionar una hoja de ruta. --- src/js/controller.js | 103 +++++++++++++++++++++++++---------------- src/js/service.js | 4 +- src/views/lista-hoja-ruta.html | 5 ++ 3 files changed, 71 insertions(+), 41 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index c37a3cd..c9743bc 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -17,31 +17,47 @@ angular.module('focaHojaRuta') $scope.comprobante = '00000000'; } function init() { + $scope.showLoading = true; hojaRutaService.getHojaRuta(loginData.chofer) .then(function (res) { - if (res.data) { - var hojaRuta = res.data; + console.log(res.data); + abrilModalHojasDeRuta(res.data); + }); + } + function abrilModalHojasDeRuta(hojasDeRuta) { + hojasDeRuta.forEach(function (hojaRuta) { + hojaRuta.comprobante = (hojaRuta.abierta ? 'RA ' : '') + + $filter('comprobante') + ([hojaRuta.sucursal, hojaRuta.numeroHojaRuta]); + }); + $scope.showLoading = false; + focaModalService.modal(parametrosModalHojasDeRuta(hojasDeRuta)) + .then(function (hojaRuta) { + console.log(hojaRuta); + if (hojaRuta) { $scope.hojaRuta = hojaRuta; $scope.puntoVenta = hojaRuta.sucursal; $scope.comprobante = hojaRuta.numeroHojaRuta; addCabecera('Transportista:', hojaRuta.transportista.NOM); addCabecera('Chofer:', hojaRuta.chofer.nombre); addCabecera('Vehículo:', hojaRuta.vehiculo.tractor); + $localStorage.hojaRuta = JSON.stringify($scope.hojaRuta); } else { focaModalService.alert('Sin hoja de ruta asignada'); $location.path('/'); } - watch(); - if (!$scope.estadoRed) { - getLSHojaRuta(); - } + // if (!$scope.estadoRed) { + // getLSHojaRuta(); + // } + }) + .catch(function (e) { + console.log(e); + $location.path('/'); }); } - function watch() { - $scope.$watch('hojaRuta', function (nuevoValor) { - $localStorage.hojaRuta = JSON.stringify(nuevoValor); - }, true); - } + $scope.$watch('hojaRuta', function (nuevoValor) { + $localStorage.hojaRuta = JSON.stringify(nuevoValor); + }, true); $scope.verDetalle = function (remito) { var modalInstance = $uibModal.open( { @@ -57,20 +73,9 @@ angular.module('focaHojaRuta') } ); modalInstance.result - .then(function (data) { - //funcion se ejecuta cuando se carga pantalla - console.log(data); - }) + .then(function (data) { console.log(data); }) .catch(function (e) { console.info(e); }); }; - $scope.rellenar = function (relleno, longitud) { - relleno = '' + relleno; - while (relleno.length < longitud) { - relleno = '0' + relleno; - } - - return relleno; - }; $scope.salir = function () { $location.path('/'); }; @@ -78,7 +83,8 @@ angular.module('focaHojaRuta') focaModalService .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' + 'otra descarga ni modificación') - .then(function () { $scope.datosExtraCierre(terminar); }); + .then(function () { $scope.datosExtraCierre(terminar); }) + .catch(function (e) { console.log('Modal ', e); }); function terminar(datosExtraCierre) { $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre); //limpio objeto para guardar @@ -149,6 +155,10 @@ angular.module('focaHojaRuta') return true; }; $scope.estaPendiente = function () { + if ($scope.hojaRuta.abierta) { + $scope.terminarHojaRuta(); + return; + } var pendiente = false; $scope.hojaRuta.remitos.forEach(function (remito) { if (pendiente === false) { @@ -171,23 +181,38 @@ angular.module('focaHojaRuta') }); 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 }); - } + if (propiedad.length === 1) propiedad[0].valor = valor; + else $scope.cabecera.push({ label: label, valor: valor }); } - function getLSHojaRuta() { - - var hojaRuta = JSON.parse($localStorage.hojaRuta || null); - - if (hojaRuta) { - console.log('getLSHojaRuta() => ', hojaRuta); - $scope.hojaRuta = hojaRuta; - delete $localStorage.hojaRuta; - } + // function getLSHojaRuta() { + // var hojaRuta = JSON.parse($localStorage.hojaRuta || null); + // if (hojaRuta) { + // $scope.hojaRuta = hojaRuta; + // delete $localStorage.hojaRuta; + // } + // } + function parametrosModalHojasDeRuta(datos) { + var parametrosModal = { + data: datos, + columnas: [ + { + propiedad: 'comprobante', + nombre: 'Número' + }, + { + propiedad: 'fechaReparto', + nombre: 'Fecha', + filtro: { + nombre: 'date', + parametro: 'yyyy-MM-dd' + } + } + ], + titulo: 'Selecciona hoja de ruta', + size: 'md' + }; + return parametrosModal; } - } ] ); diff --git a/src/js/service.js b/src/js/service.js index 94751de..e025d47 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -2,8 +2,8 @@ angular.module('focaHojaRuta') .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { var route = API_ENDPOINT.URL; return { - getHojaRuta: function(chofer) { - return $http.get(route + '/hoja-ruta/chofer/' + chofer); + getHojaRuta: function(id) { + return $http.get(route + '/hoja-ruta/chofer/' + id); }, terminarHojaRuta: function(hojaRuta) { return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta}); diff --git a/src/views/lista-hoja-ruta.html b/src/views/lista-hoja-ruta.html index 70ef526..e333b33 100644 --- a/src/views/lista-hoja-ruta.html +++ b/src/views/lista-hoja-ruta.html @@ -163,3 +163,8 @@ +
+
+
+ Cargando informacion... +
-- 1.9.1