Commit 3db891c88e7bdb2686f52f67593a0cea87a94b78

Authored by Eric Fernandez
1 parent 1e30fd1c90
Exists in master

muestro vehiculos del usuario

Showing 2 changed files with 6 additions and 0 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 $scope.botonera = ['Transportista']; 11 $scope.botonera = ['Transportista'];
12 var cabecera = ''; 12 var cabecera = '';
13 13
14 $scope.idVendedor = 0; 14 $scope.idVendedor = 0;
15 $scope.marcadores = []; 15 $scope.marcadores = [];
16 $scope.vehiculos = []; 16 $scope.vehiculos = [];
17 getSeguimiento(); 17 getSeguimiento();
18 $scope.arrastrando = false; 18 $scope.arrastrando = false;
19 $scope.general = function() { 19 $scope.general = function() {
20 $scope.idVendedor = 0; 20 $scope.idVendedor = 0;
21 getSeguimiento(); 21 getSeguimiento();
22 }; 22 };
23 23
24 //SETEO BOTONERA LATERAL 24 //SETEO BOTONERA LATERAL
25 focaBotoneraLateralService.showSalir(true); 25 focaBotoneraLateralService.showSalir(true);
26 focaBotoneraLateralService.showPausar(false); 26 focaBotoneraLateralService.showPausar(false);
27 focaBotoneraLateralService.showGuardar(false); 27 focaBotoneraLateralService.showGuardar(false);
28 28
29 focaLogisticaPedidoRutaService.getVehiculosByIdUsuario().then(function(res) {
30 $scope.vehiculos = res.data;
31 });
29 32
30 $scope.general = function() { 33 $scope.general = function() {
31 $scope.idVendedor = 0; 34 $scope.idVendedor = 0;
32 getSeguimiento(); 35 getSeguimiento();
33 $scope.$broadcast('removeCabecera', cabecera); 36 $scope.$broadcast('removeCabecera', cabecera);
34 $scope.$broadcast('addCabecera',{ 37 $scope.$broadcast('addCabecera',{
35 label: 'General', 38 label: 'General',
36 valor: '' 39 valor: ''
37 }); 40 });
38 }; 41 };
39 42
40 $scope.cargar = function(idVehiculo, punto) { 43 $scope.cargar = function(idVehiculo, punto) {
41 var idRemito; 44 var idRemito;
42 if(punto === -1) { 45 if(punto === -1) {
43 idRemito = -1; 46 idRemito = -1;
44 }else { 47 }else {
45 idRemito = JSON.parse(punto).notaPedido.remito.id; 48 idRemito = JSON.parse(punto).notaPedido.remito.id;
46 } 49 }
47 var modalInstance = $uibModal.open( 50 var modalInstance = $uibModal.open(
48 { 51 {
49 ariaLabelledBy: 'Busqueda de Vehiculo', 52 ariaLabelledBy: 'Busqueda de Vehiculo',
50 templateUrl: 'foca-detalle-vehiculo.html', 53 templateUrl: 'foca-detalle-vehiculo.html',
51 controller: 'focaDetalleVehiculo', 54 controller: 'focaDetalleVehiculo',
52 size: 'lg', 55 size: 'lg',
53 resolve: { 56 resolve: {
54 idVehiculo: function() {return idVehiculo;}, 57 idVehiculo: function() {return idVehiculo;},
55 idRemito: function() {return idRemito;} 58 idRemito: function() {return idRemito;}
56 } 59 }
57 } 60 }
58 ); 61 );
59 modalInstance.result.then(function() { 62 modalInstance.result.then(function() {
60 }, function() { 63 }, function() {
61 }); 64 });
62 }; 65 };
63 66
64 $scope.quitarVehiculo = function(vehiculo) { 67 $scope.quitarVehiculo = function(vehiculo) {
65 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + 68 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' +
66 vehiculo.codigo + '?').then(function() { 69 vehiculo.codigo + '?').then(function() {
67 eliminarVehiculo(vehiculo); 70 eliminarVehiculo(vehiculo);
68 }); 71 });
69 }; 72 };
70 73
71 $scope.hacerHojaRuta = function(vehiculo) { 74 $scope.hacerHojaRuta = function(vehiculo) {
72 var modalInstance = $uibModal.open( 75 var modalInstance = $uibModal.open(
73 { 76 {
74 ariaLabelledBy: 'Creación hoja ruta', 77 ariaLabelledBy: 'Creación hoja ruta',
75 templateUrl: 'foca-modal-crear-hoja-ruta.html', 78 templateUrl: 'foca-modal-crear-hoja-ruta.html',
76 controller: 'focaModalCrearHojaRuta', 79 controller: 'focaModalCrearHojaRuta',
77 size: 'lg', 80 size: 'lg',
78 resolve: { 81 resolve: {
79 idVehiculo: function() {return vehiculo.id;} 82 idVehiculo: function() {return vehiculo.id;}
80 } 83 }
81 } 84 }
82 ); 85 );
83 modalInstance.result.then(function() { 86 modalInstance.result.then(function() {
84 87
85 }, function() { 88 }, function() {
86 //usar cuando se cancela el modal 89 //usar cuando se cancela el modal
87 }); 90 });
88 }; 91 };
89 92
90 $scope.arrastra = function() { 93 $scope.arrastra = function() {
91 $scope.arrastrando = true; 94 $scope.arrastrando = true;
92 $scope.$digest(); 95 $scope.$digest();
93 }; 96 };
94 97
95 $scope.noArrastra = function() { 98 $scope.noArrastra = function() {
96 $scope.arrastrando = false; 99 $scope.arrastrando = false;
97 $scope.$digest(); 100 $scope.$digest();
98 }; 101 };
99 102
100 $scope.individual = function() { 103 $scope.individual = function() {
101 $scope.idVendedor = -1; 104 $scope.idVendedor = -1;
102 }; 105 };
103 106
104 $scope.mostrarDetalle = function() { 107 $scope.mostrarDetalle = function() {
105 $scope.detalle = true; 108 $scope.detalle = true;
106 }; 109 };
107 110
108 $scope.salir = function() { 111 $scope.salir = function() {
109 $location.path('/'); 112 $location.path('/');
110 }; 113 };
111 114
112 $scope.search = function(key) { 115 $scope.search = function(key) {
113 if (key === 13) { 116 if (key === 13) {
114 $scope.idVendedor = $scope.idVendedorInput; 117 $scope.idVendedor = $scope.idVendedorInput;
115 getSeguimiento(); 118 getSeguimiento();
116 $scope.$broadcast('removeCabecera', 'General'); 119 $scope.$broadcast('removeCabecera', 'General');
117 $scope.$broadcast('addCabecera', { 120 $scope.$broadcast('addCabecera', {
118 label: cabecera, 121 label: cabecera,
119 valor: $scope.idVendedorInput 122 valor: $scope.idVendedorInput
120 }); 123 });
121 } 124 }
122 }; 125 };
123 126
124 $scope.fecha = function() { 127 $scope.fecha = function() {
125 getSeguimiento(); 128 getSeguimiento();
126 }; 129 };
127 130
128 $scope.seleccionarTransportista = function() { 131 $scope.seleccionarTransportista = function() {
129 var modalInstance = $uibModal.open( 132 var modalInstance = $uibModal.open(
130 { 133 {
131 ariaLabelledBy: 'Busqueda de Transportista', 134 ariaLabelledBy: 'Busqueda de Transportista',
132 templateUrl: 'modal-proveedor.html', 135 templateUrl: 'modal-proveedor.html',
133 controller: 'focaModalProveedorCtrl', 136 controller: 'focaModalProveedorCtrl',
134 size: 'lg', 137 size: 'lg',
135 resolve: { 138 resolve: {
136 transportista: function() { 139 transportista: function() {
137 return true; 140 return true;
138 } 141 }
139 } 142 }
140 } 143 }
141 ); 144 );
142 modalInstance.result.then(function(transportista) { 145 modalInstance.result.then(function(transportista) {
143 $scope.seleccionarVehiculo(transportista.COD); 146 $scope.seleccionarVehiculo(transportista.COD);
144 }); 147 });
145 }; 148 };
146 149
147 $scope.seleccionarVehiculo = function(idTransportista) { 150 $scope.seleccionarVehiculo = function(idTransportista) {
148 var query = '/vehiculo/transportista/' + idTransportista; 151 var query = '/vehiculo/transportista/' + idTransportista;
149 var columnas = { 152 var columnas = {
150 nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], 153 nombre: ['Código', 'tractor', 'Semi', 'Capacidad'],
151 propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] 154 propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas']
152 }; 155 };
153 var titulo = 'Búsqueda de vehiculos'; 156 var titulo = 'Búsqueda de vehiculos';
154 focaModalService.modal(columnas, query, titulo).then( 157 focaModalService.modal(columnas, query, titulo).then(
155 function(vehiculo) { 158 function(vehiculo) {
156 var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); 159 var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id});
157 if(existe.length) { 160 if(existe.length) {
158 focaModalService.alert('El vehiculo ya ha sido cargado'); 161 focaModalService.alert('El vehiculo ya ha sido cargado');
159 return; 162 return;
160 } 163 }
161 if(!vehiculo.cisternas.length) { 164 if(!vehiculo.cisternas.length) {
162 focaModalService.alert('El vehiculo no tiene cisternas'); 165 focaModalService.alert('El vehiculo no tiene cisternas');
163 return; 166 return;
164 } 167 }
165 $scope.vehiculos.push(vehiculo); 168 $scope.vehiculos.push(vehiculo);
166 }, function() { 169 }, function() {
167 // funcion ejecutada cuando se cancela el modal 170 // funcion ejecutada cuando se cancela el modal
168 }); 171 });
169 }; 172 };
170 173
171 function getSeguimiento() { 174 function getSeguimiento() {
172 var desde = new Date('1900/01/01'); 175 var desde = new Date('1900/01/01');
173 var hasta = new Date('2099/01/01'); 176 var hasta = new Date('2099/01/01');
174 if ($scope.now) { 177 if ($scope.now) {
175 var now = $scope.now; 178 var now = $scope.now;
176 desde = new Date(new Date(now.setHours(0)).setMinutes(0)); 179 desde = new Date(new Date(now.setHours(0)).setMinutes(0));
177 desde = desde.setDate(desde.getDate() - 1); 180 desde = desde.setDate(desde.getDate() - 1);
178 desde = new Date(desde); 181 desde = new Date(desde);
179 } 182 }
180 var datos = { 183 var datos = {
181 actividad: $scope.actividad, 184 actividad: $scope.actividad,
182 idUsuario: $scope.idVendedor, 185 idUsuario: $scope.idVendedor,
183 fechaDesde: desde, 186 fechaDesde: desde,
184 fechaHasta: hasta 187 fechaHasta: hasta
185 }; 188 };
186 189
187 $scope.datosBuscados = { 190 $scope.datosBuscados = {
188 actividad: $scope.actividad, 191 actividad: $scope.actividad,
189 individual: $scope.idVendedor ? true : false 192 individual: $scope.idVendedor ? true : false
190 }; 193 };
191 194
192 focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { 195 focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) {
193 if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { 196 if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) {
194 $scope.marcadores = datos.data; 197 $scope.marcadores = datos.data;
195 } 198 }
196 }); 199 });
197 } 200 }
198 201
199 function eliminarVehiculo(vehiculo) { 202 function eliminarVehiculo(vehiculo) {
200 focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { 203 focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) {
201 if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { 204 if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) {
202 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 205 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
203 }else { 206 }else {
204 focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + 207 focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' +
205 'tiene remitos asociados').then(function() { 208 'tiene remitos asociados').then(function() {
206 $scope.hacerHojaRuta(vehiculo); 209 $scope.hacerHojaRuta(vehiculo);
207 }); 210 });
208 } 211 }
209 }); 212 });
210 } 213 }
211 $interval(function() { 214 $interval(function() {
212 getSeguimiento(); 215 getSeguimiento();
213 }, 5000); 216 }, 5000);
214 } 217 }
215 ]); 218 ]);
216 219
1 angular.module('focaLogisticaPedidoRuta') 1 angular.module('focaLogisticaPedidoRuta')
2 .service( 2 .service(
3 'focaLogisticaPedidoRutaService', [ 3 'focaLogisticaPedidoRutaService', [
4 '$http', 4 '$http',
5 '$cookies', 5 '$cookies',
6 'API_ENDPOINT', 6 'API_ENDPOINT',
7 '$filter', 7 '$filter',
8 function($http, $cookies, API_ENDPOINT, $filter) { 8 function($http, $cookies, API_ENDPOINT, $filter) {
9 return { 9 return {
10 idUsuario: $cookies.get('idUsuario'), 10 idUsuario: $cookies.get('idUsuario'),
11 obtenerActividad: function(parametros) { 11 obtenerActividad: function(parametros) {
12 return $http.post(API_ENDPOINT.URL + '/seguimiento/filtros', parametros); 12 return $http.post(API_ENDPOINT.URL + '/seguimiento/filtros', parametros);
13 }, 13 },
14 obtenerVehiculoById: function(idVehiculo) { 14 obtenerVehiculoById: function(idVehiculo) {
15 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + idVehiculo); 15 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + idVehiculo);
16 }, 16 },
17 obtenerRemitoById: function(idRemito) { 17 obtenerRemitoById: function(idRemito) {
18 return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito); 18 return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito);
19 }, 19 },
20 guardarCisternas: function(cisterna, idRemito) { 20 guardarCisternas: function(cisterna, idRemito) {
21 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' + 21 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' +
22 this.idUsuario + '/' + idRemito,cisterna); 22 this.idUsuario + '/' + idRemito,cisterna);
23 }, 23 },
24 numeroHojaRuta: function() { 24 numeroHojaRuta: function() {
25 return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente'); 25 return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente');
26 }, 26 },
27 getRemitos: function(idVehiculo) { 27 getRemitos: function(idVehiculo) {
28 return $http.get(API_ENDPOINT.URL + '/remito/sin-hoja-ruta/' +idVehiculo); 28 return $http.get(API_ENDPOINT.URL + '/remito/sin-hoja-ruta/' +idVehiculo);
29 }, 29 },
30 crearHojaRuta: function(hojaRuta) { 30 crearHojaRuta: function(hojaRuta) {
31 return $http.post(API_ENDPOINT.URL + '/hoja-ruta', hojaRuta); 31 return $http.post(API_ENDPOINT.URL + '/hoja-ruta', hojaRuta);
32 }, 32 },
33 desasociarRemitos: function(remitos, idVehiculo, sinRemitos) { 33 desasociarRemitos: function(remitos, idVehiculo, sinRemitos) {
34 var idsRemitos = []; 34 var idsRemitos = [];
35 for (var i = 0; i < remitos.length; i++) { 35 for (var i = 0; i < remitos.length; i++) {
36 idsRemitos.push(remitos[i].id); 36 idsRemitos.push(remitos[i].id);
37 } 37 }
38 return $http.post(API_ENDPOINT.URL + '/vehiculo/desasociar-remitos', 38 return $http.post(API_ENDPOINT.URL + '/vehiculo/desasociar-remitos',
39 { 39 {
40 idsRemitos: idsRemitos, 40 idsRemitos: idsRemitos,
41 idVehiculo: idVehiculo, 41 idVehiculo: idVehiculo,
42 vehiculoSinRemitos: sinRemitos 42 vehiculoSinRemitos: sinRemitos
43 }); 43 });
44 }, 44 },
45 obtenerRemitosDeCarga: function(remitos) { 45 obtenerRemitosDeCarga: function(remitos) {
46 var remitosRes = []; 46 var remitosRes = [];
47 for(var i = 0; i < remitos.cisternas.length; i++) { 47 for(var i = 0; i < remitos.cisternas.length; i++) {
48 procesoCistena(remitos.cisternas[i]); 48 procesoCistena(remitos.cisternas[i]);
49 } 49 }
50 function procesoCistena(cisterna) { 50 function procesoCistena(cisterna) {
51 for(var j = 0; j < cisterna.cisternaCarga.cisternaMovimientos.length; 51 for(var j = 0; j < cisterna.cisternaCarga.cisternaMovimientos.length;
52 j++) { 52 j++) {
53 procesoMovimiento( 53 procesoMovimiento(
54 cisterna.cisternaCarga.cisternaMovimientos[j]); 54 cisterna.cisternaCarga.cisternaMovimientos[j]);
55 } 55 }
56 } 56 }
57 function procesoMovimiento(movimiento) { 57 function procesoMovimiento(movimiento) {
58 if(!movimiento.anulado && movimiento.remito && 58 if(!movimiento.anulado && movimiento.remito &&
59 !movimiento.remito.idHojaRuta) { 59 !movimiento.remito.idHojaRuta) {
60 var remito = movimiento.remito; 60 var remito = movimiento.remito;
61 var yaEstaCargado = $filter('filter')(remitosRes, {id: remito.id}); 61 var yaEstaCargado = $filter('filter')(remitosRes, {id: remito.id});
62 if(!yaEstaCargado.length && movimiento.metodo === 'carga') { 62 if(!yaEstaCargado.length && movimiento.metodo === 'carga') {
63 remitosRes.push(remito); 63 remitosRes.push(remito);
64 } 64 }
65 } 65 }
66 } 66 }
67 return remitosRes; 67 return remitosRes;
68 },
69 getVehiculosByIdUsuario: function() {
70 return $http.get(API_ENDPOINT.URL + '/vehiculo/usuario/' + this.idUsuario);
68 } 71 }
69 }; 72 };
70 }]); 73 }]);
71 74