Commit bfc813dc28edcad0041d2d61bf97b459bd790673

Authored by Eric Fernandez
1 parent 65544829dd
Exists in master and in 1 other branch develop

leyenda correcta

Showing 1 changed file with 1 additions and 1 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', 1 angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'focaCrearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 function($scope, $uibModal, $location, $filter, $timeout, 11 function($scope, $uibModal, $location, $filter, $timeout,
12 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) { 12 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) {
13 13
14 $scope.botonera = focaCrearHojaRutaService.getBotonera(); 14 $scope.botonera = focaCrearHojaRutaService.getBotonera();
15 $scope.datepickerAbierto = false; 15 $scope.datepickerAbierto = false;
16 16
17 $scope.show = false; 17 $scope.show = false;
18 $scope.cargando = true; 18 $scope.cargando = true;
19 19
20 function nuevaHojaRuta() { 20 function nuevaHojaRuta() {
21 $scope.hojaRuta = { 21 $scope.hojaRuta = {
22 fecha: new Date(), 22 fecha: new Date(),
23 litros: 0, 23 litros: 0,
24 chofer: {}, 24 chofer: {},
25 vehiculo: { 25 vehiculo: {
26 capacidad: 0 26 capacidad: 0
27 }, 27 },
28 transportista: {}, 28 transportista: {},
29 tarifario: { 29 tarifario: {
30 costo: null 30 costo: null
31 } 31 }
32 }; 32 };
33 } 33 }
34 nuevaHojaRuta(); 34 nuevaHojaRuta();
35 $scope.showCabecera = true; 35 $scope.showCabecera = true;
36 36
37 $scope.now = new Date(); 37 $scope.now = new Date();
38 $scope.puntoVenta = '0000'; 38 $scope.puntoVenta = '0000';
39 $scope.comprobante = '00000000'; 39 $scope.comprobante = '00000000';
40 $scope.remitosTabla = []; 40 $scope.remitosTabla = [];
41 $scope.idLista = undefined; 41 $scope.idLista = undefined;
42 42
43 //SETEO BOTONERA LATERAL 43 //SETEO BOTONERA LATERAL
44 $timeout(function() { 44 $timeout(function() {
45 focaBotoneraLateralService.showSalir(true); 45 focaBotoneraLateralService.showSalir(true);
46 focaBotoneraLateralService.showPausar(true); 46 focaBotoneraLateralService.showPausar(true);
47 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 47 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
48 }); 48 });
49 49
50 focaCrearHojaRutaService.getNumeroHojaRuta().then( 50 focaCrearHojaRutaService.getNumeroHojaRuta().then(
51 function(res) { 51 function(res) {
52 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); 52 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4);
53 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 53 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
54 }, 54 },
55 function(err) { 55 function(err) {
56 focaModalService.alert('La terminal no esta configurada correctamente'); 56 focaModalService.alert('La terminal no esta configurada correctamente');
57 console.info(err); 57 console.info(err);
58 } 58 }
59 ); 59 );
60 $scope.crearHojaRuta = function() { 60 $scope.crearHojaRuta = function() {
61 if(!$scope.remitosTabla.length) { 61 if(!$scope.remitosTabla.length) {
62 focaModalService.alert('Ingrese Remitos'); 62 focaModalService.alert('Ingrese Remitos');
63 return; 63 return;
64 } 64 }
65 if(!$scope.hojaRuta.chofer.id) { 65 if(!$scope.hojaRuta.chofer.id) {
66 focaModalService.alert('Ingrese Chofer'); 66 focaModalService.alert('Ingrese Chofer');
67 return; 67 return;
68 } 68 }
69 if(!$scope.hojaRuta.vehiculo.id) { 69 if(!$scope.hojaRuta.vehiculo.id) {
70 focaModalService.alert('Ingrese Vehiculo'); 70 focaModalService.alert('Ingrese Vehiculo');
71 return; 71 return;
72 } 72 }
73 if(!$scope.hojaRuta.transportista.COD) { 73 if(!$scope.hojaRuta.transportista.COD) {
74 focaModalService.alert('Ingrese Transportista'); 74 focaModalService.alert('Ingrese Transportista');
75 return; 75 return;
76 } 76 }
77 if(!$scope.hojaRuta.tarifario.costo) { 77 if(!$scope.hojaRuta.tarifario.costo) {
78 focaModalService.alert('Ingrese Tarifario'); 78 focaModalService.alert('Ingrese Tarifario');
79 return; 79 return;
80 } 80 }
81 if(!$scope.hojaRuta.datosExtra) { 81 if(!$scope.hojaRuta.datosExtra) {
82 focaModalService.alert('Ingrese Datos extra'); 82 focaModalService.alert('Ingrese Datos extra');
83 return; 83 return;
84 } 84 }
85 var date = new Date(); 85 var date = new Date();
86 var save = { 86 var save = {
87 hojaRuta: { 87 hojaRuta: {
88 id: 0, 88 id: 0,
89 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 89 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
90 .replace('T', ' '), 90 .replace('T', ' '),
91 idTransportista: $scope.hojaRuta.transportista.COD, 91 idTransportista: $scope.hojaRuta.transportista.COD,
92 idChofer: $scope.hojaRuta.chofer.id, 92 idChofer: $scope.hojaRuta.chofer.id,
93 idVehiculo: $scope.hojaRuta.vehiculo.id, 93 idVehiculo: $scope.hojaRuta.vehiculo.id,
94 tarifaFlete: $scope.hojaRuta.tarifario.costo, 94 tarifaFlete: $scope.hojaRuta.tarifario.costo,
95 fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), 95 fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10),
96 estado: 0 96 estado: 0
97 }, 97 },
98 remitos: $scope.remitosTabla 98 remitos: $scope.remitosTabla
99 }; 99 };
100 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 100 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
101 focaCrearHojaRutaService.crearHojaRuta(save).then( 101 focaCrearHojaRutaService.crearHojaRuta(save).then(
102 function(data) { 102 function(data) {
103 focaModalService.alert( 103 focaModalService.alert(
104 'Hoja ruta creada Nº: ' + 104 'Hoja ruta creada Nº: ' +
105 $scope.rellenar(data.data.sucursal, 4) + 105 $scope.rellenar(data.data.sucursal, 4) +
106 '-' + 106 '-' +
107 $scope.rellenar(data.data.numeroHojaRuta, 8) 107 $scope.rellenar(data.data.numeroHojaRuta, 8)
108 ); 108 );
109 nuevaHojaRuta(); 109 nuevaHojaRuta();
110 $scope.remitosTabla = []; 110 $scope.remitosTabla = [];
111 $scope.$broadcast('cleanCabecera'); 111 $scope.$broadcast('cleanCabecera');
112 112
113 focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) { 113 focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) {
114 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 114 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
115 }); 115 });
116 }, 116 },
117 function(error) { 117 function(error) {
118 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 118 focaModalService.alert('Hubo un error al crear la hoja de ruta');
119 console.info(error); 119 console.info(error);
120 } 120 }
121 ); 121 );
122 }; 122 };
123 123
124 $scope.seleccionarTransportista = function() { 124 $scope.seleccionarTransportista = function() {
125 if(eligioPreConfirmado()) return; 125 if(eligioPreConfirmado()) return;
126 var modalInstance = $uibModal.open( 126 var modalInstance = $uibModal.open(
127 { 127 {
128 ariaLabelledBy: 'Busqueda de Transportista', 128 ariaLabelledBy: 'Busqueda de Transportista',
129 templateUrl: 'modal-proveedor.html', 129 templateUrl: 'modal-proveedor.html',
130 controller: 'focaModalProveedorCtrl', 130 controller: 'focaModalProveedorCtrl',
131 size: 'lg', 131 size: 'lg',
132 resolve: { 132 resolve: {
133 transportista: function() { 133 transportista: function() {
134 return true; 134 return true;
135 } 135 }
136 } 136 }
137 } 137 }
138 ); 138 );
139 modalInstance.result.then( 139 modalInstance.result.then(
140 function(proveedor) { 140 function(proveedor) {
141 $scope.hojaRuta.transportista = proveedor; 141 $scope.hojaRuta.transportista = proveedor;
142 $scope.$broadcast('addCabecera', { 142 $scope.$broadcast('addCabecera', {
143 label: 'Transportista:', 143 label: 'Transportista:',
144 valor: proveedor.NOM 144 valor: proveedor.NOM
145 }); 145 });
146 }, function() { 146 }, function() {
147 147
148 } 148 }
149 ); 149 );
150 }; 150 };
151 151
152 $scope.seleccionarChofer = function() { 152 $scope.seleccionarChofer = function() {
153 var modalInstance = $uibModal.open( 153 var modalInstance = $uibModal.open(
154 { 154 {
155 ariaLabelledBy: 'Busqueda de Chofer', 155 ariaLabelledBy: 'Busqueda de Chofer',
156 templateUrl: 'modal-chofer.html', 156 templateUrl: 'modal-chofer.html',
157 controller: 'focaModalChoferController', 157 controller: 'focaModalChoferController',
158 size: 'lg' 158 size: 'lg'
159 } 159 }
160 ); 160 );
161 161
162 modalInstance.result.then( 162 modalInstance.result.then(
163 function(chofer) { 163 function(chofer) {
164 $scope.hojaRuta.chofer = chofer; 164 $scope.hojaRuta.chofer = chofer;
165 $scope.$broadcast('addCabecera', { 165 $scope.$broadcast('addCabecera', {
166 label: 'Chofer:', 166 label: 'Chofer:',
167 valor: chofer.nombre 167 valor: chofer.nombre
168 }); 168 });
169 }, function() { 169 }, function() {
170 // funcion ejecutada cuando se cancela el modal 170 // funcion ejecutada cuando se cancela el modal
171 } 171 }
172 ); 172 );
173 }; 173 };
174 174
175 $scope.seleccionarVehiculo = function() { 175 $scope.seleccionarVehiculo = function() {
176 if(eligioPreConfirmado()) return; 176 if(eligioPreConfirmado()) return;
177 modalVehiculos(); 177 modalVehiculos();
178 }; 178 };
179 179
180 $scope.seleccionarTarifario = function() { 180 $scope.seleccionarTarifario = function() {
181 var modalInstance = $uibModal.open( 181 var modalInstance = $uibModal.open(
182 { 182 {
183 ariaLabelledBy: 'Busqueda de Tarifario', 183 ariaLabelledBy: 'Busqueda de Tarifario',
184 templateUrl: 'modal-tarifa-flete.html', 184 templateUrl: 'modal-tarifa-flete.html',
185 controller: 'focaModalTarifaFleteController', 185 controller: 'focaModalTarifaFleteController',
186 size: 'lg', 186 size: 'lg',
187 resolve: { 187 resolve: {
188 parametrosTarifaFlete: function() { 188 parametrosTarifaFlete: function() {
189 return $scope.hojaRuta.tarifario.costo; 189 return $scope.hojaRuta.tarifario.costo;
190 } 190 }
191 } 191 }
192 } 192 }
193 ); 193 );
194 194
195 modalInstance.result.then( 195 modalInstance.result.then(
196 function(tarifario) { 196 function(tarifario) {
197 $scope.hojaRuta.tarifario = tarifario; 197 $scope.hojaRuta.tarifario = tarifario;
198 $scope.$broadcast('addCabecera', { 198 $scope.$broadcast('addCabecera', {
199 label: 'Tarifario:', 199 label: 'Tarifario:',
200 valor: tarifario.costo 200 valor: tarifario.costo
201 }); 201 });
202 }, function() { 202 }, function() {
203 // funcion ejecutada cuando se cancela el modal 203 // funcion ejecutada cuando se cancela el modal
204 } 204 }
205 ); 205 );
206 }; 206 };
207 207
208 $scope.seleccionarRemitos = function() { 208 $scope.seleccionarRemitos = function() {
209 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 209 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
210 var modalInstance = $uibModal.open( 210 var modalInstance = $uibModal.open(
211 { 211 {
212 ariaLabelledBy: 'Busqueda de Remito', 212 ariaLabelledBy: 'Busqueda de Remito',
213 templateUrl: 'foca-modal-remito.html', 213 templateUrl: 'foca-modal-remito.html',
214 controller: 'focaModalRemitoController', 214 controller: 'focaModalRemitoController',
215 size: 'lg', 215 size: 'lg',
216 resolve: {usadoPor: function() {return 'hojaRuta';}} 216 resolve: {usadoPor: function() {return 'hojaRuta';}}
217 } 217 }
218 ); 218 );
219 modalInstance.result.then( 219 modalInstance.result.then(
220 function(remito) { 220 function(remito) {
221 // TODO: borrar cuando no se use definitivamente 221 // TODO: borrar cuando no se use definitivamente
222 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { 222 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) {
223 // if ($scope.remitosTabla[i].id === remito.id) { 223 // if ($scope.remitosTabla[i].id === remito.id) {
224 // focaModalService.alert('Remito ya incluido'); 224 // focaModalService.alert('Remito ya incluido');
225 // return; 225 // return;
226 // } 226 // }
227 // } 227 // }
228 228
229 // var litros = 0; 229 // var litros = 0;
230 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 230 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
231 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 231 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
232 // } 232 // }
233 233
234 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 234 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
235 // focaModalService.alert( 235 // focaModalService.alert(
236 // 'Debe ingresar toda la información para el transporte' 236 // 'Debe ingresar toda la información para el transporte'
237 // ); 237 // );
238 // return; 238 // return;
239 // } 239 // }
240 240
241 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 241 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
242 // { 242 // {
243 // var litrostotales = litros; 243 // var litrostotales = litros;
244 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 244 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
245 // focaModalService.alert( 245 // focaModalService.alert(
246 // 'La carga excede la capacidad disponible del vehiculo. ' + 246 // 'La carga excede la capacidad disponible del vehiculo. ' +
247 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 247 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
248 // ); 248 // );
249 // } 249 // }
250 250
251 // remito.litros = litros; 251 // remito.litros = litros;
252 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 252 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
253 $scope.cargarCisterna(remito.id).then(function() { 253 $scope.cargarCisterna(remito.id).then(function() {
254 $scope.remitosTabla.push(remito); 254 $scope.remitosTabla.push(remito);
255 $scope.seleccionarRemitos(); 255 $scope.seleccionarRemitos();
256 }, function() { 256 }, function() {
257 $scope.seleccionarRemitos(); 257 $scope.seleccionarRemitos();
258 }); 258 });
259 }, function() { 259 }, function() {
260 // funcion ejecutada cuando se cancela el modal 260 // funcion ejecutada cuando se cancela el modal
261 } 261 }
262 ); 262 );
263 }; 263 };
264 264
265 $scope.seleccionarVehiculosPrecargados = function() { 265 $scope.seleccionarVehiculosPrecargados = function() {
266 if(!eligioFecha()) return; 266 if(!eligioFecha()) return;
267 modalVehiculos(true); 267 modalVehiculos(true);
268 }; 268 };
269 269
270 $scope.cargarCisterna = function(idRemito) { 270 $scope.cargarCisterna = function(idRemito) {
271 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 271 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
272 var modalInstance = $uibModal.open( 272 var modalInstance = $uibModal.open(
273 { 273 {
274 ariaLabelledBy: 'Busqueda de Vehiculo', 274 ariaLabelledBy: 'Busqueda de Vehiculo',
275 templateUrl: 'foca-detalle-vehiculo.html', 275 templateUrl: 'foca-detalle-vehiculo.html',
276 controller: 'focaDetalleVehiculo', 276 controller: 'focaDetalleVehiculo',
277 size: 'lg', 277 size: 'lg',
278 resolve: { 278 resolve: {
279 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, 279 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
280 idRemito: function() {return idRemito;}, 280 idRemito: function() {return idRemito;},
281 fechaReparto: function() {return $scope.fechaReparto;} 281 fechaReparto: function() {return $scope.fechaReparto;}
282 } 282 }
283 } 283 }
284 ); 284 );
285 return modalInstance.result; 285 return modalInstance.result;
286 }; 286 };
287 287
288 $scope.seleccionarFechaEntrega = function() { 288 $scope.seleccionarFechaEntrega = function() {
289 if(!$scope.fechaReparto) { 289 if(!$scope.fechaReparto) {
290 elegirFecha(); 290 elegirFecha();
291 return; 291 return;
292 } 292 }
293 focaModalService 293 focaModalService
294 .confirm('Si cambia la fecha se perderán los datos actuales') 294 .confirm('Si cambia la fecha se perderán los datos actuales')
295 .then(function() { 295 .then(function() {
296 elegirFecha(); 296 elegirFecha();
297 }, function() { 297 }, function() {
298 return ; 298 return ;
299 }); 299 });
300 }; 300 };
301 301
302 $scope.seleccionarDatosExtra = function() { 302 $scope.seleccionarDatosExtra = function() {
303 var datosHojaRuta = $scope.hojaRuta.datosExtra; 303 var datosHojaRuta = $scope.hojaRuta.datosExtra;
304 var modalInstance = $uibModal.open( 304 var modalInstance = $uibModal.open(
305 { 305 {
306 templateUrl: 'foca-modal-datos-hoja-ruta.html', 306 templateUrl: 'foca-modal-datos-hoja-ruta.html',
307 controller: 'focaModalDatosHojaRutaCtrl', 307 controller: 'focaModalDatosHojaRutaCtrl',
308 size: 'lg', 308 size: 'lg',
309 resolve: { 309 resolve: {
310 parametrosDatos: function() { 310 parametrosDatos: function() {
311 return { 311 return {
312 datosHojaRuta: datosHojaRuta 312 datosHojaRuta: datosHojaRuta
313 }; 313 };
314 } 314 }
315 } 315 }
316 } 316 }
317 ); 317 );
318 return modalInstance.result.then(function(datosExtra) { 318 return modalInstance.result.then(function(datosExtra) {
319 $scope.hojaRuta.datosExtra = datosExtra; 319 $scope.hojaRuta.datosExtra = datosExtra;
320 }, function() { 320 }, function() {
321 //se ejecuta cuando se cancela el modal 321 //se ejecuta cuando se cancela el modal
322 }); 322 });
323 }; 323 };
324 324
325 $scope.desasociarRemito = function(key, idRemito) { 325 $scope.desasociarRemito = function(key, idRemito) {
326 var idsRemito = [idRemito]; 326 var idsRemito = [idRemito];
327 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 327 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
328 ' vehículo?').then(function() { 328 ' vehículo?').then(function() {
329 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 329 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
330 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( 330 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then(
331 function() { 331 function() {
332 $scope.remitosTabla.splice(key, 1); 332 $scope.remitosTabla.splice(key, 1);
333 focaModalService.alert('Remitos desasociados con éxito'); 333 focaModalService.alert('Remito desasociados con éxito');
334 } 334 }
335 ); 335 );
336 }); 336 });
337 }; 337 };
338 338
339 function elegirFecha() { 339 function elegirFecha() {
340 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { 340 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) {
341 $scope.$broadcast('addCabecera', { 341 $scope.$broadcast('addCabecera', {
342 label: 'Fecha de entrega:', 342 label: 'Fecha de entrega:',
343 valor: fecha.toLocaleDateString() 343 valor: fecha.toLocaleDateString()
344 }); 344 });
345 $scope.fechaReparto = fecha; 345 $scope.fechaReparto = fecha;
346 nuevaHojaRuta(); 346 nuevaHojaRuta();
347 }); 347 });
348 } 348 }
349 349
350 $scope.rellenar = function(relleno, longitud) { 350 $scope.rellenar = function(relleno, longitud) {
351 relleno = '' + relleno; 351 relleno = '' + relleno;
352 while (relleno.length < longitud) { 352 while (relleno.length < longitud) {
353 relleno = '0' + relleno; 353 relleno = '0' + relleno;
354 } 354 }
355 return relleno; 355 return relleno;
356 }; 356 };
357 357
358 function eligioPreConfirmado() { 358 function eligioPreConfirmado() {
359 if($scope.eligioPreConfirmado) { 359 if($scope.eligioPreConfirmado) {
360 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 360 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
361 return true; 361 return true;
362 } 362 }
363 return false; 363 return false;
364 } 364 }
365 365
366 function eligioFecha() { 366 function eligioFecha() {
367 if(!$scope.fechaReparto) { 367 if(!$scope.fechaReparto) {
368 focaModalService.alert('Primero seleccione fecha de reparto'); 368 focaModalService.alert('Primero seleccione fecha de reparto');
369 return false; 369 return false;
370 } 370 }
371 return true; 371 return true;
372 } 372 }
373 373
374 function eligioVehiculo() { 374 function eligioVehiculo() {
375 if(!$scope.hojaRuta.vehiculo.id) { 375 if(!$scope.hojaRuta.vehiculo.id) {
376 focaModalService.alert('Primero seleccione vehiculo'); 376 focaModalService.alert('Primero seleccione vehiculo');
377 return false; 377 return false;
378 } 378 }
379 return true; 379 return true;
380 } 380 }
381 381
382 function modalVehiculos(preCargados) { 382 function modalVehiculos(preCargados) {
383 var query = ''; 383 var query = '';
384 var titulo = ''; 384 var titulo = '';
385 if(preCargados) { 385 if(preCargados) {
386 query = '/vehiculo/obtener/pre-confirmados/' + $scope.fechaReparto 386 query = '/vehiculo/obtener/pre-confirmados/' + $scope.fechaReparto
387 .toISOString().substring(0, 10); 387 .toISOString().substring(0, 10);
388 titulo = 'Búsqueda de vehiculos pre confirmados'; 388 titulo = 'Búsqueda de vehiculos pre confirmados';
389 }else { 389 }else {
390 query = '/vehiculo'; 390 query = '/vehiculo';
391 titulo = 'Búsqueda de vehículos'; 391 titulo = 'Búsqueda de vehículos';
392 } 392 }
393 var columnas = { 393 var columnas = {
394 nombre: ['Código', 'tractor', 'Semi'], 394 nombre: ['Código', 'tractor', 'Semi'],
395 propiedad: ['codigo', 'tractor', 'semi'] 395 propiedad: ['codigo', 'tractor', 'semi']
396 }; 396 };
397 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) { 397 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) {
398 $scope.hojaRuta.vehiculo = vehiculo; 398 $scope.hojaRuta.vehiculo = vehiculo;
399 $scope.hojaRuta.transportista = vehiculo.transportista; 399 $scope.hojaRuta.transportista = vehiculo.transportista;
400 if(preCargados) { 400 if(preCargados) {
401 $scope.eligioPreConfirmado = true; 401 $scope.eligioPreConfirmado = true;
402 $scope.hojaRuta.vehiculo = vehiculo; 402 $scope.hojaRuta.vehiculo = vehiculo;
403 $scope.$broadcast('addCabecera', { 403 $scope.$broadcast('addCabecera', {
404 label: 'Transportista:', 404 label: 'Transportista:',
405 valor: vehiculo.transportista.NOM 405 valor: vehiculo.transportista.NOM
406 }); 406 });
407 focaCrearHojaRutaService 407 focaCrearHojaRutaService
408 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) 408 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
409 .then(function(res) { 409 .then(function(res) {
410 $scope.remitosTabla = res.data; 410 $scope.remitosTabla = res.data;
411 }); 411 });
412 } 412 }
413 $scope.$broadcast('addCabecera', { 413 $scope.$broadcast('addCabecera', {
414 label: 'Tractor:', 414 label: 'Tractor:',
415 valor: vehiculo.tractor 415 valor: vehiculo.tractor
416 }); 416 });
417 $scope.$broadcast('addCabecera', { 417 $scope.$broadcast('addCabecera', {
418 label: 'Semi:', 418 label: 'Semi:',
419 valor: vehiculo.semi 419 valor: vehiculo.semi
420 }); 420 });
421 $scope.$broadcast('addCabecera', { 421 $scope.$broadcast('addCabecera', {
422 label: 'Capacidad:', 422 label: 'Capacidad:',
423 valor: vehiculo.capacidad 423 valor: vehiculo.capacidad
424 }); 424 });
425 }); 425 });
426 } 426 }
427 } 427 }
428 ]); 428 ]);
429 429