Commit 1f7131cfa824854523ad490ec821d07d8af98b89

Authored by Eric Fernandez
Exists in master

Merge branch 'develop' into 'master'

Develop

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