Commit b89f9e9f5158f91b9c3d752594ef47524f0d52a0
1 parent
170aba0064
Exists in
develop
Change
Codigo identado
Showing
1 changed file
with
308 additions
and
330 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 | //Datos Pantalla | 8 | //Datos Pantalla |
| 9 | $scope.titulo = 'Logistica de Pedidos'; | 9 | $scope.titulo = 'Logistica de Pedidos'; |
| 10 | 10 | ||
| 11 | var transportista = { | 11 | const transportista = { label: 'Vehículo', image: 'abmChofer.png' }; |
| 12 | label: 'Vehículo', | 12 | const fecha = { label: 'Fecha Reparto', image: 'FechaEntrega.png' }; |
| 13 | image: 'abmChofer.png' | 13 | $scope.botonera = [fecha, transportista]; |
| 14 | }; | 14 | var cabecera = ''; |
| 15 | var fecha = { | 15 | $scope.now = new Date(); |
| 16 | label: 'Fecha Reparto', | 16 | $scope.idVendedor = 0; |
| 17 | image: 'FechaEntrega.png' | 17 | $scope.marcadores = []; |
| 18 | }; | 18 | $scope.vehiculos = []; |
| 19 | $scope.botonera = [fecha, transportista]; | 19 | getSeguimiento(); |
| 20 | var cabecera = ''; | 20 | $scope.arrastrando = false; |
| 21 | $scope.now = new Date(); | 21 | $scope.general = function () { |
| 22 | $scope.idVendedor = 0; | 22 | $scope.idVendedor = 0; |
| 23 | $scope.marcadores = []; | 23 | getSeguimiento(); |
| 24 | $scope.vehiculos = []; | 24 | }; |
| 25 | getSeguimiento(); | ||
| 26 | $scope.arrastrando = false; | ||
| 27 | $scope.general = function() { | ||
| 28 | $scope.idVendedor = 0; | ||
| 29 | getSeguimiento(); | ||
| 30 | }; | ||
| 31 | 25 | ||
| 32 | setearFecha(new Date()); | 26 | setearFecha(new Date()); |
| 33 | 27 | ||
| 34 | //SETEO BOTONERA LATERAL | 28 | //SETEO BOTONERA LATERAL |
| 35 | focaBotoneraLateralService.showSalir(true); | 29 | focaBotoneraLateralService.showSalir(true); |
| 36 | focaBotoneraLateralService.showPausar(false); | 30 | focaBotoneraLateralService.showPausar(false); |
| 37 | focaBotoneraLateralService.showGuardar(false); | 31 | focaBotoneraLateralService.showGuardar(false); |
| 38 | 32 | ||
| 39 | $scope.general = function() { | 33 | $scope.general = function () { |
| 40 | $scope.idVendedor = 0; | 34 | $scope.idVendedor = 0; |
| 41 | getSeguimiento(); | 35 | getSeguimiento(); |
| 42 | $scope.$broadcast('removeCabecera', cabecera); | 36 | $scope.$broadcast('removeCabecera', cabecera); |
| 43 | $scope.$broadcast('addCabecera', { | 37 | $scope.$broadcast('addCabecera', { |
| 44 | label: 'General', | 38 | label: 'General', |
| 45 | valor: '' | 39 | valor: '' |
| 46 | }); | 40 | }); |
| 47 | }; | 41 | }; |
| 48 | 42 | ||
| 49 | $scope.cargar = function(idVehiculo, punto) { | 43 | $scope.cargar = function (idVehiculo, punto) { |
| 50 | if (!eligioFecha()) return; | 44 | if (!eligioFecha()) return; |
| 51 | var idRemito; | 45 | const idRemito = (punto === -1) ? -1 : JSON.parse(punto).notaPedido.remito.id; |
| 52 | if (punto === -1) { | 46 | $uibModal.open( |
| 53 | idRemito = -1; | 47 | { |
| 54 | } else { | 48 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 55 | idRemito = JSON.parse(punto).notaPedido.remito.id; | 49 | templateUrl: 'foca-detalle-vehiculo.html', |
| 56 | } | 50 | controller: 'focaDetalleVehiculo', |
| 57 | $uibModal.open( | 51 | size: 'lg', |
| 58 | { | 52 | resolve: { |
| 59 | ariaLabelledBy: 'Busqueda de Vehiculo', | 53 | idVehiculo: function () { return idVehiculo; }, |
| 60 | templateUrl: 'foca-detalle-vehiculo.html', | 54 | idRemito: function () { return idRemito; }, |
| 61 | controller: 'focaDetalleVehiculo', | 55 | fechaReparto: function () { return $scope.fechaReparto; } |
| 62 | size: 'lg', | 56 | } |
| 63 | resolve: { | 57 | } |
| 64 | idVehiculo: function() {return idVehiculo;}, | 58 | ); |
| 65 | idRemito: function() {return idRemito;}, | 59 | }; |
| 66 | fechaReparto: function() {return $scope.fechaReparto;} | ||
| 67 | } | ||
| 68 | } | ||
| 69 | ); | ||
| 70 | }; | ||
| 71 | 60 | ||
| 72 | $scope.quitarVehiculo = function(vehiculo) { | 61 | $scope.quitarVehiculo = function (vehiculo) { |
| 73 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; | 62 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 63 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + | ||
| 64 | vehiculo.codigo + ' de ' + vehiculo.transportista.NOM + '?').then(function () { | ||
| 65 | eliminarVehiculo(vehiculo); | ||
| 66 | }); | ||
| 67 | }; | ||
| 74 | 68 | ||
| 75 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + | 69 | $scope.hacerHojaRuta = function (vehiculo, cerrar) { |
| 76 | vehiculo.codigo + ' de ' + vehiculo.transportista.NOM + '?').then(function() { | 70 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; |
| 77 | eliminarVehiculo(vehiculo); | 71 | var modalInstance = $uibModal.open( |
| 78 | }); | 72 | { |
| 79 | }; | 73 | ariaLabelledBy: 'Creación hoja ruta', |
| 74 | templateUrl: 'foca-modal-cerrar-vehiculo.html', | ||
| 75 | controller: 'focaModalCerrarVehiculo', | ||
| 76 | size: 'lg', | ||
| 77 | resolve: { | ||
| 78 | idVehiculo: function () { return vehiculo.id; }, | ||
| 79 | fechaReparto: function () { return $scope.fechaReparto; }, | ||
| 80 | cerrar: function () { return cerrar; } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | ); | ||
| 84 | modalInstance.result | ||
| 85 | .then(function () { }, function () { }); | ||
| 86 | }; | ||
| 80 | 87 | ||
| 81 | $scope.hacerHojaRuta = function(vehiculo, cerrar) { | 88 | $scope.arrastra = function () { |
| 82 | if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; | 89 | $scope.arrastrando = true; |
| 83 | var modalInstance = $uibModal.open( | 90 | $scope.$digest(); |
| 84 | { | 91 | }; |
| 85 | ariaLabelledBy: 'Creación hoja ruta', | ||
| 86 | templateUrl: 'foca-modal-cerrar-vehiculo.html', | ||
| 87 | controller: 'focaModalCerrarVehiculo', | ||
| 88 | size: 'lg', | ||
| 89 | resolve: { | ||
| 90 | idVehiculo: function() {return vehiculo.id;}, | ||
| 91 | fechaReparto: function() {return $scope.fechaReparto;}, | ||
| 92 | cerrar: function() {return cerrar;} | ||
| 93 | } | ||
| 94 | } | ||
| 95 | ); | ||
| 96 | modalInstance.result.then(function() { | ||
| 97 | |||
| 98 | }, function() { | ||
| 99 | //usar cuando se cancela el modal | ||
| 100 | }); | ||
| 101 | }; | ||
| 102 | 92 | ||
| 103 | $scope.arrastra = function() { | 93 | $scope.noArrastra = function () { |
| 104 | $scope.arrastrando = true; | 94 | $scope.arrastrando = false; |
| 105 | $scope.$digest(); | 95 | $scope.$digest(); |
| 106 | }; | 96 | }; |
| 107 | 97 | ||
| 108 | $scope.noArrastra = function() { | 98 | $scope.individual = function () { |
| 109 | $scope.arrastrando = false; | 99 | $scope.idVendedor = -1; |
| 110 | $scope.$digest(); | 100 | }; |
| 111 | }; | ||
| 112 | 101 | ||
| 113 | $scope.individual = function() { | 102 | $scope.mostrarDetalle = function () { |
| 114 | $scope.idVendedor = -1; | 103 | $scope.detalle = true; |
| 115 | }; | 104 | }; |
| 116 | 105 | ||
| 117 | $scope.mostrarDetalle = function() { | 106 | $scope.salir = function () { |
| 118 | $scope.detalle = true; | 107 | $location.path('/'); |
| 119 | }; | 108 | }; |
| 120 | 109 | ||
| 121 | $scope.salir = function() { | 110 | $scope.search = function () { |
| 122 | $location.path('/'); | 111 | getSeguimiento(); |
| 123 | }; | 112 | }; |
| 124 | 113 | ||
| 125 | $scope.search = function() { | 114 | $scope.fecha = function () { |
| 126 | getSeguimiento(); | 115 | getSeguimiento(); |
| 127 | }; | 116 | }; |
| 128 | 117 | ||
| 129 | $scope.fecha = function() { | 118 | $scope.seleccionarVehículo = function () { |
| 130 | getSeguimiento(); | 119 | var parametrosModal = { |
| 131 | }; | 120 | titulo: 'Búsqueda de Transportista', |
| 121 | query: '/transportista', | ||
| 122 | columnas: [ | ||
| 123 | { | ||
| 124 | nombre: 'Código', | ||
| 125 | propiedad: 'COD' | ||
| 126 | }, | ||
| 127 | { | ||
| 128 | nombre: 'Nombre', | ||
| 129 | propiedad: 'NOM' | ||
| 130 | }, | ||
| 131 | { | ||
| 132 | nombre: 'CUIT', | ||
| 133 | propiedad: 'CUIT' | ||
| 134 | } | ||
| 135 | ] | ||
| 136 | }; | ||
| 137 | focaModalService.modal(parametrosModal) | ||
| 138 | .then(function (transportista) { | ||
| 139 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | ||
| 140 | }); | ||
| 141 | }; | ||
| 132 | 142 | ||
| 133 | $scope.seleccionarVehículo = function() { | 143 | $scope.seleccionarRemito = function () { |
| 134 | var parametrosModal = { | 144 | var modalInstance = $uibModal.open( |
| 135 | titulo: 'Búsqueda de Transportista', | 145 | { |
| 136 | query: '/transportista', | 146 | ariaLabelledBy: 'Busqueda de Remito', |
| 137 | columnas: [ | 147 | templateUrl: 'foca-modal-remito.html', |
| 138 | { | 148 | controller: 'focaModalRemitoController', |
| 139 | nombre: 'Código', | 149 | size: 'lg', |
| 140 | propiedad: 'COD' | 150 | resolve: { usadoPor: function () { return 'remito'; } } |
| 141 | }, | 151 | } |
| 142 | { | 152 | ); |
| 143 | nombre: 'Nombre', | 153 | modalInstance.result |
| 144 | propiedad: 'NOM' | 154 | .then(function (remito) { |
| 145 | }, | 155 | $scope.remito = remito; |
| 146 | { | 156 | $scope.remito.numero = $filter('rellenarDigitos')(remito.lugar, 4) + '-' + |
| 147 | nombre: 'CUIT', | 157 | $filter('rellenarDigitos')(remito.numeroRemito, 6); |
| 148 | propiedad: 'CUIT' | 158 | $scope.cliente = remito.cliente.NOM; |
| 149 | } | 159 | }, function () { }); |
| 150 | ] | 160 | }; |
| 151 | }; | ||
| 152 | focaModalService.modal(parametrosModal).then(function(transportista) { | ||
| 153 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | ||
| 154 | }); | ||
| 155 | }; | ||
| 156 | 161 | ||
| 157 | $scope.seleccionarRemito = function () { | 162 | $scope.selectVehiculo = function (idTransportista, nombreTransportista) { |
| 158 | var modalInstance = $uibModal.open( | 163 | var parametrosModal = { |
| 159 | { | 164 | columnas: [ |
| 160 | ariaLabelledBy: 'Busqueda de Remito', | 165 | { |
| 161 | templateUrl: 'foca-modal-remito.html', | 166 | propiedad: 'codigo', |
| 162 | controller: 'focaModalRemitoController', | 167 | nombre: 'Código' |
| 163 | size: 'lg', | 168 | }, |
| 164 | resolve: { usadoPor: function () { return 'remito'; } } | 169 | { |
| 165 | } | 170 | propiedad: 'tractor', |
| 166 | ); | 171 | nombre: 'tractor' |
| 167 | modalInstance.result.then(function(remito) { | 172 | }, |
| 168 | $scope.remito = remito; | 173 | { |
| 169 | $scope.remito.numero = $filter('rellenarDigitos')(remito.lugar, 4) + '-' + | 174 | propiedad: 'semi', |
| 170 | $filter('rellenarDigitos')(remito.numeroRemito, 6); | 175 | nombre: 'Semi' |
| 171 | $scope.cliente = remito.cliente.NOM; | 176 | }, |
| 172 | }, function () { | 177 | { |
| 173 | // funcion ejecutada cuando se cancela el modal | 178 | propiedad: 'capacidadTotalCisternas', |
| 174 | } | 179 | nombre: 'Capacidad' |
| 175 | ); | 180 | } |
| 176 | }; | 181 | ], |
| 182 | query: '/vehiculo/transportista/' + idTransportista, | ||
| 183 | titulo: 'Búsqueda de vehiculos', | ||
| 184 | subTitulo: idTransportista + '-' + nombreTransportista | ||
| 185 | }; | ||
| 186 | focaModalService.modal(parametrosModal) | ||
| 187 | .then( | ||
| 188 | function (vehiculo) { | ||
| 189 | var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); | ||
| 190 | if (existe.length) { | ||
| 191 | focaModalService.alert('El vehiculo ya ha sido cargado'); | ||
| 192 | return; | ||
| 193 | } | ||
| 194 | if (!vehiculo.cisternas.length) { | ||
| 195 | focaModalService.alert('El vehiculo no tiene cisternas'); | ||
| 196 | return; | ||
| 197 | } | ||
| 198 | $scope.vehiculos.push(vehiculo); | ||
| 199 | }, function () { }); | ||
| 200 | }; | ||
| 177 | 201 | ||
| 178 | $scope.selectVehiculo = function(idTransportista, nombreTransportista) { | 202 | $scope.seleccionarFechaReparto = function () { |
| 179 | var parametrosModal = { | 203 | focaModalService.modalFecha('Fecha de reparto') |
| 180 | columnas: [ | 204 | .then(function (fecha) { |
| 181 | { | 205 | setearFecha(fecha); |
| 182 | propiedad: 'codigo', | 206 | }); |
| 183 | nombre: 'Código' | 207 | }; |
| 184 | }, | ||
| 185 | { | ||
| 186 | propiedad: 'tractor', | ||
| 187 | nombre: 'tractor' | ||
| 188 | }, | ||
| 189 | { | ||
| 190 | propiedad: 'semi', | ||
| 191 | nombre: 'Semi' | ||
| 192 | }, | ||
| 193 | { | ||
| 194 | propiedad: 'capacidadTotalCisternas', | ||
| 195 | nombre: 'Capacidad' | ||
| 196 | } | ||
| 197 | ], | ||
| 198 | query: '/vehiculo/transportista/' + idTransportista, | ||
| 199 | titulo: 'Búsqueda de vehiculos', | ||
| 200 | subTitulo: idTransportista + '-' + nombreTransportista | ||
| 201 | }; | ||
| 202 | focaModalService.modal(parametrosModal).then( | ||
| 203 | function(vehiculo) { | ||
| 204 | var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); | ||
| 205 | if (existe.length) { | ||
| 206 | focaModalService.alert('El vehiculo ya ha sido cargado'); | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | if (!vehiculo.cisternas.length) { | ||
| 210 | focaModalService.alert('El vehiculo no tiene cisternas'); | ||
| 211 | return; | ||
| 212 | } | ||
| 213 | $scope.vehiculos.push(vehiculo); | ||
| 214 | }, function() { | ||
| 215 | // funcion ejecutada cuando se cancela el modal | ||
| 216 | }); | ||
| 217 | }; | ||
| 218 | $scope.seleccionarFechaReparto = function() { | ||
| 219 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { | ||
| 220 | setearFecha(fecha); | ||
| 221 | }); | ||
| 222 | }; | ||
| 223 | 208 | ||
| 224 | function actualizarMarcadores (filtros) { | 209 | function actualizarMarcadores(filtros) { |
| 225 | var marcadores = []; | 210 | var marcadores = []; |
| 226 | if (filtros.cliente && filtros.remito === undefined) { | 211 | if (filtros.cliente && filtros.remito === undefined) { |
| 227 | 212 | ||
| 228 | $scope.marcadores.forEach( function (marcador) { | 213 | $scope.marcadores.forEach(function (marcador) { |
| 229 | if (marcador.notaPedido.cliente.NOM === filtros.cliente) { | 214 | if (marcador.notaPedido.cliente.NOM === filtros.cliente) { |
| 230 | marcadores.push(marcador); | 215 | marcadores.push(marcador); |
| 231 | } | 216 | } |
| 232 | }); | 217 | }); |
| 233 | 218 | ||
| 234 | if (marcadores.length === 0) { | 219 | if (marcadores.length === 0) { |
| 235 | focaModalService.alert('No se encontraron coincidencias en la busqueda') | 220 | focaModalService.alert('No se encontraron coincidencias en la busqueda') |
| 236 | .then(function (data) { | 221 | .then(function (data) { |
| 237 | if (data) { | 222 | if (data) $scope.marcadoresFiltro = marcadores; |
| 238 | $scope.marcadoresFiltro = marcadores; | 223 | }); |
| 239 | } | 224 | $scope.$broadcast('cleanCabecera'); |
| 240 | }); | 225 | setearFecha(new Date()); |
| 241 | $scope.$broadcast('cleanCabecera'); | 226 | return; |
| 242 | setearFecha(new Date()); | 227 | } else { |
| 243 | return; | 228 | $scope.marcadoresFiltro = marcadores; |
| 244 | } else { | 229 | $scope.$broadcast('addCabecera', { |
| 245 | $scope.marcadoresFiltro = marcadores; | 230 | label: 'Cliente:', |
| 246 | $scope.$broadcast('addCabecera', { | 231 | valor: filtros.cliente |
| 247 | label: 'Cliente:', | 232 | }); |
| 248 | valor: filtros.cliente | ||
| 249 | }); | ||
| 250 | } | ||
| 251 | } else { | ||
| 252 | $scope.marcadores.forEach( function (marcador) { | ||
| 253 | if (filtros.remito.id === marcador.notaPedido.remito.id) { | ||
| 254 | marcadores.push(marcador); | ||
| 255 | } | ||
| 256 | }); | ||
| 257 | if (marcadores.length === 0) { | ||
| 258 | focaModalService.alert('No se encontraron coincidencias en la busqueda') | ||
| 259 | .then(function (data) { | ||
| 260 | if (data) { | ||
| 261 | $scope.marcadoresFiltro = marcadores; | ||
| 262 | } | ||
| 263 | }); | ||
| 264 | $scope.$broadcast('cleanCabecera'); | ||
| 265 | setearFecha(new Date()); | ||
| 266 | return; | ||
| 267 | } else { | ||
| 268 | $scope.marcadoresFiltro = marcadores; | ||
| 269 | $scope.$broadcast('addCabecera', { | ||
| 270 | label: 'Cliente:', | ||
| 271 | valor: filtros.cliente | ||
| 272 | }); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | 233 | } |
| 276 | 234 | } else { | |
| 277 | function setearFecha(fecha) { | 235 | $scope.marcadores.forEach(function (marcador) { |
| 278 | $scope.fechaReparto = fecha; | 236 | if (filtros.remito.id === marcador.notaPedido.remito.id) marcadores.push(marcador); |
| 279 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); | 237 | }); |
| 280 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res){ | 238 | if (marcadores.length === 0) { |
| 281 | $scope.vehiculos = res.data; | 239 | focaModalService.alert('No se encontraron coincidencias en la busqueda') |
| 282 | $scope.$broadcast('addCabecera', { | 240 | .then(function (data) { |
| 283 | label: 'Fecha:', | 241 | if (data) $scope.marcadoresFiltro = marcadores; |
| 284 | valor: fecha.toLocaleDateString() | ||
| 285 | }); | ||
| 286 | }); | 242 | }); |
| 243 | $scope.$broadcast('cleanCabecera'); | ||
| 244 | setearFecha(new Date()); | ||
| 245 | return; | ||
| 246 | } else { | ||
| 247 | $scope.marcadoresFiltro = marcadores; | ||
| 248 | $scope.$broadcast('addCabecera', { | ||
| 249 | label: 'Cliente:', | ||
| 250 | valor: filtros.cliente | ||
| 251 | }); | ||
| 287 | } | 252 | } |
| 253 | } | ||
| 254 | } | ||
| 288 | 255 | ||
| 289 | function getSeguimiento() { | 256 | function setearFecha(fecha) { |
| 290 | var desde = new Date('1900/01/01'); | 257 | $scope.fechaReparto = fecha; |
| 291 | var hasta = new Date('2099/01/01'); | 258 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); |
| 292 | if ($scope.fechaDesde) { | 259 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function (res) { |
| 293 | var fechaDesde = $scope.fechaDesde; | 260 | $scope.vehiculos = res.data; |
| 294 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); | 261 | $scope.$broadcast('addCabecera', { |
| 295 | desde = new Date(desde); | 262 | label: 'Fecha:', |
| 296 | } | 263 | valor: fecha.toLocaleDateString() |
| 297 | if ($scope.fechaHasta) { | 264 | }); |
| 298 | var fechaHasta = $scope.fechaHasta; | 265 | }); |