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
| 1 | angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaController', [ | 1 | angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaController', [ |
| 2 | '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', | 2 | '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', |
| 3 | 'focaModalService', 'focaBotoneraLateralService', '$interval', | 3 | 'focaModalService', 'focaBotoneraLateralService', '$interval', |
| 4 | function ($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, | 4 | function ($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, |
| 5 | focaModalService, focaBotoneraLateralService, $interval | 5 | focaModalService, focaBotoneraLateralService, $interval |
| 6 | ) { | 6 | ) { |
| 7 | |||
| 7 | $scope.actividad = 'Logistica'; | 8 | $scope.actividad = 'Logistica'; |
| 8 | //Datos Pantalla | ||
| 9 | $scope.titulo = 'Logistica de Pedidos'; | 9 | $scope.titulo = 'Logistica de Pedidos'; |
| 10 | 10 | ||
| 11 | var transportista = { | 11 | var transportista = { |
| 12 | label: 'Vehículo', | 12 | label: 'Vehículo', |
| 13 | image: 'abmChofer.png' | 13 | image: 'abmChofer.png' |
| 14 | }; | 14 | }; |
| 15 | var fecha = { | 15 | var fecha = { |
| 16 | label: 'Fecha Reparto', | 16 | label: 'Fecha Reparto', |
| 17 | image: 'FechaEntrega.png' | 17 | image: 'FechaEntrega.png' |
| 18 | }; | 18 | }; |
| 19 | $scope.botonera = [fecha, transportista]; | 19 | $scope.botonera = [fecha, transportista]; |
| 20 | var cabecera = ''; | 20 | var cabecera = ''; |
| 21 | $scope.now = new Date(); | 21 | $scope.now = new Date(); |
| 22 | $scope.idVendedor = 0; | 22 | $scope.idVendedor = 0; |
| 23 | $scope.marcadores = []; | 23 | $scope.marcadores = []; |
| 24 | $scope.vehiculos = []; | 24 | $scope.vehiculos = []; |
| 25 | getSeguimiento(); | 25 | getSeguimiento(); |
| 26 | $scope.arrastrando = false; | 26 | $scope.arrastrando = false; |
| 27 | $scope.general = function () { | 27 | $scope.general = function () { |
| 28 | $scope.idVendedor = 0; | 28 | $scope.idVendedor = 0; |
| 29 | getSeguimiento(); | 29 | getSeguimiento(); |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | setearFecha(new Date()); | 32 | setearFecha(new Date()); |
| 33 | 33 | ||
| 34 | //SETEO BOTONERA LATERAL | 34 | //SETEO BOTONERA LATERAL |
| 35 | focaBotoneraLateralService.showSalir(true); | 35 | focaBotoneraLateralService.showSalir(true); |
| 36 | focaBotoneraLateralService.showPausar(false); | 36 | focaBotoneraLateralService.showPausar(false); |
| 37 | focaBotoneraLateralService.showGuardar(false); | 37 | focaBotoneraLateralService.showGuardar(false); |
| 38 | 38 | ||
| 39 | $scope.general = function () { | 39 | $scope.general = function () { |
| 40 | $scope.idVendedor = 0; | 40 | $scope.idVendedor = 0; |
| 41 | getSeguimiento(); | 41 | getSeguimiento(); |
| 42 | $scope.$broadcast('removeCabecera', cabecera); | 42 | $scope.$broadcast('removeCabecera', cabecera); |
| 43 | $scope.$broadcast('addCabecera', { | 43 | $scope.$broadcast('addCabecera', { |
| 44 | label: 'General', | 44 | label: 'General', |
| 45 | valor: '' | 45 | valor: '' |
| 46 | }); | 46 | }); |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | $scope.cargar = function (idVehiculo, punto) { | 49 | $scope.cargar = function (idVehiculo, punto) { |
| 50 | |||
| 50 | if (!eligioFecha()) return; | 51 | if (!eligioFecha()) return; |
| 51 | var idRemito; | 52 | var idRemito; |
| 52 | if (punto === -1) { | 53 | if (punto === -1) { |
| 53 | idRemito = -1; | 54 | idRemito = -1; |
| 54 | } else { | 55 | } else { |
| 55 | idRemito = JSON.parse(punto).notaPedido.remito.id; | 56 | idRemito = JSON.parse(punto).notaPedido.remito.id; |
| 56 | } | 57 | } |
| 57 | $uibModal.open( | 58 | $uibModal.open( |
| 58 | { | 59 | { |
| 59 | ariaLabelledBy: 'Busqueda de Vehiculo', | 60 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 60 | templateUrl: 'foca-detalle-vehiculo.html', | 61 | templateUrl: 'foca-detalle-vehiculo.html', |
| 61 | controller: 'focaDetalleVehiculo', | 62 | controller: 'focaDetalleVehiculo', |
| 62 | size: 'lg', | 63 | size: 'lg', |
| 63 | resolve: { | 64 | resolve: { |
| 64 | idVehiculo: function () { return idVehiculo; }, | 65 | idVehiculo: function () { return idVehiculo; }, |
| 65 | idRemito: function () { return idRemito; }, | 66 | idRemito: function () { return idRemito; }, |
| 66 | fechaReparto: function () { return $scope.fechaReparto; } | 67 | fechaReparto: function () { return $scope.fechaReparto; } |
| 67 | } | 68 | } |
| 68 | } | 69 | } |
| 69 | ); | 70 | ); |
| 70 | }; | 71 | }; |
| 71 | 72 | ||
| 72 | $scope.quitarVehiculo = function (vehiculo) { | 73 | $scope.quitarVehiculo = function (vehiculo) { |
| 74 | |||
| 73 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; | 75 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 74 | 76 | ||
| 75 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + | 77 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + |
| 76 | vehiculo.codigo + ' de ' + vehiculo.transportista.NOM + '?').then(function () { | 78 | vehiculo.codigo + ' de ' + vehiculo.transportista.NOM + '?').then(function () { |
| 77 | eliminarVehiculo(vehiculo); | 79 | eliminarVehiculo(vehiculo); |
| 78 | }); | 80 | }); |
| 79 | }; | 81 | }; |
| 80 | 82 | ||
| 81 | $scope.hacerHojaRuta = function (vehiculo, cerrar) { | 83 | $scope.hacerHojaRuta = function (vehiculo, cerrar) { |
| 82 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; | 84 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 83 | var modalInstance = $uibModal.open( | 85 | var modalInstance = $uibModal.open( |
| 84 | { | 86 | { |
| 85 | ariaLabelledBy: 'Creación hoja ruta', | 87 | ariaLabelledBy: 'Creación hoja ruta', |
| 86 | templateUrl: 'foca-modal-cerrar-vehiculo.html', | 88 | templateUrl: 'foca-modal-cerrar-vehiculo.html', |
| 87 | controller: 'focaModalCerrarVehiculo', | 89 | controller: 'focaModalCerrarVehiculo', |
| 88 | size: 'lg', | 90 | size: 'lg', |
| 89 | resolve: { | 91 | resolve: { |
| 90 | idVehiculo: function () { return vehiculo.id; }, | 92 | idVehiculo: function () { return vehiculo.id; }, |
| 91 | fechaReparto: function () { return $scope.fechaReparto; }, | 93 | fechaReparto: function () { return $scope.fechaReparto; }, |
| 92 | cerrar: function () { return cerrar; } | 94 | cerrar: function () { return cerrar; } |
| 93 | } | 95 | } |
| 94 | } | 96 | } |
| 95 | ); | 97 | ); |
| 96 | modalInstance.result.then(function () { | 98 | modalInstance.result |
| 99 | .then(function () { | ||
| 97 | 100 | ||
| 98 | }, function () { | 101 | }) |
| 99 | //usar cuando se cancela el modal | 102 | .catch(function (err) { console.error(err); }); |
| 100 | }); | ||
| 101 | }; | 103 | }; |
| 102 | 104 | ||
| 103 | $scope.arrastra = function () { | 105 | $scope.arrastra = function () { |
| 106 | |||
| 104 | $scope.arrastrando = true; | 107 | $scope.arrastrando = true; |
| 105 | $scope.$digest(); | 108 | $scope.$digest(); |
| 106 | }; | 109 | }; |
| 107 | 110 | ||
| 108 | $scope.noArrastra = function () { | 111 | $scope.noArrastra = function () { |
| 112 | |||
| 109 | $scope.arrastrando = false; | 113 | $scope.arrastrando = false; |
| 110 | $scope.$digest(); | 114 | $scope.$digest(); |
| 111 | }; | 115 | }; |
| 112 | 116 | ||
| 113 | $scope.individual = function () { | 117 | $scope.individual = function () { |
| 118 | |||
| 114 | $scope.idVendedor = -1; | 119 | $scope.idVendedor = -1; |
| 115 | }; | 120 | }; |
| 116 | 121 | ||
| 117 | $scope.mostrarDetalle = function () { | 122 | $scope.mostrarDetalle = function () { |
| 123 | |||
| 118 | $scope.detalle = true; | 124 | $scope.detalle = true; |
| 119 | }; | 125 | }; |
| 120 | 126 | ||
| 121 | $scope.salir = function () { | 127 | $scope.salir = function () { |
| 128 | |||
| 122 | $location.path('/'); | 129 | $location.path('/'); |
| 123 | }; | 130 | }; |
| 124 | 131 | ||
| 125 | $scope.search = function () { | 132 | $scope.search = function () { |
| 133 | |||
| 126 | getSeguimiento(); | 134 | getSeguimiento(); |
| 127 | }; | 135 | }; |
| 128 | 136 | ||
| 129 | $scope.fecha = function () { | 137 | $scope.fecha = function () { |
| 138 | |||
| 130 | getSeguimiento(); | 139 | getSeguimiento(); |
| 131 | }; | 140 | }; |
| 132 | 141 | ||
| 133 | $scope.seleccionarVehículo = function () { | 142 | $scope.seleccionarVehículo = function () { |
| 143 | |||
| 134 | var parametrosModal = { | 144 | var parametrosModal = { |
| 135 | titulo: 'Búsqueda de Transportista', | 145 | titulo: 'Búsqueda de Transportista', |
| 136 | query: '/transportista', | 146 | query: '/transportista', |
| 137 | columnas: [ | 147 | columnas: [ |
| 138 | { | 148 | { |
| 139 | nombre: 'Código', | 149 | nombre: 'Código', |
| 140 | propiedad: 'COD' | 150 | propiedad: 'COD' |
| 141 | }, | 151 | }, |
| 142 | { | 152 | { |
| 143 | nombre: 'Nombre', | 153 | nombre: 'Nombre', |
| 144 | propiedad: 'NOM' | 154 | propiedad: 'NOM' |
| 145 | }, | 155 | }, |
| 146 | { | 156 | { |
| 147 | nombre: 'CUIT', | 157 | nombre: 'CUIT', |
| 148 | propiedad: 'CUIT' | 158 | propiedad: 'CUIT' |
| 149 | } | 159 | } |
| 150 | ] | 160 | ] |
| 151 | }; | 161 | }; |
| 152 | focaModalService.modal(parametrosModal).then(function (transportista) { | 162 | focaModalService.modal(parametrosModal) |
| 153 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | 163 | .then(function (transportista) { |
| 154 | }); | 164 | $scope.selectVehiculo(transportista.COD, transportista.NOM); |
| 165 | }); | ||
| 155 | }; | 166 | }; |
| 156 | 167 | ||
| 157 | $scope.busquedaAvanzada = function () { | 168 | $scope.busquedaAvanzada = function () { |
| 169 | |||
| 158 | var modalInstance = $uibModal.open( | 170 | var modalInstance = $uibModal.open( |
| 159 | { | 171 | { |
| 160 | ariaLabelledBy: 'Busqueda Avanzada', | 172 | ariaLabelledBy: 'Busqueda Avanzada', |
| 161 | templateUrl: 'foca-modal-busqueda-avanzada.html', | 173 | templateUrl: 'foca-modal-busqueda-avanzada.html', |
| 162 | controller: 'focaModalBusquedaAvanzadaController', | 174 | controller: 'focaModalBusquedaAvanzadaController', |
| 163 | resolve: { | 175 | resolve: { |
| 164 | parametrosModal: function () { | 176 | parametrosModal: function () { |
| 165 | return { | 177 | return { |
| 166 | remitos: $scope.marcadores | 178 | remitos: $scope.marcadores |
| 167 | }; | 179 | }; |
| 168 | } | 180 | } |
| 169 | } | 181 | } |
| 170 | } | 182 | } |
| 171 | ); | 183 | ); |
| 172 | modalInstance.result.then(function(data) { | 184 | modalInstance.result |
| 173 | actualizarMarcadores(data); | 185 | .then(function (data) { |
| 174 | }, function () { | 186 | actualizarMarcadores(data); |
| 175 | // funcion ejecutada cuando se cancela el modal | 187 | }) |
| 176 | } | 188 | .catch(function (err) { console.err(err); }); |
| 177 | ); | ||
| 178 | }; | 189 | }; |
| 179 | 190 | ||
| 180 | $scope.selectVehiculo = function(idTransportista, nombreTransportista) { | 191 | $scope.selectVehiculo = function (idTransportista, nombreTransportista) { |
| 192 | |||
| 181 | var parametrosModal = { | 193 | var parametrosModal = { |
| 182 | columnas: [ | 194 | columnas: [ |
| 183 | { | 195 | { |
| 184 | propiedad: 'codigo', | 196 | propiedad: 'codigo', |
| 185 | nombre: 'Código' | 197 | nombre: 'Código' |
| 186 | }, | 198 | }, |
| 187 | { | 199 | { |
| 188 | propiedad: 'tractor', | 200 | propiedad: 'tractor', |
| 189 | nombre: 'tractor' | 201 | nombre: 'tractor' |
| 190 | }, | 202 | }, |
| 191 | { | 203 | { |
| 192 | propiedad: 'semi', | 204 | propiedad: 'semi', |
| 193 | nombre: 'Semi' | 205 | nombre: 'Semi' |
| 194 | }, | 206 | }, |
| 195 | { | 207 | { |
| 196 | propiedad: 'capacidadTotalCisternas', | 208 | propiedad: 'capacidadTotalCisternas', |
| 197 | nombre: 'Capacidad' | 209 | nombre: 'Capacidad' |
| 198 | } | 210 | } |
| 199 | ], | 211 | ], |
| 200 | query: '/vehiculo/transportista/' + idTransportista, | 212 | query: '/vehiculo/transportista/' + idTransportista, |
| 201 | titulo: 'Búsqueda de vehiculos', | 213 | titulo: 'Búsqueda de vehiculos', |
| 202 | subTitulo: idTransportista + '-' + nombreTransportista | 214 | subTitulo: idTransportista + '-' + nombreTransportista |
| 203 | }; | 215 | }; |
| 204 | focaModalService.modal(parametrosModal).then( | 216 | focaModalService.modal(parametrosModal) |
| 205 | function (vehiculo) { | 217 | .then( |
| 206 | var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); | 218 | function (vehiculo) { |
| 207 | if (existe.length) { | 219 | var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); |
| 208 | focaModalService.alert('El vehiculo ya ha sido cargado'); | 220 | if (existe.length) { |
| 209 | return; | 221 | focaModalService.alert('El vehiculo ya ha sido cargado'); |
| 210 | } | 222 | return; |
| 211 | if (!vehiculo.cisternas.length) { | 223 | } |
| 212 | focaModalService.alert('El vehiculo no tiene cisternas'); | 224 | if (!vehiculo.cisternas.length) { |
| 213 | return; | 225 | focaModalService.alert('El vehiculo no tiene cisternas'); |
| 214 | } | 226 | return; |
| 215 | $scope.vehiculos.push(vehiculo); | 227 | } |
| 216 | }, function () { | 228 | $scope.vehiculos.push(vehiculo); |
| 217 | // funcion ejecutada cuando se cancela el modal | 229 | }, function () { |
| 218 | }); | 230 | // funcion ejecutada cuando se cancela el modal |
| 231 | }); | ||
| 219 | }; | 232 | }; |
| 220 | $scope.seleccionarFechaReparto = function() { | 233 | $scope.seleccionarFechaReparto = function () { |
| 221 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { | 234 | |
| 235 | focaModalService.modalFecha('Fecha de reparto').then(function (fecha) { | ||
| 222 | setearFecha(fecha); | 236 | setearFecha(fecha); |
| 223 | }); | 237 | }); |
| 224 | }; | 238 | }; |
| 225 | 239 | ||
| 226 | function actualizarMarcadores (filtros) { | 240 | function actualizarMarcadores(filtros) { |
| 241 | |||
| 227 | var marcadores = []; | 242 | var marcadores = []; |
| 228 | if (filtros.cliente && filtros.remito === undefined) { | 243 | if (filtros.cliente && filtros.remito === undefined) { |
| 229 | 244 | ||
| 230 | $scope.marcadores.forEach( function (marcador) { | 245 | $scope.marcadores.forEach(function (marcador) { |
| 231 | if (marcador.notaPedido.cliente.NOM === filtros.cliente) { | 246 | if (marcador.notaPedido.cliente.NOM === filtros.cliente) { |
| 232 | marcadores.push(marcador); | 247 | marcadores.push(marcador); |
| 233 | } | 248 | } |
| 234 | }); | 249 | }); |
| 235 | 250 | ||
| 236 | if (marcadores.length === 0) { | 251 | if (marcadores.length === 0) { |
| 237 | focaModalService.alert('No se encontraron coincidencias en la busqueda') | 252 | focaModalService.alert('No se encontraron coincidencias en la busqueda') |
| 238 | .then(function (data) { | 253 | .then(function (data) { |
| 239 | if (data) { | 254 | if (data) { |
| 240 | $scope.marcadoresFiltro = marcadores; | 255 | $scope.marcadoresFiltro = marcadores; |
| 241 | } | 256 | } |
| 242 | }); | 257 | }); |
| 243 | $scope.$broadcast('cleanCabecera'); | 258 | $scope.$broadcast('cleanCabecera'); |
| 244 | setearFecha(new Date()); | 259 | setearFecha(new Date()); |
| 245 | return; | 260 | return; |
| 246 | } else { | 261 | } else { |
| 247 | $scope.marcadoresFiltro = marcadores; | 262 | $scope.marcadoresFiltro = marcadores; |
| 248 | $scope.$broadcast('addCabecera', { | 263 | $scope.$broadcast('addCabecera', { |
| 249 | label: 'Cliente:', | 264 | label: 'Cliente:', |
| 250 | valor: filtros.cliente | 265 | valor: filtros.cliente |
| 251 | }); | 266 | }); |
| 252 | } | 267 | } |
| 253 | } else { | 268 | } else { |
| 254 | $scope.marcadores.forEach( function (marcador) { | 269 | $scope.marcadores.forEach(function (marcador) { |
| 255 | if (filtros.remito.id === marcador.notaPedido.remito.id) { | 270 | if (filtros.remito.id === marcador.notaPedido.remito.id) { |
| 256 | marcadores.push(marcador); | 271 | marcadores.push(marcador); |
| 257 | } | 272 | } |
| 258 | }); | 273 | }); |
| 259 | if (marcadores.length === 0) { | 274 | if (marcadores.length === 0) { |
| 260 | focaModalService.alert('No se encontraron coincidencias en la busqueda') | 275 | focaModalService.alert('No se encontraron coincidencias en la busqueda') |
| 261 | .then(function (data) { | 276 | .then(function (data) { |
| 262 | if (data) { | 277 | if (data) { |
| 263 | $scope.marcadoresFiltro = marcadores; | 278 | $scope.marcadoresFiltro = marcadores; |
| 264 | } | 279 | } |
| 265 | }); | 280 | }); |
| 266 | $scope.$broadcast('cleanCabecera'); | 281 | $scope.$broadcast('cleanCabecera'); |
| 267 | setearFecha(new Date()); | 282 | setearFecha(new Date()); |
| 268 | return; | 283 | return; |
| 269 | } else { | 284 | } else { |
| 270 | $scope.marcadoresFiltro = marcadores; | 285 | $scope.marcadoresFiltro = marcadores; |
| 271 | $scope.$broadcast('addCabecera', { | 286 | $scope.$broadcast('addCabecera', { |
| 272 | label: 'Cliente:', | 287 | label: 'Cliente:', |
| 273 | valor: filtros.cliente | 288 | valor: filtros.cliente |
| 274 | }); | 289 | }); |
| 275 | } | 290 | } |
| 276 | } | 291 | } |
| 277 | } | 292 | } |
| 278 | 293 | ||
| 279 | function setearFecha(fecha) { | 294 | function setearFecha(fecha) { |
| 295 | |||
| 280 | $scope.fechaReparto = fecha; | 296 | $scope.fechaReparto = fecha; |
| 281 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); | 297 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); |
| 282 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function (res) { | 298 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha) |
| 283 | $scope.vehiculos = res.data; | 299 | .then(function (res) { |
| 284 | $scope.$broadcast('addCabecera', { | 300 | $scope.vehiculos = res.data; |
| 285 | label: 'Fecha:', | 301 | $scope.$broadcast('addCabecera', { |
| 286 | valor: fecha.toLocaleDateString() | 302 | label: 'Fecha:', |
| 303 | valor: fecha.toLocaleDateString() | ||
| 304 | }); | ||
| 287 | }); | 305 | }); |
| 288 | }); | ||
| 289 | } | 306 | } |
| 290 | 307 | ||
| 291 | function getSeguimiento() { | 308 | function getSeguimiento() { |
| 309 | |||
| 292 | var desde = new Date('1900/01/01'); | 310 | var desde = new Date('1900/01/01'); |
| 293 | var hasta = new Date('2099/01/01'); | 311 | var hasta = new Date('2099/01/01'); |
| 294 | if ($scope.fechaDesde) { | 312 | if ($scope.fechaDesde) { |
| 295 | var fechaDesde = $scope.fechaDesde; | 313 | var fechaDesde = $scope.fechaDesde; |
| 296 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); | 314 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); |
| 297 | desde = new Date(desde); | 315 | desde = new Date(desde); |
| 298 | } | 316 | } |
| 299 | if ($scope.fechaHasta) { | 317 | if ($scope.fechaHasta) { |
| 300 | var fechaHasta = $scope.fechaHasta; | 318 | var fechaHasta = $scope.fechaHasta; |
| 301 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); | 319 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); |
| 302 | hasta = hasta.setDate(hasta.getDate() + 1); | 320 | hasta = hasta.setDate(hasta.getDate() + 1); |
| 303 | hasta = new Date(hasta); | 321 | hasta = new Date(hasta); |
| 304 | } | 322 | } |
| 305 | var datos = { | 323 | var datos = { |
| 306 | actividad: $scope.actividad, | 324 | actividad: $scope.actividad, |
| 307 | idUsuario: $scope.idVendedor, | 325 | idUsuario: $scope.idVendedor, |
| 308 | fechaDesde: desde, | 326 | fechaDesde: desde, |
| 309 | fechaHasta: hasta, | 327 | fechaHasta: hasta, |
| 310 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? | 328 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? |
| 311 | false : undefined) | 329 | false : undefined) |
| 312 | }; | 330 | }; |
| 313 | 331 | ||
| 314 | $scope.datosBuscados = { | 332 | $scope.datosBuscados = { |
| 315 | actividad: $scope.actividad, | 333 | actividad: $scope.actividad, |
| 316 | individual: $scope.idVendedor ? true : false | 334 | individual: $scope.idVendedor ? true : false |
| 317 | }; | 335 | }; |
| 318 | 336 | ||
| 319 | focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { | 337 | focaLogisticaPedidoRutaService.obtenerActividad(datos) |
| 320 | if (!angular.equals($scope.marcadores, datos.data)) { | 338 | .then(function (datos) { |
| 321 | $scope.marcadores = datos.data; | 339 | if (!angular.equals($scope.marcadores, datos.data)) { |
| 322 | $scope.marcadoresFiltro = $scope.marcadores; | 340 | $scope.marcadores = datos.data; |
| 323 | } | 341 | $scope.marcadoresFiltro = $scope.marcadores; |
| 324 | }); | 342 | } |
| 343 | }); | ||
| 325 | } | 344 | } |
| 326 | 345 | ||
| 327 | function eliminarVehiculo(vehiculo) { | 346 | function eliminarVehiculo(vehiculo) { |
| 328 | focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id).then(function (res) { | 347 | |
| 329 | if (!res.data.length) { | 348 | focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id) |
| 330 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 349 | .then(function (res) { |
| 331 | } else { | 350 | if (!res.data.length) { |
| 332 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + | 351 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 333 | 'tiene remitos asociados').then(function () { | 352 | } else { |
| 334 | $scope.hacerHojaRuta(vehiculo, true); | 353 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + |
| 335 | }); | 354 | 'tiene remitos asociados').then(function () { |
| 336 | } | 355 | $scope.hacerHojaRuta(vehiculo, true); |
| 337 | }); | 356 | }); |
| 357 | } | ||
| 358 | }); | ||
| 338 | } | 359 | } |
| 339 | 360 | ||
| 340 | function eligioFecha() { | 361 | function eligioFecha() { |
| 362 | |||
| 341 | if (!$scope.fechaReparto) { | 363 | if (!$scope.fechaReparto) { |
| 342 | focaModalService.alert('Primero seleccione fecha de reparto'); | 364 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 343 | return false; | 365 | return false; |
| 344 | } | 366 | } |
| 345 | return true; | 367 | return true; |
| 346 | } | 368 | } |
| 347 | 369 | ||
| 348 | function vehiculoEnUso(vehiculo) { | 370 | function vehiculoEnUso(vehiculo) { |
| 371 | |||
| 349 | var idUsuario = focaLogisticaPedidoRutaService.idUsuario; | 372 | var idUsuario = focaLogisticaPedidoRutaService.idUsuario; |
| 350 | for (var i = 0; i < vehiculo.cisternas.length; i++) { | 373 | for (var i = 0; i < vehiculo.cisternas.length; i++) { |
| 351 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 374 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
| 352 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 375 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
| 353 | if (cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto | 376 | if (cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto |
| 354 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && | 377 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && |
| 355 | cisternaCarga.idUsuarioProceso !== idUsuario) { | 378 | cisternaCarga.idUsuarioProceso !== idUsuario) { |
| 356 | focaModalService.alert('El vehículo está siendo usado por otro usuario'); | 379 | focaModalService.alert('El vehículo está siendo usado por otro usuario'); |
| 357 | return true; | 380 | return true; |
| 358 | } | 381 | } |
| 359 | } | 382 | } |
| 360 | } | 383 | } |
| 361 | return false; | 384 | return false; |
| 362 | } | 385 | } |
| 363 | // $interval(function() { | 386 | // $interval(function() { |
| 364 | // getSeguimiento(); | 387 | // getSeguimiento(); |