Commit b9513452f3ed3b72bbd0118ce5e2d035f3313ad4

Authored by Marcelo Puebla
1 parent 6b9369a8dc
Exists in master and in 2 other branches develop, lab

Agregado modal para seleccionar una hoja de ruta.

src/js/controller.js
... ... @@ -17,31 +17,47 @@ angular.module('focaHojaRuta')
17 17 $scope.comprobante = '00000000';
18 18 }
19 19 function init() {
  20 + $scope.showLoading = true;
20 21 hojaRutaService.getHojaRuta(loginData.chofer)
21 22 .then(function (res) {
22   - if (res.data) {
23   - var hojaRuta = res.data;
  23 + console.log(res.data);
  24 + abrilModalHojasDeRuta(res.data);
  25 + });
  26 + }
  27 + function abrilModalHojasDeRuta(hojasDeRuta) {
  28 + hojasDeRuta.forEach(function (hojaRuta) {
  29 + hojaRuta.comprobante = (hojaRuta.abierta ? 'RA ' : '') +
  30 + $filter('comprobante')
  31 + ([hojaRuta.sucursal, hojaRuta.numeroHojaRuta]);
  32 + });
  33 + $scope.showLoading = false;
  34 + focaModalService.modal(parametrosModalHojasDeRuta(hojasDeRuta))
  35 + .then(function (hojaRuta) {
  36 + console.log(hojaRuta);
  37 + if (hojaRuta) {
24 38 $scope.hojaRuta = hojaRuta;
25 39 $scope.puntoVenta = hojaRuta.sucursal;
26 40 $scope.comprobante = hojaRuta.numeroHojaRuta;
27 41 addCabecera('Transportista:', hojaRuta.transportista.NOM);
28 42 addCabecera('Chofer:', hojaRuta.chofer.nombre);
29 43 addCabecera('Vehículo:', hojaRuta.vehiculo.tractor);
  44 + $localStorage.hojaRuta = JSON.stringify($scope.hojaRuta);
30 45 } else {
31 46 focaModalService.alert('Sin hoja de ruta asignada');
32 47 $location.path('/');
33 48 }
34   - watch();
35   - if (!$scope.estadoRed) {
36   - getLSHojaRuta();
37   - }
  49 + // if (!$scope.estadoRed) {
  50 + // getLSHojaRuta();
  51 + // }
  52 + })
  53 + .catch(function (e) {
  54 + console.log(e);
  55 + $location.path('/');
38 56 });
39 57 }
40   - function watch() {
41   - $scope.$watch('hojaRuta', function (nuevoValor) {
42   - $localStorage.hojaRuta = JSON.stringify(nuevoValor);
43   - }, true);
44   - }
  58 + $scope.$watch('hojaRuta', function (nuevoValor) {
  59 + $localStorage.hojaRuta = JSON.stringify(nuevoValor);
  60 + }, true);
45 61 $scope.verDetalle = function (remito) {
46 62 var modalInstance = $uibModal.open(
47 63 {
... ... @@ -57,20 +73,9 @@ angular.module('focaHojaRuta')
57 73 }
58 74 );
59 75 modalInstance.result
60   - .then(function (data) {
61   - //funcion se ejecuta cuando se carga pantalla
62   - console.log(data);
63   - })
  76 + .then(function (data) { console.log(data); })
64 77 .catch(function (e) { console.info(e); });
65 78 };
66   - $scope.rellenar = function (relleno, longitud) {
67   - relleno = '' + relleno;
68   - while (relleno.length < longitud) {
69   - relleno = '0' + relleno;
70   - }
71   -
72   - return relleno;
73   - };
74 79 $scope.salir = function () {
75 80 $location.path('/');
76 81 };
... ... @@ -78,7 +83,8 @@ angular.module(&#39;focaHojaRuta&#39;)
78 83 focaModalService
79 84 .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' +
80 85 'otra descarga ni modificación')
81   - .then(function () { $scope.datosExtraCierre(terminar); });
  86 + .then(function () { $scope.datosExtraCierre(terminar); })
  87 + .catch(function (e) { console.log('Modal ', e); });
82 88 function terminar(datosExtraCierre) {
83 89 $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre);
84 90 //limpio objeto para guardar
... ... @@ -149,6 +155,10 @@ angular.module(&#39;focaHojaRuta&#39;)
149 155 return true;
150 156 };
151 157 $scope.estaPendiente = function () {
  158 + if ($scope.hojaRuta.abierta) {
  159 + $scope.terminarHojaRuta();
  160 + return;
  161 + }
152 162 var pendiente = false;
153 163 $scope.hojaRuta.remitos.forEach(function (remito) {
154 164 if (pendiente === false) {
... ... @@ -171,23 +181,38 @@ angular.module(&#39;focaHojaRuta&#39;)
171 181 });
172 182 function addCabecera(label, valor) {
173 183 var propiedad = $filter('filter')($scope.cabecera, { label: label }, true);
174   - if (propiedad.length === 1) {
175   - propiedad[0].valor = valor;
176   - } else {
177   - $scope.cabecera.push({ label: label, valor: valor });
178   - }
  184 + if (propiedad.length === 1) propiedad[0].valor = valor;
  185 + else $scope.cabecera.push({ label: label, valor: valor });
179 186 }
180   - function getLSHojaRuta() {
181   -
182   - var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
183   -
184   - if (hojaRuta) {
185   - console.log('getLSHojaRuta() => ', hojaRuta);
186   - $scope.hojaRuta = hojaRuta;
187   - delete $localStorage.hojaRuta;
188   - }
  187 + // function getLSHojaRuta() {
  188 + // var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
  189 + // if (hojaRuta) {
  190 + // $scope.hojaRuta = hojaRuta;
  191 + // delete $localStorage.hojaRuta;
  192 + // }
  193 + // }
  194 + function parametrosModalHojasDeRuta(datos) {
  195 + var parametrosModal = {
  196 + data: datos,
  197 + columnas: [
  198 + {
  199 + propiedad: 'comprobante',
  200 + nombre: 'Número'
  201 + },
  202 + {
  203 + propiedad: 'fechaReparto',
  204 + nombre: 'Fecha',
  205 + filtro: {
  206 + nombre: 'date',
  207 + parametro: 'yyyy-MM-dd'
  208 + }
  209 + }
  210 + ],
  211 + titulo: 'Selecciona hoja de ruta',
  212 + size: 'md'
  213 + };
  214 + return parametrosModal;
189 215 }
190   -
191 216 }
192 217 ]
193 218 );
... ... @@ -2,8 +2,8 @@ angular.module(&#39;focaHojaRuta&#39;)
2 2 .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 3 var route = API_ENDPOINT.URL;
4 4 return {
5   - getHojaRuta: function(chofer) {
6   - return $http.get(route + '/hoja-ruta/chofer/' + chofer);
  5 + getHojaRuta: function(id) {
  6 + return $http.get(route + '/hoja-ruta/chofer/' + id);
7 7 },
8 8 terminarHojaRuta: function(hojaRuta) {
9 9 return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta});
src/views/lista-hoja-ruta.html
... ... @@ -163,3 +163,8 @@
163 163 </div>
164 164 </div>
165 165 </div>
  166 +<div ng-show="showLoading == true" class="cover-spin align-items-center justify-content-center">
  167 + <div class="spinner-border foca-text-danger m-2" style="width: 3rem; height: 3rem;" role="status">
  168 + </div>
  169 + <strong>Cargando informacion...</strong>
  170 +</div>