Commit 94dc34b5e1c9a9b6d8a63a5f5e48249e747bd718

Authored by Eric Fernandez
1 parent 521305bca4
Exists in master

reemplazo modal vehículo por modal parametrizable

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