Commit 16f1bb1958e37647888c1d73d9759ad54e8e9831

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !22
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 parametrosModal = {
130 { 130 titulo: 'Búsqueda de transportista',
131 ariaLabelledBy: 'Busqueda de Transportista', 131 query: '/transportista',
132 templateUrl: 'modal-proveedor.html', 132 columnas: [
133 controller: 'focaModalProveedorCtrl', 133 {
134 size: 'lg', 134 nombre: 'Código',
135 resolve: { 135 propiedad: 'COD'
136 transportista: function() { 136 },
137 return true; 137 {
138 } 138 nombre: 'Nombre',
139 propiedad: 'NOM'
140 },
141 {
142 nombre: 'CUIT',
143 propiedad: 'CUIT'
139 } 144 }
140 } 145 ]
141 ); 146 };
142 modalInstance.result.then( 147 focaModalService.modal(parametrosModal).then(
143 function(proveedor) { 148 function(proveedor) {
144 $scope.hojaRuta.transportista = proveedor; 149 $scope.hojaRuta.transportista = proveedor;
145 $scope.$broadcast('addCabecera', { 150 $scope.$broadcast('addCabecera', {
146 label: 'Transportista:', 151 label: 'Transportista:',
147 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 152 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
148 proveedor.NOM 153 proveedor.NOM
149 }); 154 });
150 }, function() { 155 }, function() {
151 156
152 } 157 }
153 ); 158 );
154 }; 159 };
155 160
156 $scope.seleccionarChofer = function() { 161 $scope.seleccionarChofer = function() {
157 var parametrosModal = { 162 var parametrosModal = {
158 titulo: 'Búsqueda de Chofer', 163 titulo: 'Búsqueda de Chofer',
159 query: '/chofer', 164 query: '/chofer',
160 columnas: [ 165 columnas: [
161 { 166 {
162 propiedad: 'id', 167 propiedad: 'id',
163 nombre: 'Código', 168 nombre: 'Código',
164 filtro: { 169 filtro: {
165 nombre: 'rellenarDigitos', 170 nombre: 'rellenarDigitos',
166 parametro: 3 171 parametro: 3
167 } 172 }
168 }, 173 },
169 { 174 {
170 propiedad: 'nombre', 175 propiedad: 'nombre',
171 nombre: 'Nombre' 176 nombre: 'Nombre'
172 }, 177 },
173 { 178 {
174 propiedad: 'dni', 179 propiedad: 'dni',
175 nombre: 'DNI' 180 nombre: 'DNI'
176 }, 181 },
177 { 182 {
178 propiedad: 'telefono', 183 propiedad: 'telefono',
179 nombre: 'Teléfono' 184 nombre: 'Teléfono'
180 } 185 }
181 ] 186 ]
182 }; 187 };
183 focaModalService.modal(parametrosModal).then( 188 focaModalService.modal(parametrosModal).then(
184 function(chofer) { 189 function(chofer) {
185 $scope.hojaRuta.chofer = chofer; 190 $scope.hojaRuta.chofer = chofer;
186 $scope.$broadcast('addCabecera', { 191 $scope.$broadcast('addCabecera', {
187 label: 'Chofer:', 192 label: 'Chofer:',
188 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre 193 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre
189 }); 194 });
190 }, function() { 195 }, function() {
191 // funcion ejecutada cuando se cancela el modal 196 // funcion ejecutada cuando se cancela el modal
192 } 197 }
193 ); 198 );
194 }; 199 };
195 200
196 $scope.seleccionarVehiculo = function() { 201 $scope.seleccionarVehiculo = function() {
197 if(!eligioFecha() || eligioPreConfirmado()) return; 202 if(!eligioFecha() || eligioPreConfirmado()) return;
198 modalVehiculos(); 203 modalVehiculos();
199 }; 204 };
200 205
201 $scope.seleccionarTarifario = function() { 206 $scope.seleccionarTarifario = function() {
202 var modalInstance = $uibModal.open( 207 var modalInstance = $uibModal.open(
203 { 208 {
204 ariaLabelledBy: 'Busqueda de Tarifario', 209 ariaLabelledBy: 'Busqueda de Tarifario',
205 templateUrl: 'modal-tarifa-flete.html', 210 templateUrl: 'modal-tarifa-flete.html',
206 controller: 'focaModalTarifaFleteController', 211 controller: 'focaModalTarifaFleteController',
207 size: 'lg', 212 size: 'lg',
208 resolve: { 213 resolve: {
209 parametrosTarifaFlete: function() { 214 parametrosTarifaFlete: function() {
210 return $scope.hojaRuta.tarifario.costo; 215 return $scope.hojaRuta.tarifario.costo;
211 } 216 }
212 } 217 }
213 } 218 }
214 ); 219 );
215 220
216 modalInstance.result.then( 221 modalInstance.result.then(
217 function(tarifario) { 222 function(tarifario) {
218 $scope.hojaRuta.tarifario = tarifario; 223 $scope.hojaRuta.tarifario = tarifario;
219 $scope.$broadcast('addCabecera', { 224 $scope.$broadcast('addCabecera', {
220 label: 'Tarifario:', 225 label: 'Tarifario:',
221 valor: tarifario.costo 226 valor: tarifario.costo
222 }); 227 });
223 }, function() { 228 }, function() {
224 // funcion ejecutada cuando se cancela el modal 229 // funcion ejecutada cuando se cancela el modal
225 } 230 }
226 ); 231 );
227 }; 232 };
228 233
229 $scope.seleccionarRemitos = function() { 234 $scope.seleccionarRemitos = function() {
230 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 235 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
231 var modalInstance = $uibModal.open( 236 var modalInstance = $uibModal.open(
232 { 237 {
233 ariaLabelledBy: 'Busqueda de Remito', 238 ariaLabelledBy: 'Busqueda de Remito',
234 templateUrl: 'foca-modal-remito.html', 239 templateUrl: 'foca-modal-remito.html',
235 controller: 'focaModalRemitoController', 240 controller: 'focaModalRemitoController',
236 size: 'lg', 241 size: 'lg',
237 resolve: {usadoPor: function() {return 'hojaRuta';}} 242 resolve: {usadoPor: function() {return 'hojaRuta';}}
238 } 243 }
239 ); 244 );
240 modalInstance.result.then( 245 modalInstance.result.then(
241 function(remito) { 246 function(remito) {
242 // TODO: borrar cuando no se use definitivamente 247 // TODO: borrar cuando no se use definitivamente
243 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { 248 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) {
244 // if ($scope.remitosTabla[i].id === remito.id) { 249 // if ($scope.remitosTabla[i].id === remito.id) {
245 // focaModalService.alert('Remito ya incluido'); 250 // focaModalService.alert('Remito ya incluido');
246 // return; 251 // return;
247 // } 252 // }
248 // } 253 // }
249 254
250 // var litros = 0; 255 // var litros = 0;
251 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 256 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
252 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 257 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
253 // } 258 // }
254 259
255 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 260 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
256 // focaModalService.alert( 261 // focaModalService.alert(
257 // 'Debe ingresar toda la información para el transporte' 262 // 'Debe ingresar toda la información para el transporte'
258 // ); 263 // );
259 // return; 264 // return;
260 // } 265 // }
261 266
262 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 267 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
263 // { 268 // {
264 // var litrostotales = litros; 269 // var litrostotales = litros;
265 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 270 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
266 // focaModalService.alert( 271 // focaModalService.alert(
267 // 'La carga excede la capacidad disponible del vehiculo. ' + 272 // 'La carga excede la capacidad disponible del vehiculo. ' +
268 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 273 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
269 // ); 274 // );
270 // } 275 // }
271 276
272 // remito.litros = litros; 277 // remito.litros = litros;
273 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 278 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
274 $scope.cargarCisterna(remito.id).then(function() { 279 $scope.cargarCisterna(remito.id).then(function() {
275 $scope.remitosTabla.push(remito); 280 $scope.remitosTabla.push(remito);
276 $scope.seleccionarRemitos(); 281 $scope.seleccionarRemitos();
277 }, function() { 282 }, function() {
278 $scope.seleccionarRemitos(); 283 $scope.seleccionarRemitos();
279 }); 284 });
280 }, function() { 285 }, function() {
281 // funcion ejecutada cuando se cancela el modal 286 // funcion ejecutada cuando se cancela el modal
282 } 287 }
283 ); 288 );
284 }; 289 };
285 290
286 $scope.seleccionarVehiculosPrecargados = function() { 291 $scope.seleccionarVehiculosPrecargados = function() {
287 if(!eligioFecha()) return; 292 if(!eligioFecha()) return;
288 modalVehiculos(true); 293 modalVehiculos(true);
289 }; 294 };
290 295
291 $scope.cargarCisterna = function(idRemito) { 296 $scope.cargarCisterna = function(idRemito) {
292 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 297 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
293 var modalInstance = $uibModal.open( 298 var modalInstance = $uibModal.open(
294 { 299 {
295 ariaLabelledBy: 'Busqueda de Vehiculo', 300 ariaLabelledBy: 'Busqueda de Vehiculo',
296 templateUrl: 'foca-detalle-vehiculo.html', 301 templateUrl: 'foca-detalle-vehiculo.html',
297 controller: 'focaDetalleVehiculo', 302 controller: 'focaDetalleVehiculo',
298 size: 'lg', 303 size: 'lg',
299 resolve: { 304 resolve: {
300 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, 305 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
301 idRemito: function() {return idRemito;}, 306 idRemito: function() {return idRemito;},
302 fechaReparto: function() {return $scope.fechaReparto;} 307 fechaReparto: function() {return $scope.fechaReparto;}
303 } 308 }
304 } 309 }
305 ); 310 );
306 return modalInstance.result; 311 return modalInstance.result;
307 }; 312 };
308 313
309 $scope.seleccionarFechaEntrega = function() { 314 $scope.seleccionarFechaEntrega = function() {
310 if(!$scope.fechaReparto) { 315 if(!$scope.fechaReparto) {
311 elegirFecha(); 316 elegirFecha();
312 return; 317 return;
313 } 318 }
314 focaModalService 319 focaModalService
315 .confirm('Si cambia la fecha se perderán los datos actuales') 320 .confirm('Si cambia la fecha se perderán los datos actuales')
316 .then(function() { 321 .then(function() {
317 elegirFecha(); 322 elegirFecha();
318 }, function() { 323 }, function() {
319 return ; 324 return ;
320 }); 325 });
321 }; 326 };
322 327
323 $scope.seleccionarDatosExtra = function() { 328 $scope.seleccionarDatosExtra = function() {
324 var datosHojaRuta = $scope.hojaRuta.datosExtra; 329 var datosHojaRuta = $scope.hojaRuta.datosExtra;
325 var modalInstance = $uibModal.open( 330 var modalInstance = $uibModal.open(
326 { 331 {
327 templateUrl: 'foca-modal-datos-hoja-ruta.html', 332 templateUrl: 'foca-modal-datos-hoja-ruta.html',
328 controller: 'focaModalDatosHojaRutaCtrl', 333 controller: 'focaModalDatosHojaRutaCtrl',
329 size: 'lg', 334 size: 'lg',
330 resolve: { 335 resolve: {
331 parametrosDatos: function() { 336 parametrosDatos: function() {
332 return { 337 return {
333 datosHojaRuta: datosHojaRuta 338 datosHojaRuta: datosHojaRuta
334 }; 339 };
335 } 340 }
336 } 341 }
337 } 342 }
338 ); 343 );
339 return modalInstance.result.then(function(datosExtra) { 344 return modalInstance.result.then(function(datosExtra) {
340 $scope.hojaRuta.datosExtra = datosExtra; 345 $scope.hojaRuta.datosExtra = datosExtra;
341 }, function() { 346 }, function() {
342 //se ejecuta cuando se cancela el modal 347 //se ejecuta cuando se cancela el modal
343 }); 348 });
344 }; 349 };
345 350
346 $scope.desasociarRemito = function(key, idRemito) { 351 $scope.desasociarRemito = function(key, idRemito) {
347 var idsRemito = [idRemito]; 352 var idsRemito = [idRemito];
348 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 353 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
349 ' vehículo?').then(function() { 354 ' vehículo?').then(function() {
350 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 355 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
351 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( 356 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then(
352 function() { 357 function() {
353 $scope.remitosTabla.splice(key, 1); 358 $scope.remitosTabla.splice(key, 1);
354 focaModalService.alert('Remito desasociado con éxito'); 359 focaModalService.alert('Remito desasociado con éxito');
355 } 360 }
356 ); 361 );
357 }); 362 });
358 }; 363 };
359 364
360 function elegirFecha() { 365 function elegirFecha() {
361 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { 366 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) {
362 $scope.$broadcast('addCabecera', { 367 $scope.$broadcast('addCabecera', {
363 label: 'Fecha de entrega:', 368 label: 'Fecha de entrega:',
364 valor: fecha.toLocaleDateString() 369 valor: fecha.toLocaleDateString()
365 }); 370 });
366 $scope.fechaReparto = fecha; 371 $scope.fechaReparto = fecha;
367 nuevaHojaRuta(); 372 nuevaHojaRuta();
368 }); 373 });
369 } 374 }
370 375
371 $scope.rellenar = function(relleno, longitud) { 376 $scope.rellenar = function(relleno, longitud) {
372 relleno = '' + relleno; 377 relleno = '' + relleno;
373 while (relleno.length < longitud) { 378 while (relleno.length < longitud) {
374 relleno = '0' + relleno; 379 relleno = '0' + relleno;
375 } 380 }
376 return relleno; 381 return relleno;
377 }; 382 };
378 383
379 function eligioPreConfirmado() { 384 function eligioPreConfirmado() {
380 if($scope.eligioPreConfirmado) { 385 if($scope.eligioPreConfirmado) {
381 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 386 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
382 return true; 387 return true;
383 } 388 }
384 return false; 389 return false;
385 } 390 }
386 391
387 function eligioFecha() { 392 function eligioFecha() {
388 if(!$scope.fechaReparto) { 393 if(!$scope.fechaReparto) {
389 focaModalService.alert('Primero seleccione fecha de reparto'); 394 focaModalService.alert('Primero seleccione fecha de reparto');
390 return false; 395 return false;
391 } 396 }
392 return true; 397 return true;
393 } 398 }
394 399
395 function eligioVehiculo() { 400 function eligioVehiculo() {
396 if(!$scope.hojaRuta.vehiculo.id) { 401 if(!$scope.hojaRuta.vehiculo.id) {
397 focaModalService.alert('Primero seleccione vehiculo'); 402 focaModalService.alert('Primero seleccione vehiculo');
398 return false; 403 return false;
399 } 404 }
400 return true; 405 return true;
401 } 406 }
402 407
403 function modalVehiculos(preCargados) { 408 function modalVehiculos(preCargados) {
404 var parametrosModal = {}; 409 var parametrosModal = {};
405 if(preCargados) { 410 if(preCargados) {
406 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 411 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
407 $scope.fechaReparto.toISOString().substring(0, 10); 412 $scope.fechaReparto.toISOString().substring(0, 10);
408 parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; 413 parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados';
409 }else { 414 }else {
410 parametrosModal.query = '/vehiculo'; 415 parametrosModal.query = '/vehiculo';
411 parametrosModal.titulo = 'Búsqueda de vehículos'; 416 parametrosModal.titulo = 'Búsqueda de vehículos';
412 } 417 }
413 parametrosModal.columnas = [ 418 parametrosModal.columnas = [
414 { 419 {
415 propiedad: 'codigo', 420 propiedad: 'codigo',
416 nombre: 'Código' 421 nombre: 'Código'
417 }, 422 },
418 { 423 {
419 propiedad: 'tractor', 424 propiedad: 'tractor',
420 nombre: 'tractor' 425 nombre: 'tractor'
421 }, 426 },
422 { 427 {
423 propiedad: 'semi', 428 propiedad: 'semi',
424 nombre: 'Semi' 429 nombre: 'Semi'
425 } 430 }
426 ]; 431 ];
427 focaModalService.modal(parametrosModal).then(function(vehiculo) { 432 focaModalService.modal(parametrosModal).then(function(vehiculo) {
428 if(!preCargados && vehiculoEnUso(vehiculo)) return; 433 if(!preCargados && vehiculoEnUso(vehiculo)) return;
429 $scope.hojaRuta.vehiculo = vehiculo; 434 $scope.hojaRuta.vehiculo = vehiculo;
430 $scope.hojaRuta.transportista = vehiculo.transportista; 435 $scope.hojaRuta.transportista = vehiculo.transportista;
431 if(preCargados) { 436 if(preCargados) {
432 $scope.eligioPreConfirmado = true; 437 $scope.eligioPreConfirmado = true;
433 $scope.hojaRuta.vehiculo = vehiculo; 438 $scope.hojaRuta.vehiculo = vehiculo;
434 $scope.$broadcast('addCabecera', { 439 $scope.$broadcast('addCabecera', {
435 label: 'Transportista:', 440 label: 'Transportista:',
436 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 441 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
437 ' - ' + vehiculo.transportista.NOM 442 ' - ' + vehiculo.transportista.NOM
438 }); 443 });
439 focaCrearHojaRutaService 444 focaCrearHojaRutaService
440 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) 445 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
441 .then(function(res) { 446 .then(function(res) {
442 $scope.remitosTabla = res.data; 447 $scope.remitosTabla = res.data;
443 }); 448 });
444 }else { 449 }else {
445 focaCrearHojaRutaService 450 focaCrearHojaRutaService
446 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) 451 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true)
447 .then(function(res) { 452 .then(function(res) {
448 $scope.remitosTabla = res.data; 453 $scope.remitosTabla = res.data;
449 }); 454 });
450 } 455 }
451 $scope.$broadcast('addCabecera', { 456 $scope.$broadcast('addCabecera', {
452 label: 'Tractor:', 457 label: 'Tractor:',
453 valor: vehiculo.tractor 458 valor: vehiculo.tractor
454 }); 459 });
455 $scope.$broadcast('addCabecera', { 460 $scope.$broadcast('addCabecera', {
456 label: 'Semi:', 461 label: 'Semi:',
457 valor: vehiculo.semi 462 valor: vehiculo.semi
458 }); 463 });
459 $scope.$broadcast('addCabecera', { 464 $scope.$broadcast('addCabecera', {
460 label: 'Capacidad:', 465 label: 'Capacidad:',
461 valor: vehiculo.capacidad 466 valor: vehiculo.capacidad
462 }); 467 });
463 }); 468 });
464 } 469 }
465 470
466 function vehiculoEnUso(vehiculo) { 471 function vehiculoEnUso(vehiculo) {
467 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 472 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
468 for(var i = 0; i < vehiculo.cisternas.length; i++) { 473 for(var i = 0; i < vehiculo.cisternas.length; i++) {
469 for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 474 for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
470 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 475 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
471 if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto 476 if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
472 .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && 477 .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso &&
473 cisternaCarga.idUsuarioProceso !== idUsuario) 478 cisternaCarga.idUsuarioProceso !== idUsuario)
474 { 479 {
475 focaModalService.alert('El vehículo está siendo usado por otro' + 480 focaModalService.alert('El vehículo está siendo usado por otro' +
476 ' usuario'); 481 ' usuario');
477 return true; 482 return true;
478 } 483 }
479 } 484 }
480 } 485 }
481 return false; 486 return false;
482 } 487 }
483 } 488 }
484 ]); 489 ]);
485 490