Commit b2c6a31c5bd14c800ed1f25062839013c9a01aed
1 parent
9718d371ba
Exists in
master
Codigo identado.
Showing
1 changed file
with
80 additions
and
57 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -4,8 +4,8 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 4 | 4 | function ($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, |
| 5 | 5 | focaModalService, focaBotoneraLateralService, $interval |
| 6 | 6 | ) { |
| 7 | + | |
| 7 | 8 | $scope.actividad = 'Logistica'; |
| 8 | - //Datos Pantalla | |
| 9 | 9 | $scope.titulo = 'Logistica de Pedidos'; |
| 10 | 10 | |
| 11 | 11 | var transportista = { |
| ... | ... | @@ -47,6 +47,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 49 | $scope.cargar = function (idVehiculo, punto) { |
| 50 | + | |
| 50 | 51 | if (!eligioFecha()) return; |
| 51 | 52 | var idRemito; |
| 52 | 53 | if (punto === -1) { |
| ... | ... | @@ -70,6 +71,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 70 | 71 | }; |
| 71 | 72 | |
| 72 | 73 | $scope.quitarVehiculo = function (vehiculo) { |
| 74 | + | |
| 73 | 75 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 74 | 76 | |
| 75 | 77 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + |
| ... | ... | @@ -93,44 +95,52 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 93 | 95 | } |
| 94 | 96 | } |
| 95 | 97 | ); |
| 96 | - modalInstance.result.then(function () { | |
| 98 | + modalInstance.result | |
| 99 | + .then(function () { | |
| 97 | 100 | |
| 98 | - }, function () { | |
| 99 | - //usar cuando se cancela el modal | |
| 100 | - }); | |
| 101 | + }) | |
| 102 | + .catch(function (err) { console.error(err); }); | |
| 101 | 103 | }; |
| 102 | 104 | |
| 103 | 105 | $scope.arrastra = function () { |
| 106 | + | |
| 104 | 107 | $scope.arrastrando = true; |
| 105 | 108 | $scope.$digest(); |
| 106 | 109 | }; |
| 107 | 110 | |
| 108 | 111 | $scope.noArrastra = function () { |
| 112 | + | |
| 109 | 113 | $scope.arrastrando = false; |
| 110 | 114 | $scope.$digest(); |
| 111 | 115 | }; |
| 112 | 116 | |
| 113 | 117 | $scope.individual = function () { |
| 118 | + | |
| 114 | 119 | $scope.idVendedor = -1; |
| 115 | 120 | }; |
| 116 | 121 | |
| 117 | 122 | $scope.mostrarDetalle = function () { |
| 123 | + | |
| 118 | 124 | $scope.detalle = true; |
| 119 | 125 | }; |
| 120 | 126 | |
| 121 | 127 | $scope.salir = function () { |
| 128 | + | |
| 122 | 129 | $location.path('/'); |
| 123 | 130 | }; |
| 124 | 131 | |
| 125 | 132 | $scope.search = function () { |
| 133 | + | |
| 126 | 134 | getSeguimiento(); |
| 127 | 135 | }; |
| 128 | 136 | |
| 129 | 137 | $scope.fecha = function () { |
| 138 | + | |
| 130 | 139 | getSeguimiento(); |
| 131 | 140 | }; |
| 132 | 141 | |
| 133 | 142 | $scope.seleccionarVehículo = function () { |
| 143 | + | |
| 134 | 144 | var parametrosModal = { |
| 135 | 145 | titulo: 'Búsqueda de Transportista', |
| 136 | 146 | query: '/transportista', |
| ... | ... | @@ -149,12 +159,14 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 149 | 159 | } |
| 150 | 160 | ] |
| 151 | 161 | }; |
| 152 | - focaModalService.modal(parametrosModal).then(function (transportista) { | |
| 153 | - $scope.selectVehiculo(transportista.COD, transportista.NOM); | |
| 154 | - }); | |
| 162 | + focaModalService.modal(parametrosModal) | |
| 163 | + .then(function (transportista) { | |
| 164 | + $scope.selectVehiculo(transportista.COD, transportista.NOM); | |
| 165 | + }); | |
| 155 | 166 | }; |
| 156 | 167 | |
| 157 | 168 | $scope.busquedaAvanzada = function () { |
| 169 | + | |
| 158 | 170 | var modalInstance = $uibModal.open( |
| 159 | 171 | { |
| 160 | 172 | ariaLabelledBy: 'Busqueda Avanzada', |
| ... | ... | @@ -169,15 +181,15 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 169 | 181 | } |
| 170 | 182 | } |
| 171 | 183 | ); |
| 172 | - modalInstance.result.then(function(data) { | |
| 173 | - actualizarMarcadores(data); | |
| 174 | - }, function () { | |
| 175 | - // funcion ejecutada cuando se cancela el modal | |
| 176 | - } | |
| 177 | - ); | |
| 184 | + modalInstance.result | |
| 185 | + .then(function (data) { | |
| 186 | + actualizarMarcadores(data); | |
| 187 | + }) | |
| 188 | + .catch(function (err) { console.err(err); }); | |
| 178 | 189 | }; |
| 179 | 190 | |
| 180 | - $scope.selectVehiculo = function(idTransportista, nombreTransportista) { | |
| 191 | + $scope.selectVehiculo = function (idTransportista, nombreTransportista) { | |
| 192 | + | |
| 181 | 193 | var parametrosModal = { |
| 182 | 194 | columnas: [ |
| 183 | 195 | { |
| ... | ... | @@ -201,33 +213,36 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 201 | 213 | titulo: 'Búsqueda de vehiculos', |
| 202 | 214 | subTitulo: idTransportista + '-' + nombreTransportista |
| 203 | 215 | }; |
| 204 | - focaModalService.modal(parametrosModal).then( | |
| 205 | - function (vehiculo) { | |
| 206 | - var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); | |
| 207 | - if (existe.length) { | |
| 208 | - focaModalService.alert('El vehiculo ya ha sido cargado'); | |
| 209 | - return; | |
| 210 | - } | |
| 211 | - if (!vehiculo.cisternas.length) { | |
| 212 | - focaModalService.alert('El vehiculo no tiene cisternas'); | |
| 213 | - return; | |
| 214 | - } | |
| 215 | - $scope.vehiculos.push(vehiculo); | |
| 216 | - }, function () { | |
| 217 | - // funcion ejecutada cuando se cancela el modal | |
| 218 | - }); | |
| 216 | + focaModalService.modal(parametrosModal) | |
| 217 | + .then( | |
| 218 | + function (vehiculo) { | |
| 219 | + var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); | |
| 220 | + if (existe.length) { | |
| 221 | + focaModalService.alert('El vehiculo ya ha sido cargado'); | |
| 222 | + return; | |
| 223 | + } | |
| 224 | + if (!vehiculo.cisternas.length) { | |
| 225 | + focaModalService.alert('El vehiculo no tiene cisternas'); | |
| 226 | + return; | |
| 227 | + } | |
| 228 | + $scope.vehiculos.push(vehiculo); | |
| 229 | + }, function () { | |
| 230 | + // funcion ejecutada cuando se cancela el modal | |
| 231 | + }); | |
| 219 | 232 | }; |
| 220 | - $scope.seleccionarFechaReparto = function() { | |
| 221 | - focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { | |
| 233 | + $scope.seleccionarFechaReparto = function () { | |
| 234 | + | |
| 235 | + focaModalService.modalFecha('Fecha de reparto').then(function (fecha) { | |
| 222 | 236 | setearFecha(fecha); |
| 223 | 237 | }); |
| 224 | 238 | }; |
| 225 | 239 | |
| 226 | - function actualizarMarcadores (filtros) { | |
| 240 | + function actualizarMarcadores(filtros) { | |
| 241 | + | |
| 227 | 242 | var marcadores = []; |
| 228 | 243 | if (filtros.cliente && filtros.remito === undefined) { |
| 229 | 244 | |
| 230 | - $scope.marcadores.forEach( function (marcador) { | |
| 245 | + $scope.marcadores.forEach(function (marcador) { | |
| 231 | 246 | if (marcador.notaPedido.cliente.NOM === filtros.cliente) { |
| 232 | 247 | marcadores.push(marcador); |
| 233 | 248 | } |
| ... | ... | @@ -251,7 +266,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 251 | 266 | }); |
| 252 | 267 | } |
| 253 | 268 | } else { |
| 254 | - $scope.marcadores.forEach( function (marcador) { | |
| 269 | + $scope.marcadores.forEach(function (marcador) { | |
| 255 | 270 | if (filtros.remito.id === marcador.notaPedido.remito.id) { |
| 256 | 271 | marcadores.push(marcador); |
| 257 | 272 | } |
| ... | ... | @@ -277,18 +292,21 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 277 | 292 | } |
| 278 | 293 | |
| 279 | 294 | function setearFecha(fecha) { |
| 295 | + | |
| 280 | 296 | $scope.fechaReparto = fecha; |
| 281 | 297 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); |
| 282 | - focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function (res) { | |
| 283 | - $scope.vehiculos = res.data; | |
| 284 | - $scope.$broadcast('addCabecera', { | |
| 285 | - label: 'Fecha:', | |
| 286 | - valor: fecha.toLocaleDateString() | |
| 298 | + focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha) | |
| 299 | + .then(function (res) { | |
| 300 | + $scope.vehiculos = res.data; | |
| 301 | + $scope.$broadcast('addCabecera', { | |
| 302 | + label: 'Fecha:', | |
| 303 | + valor: fecha.toLocaleDateString() | |
| 304 | + }); | |
| 287 | 305 | }); |
| 288 | - }); | |
| 289 | 306 | } |
| 290 | 307 | |
| 291 | 308 | function getSeguimiento() { |
| 309 | + | |
| 292 | 310 | var desde = new Date('1900/01/01'); |
| 293 | 311 | var hasta = new Date('2099/01/01'); |
| 294 | 312 | if ($scope.fechaDesde) { |
| ... | ... | @@ -316,28 +334,32 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 316 | 334 | individual: $scope.idVendedor ? true : false |
| 317 | 335 | }; |
| 318 | 336 | |
| 319 | - focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { | |
| 320 | - if (!angular.equals($scope.marcadores, datos.data)) { | |
| 321 | - $scope.marcadores = datos.data; | |
| 322 | - $scope.marcadoresFiltro = $scope.marcadores; | |
| 323 | - } | |
| 324 | - }); | |
| 337 | + focaLogisticaPedidoRutaService.obtenerActividad(datos) | |
| 338 | + .then(function (datos) { | |
| 339 | + if (!angular.equals($scope.marcadores, datos.data)) { | |
| 340 | + $scope.marcadores = datos.data; | |
| 341 | + $scope.marcadoresFiltro = $scope.marcadores; | |
| 342 | + } | |
| 343 | + }); | |
| 325 | 344 | } |
| 326 | 345 | |
| 327 | 346 | function eliminarVehiculo(vehiculo) { |
| 328 | - focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id).then(function (res) { | |
| 329 | - if (!res.data.length) { | |
| 330 | - $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | |
| 331 | - } else { | |
| 332 | - focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + | |
| 333 | - 'tiene remitos asociados').then(function () { | |
| 334 | - $scope.hacerHojaRuta(vehiculo, true); | |
| 335 | - }); | |
| 336 | - } | |
| 337 | - }); | |
| 347 | + | |
| 348 | + focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id) | |
| 349 | + .then(function (res) { | |
| 350 | + if (!res.data.length) { | |
| 351 | + $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | |
| 352 | + } else { | |
| 353 | + focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + | |
| 354 | + 'tiene remitos asociados').then(function () { | |
| 355 | + $scope.hacerHojaRuta(vehiculo, true); | |
| 356 | + }); | |
| 357 | + } | |
| 358 | + }); | |
| 338 | 359 | } |
| 339 | 360 | |
| 340 | 361 | function eligioFecha() { |
| 362 | + | |
| 341 | 363 | if (!$scope.fechaReparto) { |
| 342 | 364 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 343 | 365 | return false; |
| ... | ... | @@ -346,6 +368,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon |
| 346 | 368 | } |
| 347 | 369 | |
| 348 | 370 | function vehiculoEnUso(vehiculo) { |
| 371 | + | |
| 349 | 372 | var idUsuario = focaLogisticaPedidoRutaService.idUsuario; |
| 350 | 373 | for (var i = 0; i < vehiculo.cisternas.length; i++) { |
| 351 | 374 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |