Commit 91feb3b0e618b9ba1f256d442c42fe589d99fc92

Authored by Eric Fernandez
1 parent 3aa098359e
Exists in master and in 1 other branch develop

refactor columnas

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