Commit e8d8095a989955fb196a154d2cd51e2f729f611f

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

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