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