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