Commit b24b9e3cee6a3b507936d1448a2cb6dd0e1cffb7

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

salto de linea

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