Commit 4f696483ae02ebf3e6cf9c7d56584cb92f65ab48
1 parent
fc40aa4296
Exists in
master
obtengo vehiculos por fecha
Showing
1 changed file
with
11 additions
and
6 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: 'abmChofer.png' | 17 | image: 'abmChofer.png' |
18 | }; | 18 | }; |
19 | $scope.botonera = [transportista, fecha]; | 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 | // TODO: obtener vehiculos con remitos cargados para esa fecha que no han sido confirmados | 37 | |
38 | // focaLogisticaPedidoRutaService.getVehiculosByIdUsuario().then(function(res) { | ||
39 | // $scope.vehiculos = res.data; | ||
40 | // }); | ||
41 | 38 | ||
42 | $scope.general = function() { | 39 | $scope.general = function() { |
43 | $scope.idVendedor = 0; | 40 | $scope.idVendedor = 0; |
44 | getSeguimiento(); | 41 | getSeguimiento(); |
45 | $scope.$broadcast('removeCabecera', cabecera); | 42 | $scope.$broadcast('removeCabecera', cabecera); |
46 | $scope.$broadcast('addCabecera',{ | 43 | $scope.$broadcast('addCabecera',{ |
47 | label: 'General', | 44 | label: 'General', |
48 | valor: '' | 45 | valor: '' |
49 | }); | 46 | }); |
50 | }; | 47 | }; |
51 | 48 | ||
52 | $scope.cargar = function(idVehiculo, punto) { | 49 | $scope.cargar = function(idVehiculo, punto) { |
53 | if(!$scope.fechaReparto) { | 50 | if(!$scope.fechaReparto) { |
54 | focaModalService.alert('elija primero una fecha de reparto'); | 51 | focaModalService.alert('Primero seleccione fecha de reparto'); |
55 | return; | 52 | return; |
56 | } | 53 | } |
57 | var idRemito; | 54 | var idRemito; |
58 | if(punto === -1) { | 55 | if(punto === -1) { |
59 | idRemito = -1; | 56 | idRemito = -1; |
60 | }else { | 57 | }else { |
61 | idRemito = JSON.parse(punto).notaPedido.remito.id; | 58 | idRemito = JSON.parse(punto).notaPedido.remito.id; |
62 | } | 59 | } |
63 | var modalInstance = $uibModal.open( | 60 | var modalInstance = $uibModal.open( |
64 | { | 61 | { |
65 | ariaLabelledBy: 'Busqueda de Vehiculo', | 62 | ariaLabelledBy: 'Busqueda de Vehiculo', |
66 | templateUrl: 'foca-detalle-vehiculo.html', | 63 | templateUrl: 'foca-detalle-vehiculo.html', |
67 | controller: 'focaDetalleVehiculo', | 64 | controller: 'focaDetalleVehiculo', |
68 | size: 'lg', | 65 | size: 'lg', |
69 | resolve: { | 66 | resolve: { |
70 | idVehiculo: function() {return idVehiculo;}, | 67 | idVehiculo: function() {return idVehiculo;}, |
71 | idRemito: function() {return idRemito;}, | 68 | idRemito: function() {return idRemito;}, |
72 | fechaReparto: function() {return $scope.fechaReparto;} | 69 | fechaReparto: function() {return $scope.fechaReparto;} |
73 | } | 70 | } |
74 | } | 71 | } |
75 | ); | 72 | ); |
76 | modalInstance.result.then(function() { | 73 | modalInstance.result.then(function() { |
77 | }, function() { | 74 | }, function() { |
78 | }); | 75 | }); |
79 | }; | 76 | }; |
80 | 77 | ||
81 | $scope.quitarVehiculo = function(vehiculo) { | 78 | $scope.quitarVehiculo = function(vehiculo) { |
82 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + | 79 | focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + |
83 | vehiculo.codigo + '?').then(function() { | 80 | vehiculo.codigo + '?').then(function() { |
84 | eliminarVehiculo(vehiculo); | 81 | eliminarVehiculo(vehiculo); |
85 | }); | 82 | }); |
86 | }; | 83 | }; |
87 | 84 | ||
88 | $scope.hacerHojaRuta = function(vehiculo) { | 85 | $scope.hacerHojaRuta = function(vehiculo) { |
86 | if(!$scope.fechaReparto) { | ||
87 | focaModalService.alert('Primero seleccione fecha de reparto'); | ||
88 | return; | ||
89 | } | ||
89 | var modalInstance = $uibModal.open( | 90 | var modalInstance = $uibModal.open( |
90 | { | 91 | { |
91 | ariaLabelledBy: 'Creación hoja ruta', | 92 | ariaLabelledBy: 'Creación hoja ruta', |
92 | templateUrl: 'foca-modal-crear-hoja-ruta.html', | 93 | templateUrl: 'foca-modal-crear-hoja-ruta.html', |
93 | controller: 'focaModalCrearHojaRuta', | 94 | controller: 'focaModalCrearHojaRuta', |
94 | size: 'lg', | 95 | size: 'lg', |
95 | resolve: { | 96 | resolve: { |
96 | idVehiculo: function() {return vehiculo.id;} | 97 | idVehiculo: function() {return vehiculo.id;} |
97 | } | 98 | } |
98 | } | 99 | } |
99 | ); | 100 | ); |
100 | modalInstance.result.then(function() { | 101 | modalInstance.result.then(function() { |
101 | 102 | ||
102 | }, function() { | 103 | }, function() { |
103 | //usar cuando se cancela el modal | 104 | //usar cuando se cancela el modal |
104 | }); | 105 | }); |
105 | }; | 106 | }; |
106 | 107 | ||
107 | $scope.arrastra = function() { | 108 | $scope.arrastra = function() { |
108 | $scope.arrastrando = true; | 109 | $scope.arrastrando = true; |
109 | $scope.$digest(); | 110 | $scope.$digest(); |
110 | }; | 111 | }; |
111 | 112 | ||
112 | $scope.noArrastra = function() { | 113 | $scope.noArrastra = function() { |
113 | $scope.arrastrando = false; | 114 | $scope.arrastrando = false; |
114 | $scope.$digest(); | 115 | $scope.$digest(); |
115 | }; | 116 | }; |
116 | 117 | ||
117 | $scope.individual = function() { | 118 | $scope.individual = function() { |
118 | $scope.idVendedor = -1; | 119 | $scope.idVendedor = -1; |
119 | }; | 120 | }; |
120 | 121 | ||
121 | $scope.mostrarDetalle = function() { | 122 | $scope.mostrarDetalle = function() { |
122 | $scope.detalle = true; | 123 | $scope.detalle = true; |
123 | }; | 124 | }; |
124 | 125 | ||
125 | $scope.salir = function() { | 126 | $scope.salir = function() { |
126 | $location.path('/'); | 127 | $location.path('/'); |
127 | }; | 128 | }; |
128 | 129 | ||
129 | $scope.search = function() { | 130 | $scope.search = function() { |
130 | getSeguimiento(); | 131 | getSeguimiento(); |
131 | }; | 132 | }; |
132 | 133 | ||
133 | $scope.fecha = function() { | 134 | $scope.fecha = function() { |
134 | getSeguimiento(); | 135 | getSeguimiento(); |
135 | }; | 136 | }; |
136 | 137 | ||
137 | $scope.seleccionarUnidad = function() { | 138 | $scope.seleccionarUnidad = function() { |
138 | var modalInstance = $uibModal.open( | 139 | var modalInstance = $uibModal.open( |
139 | { | 140 | { |
140 | ariaLabelledBy: 'Busqueda de Transportista', | 141 | ariaLabelledBy: 'Busqueda de Transportista', |
141 | templateUrl: 'modal-proveedor.html', | 142 | templateUrl: 'modal-proveedor.html', |
142 | controller: 'focaModalProveedorCtrl', | 143 | controller: 'focaModalProveedorCtrl', |
143 | size: 'lg', | 144 | size: 'lg', |
144 | resolve: { | 145 | resolve: { |
145 | transportista: function() { | 146 | transportista: function() { |
146 | return true; | 147 | return true; |
147 | } | 148 | } |
148 | } | 149 | } |
149 | } | 150 | } |
150 | ); | 151 | ); |
151 | modalInstance.result.then(function(transportista) { | 152 | modalInstance.result.then(function(transportista) { |
152 | $scope.seleccionarVehiculo(transportista.COD); | 153 | $scope.seleccionarVehiculo(transportista.COD); |
153 | }); | 154 | }); |
154 | }; | 155 | }; |
155 | 156 | ||
156 | $scope.seleccionarVehiculo = function(idTransportista) { | 157 | $scope.seleccionarVehiculo = function(idTransportista) { |
157 | var query = '/vehiculo/transportista/' + idTransportista; | 158 | var query = '/vehiculo/transportista/' + idTransportista; |
158 | var columnas = { | 159 | var columnas = { |
159 | nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], | 160 | nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], |
160 | propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] | 161 | propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] |
161 | }; | 162 | }; |
162 | var titulo = 'Búsqueda de vehiculos'; | 163 | var titulo = 'Búsqueda de vehiculos'; |
163 | focaModalService.modal(columnas, query, titulo).then( | 164 | focaModalService.modal(columnas, query, titulo).then( |
164 | function(vehiculo) { | 165 | function(vehiculo) { |
165 | var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); | 166 | var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); |
166 | if(existe.length) { | 167 | if(existe.length) { |
167 | focaModalService.alert('El vehiculo ya ha sido cargado'); | 168 | focaModalService.alert('El vehiculo ya ha sido cargado'); |
168 | return; | 169 | return; |
169 | } | 170 | } |
170 | if(!vehiculo.cisternas.length) { | 171 | if(!vehiculo.cisternas.length) { |
171 | focaModalService.alert('El vehiculo no tiene cisternas'); | 172 | focaModalService.alert('El vehiculo no tiene cisternas'); |
172 | return; | 173 | return; |
173 | } | 174 | } |
174 | $scope.vehiculos.push(vehiculo); | 175 | $scope.vehiculos.push(vehiculo); |
175 | }, function() { | 176 | }, function() { |
176 | // funcion ejecutada cuando se cancela el modal | 177 | // funcion ejecutada cuando se cancela el modal |
177 | }); | 178 | }); |
178 | }; | 179 | }; |
179 | 180 | ||
180 | $scope.seleccionarFechaReparto = function() { | 181 | $scope.seleccionarFechaReparto = function() { |
181 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { | 182 | focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { |
182 | $scope.$broadcast('addCabecera',{ | 183 | $scope.$broadcast('addCabecera',{ |
183 | label: 'Fecha:', | 184 | label: 'Fecha:', |
184 | valor: fecha.toLocaleDateString() | 185 | valor: fecha.toLocaleDateString() |
185 | }); | 186 | }); |
186 | $scope.fechaReparto = fecha; | 187 | $scope.fechaReparto = fecha; |
188 | focaLogisticaPedidoRutaService.setFechaReparto(fecha); | ||
189 | focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res) { | ||
190 | $scope.vehiculos = res.data; | ||
191 | }); | ||
187 | }); | 192 | }); |
188 | }; | 193 | }; |
189 | 194 | ||
190 | function getSeguimiento() { | 195 | function getSeguimiento() { |
191 | var desde = new Date('1900/01/01'); | 196 | var desde = new Date('1900/01/01'); |
192 | var hasta = new Date('2099/01/01'); | 197 | var hasta = new Date('2099/01/01'); |
193 | if($scope.fechaDesde) { | 198 | if($scope.fechaDesde) { |
194 | var fechaDesde = $scope.fechaDesde; | 199 | var fechaDesde = $scope.fechaDesde; |
195 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); | 200 | desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); |
196 | desde = new Date(desde); | 201 | desde = new Date(desde); |
197 | } | 202 | } |
198 | if($scope.fechaHasta) { | 203 | if($scope.fechaHasta) { |
199 | var fechaHasta = $scope.fechaHasta; | 204 | var fechaHasta = $scope.fechaHasta; |
200 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); | 205 | hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); |
201 | hasta = hasta.setDate(hasta.getDate() + 1); | 206 | hasta = hasta.setDate(hasta.getDate() + 1); |
202 | hasta = new Date(hasta); | 207 | hasta = new Date(hasta); |
203 | } | 208 | } |
204 | var datos = { | 209 | var datos = { |
205 | actividad: $scope.actividad, | 210 | actividad: $scope.actividad, |
206 | idUsuario: $scope.idVendedor, | 211 | idUsuario: $scope.idVendedor, |
207 | fechaDesde: desde, | 212 | fechaDesde: desde, |
208 | fechaHasta: hasta, | 213 | fechaHasta: hasta, |
209 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? | 214 | asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? |
210 | false : undefined) | 215 | false : undefined) |
211 | }; | 216 | }; |
212 | 217 | ||
213 | $scope.datosBuscados = { | 218 | $scope.datosBuscados = { |
214 | actividad: $scope.actividad, | 219 | actividad: $scope.actividad, |
215 | individual: $scope.idVendedor ? true : false | 220 | individual: $scope.idVendedor ? true : false |
216 | }; | 221 | }; |
217 | 222 | ||
218 | focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { | 223 | focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { |
219 | if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { | 224 | if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { |
220 | $scope.marcadores = datos.data; | 225 | $scope.marcadores = datos.data; |
221 | } | 226 | } |
222 | }); | 227 | }); |
223 | } | 228 | } |
224 | 229 | ||
225 | function eliminarVehiculo(vehiculo) { | 230 | function eliminarVehiculo(vehiculo) { |
226 | focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { | 231 | focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { |
227 | if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { | 232 | if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { |
228 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 233 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
229 | }else { | 234 | }else { |
230 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + | 235 | focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + |
231 | 'tiene remitos asociados').then(function() { | 236 | 'tiene remitos asociados').then(function() { |
232 | $scope.hacerHojaRuta(vehiculo); | 237 | $scope.hacerHojaRuta(vehiculo); |
233 | }); | 238 | }); |
234 | } | 239 | } |
235 | }); | 240 | }); |
236 | } | 241 | } |
237 | $interval(function() { | 242 | $interval(function() { |
238 | getSeguimiento(); | 243 | getSeguimiento(); |
239 | }, 5000); | 244 | }, 5000); |