Commit 8fe02f5aa8436cb46f8a68b0fe9f3a6bdd247480

Authored by Eric Fernandez
1 parent ee3db70dc0
Exists in master

refactor validations

src/js/controller.js
... ... @@ -40,17 +40,14 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo
40 40 $scope.idVendedor = 0;
41 41 getSeguimiento();
42 42 $scope.$broadcast('removeCabecera', cabecera);
43   - $scope.$broadcast('addCabecera',{
  43 + $scope.$broadcast('addCabecera', {
44 44 label: 'General',
45 45 valor: ''
46 46 });
47 47 };
48 48  
49 49 $scope.cargar = function(idVehiculo, punto) {
50   - if(!$scope.fechaReparto) {
51   - focaModalService.alert('Primero seleccione fecha de reparto');
52   - return;
53   - }
  50 + if(!eligioFecha()) return;
54 51 var idRemito;
55 52 if(punto === -1) {
56 53 idRemito = -1;
... ... @@ -76,21 +73,8 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo
76 73 };
77 74  
78 75 $scope.quitarVehiculo = function(vehiculo) {
79   - //TODO: Pasar validación a función
80   - $scope.fechaReparto.setHours(0, 0, 0, 0);
81   - var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
82   - for(var i = 0; i < vehiculo.cisternas.length; i++) {
83   - for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
84   - var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
85   - if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
86   - .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
87   - idUsuario)
88   - {
89   - focaModalService.alert('El vehículo está siendo usado por otro usuario');
90   - return;
91   - }
92   - }
93   - }
  76 + if(!eligioFecha()) return;
  77 + if(vehiculoEnUso(vehiculo)) return;
94 78 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' +
95 79 vehiculo.codigo + '?').then(function() {
96 80 eliminarVehiculo(vehiculo);
... ... @@ -98,25 +82,9 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;) .controller(&#39;focaLogisticaPedidoRutaCo
98 82 };
99 83  
100 84 $scope.hacerHojaRuta = function(vehiculo) {
101   - if(!$scope.fechaReparto) {
102   - focaModalService.alert('Primero seleccione fecha de reparto');
103   - return;
104   - }
105   - //TODO: Pasar validación a función
106   - $scope.fechaReparto.setHours(0, 0, 0, 0);
107   - var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
108   - for(var i = 0; i < vehiculo.cisternas.length; i++) {
109   - for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
110   - var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
111   - if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
112   - .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
113   - idUsuario)
114   - {
115   - focaModalService.alert('El vehículo está siendo usado por otro usuario');
116   - return;
117   - }
118   - }
119   - }
  85 + if(!eligioFecha()) return;
  86 + if(vehiculoEnUso(vehiculo)) return;
  87 +
120 88 var modalInstance = $uibModal.open(
121 89 {
122 90 ariaLabelledBy: 'Creación hoja ruta',
... ... @@ -124,7 +92,8 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;) .controller(&#39;focaLogisticaPedidoRutaCo
124 92 controller: 'focaModalCerrarVehiculo',
125 93 size: 'lg',
126 94 resolve: {
127   - idVehiculo: function() {return vehiculo.id;}
  95 + idVehiculo: function() {return vehiculo.id;},
  96 + fechaReparto: function() {return $scope.fechaReparto;}
128 97 }
129 98 }
130 99 );
... ... @@ -269,6 +238,32 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;) .controller(&#39;focaLogisticaPedidoRutaCo
269 238 }
270 239 });
271 240 }
  241 +
  242 + function eligioFecha() {
  243 + if(!$scope.fechaReparto) {
  244 + focaModalService.alert('Primero seleccione fecha de reparto');
  245 + return false;
  246 + }
  247 + return true;
  248 + }
  249 +
  250 + function vehiculoEnUso(vehiculo) {
  251 + $scope.fechaReparto.setHours(0, 0, 0, 0);
  252 + var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
  253 + for(var i = 0; i < vehiculo.cisternas.length; i++) {
  254 + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  255 + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
  256 + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
  257 + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
  258 + idUsuario)
  259 + {
  260 + focaModalService.alert('El vehículo está siendo usado por otro usuario');
  261 + return true;
  262 + }
  263 + }
  264 + }
  265 + return false;
  266 + }
272 267 // TODO: descomentar en produccion
273 268 // $interval(function() {
274 269 // getSeguimiento();
src/js/controllerCerrarVehiculo.js
... ... @@ -7,11 +7,12 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
7 7 'idVehiculo',
8 8 'focaModalService',
9 9 '$filter',
  10 + 'fechaReparto',
10 11 function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService,
11   - idVehiculo, focaModalService, $filter) {
  12 + idVehiculo, focaModalService, $filter, fechaReparto) {
12 13 $scope.vehiculo = {};
13 14 $scope.remitos = [];
14   - $scope.now = new Date();
  15 + $scope.now = fechaReparto;
15 16 focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) {
16 17 $scope.vehiculo = res.data;
17 18 });
src/js/controllerDetalleVehiculo.js
... ... @@ -31,7 +31,10 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
31 31 $scope.cargandoDatos = false;
32 32 $scope.vehiculo = res[0].data;
33 33 $scope.cisternas = res[1].data;
34   - if(!res[2]) return;
  34 + if(!res[2]) {
  35 + $scope.$digest();
  36 + return;
  37 + }
35 38 $scope.remito = res[2].data;
36 39 if($scope.remito.idUsuarioProceso) {
37 40 focaModalService.alert('Remito ya asignado');
... ... @@ -40,7 +43,7 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
40 43 $scope.articulos = $scope.remito.articulosRemito;
41 44 $scope.seleccionarArticulo($scope.articulos[0]);
42 45 var tieneUsuario = $scope.cisternas.filter(function(cisterna) {
43   - if(cisterna.cisternaCarga) {
  46 + if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) {
44 47 return cisterna.cisternaCarga.idUsuarioProceso !==
45 48 focaLogisticaPedidoRutaService.idUsuario;
46 49 }
... ... @@ -48,7 +51,6 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
48 51 if(tieneUsuario.length) {
49 52 focaModalService.alert('Otro usario esta usando este vehículo');
50 53 $uibModalInstance.close();
51   - return;
52 54 }
53 55 $scope.$digest();
54 56 });
src/views/foca-modal-cerrar-vehiculo.html
... ... @@ -12,7 +12,6 @@
12 12 show-button-bar="false"
13 13 is-open="datepickerOpen"
14 14 on-open-focus="false"
15   - ng-focus="datepickerOpen = true"
16 15 class="form-control col-8"/>
17 16 </div>
18 17 </div>