Commit 102db7330859df7c552a4c6bcafd16c007a19e40
1 parent
8fe02f5aa8
Exists in
master
code revir
Showing
1 changed file
with
2 additions
and
5 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 | $scope.actividad = 'Logistica'; | 7 | $scope.actividad = 'Logistica'; |
| 8 | 8 | ||
| 9 | //Datos Pantalla | 9 | //Datos Pantalla |
| 10 | $scope.titulo = 'Logistica de Pedidos'; | 10 | $scope.titulo = 'Logistica de Pedidos'; |
| 11 | var transportista = { | 11 | var transportista = { |
| 12 | label: 'Unidad', | 12 | label: 'Unidad', |
| 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: 'fechaDeReparto.png' | 17 | image: 'fechaDeReparto.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 | //SETEO BOTONERA LATERAL | 32 | //SETEO BOTONERA LATERAL |
| 33 | focaBotoneraLateralService.showSalir(true); | 33 | focaBotoneraLateralService.showSalir(true); |
| 34 | focaBotoneraLateralService.showPausar(false); | 34 | focaBotoneraLateralService.showPausar(false); |
| 35 | focaBotoneraLateralService.showGuardar(false); | 35 | focaBotoneraLateralService.showGuardar(false); |
| 36 | 36 | ||
| 37 | 37 | ||
| 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 | if(!eligioFecha()) return; | 50 | if(!eligioFecha()) return; |
| 51 | var idRemito; | 51 | var idRemito; |
| 52 | if(punto === -1) { | 52 | if(punto === -1) { |
| 53 | idRemito = -1; | 53 | idRemito = -1; |
| 54 | }else { | 54 | }else { |
| 55 | idRemito = JSON.parse(punto).notaPedido.remito.id; | 55 | idRemito = JSON.parse(punto).notaPedido.remito.id; |
| 56 | } | 56 | } |
| 57 | var modalInstance = $uibModal.open( | 57 | var modalInstance = $uibModal.open( |
| 58 | { | 58 | { |
| 59 | ariaLabelledBy: 'Busqueda de Vehiculo', | 59 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 60 | templateUrl: 'foca-detalle-vehiculo.html', | 60 | templateUrl: 'foca-detalle-vehiculo.html', |
| 61 | controller: 'focaDetalleVehiculo', | 61 | controller: 'focaDetalleVehiculo', |
| 62 | size: 'lg', | 62 | size: 'lg', |
| 63 | resolve: { | 63 | resolve: { |
| 64 | idVehiculo: function() {return idVehiculo;}, | 64 | idVehiculo: function() {return idVehiculo;}, |
| 65 | idRemito: function() {return idRemito;}, | 65 | idRemito: function() {return idRemito;}, |
| 66 | fechaReparto: function() {return $scope.fechaReparto;} | 66 | fechaReparto: function() {return $scope.fechaReparto;} |
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | ); | 69 | ); |
| 70 | modalInstance.result.then(function() { | 70 | modalInstance.result.then(function() { |
| 71 | }, function() { | 71 | }, function() { |
| 72 | }); | 72 | }); |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | $scope.quitarVehiculo = function(vehiculo) { | 75 | $scope.quitarVehiculo = function(vehiculo) { |
| 76 | if(!eligioFecha()) return; | 76 | if(!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 77 | if(vehiculoEnUso(vehiculo)) return; | ||
| 78 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + | 77 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + |
| 79 | vehiculo.codigo + '?').then(function() { | 78 | vehiculo.codigo + '?').then(function() { |
| 80 | eliminarVehiculo(vehiculo); | 79 | eliminarVehiculo(vehiculo); |
| 81 | }); | 80 | }); |
| 82 | }; | 81 | }; |
| 83 | 82 | ||
| 84 | $scope.hacerHojaRuta = function(vehiculo) { | 83 | $scope.hacerHojaRuta = function(vehiculo) { |
| 85 | if(!eligioFecha()) return; | 84 | if(!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 86 | if(vehiculoEnUso(vehiculo)) return; | ||
| 87 | |||
| 88 | var modalInstance = $uibModal.open( | 85 | var modalInstance = $uibModal.open( |
| 89 | { | 86 | { |
| 90 | ariaLabelledBy: 'Creación hoja ruta', | 87 | ariaLabelledBy: 'Creación hoja ruta', |
| 91 | templateUrl: 'foca-modal-cerrar-vehiculo.html', | 88 | templateUrl: 'foca-modal-cerrar-vehiculo.html', |
| 92 | controller: 'focaModalCerrarVehiculo', | 89 | controller: 'focaModalCerrarVehiculo', |
| 93 | size: 'lg', | 90 | size: 'lg', |
| 94 | resolve: { | 91 | resolve: { |
| 95 | idVehiculo: function() {return vehiculo.id;}, | 92 | idVehiculo: function() {return vehiculo.id;}, |
| 96 | fechaReparto: function() {return $scope.fechaReparto;} | 93 | fechaReparto: function() {return $scope.fechaReparto;} |
| 97 | } | 94 | } |
| 98 | } | 95 | } |
| 99 | ); | 96 | ); |
| 100 | modalInstance.result.then(function() { | 97 | modalInstance.result.then(function() { |
| 101 | 98 | ||
| 102 | }, function() { | 99 | }, function() { |
| 103 | //usar cuando se cancela el modal | 100 | //usar cuando se cancela el modal |
| 104 | }); | 101 | }); |
| 105 | }; | 102 | }; |
| 106 | 103 | ||
| 107 | $scope.arrastra = function() { | 104 | $scope.arrastra = function() { |
| 108 | $scope.arrastrando = true; | 105 | $scope.arrastrando = true; |
| 109 | $scope.$digest(); | 106 | $scope.$digest(); |
| 110 | }; | 107 | }; |
| 111 | 108 | ||
| 112 | $scope.noArrastra = function() { | 109 | $scope.noArrastra = function() { |
| 113 | $scope.arrastrando = false; | 110 | $scope.arrastrando = false; |
| 114 | $scope.$digest(); | 111 | $scope.$digest(); |
| 115 | }; | 112 | }; |
| 116 | 113 | ||
| 117 | $scope.individual = function() { | 114 | $scope.individual = function() { |
| 118 | $scope.idVendedor = -1; | 115 | $scope.idVendedor = -1; |
| 119 | }; | 116 | }; |
| 120 | 117 | ||
| 121 | $scope.mostrarDetalle = function() { | 118 | $scope.mostrarDetalle = function() { |
| 122 | $scope.detalle = true; | 119 | $scope.detalle = true; |
| 123 | }; | 120 | }; |
| 124 | 121 | ||
| 125 | $scope.salir = function() { | 122 | $scope.salir = function() { |
| 126 | $location.path('/'); | 123 | $location.path('/'); |
| 127 | }; | 124 | }; |
| 128 | 125 | ||
| 129 | $scope.search = function() { | 126 | $scope.search = function() { |
| 130 | getSeguimiento(); | 127 | getSeguimiento(); |
| 131 | }; | 128 | }; |
| 132 | 129 | ||
| 133 | $scope.fecha = function() { | 130 | $scope.fecha = function() { |
| 134 | getSeguimiento(); | 131 | getSeguimiento(); |
| 135 | }; | 132 | }; |
| 136 | 133 | ||
| 137 | $scope.seleccionarUnidad = function() { | 134 | $scope.seleccionarUnidad = function() { |
| 138 | var modalInstance = $uibModal.open( | 135 | var modalInstance = $uibModal.open( |
| 139 | { | 136 | { |
| 140 | ariaLabelledBy: 'Busqueda de Transportista', | 137 | ariaLabelledBy: 'Busqueda de Transportista', |
| 141 | templateUrl: 'modal-proveedor.html', | 138 | templateUrl: 'modal-proveedor.html', |
| 142 | controller: 'focaModalProveedorCtrl', | 139 | controller: 'focaModalProveedorCtrl', |
| 143 | size: 'lg', | 140 | size: 'lg', |
| 144 | resolve: { | 141 | resolve: { |
| 145 | transportista: function() { | 142 | transportista: function() { |
| 146 | return true; | 143 | return true; |
| 147 | } | 144 | } |
| 148 | } | 145 | } |
| 149 | } | 146 | } |
| 150 | ); | 147 | ); |
| 151 | modalInstance.result.then(function(transportista) { | 148 | modalInstance.result.then(function(transportista) { |
| 152 | $scope.seleccionarVehiculo(transportista.COD); | 149 | $scope.seleccionarVehiculo(transportista.COD); |
| 153 | }); | 150 | }); |
| 154 | }; | 151 | }; |
| 155 | 152 | ||
| 156 | $scope.seleccionarVehiculo = function(idTransportista) { | 153 | $scope.seleccionarVehiculo = function(idTransportista) { |
| 157 | var query = '/vehiculo/transportista/' + idTransportista; | 154 | var query = '/vehiculo/transportista/' + idTransportista; |
| 158 | var columnas = { | 155 | var columnas = { |
| 159 | nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], | 156 | nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], |
| 160 | propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] | 157 | propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] |
| 161 | }; | 158 | }; |
| 162 | var titulo = 'Búsqueda de vehiculos'; | 159 | var titulo = 'Búsqueda de vehiculos'; |
| 163 | focaModalService.modal(columnas, query, titulo).then( | 160 | focaModalService.modal(columnas, query, titulo).then( |
| 164 | function(vehiculo) { | 161 | function(vehiculo) { |
| 165 | var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); | 162 | var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); |
| 166 | if(existe.length) { | 163 | if(existe.length) { |
| 167 | focaModalService.alert('El vehiculo ya ha sido cargado'); | 164 | focaModalService.alert('El vehiculo ya ha sido cargado'); |
| 168 | return; | 165 | return; |
| 169 | } | 166 | } |
| 170 | if(!vehiculo.cisternas.length) { | 167 | if(!vehiculo.cisternas.length) { |
| 171 | focaModalService.alert('El vehiculo no tiene cisternas'); | 168 | focaModalService.alert('El vehiculo no tiene cisternas'); |
| 172 | return; | 169 | return; |
| 173 | } | 170 | } |
| 174 | $scope.vehiculos.push(vehiculo); | 171 | $scope.vehiculos.push(vehiculo); |
| 175 | }, function() { | 172 | }, function() { |
| 176 | // funcion ejecutada cuando se cancela el modal | 173 | // funcion ejecutada cuando se cancela el modal |
| 177 | }); | 174 | }); |
| 178 | }; | 175 | }; |
| 179 | 176 | ||
| 180 | $scope.seleccionarFechaReparto = function() { | 177 | $scope.seleccionarFechaReparto = function() { |
| 181 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { | 178 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { |
| 182 | $scope.$broadcast('addCabecera',{ | 179 | $scope.$broadcast('addCabecera',{ |
| 183 | label: 'Fecha:', | 180 | label: 'Fecha:', |
| 184 | valor: fecha.toLocaleDateString() | 181 | valor: fecha.toLocaleDateString() |
| 185 | }); | 182 | }); |
| 186 | $scope.fechaReparto = fecha; | 183 | $scope.fechaReparto = fecha; |
| 187 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); | 184 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); |
| 188 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res) { | 185 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res) { |
| 189 | $scope.vehiculos = res.data; | 186 | $scope.vehiculos = res.data; |
| 190 | }); | 187 | }); |
| 191 | }); | 188 | }); |
| 192 | }; | 189 | }; |
| 193 | 190 | ||
| 194 | function getSeguimiento() { | 191 | function getSeguimiento() { |
| 195 | var desde = new Date('1900/01/01'); | 192 | var desde = new Date('1900/01/01'); |
| 196 | var hasta = new Date('2099/01/01'); | 193 | var hasta = new Date('2099/01/01'); |
| 197 | if($scope.fechaDesde) { | 194 | if($scope.fechaDesde) { |
| 198 | var fechaDesde = $scope.fechaDesde; | 195 | var fechaDesde = $scope.fechaDesde; |
| 199 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); | 196 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); |
| 200 | desde = new Date(desde); | 197 | desde = new Date(desde); |
| 201 | } | 198 | } |
| 202 | if($scope.fechaHasta) { | 199 | if($scope.fechaHasta) { |
| 203 | var fechaHasta = $scope.fechaHasta; | 200 | var fechaHasta = $scope.fechaHasta; |
| 204 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); | 201 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); |
| 205 | hasta = hasta.setDate(hasta.getDate() + 1); | 202 | hasta = hasta.setDate(hasta.getDate() + 1); |
| 206 | hasta = new Date(hasta); | 203 | hasta = new Date(hasta); |
| 207 | } | 204 | } |
| 208 | var datos = { | 205 | var datos = { |
| 209 | actividad: $scope.actividad, | 206 | actividad: $scope.actividad, |
| 210 | idUsuario: $scope.idVendedor, | 207 | idUsuario: $scope.idVendedor, |
| 211 | fechaDesde: desde, | 208 | fechaDesde: desde, |
| 212 | fechaHasta: hasta, | 209 | fechaHasta: hasta, |
| 213 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? | 210 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? |
| 214 | false : undefined) | 211 | false : undefined) |
| 215 | }; | 212 | }; |
| 216 | 213 | ||
| 217 | $scope.datosBuscados = { | 214 | $scope.datosBuscados = { |
| 218 | actividad: $scope.actividad, | 215 | actividad: $scope.actividad, |
| 219 | individual: $scope.idVendedor ? true : false | 216 | individual: $scope.idVendedor ? true : false |
| 220 | }; | 217 | }; |
| 221 | 218 | ||
| 222 | focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { | 219 | focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { |
| 223 | if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { | 220 | if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { |
| 224 | $scope.marcadores = datos.data; | 221 | $scope.marcadores = datos.data; |
| 225 | } | 222 | } |
| 226 | }); | 223 | }); |
| 227 | } | 224 | } |
| 228 | 225 | ||
| 229 | function eliminarVehiculo(vehiculo) { | 226 | function eliminarVehiculo(vehiculo) { |
| 230 | focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { | 227 | focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { |
| 231 | if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { | 228 | if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { |
| 232 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 229 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 233 | }else { | 230 | }else { |
| 234 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + | 231 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + |
| 235 | 'tiene remitos asociados').then(function() { | 232 | 'tiene remitos asociados').then(function() { |
| 236 | $scope.hacerHojaRuta(vehiculo); | 233 | $scope.hacerHojaRuta(vehiculo); |
| 237 | }); | 234 | }); |
| 238 | } | 235 | } |
| 239 | }); | 236 | }); |
| 240 | } | 237 | } |
| 241 | 238 | ||
| 242 | function eligioFecha() { | 239 | function eligioFecha() { |
| 243 | if(!$scope.fechaReparto) { | 240 | if(!$scope.fechaReparto) { |
| 244 | focaModalService.alert('Primero seleccione fecha de reparto'); | 241 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 245 | return false; | 242 | return false; |
| 246 | } | 243 | } |
| 247 | return true; | 244 | return true; |
| 248 | } | 245 | } |
| 249 | 246 | ||
| 250 | function vehiculoEnUso(vehiculo) { | 247 | function vehiculoEnUso(vehiculo) { |
| 251 | $scope.fechaReparto.setHours(0, 0, 0, 0); | 248 | $scope.fechaReparto.setHours(0, 0, 0, 0); |
| 252 | var idUsuario = focaLogisticaPedidoRutaService.idUsuario; | 249 | var idUsuario = focaLogisticaPedidoRutaService.idUsuario; |
| 253 | for(var i = 0; i < vehiculo.cisternas.length; i++) { | 250 | for(var i = 0; i < vehiculo.cisternas.length; i++) { |
| 254 | for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 251 | for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
| 255 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 252 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
| 256 | if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto | 253 | if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto |
| 257 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !== | 254 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !== |
| 258 | idUsuario) | 255 | idUsuario) |
| 259 | { | 256 | { |
| 260 | focaModalService.alert('El vehículo está siendo usado por otro usuario'); | 257 | focaModalService.alert('El vehículo está siendo usado por otro usuario'); |
| 261 | return true; | 258 | return true; |
| 262 | } | 259 | } |
| 263 | } | 260 | } |
| 264 | } | 261 | } |
| 265 | return false; | 262 | return false; |
| 266 | } | 263 | } |
| 267 | // TODO: descomentar en produccion | 264 | // TODO: descomentar en produccion |
| 268 | // $interval(function() { | 265 | // $interval(function() { |
| 269 | // getSeguimiento(); | 266 | // getSeguimiento(); |
| 270 | // }, 5000); | 267 | // }, 5000); |
| 271 | } | 268 | } |
| 272 | ]); | 269 | ]); |
| 273 | 270 |