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