Commit ef7ce5994d18d993492a2385ae9489669feef99a

Authored by Eric Fernandez
1 parent 55889f9c8d
Exists in master

codigo en cabecera

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