Commit daec8d685c1371c8e0d1fd650ce561bb5fa006d6

Authored by mpuebla
1 parent bf0b86fcf9
Exists in master and in 2 other branches develop, lab

Arreglo de espacio en if, else.

Showing 1 changed file with 2 additions and 2 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 '$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 setearFecha(new Date()); 68 setearFecha(new Date());
69 $scope.inicial = angular.copy($scope.hojaRuta); 69 $scope.inicial = angular.copy($scope.hojaRuta);
70 } 70 }
71 71
72 $scope.$watch('hojaRuta', function(newValue) { 72 $scope.$watch('hojaRuta', function(newValue) {
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: 114 fechaReparto:
115 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), 115 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10),
116 estado: 0 116 estado: 0
117 }, 117 },
118 remitos: $scope.hojaRuta.remitosTabla 118 remitos: $scope.hojaRuta.remitosTabla
119 }; 119 };
120 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 120 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
121 focaCrearHojaRutaService.crearHojaRuta(save).then( 121 focaCrearHojaRutaService.crearHojaRuta(save).then(
122 function(data) { 122 function(data) {
123 focaModalService.alert( 123 focaModalService.alert(
124 'Hoja ruta creada Nº: ' + 124 'Hoja ruta creada Nº: ' +
125 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 125 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
126 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) 126 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8)
127 ); 127 );
128 128
129 init(); 129 init();
130 }, 130 },
131 function(error) { 131 function(error) {
132 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 132 focaModalService.alert('Hubo un error al crear la hoja de ruta');
133 console.info(error); 133 console.info(error);
134 } 134 }
135 ); 135 );
136 }; 136 };
137 137
138 $scope.seleccionarTransportista = function() { 138 $scope.seleccionarTransportista = function() {
139 if (eligioPreConfirmado()) return; 139 if (eligioPreConfirmado()) return;
140 var parametrosModal = { 140 var parametrosModal = {
141 titulo: 'Búsqueda de transportista', 141 titulo: 'Búsqueda de transportista',
142 query: '/transportista', 142 query: '/transportista',
143 columnas: [ 143 columnas: [
144 { 144 {
145 nombre: 'Código', 145 nombre: 'Código',
146 propiedad: 'COD' 146 propiedad: 'COD'
147 }, 147 },
148 { 148 {
149 nombre: 'Nombre', 149 nombre: 'Nombre',
150 propiedad: 'NOM' 150 propiedad: 'NOM'
151 }, 151 },
152 { 152 {
153 nombre: 'CUIT', 153 nombre: 'CUIT',
154 propiedad: 'CUIT' 154 propiedad: 'CUIT'
155 } 155 }
156 ] 156 ]
157 }; 157 };
158 focaModalService.modal(parametrosModal).then( 158 focaModalService.modal(parametrosModal).then(
159 function(proveedor) { 159 function(proveedor) {
160 $scope.hojaRuta.transportista = proveedor; 160 $scope.hojaRuta.transportista = proveedor;
161 $scope.$broadcast('addCabecera', { 161 $scope.$broadcast('addCabecera', {
162 label: 'Transportista:', 162 label: 'Transportista:',
163 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 163 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
164 proveedor.NOM 164 proveedor.NOM
165 }); 165 });
166 }, function() { 166 }, function() {
167 167
168 } 168 }
169 ); 169 );
170 }; 170 };
171 171
172 $scope.seleccionarChofer = function() { 172 $scope.seleccionarChofer = function() {
173 var parametrosModal = { 173 var parametrosModal = {
174 titulo: 'Búsqueda de Chofer', 174 titulo: 'Búsqueda de Chofer',
175 query: '/chofer', 175 query: '/chofer',
176 columnas: [ 176 columnas: [
177 { 177 {
178 propiedad: 'id', 178 propiedad: 'id',
179 nombre: 'Código', 179 nombre: 'Código',
180 filtro: { 180 filtro: {
181 nombre: 'rellenarDigitos', 181 nombre: 'rellenarDigitos',
182 parametro: 3 182 parametro: 3
183 } 183 }
184 }, 184 },
185 { 185 {
186 propiedad: 'nombre', 186 propiedad: 'nombre',
187 nombre: 'Nombre' 187 nombre: 'Nombre'
188 }, 188 },
189 { 189 {
190 propiedad: 'dni', 190 propiedad: 'dni',
191 nombre: 'DNI' 191 nombre: 'DNI'
192 }, 192 },
193 { 193 {
194 propiedad: 'telefono', 194 propiedad: 'telefono',
195 nombre: 'Teléfono' 195 nombre: 'Teléfono'
196 } 196 }
197 ] 197 ]
198 }; 198 };
199 focaModalService.modal(parametrosModal).then( 199 focaModalService.modal(parametrosModal).then(
200 function(chofer) { 200 function(chofer) {
201 $scope.hojaRuta.chofer = chofer; 201 $scope.hojaRuta.chofer = chofer;
202 $scope.$broadcast('addCabecera', { 202 $scope.$broadcast('addCabecera', {
203 label: 'Chofer:', 203 label: 'Chofer:',
204 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre 204 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre
205 }); 205 });
206 }, function() { 206 }, function() {
207 // funcion ejecutada cuando se cancela el modal 207 // funcion ejecutada cuando se cancela el modal
208 } 208 }
209 ); 209 );
210 }; 210 };
211 211
212 $scope.seleccionarVehiculo = function() { 212 $scope.seleccionarVehiculo = function() {
213 if (!eligioFecha() || eligioPreConfirmado()) return; 213 if (!eligioFecha() || eligioPreConfirmado()) return;
214 modalVehiculos(); 214 modalVehiculos();
215 }; 215 };
216 216
217 $scope.seleccionarTarifario = function() { 217 $scope.seleccionarTarifario = function() {
218 focaModalService 218 focaModalService
219 .prompt({ 219 .prompt({
220 titulo: 'Tarifa flete', 220 titulo: 'Tarifa flete',
221 value: $scope.hojaRuta.tarifario.costo 221 value: $scope.hojaRuta.tarifario.costo
222 }) 222 })
223 .then(function(costo) { 223 .then(function(costo) {
224 if (isNaN(costo)) { 224 if (isNaN(costo)) {
225 focaModalService 225 focaModalService
226 .alert('Ingrese un valor válido') 226 .alert('Ingrese un valor válido')
227 .then(function() { 227 .then(function() {
228 $scope.seleccionarTarifario(); 228 $scope.seleccionarTarifario();
229 }); 229 });
230 230
231 return; 231 return;
232 } 232 }
233 233
234 $scope.hojaRuta.tarifario.costo = costo; 234 $scope.hojaRuta.tarifario.costo = costo;
235 $scope.$broadcast('addCabecera', { 235 $scope.$broadcast('addCabecera', {
236 label: 'Tarifario:', 236 label: 'Tarifario:',
237 valor: costo 237 valor: costo
238 }); 238 });
239 }); 239 });
240 }; 240 };
241 241
242 $scope.seleccionarRemitos = function() { 242 $scope.seleccionarRemitos = function() {
243 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 243 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
244 var modalInstance = $uibModal.open( 244 var modalInstance = $uibModal.open(
245 { 245 {
246 ariaLabelledBy: 'Busqueda de Remito', 246 ariaLabelledBy: 'Busqueda de Remito',
247 templateUrl: 'foca-modal-remito.html', 247 templateUrl: 'foca-modal-remito.html',
248 controller: 'focaModalRemitoController', 248 controller: 'focaModalRemitoController',
249 size: 'lg', 249 size: 'lg',
250 resolve: {usadoPor: function() {return 'hojaRuta';}} 250 resolve: {usadoPor: function() {return 'hojaRuta';}}
251 } 251 }
252 ); 252 );
253 modalInstance.result.then( 253 modalInstance.result.then(
254 function(remito) { 254 function(remito) {
255 // TODO: borrar cuando no se use definitivamente 255 // TODO: borrar cuando no se use definitivamente
256 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { 256 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
257 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { 257 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
258 // focaModalService.alert('Remito ya incluido'); 258 // focaModalService.alert('Remito ya incluido');
259 // return; 259 // return;
260 // } 260 // }
261 // } 261 // }
262 262
263 // var litros = 0; 263 // var litros = 0;
264 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 264 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
265 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 265 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
266 // } 266 // }
267 267
268 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 268 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
269 // focaModalService.alert( 269 // focaModalService.alert(
270 // 'Debe ingresar toda la información para el transporte' 270 // 'Debe ingresar toda la información para el transporte'
271 // ); 271 // );
272 // return; 272 // return;
273 // } 273 // }
274 274
275 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 275 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
276 // { 276 // {
277 // var litrostotales = litros; 277 // var litrostotales = litros;
278 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 278 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
279 // focaModalService.alert( 279 // focaModalService.alert(
280 // 'La carga excede la capacidad disponible del vehiculo. ' + 280 // 'La carga excede la capacidad disponible del vehiculo. ' +
281 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 281 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
282 // ); 282 // );
283 // } 283 // }
284 284
285 // remito.litros = litros; 285 // remito.litros = litros;
286 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 286 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
287 $scope.cargarCisterna(remito.id).then(function() { 287 $scope.cargarCisterna(remito.id).then(function() {
288 $scope.hojaRuta.remitosTabla.push(remito); 288 $scope.hojaRuta.remitosTabla.push(remito);
289 }, function(error) { 289 }, function(error) {
290 290
291 if (error && error !== 'backdrop click') { 291 if (error && error !== 'backdrop click') {
292 292
293 focaModalService 293 focaModalService
294 .alert(error || 'Ha ocurrido un error') 294 .alert(error || 'Ha ocurrido un error')
295 .then(function() { 295 .then(function() {
296 $scope.seleccionarRemitos(); 296 $scope.seleccionarRemitos();
297 }); 297 });
298 298
299 } else { 299 } else {
300 300
301 $scope.seleccionarRemitos(); 301 $scope.seleccionarRemitos();
302 302
303 } 303 }
304 }); 304 });
305 }, function() { 305 }, function() {
306 // funcion ejecutada cuando se cancela el modal 306 // funcion ejecutada cuando se cancela el modal
307 } 307 }
308 ); 308 );
309 }; 309 };
310 310
311 $scope.seleccionarVehiculosPrecargados = function() { 311 $scope.seleccionarVehiculosPrecargados = function() {
312 if (!eligioFecha()) return; 312 if (!eligioFecha()) return;
313 modalVehiculos(true); 313 modalVehiculos(true);
314 }; 314 };
315 315
316 $scope.cargarCisterna = function(idRemito) { 316 $scope.cargarCisterna = function(idRemito) {
317 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 317 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
318 var modalInstance = $uibModal.open( 318 var modalInstance = $uibModal.open(
319 { 319 {
320 ariaLabelledBy: 'Busqueda de Vehiculo', 320 ariaLabelledBy: 'Busqueda de Vehiculo',
321 templateUrl: 'foca-detalle-vehiculo.html', 321 templateUrl: 'foca-detalle-vehiculo.html',
322 controller: 'focaDetalleVehiculo', 322 controller: 'focaDetalleVehiculo',
323 size: 'lg', 323 size: 'lg',
324 resolve: { 324 resolve: {
325 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, 325 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
326 idRemito: function() {return idRemito;}, 326 idRemito: function() {return idRemito;},
327 fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} 327 fechaReparto: function() {return $scope.hojaRuta.fechaReparto;}
328 } 328 }
329 } 329 }
330 ); 330 );
331 return modalInstance.result; 331 return modalInstance.result;
332 }; 332 };
333 333
334 $scope.seleccionarFechaEntrega = function() { 334 $scope.seleccionarFechaEntrega = function() {
335 var confirmacion = false; 335 var confirmacion = false;
336 var hasVehiculoId = $scope.hojaRuta.vehiculo.id !== undefined; 336 var hasVehiculoId = $scope.hojaRuta.vehiculo.id !== undefined;
337 var hasTarifario = $scope.hojaRuta.tarifario.costo !== null; 337 var hasTarifario = $scope.hojaRuta.tarifario.costo !== null;
338 var hasTransportista = Object.keys($scope.hojaRuta.transportista).length > 0; 338 var hasTransportista = Object.keys($scope.hojaRuta.transportista).length > 0;
339 var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0; 339 var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0;
340 var hasDatosExtra = $scope.hojaRuta.datosExtra !== undefined; 340 var hasDatosExtra = $scope.hojaRuta.datosExtra !== undefined;
341 341
342 if (hasVehiculoId || hasTarifario || hasTransportista || 342 if (hasVehiculoId || hasTarifario || hasTransportista ||
343 hasChofer || hasDatosExtra) { 343 hasChofer || hasDatosExtra) {
344 confirmacion = true; 344 confirmacion = true;
345 if (confirmacion) { 345 if (confirmacion) {
346 focaModalService 346 focaModalService
347 .confirm('Si cambia la fecha se perderán los datos actuales') 347 .confirm('Si cambia la fecha se perderán los datos actuales')
348 .then(function(data) { 348 .then(function(data) {
349 if(data){ 349 if(data) {
350 $scope.hojaRuta.vehiculo.id = undefined; 350 $scope.hojaRuta.vehiculo.id = undefined;
351 $scope.hojaRuta.tarifario.costo = null; 351 $scope.hojaRuta.tarifario.costo = null;
352 $scope.hojaRuta.transportista = {}; 352 $scope.hojaRuta.transportista = {};
353 $scope.hojaRuta.chofer = {}; 353 $scope.hojaRuta.chofer = {};
354 $scope.hojaRuta.datosExtra = undefined; 354 $scope.hojaRuta.datosExtra = undefined;
355 elegirFecha(); 355 elegirFecha();
356 } 356 }
357 }, function() { 357 }, function() {
358 return ; 358 return ;
359 }); 359 });
360 } 360 }
361 }else{ 361 } else {
362 elegirFecha(); 362 elegirFecha();
363 } 363 }
364 } 364 }
365 365
366 function setearFecha(fecha) { 366 function setearFecha(fecha) {
367 $timeout(function() { 367 $timeout(function() {
368 $scope.$broadcast('addCabecera', { 368 $scope.$broadcast('addCabecera', {
369 label: 'Fecha de entrega: ', 369 label: 'Fecha de entrega: ',
370 valor: fecha.toLocaleDateString() 370 valor: fecha.toLocaleDateString()
371 }); 371 });
372 $scope.hojaRuta.fechaReparto = fecha; 372 $scope.hojaRuta.fechaReparto = fecha;
373 }); 373 });
374 } 374 }
375 375
376 $scope.seleccionarDatosExtra = function() { 376 $scope.seleccionarDatosExtra = function() {
377 var datosHojaRuta = $scope.hojaRuta.datosExtra; 377 var datosHojaRuta = $scope.hojaRuta.datosExtra;
378 var modalInstance = $uibModal.open( 378 var modalInstance = $uibModal.open(
379 { 379 {
380 templateUrl: 'foca-modal-datos-hoja-ruta.html', 380 templateUrl: 'foca-modal-datos-hoja-ruta.html',
381 controller: 'focaModalDatosHojaRutaCtrl', 381 controller: 'focaModalDatosHojaRutaCtrl',
382 size: 'lg', 382 size: 'lg',
383 resolve: { 383 resolve: {
384 parametrosDatos: function() { 384 parametrosDatos: function() {
385 return { 385 return {
386 datosHojaRuta: datosHojaRuta 386 datosHojaRuta: datosHojaRuta
387 }; 387 };
388 } 388 }
389 } 389 }
390 } 390 }
391 ); 391 );
392 return modalInstance.result.then(function(datosExtra) { 392 return modalInstance.result.then(function(datosExtra) {
393 $scope.hojaRuta.datosExtra = datosExtra; 393 $scope.hojaRuta.datosExtra = datosExtra;
394 }, function() { 394 }, function() {
395 //se ejecuta cuando se cancela el modal 395 //se ejecuta cuando se cancela el modal
396 }); 396 });
397 }; 397 };
398 398
399 $scope.desasociarRemito = function(key, idRemito) { 399 $scope.desasociarRemito = function(key, idRemito) {
400 var idsRemito = [idRemito]; 400 var idsRemito = [idRemito];
401 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 401 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
402 ' vehículo?').then(function() { 402 ' vehículo?').then(function() {
403 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 403 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
404 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) 404 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1)
405 .then(function() { 405 .then(function() {
406 $scope.hojaRuta.remitosTabla.splice(key, 1); 406 $scope.hojaRuta.remitosTabla.splice(key, 1);
407 focaModalService.alert('Remito desasociado con éxito'); 407 focaModalService.alert('Remito desasociado con éxito');
408 }); 408 });
409 }); 409 });
410 }; 410 };
411 411
412 $scope.verProductosRemito = function(idRemito) { 412 $scope.verProductosRemito = function(idRemito) {
413 var parametrosModal = { 413 var parametrosModal = {
414 titulo: 'Articulos remito', 414 titulo: 'Articulos remito',
415 query: '/articulos/remito/' + idRemito, 415 query: '/articulos/remito/' + idRemito,
416 soloMostrar: true, 416 soloMostrar: true,
417 columnas: [ 417 columnas: [
418 { 418 {
419 nombre: 'Código', 419 nombre: 'Código',
420 propiedad: 'codigo' 420 propiedad: 'codigo'
421 }, 421 },
422 { 422 {
423 nombre: 'Descripción', 423 nombre: 'Descripción',
424 propiedad: 'descripcion' 424 propiedad: 'descripcion'
425 }, 425 },
426 { 426 {
427 nombre: 'Cantidad', 427 nombre: 'Cantidad',
428 propiedad: 'cantidad' 428 propiedad: 'cantidad'
429 } 429 }
430 ] 430 ]
431 }; 431 };
432 focaModalService.modal(parametrosModal).then(); 432 focaModalService.modal(parametrosModal).then();
433 }; 433 };
434 434
435 function elegirFecha() { 435 function elegirFecha() {
436 var fechaEntrega = { 436 var fechaEntrega = {
437 titulo: 'Fecha de entrega', 437 titulo: 'Fecha de entrega',
438 minDate: new Date() 438 minDate: new Date()
439 }; 439 };
440 focaModalService.modalFecha(fechaEntrega).then(function(fecha) { 440 focaModalService.modalFecha(fechaEntrega).then(function(fecha) {
441 $scope.$broadcast('addCabecera', { 441 $scope.$broadcast('addCabecera', {
442 label: 'Fecha de entrega: ', 442 label: 'Fecha de entrega: ',
443 valor: fecha.toLocaleDateString() 443 valor: fecha.toLocaleDateString()
444 }); 444 });
445 $scope.hojaRuta.fechaReparto = fecha; 445 $scope.hojaRuta.fechaReparto = fecha;
446 }); 446 });
447 } 447 }
448 448
449 function eligioPreConfirmado() { 449 function eligioPreConfirmado() {
450 if ($scope.eligioPreConfirmado) { 450 if ($scope.eligioPreConfirmado) {
451 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 451 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
452 return true; 452 return true;
453 } 453 }
454 return false; 454 return false;
455 } 455 }
456 456
457 function eligioFecha() { 457 function eligioFecha() {
458 if (!$scope.hojaRuta.fechaReparto) { 458 if (!$scope.hojaRuta.fechaReparto) {
459 focaModalService.alert('Primero seleccione fecha de reparto'); 459 focaModalService.alert('Primero seleccione fecha de reparto');
460 return false; 460 return false;
461 } 461 }
462 return true; 462 return true;
463 } 463 }
464 464
465 function eligioVehiculo() { 465 function eligioVehiculo() {
466 if (!$scope.hojaRuta.vehiculo.id) { 466 if (!$scope.hojaRuta.vehiculo.id) {
467 focaModalService.alert('Primero seleccione vehiculo'); 467 focaModalService.alert('Primero seleccione vehiculo');
468 return false; 468 return false;
469 } 469 }
470 return true; 470 return true;
471 } 471 }
472 472
473 function modalVehiculos(preCargados) { 473 function modalVehiculos(preCargados) {
474 var parametrosModal = {}; 474 var parametrosModal = {};
475 if (preCargados) { 475 if (preCargados) {
476 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 476 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
477 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); 477 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
478 parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; 478 parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados';
479 } else { 479 } else {
480 parametrosModal.query = '/vehiculo'; 480 parametrosModal.query = '/vehiculo';
481 parametrosModal.titulo = 'Búsqueda de vehículos'; 481 parametrosModal.titulo = 'Búsqueda de vehículos';
482 } 482 }
483 parametrosModal.columnas = [ 483 parametrosModal.columnas = [
484 { 484 {
485 propiedad: 'codigo', 485 propiedad: 'codigo',
486 nombre: 'Código' 486 nombre: 'Código'
487 }, 487 },
488 { 488 {
489 propiedad: 'tractor', 489 propiedad: 'tractor',
490 nombre: 'tractor' 490 nombre: 'tractor'
491 }, 491 },
492 { 492 {
493 propiedad: 'semi', 493 propiedad: 'semi',
494 nombre: 'Semi' 494 nombre: 'Semi'
495 } 495 }
496 ]; 496 ];
497 focaModalService.modal(parametrosModal).then(function(vehiculo) { 497 focaModalService.modal(parametrosModal).then(function(vehiculo) {
498 if (!preCargados && vehiculoEnUso(vehiculo)) return; 498 if (!preCargados && vehiculoEnUso(vehiculo)) return;
499 $scope.hojaRuta.vehiculo = vehiculo; 499 $scope.hojaRuta.vehiculo = vehiculo;
500 $scope.hojaRuta.transportista = vehiculo.transportista; 500 $scope.hojaRuta.transportista = vehiculo.transportista;
501 if (preCargados) { 501 if (preCargados) {
502 $scope.eligioPreConfirmado = true; 502 $scope.eligioPreConfirmado = true;
503 $scope.hojaRuta.vehiculo = vehiculo; 503 $scope.hojaRuta.vehiculo = vehiculo;
504 $scope.$broadcast('addCabecera', { 504 $scope.$broadcast('addCabecera', {
505 label: 'Transportista:', 505 label: 'Transportista:',
506 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 506 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
507 ' - ' + vehiculo.transportista.NOM 507 ' - ' + vehiculo.transportista.NOM
508 }); 508 });
509 focaCrearHojaRutaService 509 focaCrearHojaRutaService
510 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) 510 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
511 .then(function(res) { 511 .then(function(res) {
512 $scope.hojaRuta.remitosTabla = res.data; 512 $scope.hojaRuta.remitosTabla = res.data;
513 }); 513 });
514 } else { 514 } else {
515 focaCrearHojaRutaService 515 focaCrearHojaRutaService
516 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) 516 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
517 .then(function(res) { 517 .then(function(res) {
518 $scope.hojaRuta.remitosTabla = res.data; 518 $scope.hojaRuta.remitosTabla = res.data;
519 }); 519 });
520 } 520 }
521 $scope.$broadcast('addCabecera', { 521 $scope.$broadcast('addCabecera', {
522 label: 'Tractor:', 522 label: 'Tractor:',
523 valor: vehiculo.tractor 523 valor: vehiculo.tractor
524 }); 524 });
525 $scope.$broadcast('addCabecera', { 525 $scope.$broadcast('addCabecera', {
526 label: 'Semi:', 526 label: 'Semi:',
527 valor: vehiculo.semi 527 valor: vehiculo.semi
528 }); 528 });
529 $scope.$broadcast('addCabecera', { 529 $scope.$broadcast('addCabecera', {
530 label: 'Capacidad:', 530 label: 'Capacidad:',
531 valor: vehiculo.capacidad 531 valor: vehiculo.capacidad
532 }); 532 });
533 }); 533 });
534 } 534 }
535 535
536 function vehiculoEnUso(vehiculo) { 536 function vehiculoEnUso(vehiculo) {
537 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 537 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
538 for (var i = 0; i < vehiculo.cisternas.length; i++) { 538 for (var i = 0; i < vehiculo.cisternas.length; i++) {
539 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 539 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
540 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 540 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
541 if (cisternaCarga.fechaReparto.substring(0, 10) === 541 if (cisternaCarga.fechaReparto.substring(0, 10) ===
542 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && 542 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
543 cisternaCarga.idUsuarioProceso && 543 cisternaCarga.idUsuarioProceso &&
544 cisternaCarga.idUsuarioProceso !== idUsuario) 544 cisternaCarga.idUsuarioProceso !== idUsuario)
545 { 545 {
546 focaModalService.alert('El vehículo está siendo usado por otro' + 546 focaModalService.alert('El vehículo está siendo usado por otro' +
547 ' usuario'); 547 ' usuario');
548 return true; 548 return true;
549 } 549 }
550 } 550 }
551 } 551 }
552 return false; 552 return false;
553 } 553 }
554 554
555 function salir() { 555 function salir() {
556 var confirmacion = false; 556 var confirmacion = false;
557 557
558 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 558 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
559 confirmacion = true; 559 confirmacion = true;
560 } 560 }
561 561
562 if (confirmacion) { 562 if (confirmacion) {
563 focaModalService.confirm( 563 focaModalService.confirm(
564 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 564 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
565 ).then(function(data) { 565 ).then(function(data) {
566 if (data) { 566 if (data) {
567 $location.path('/'); 567 $location.path('/');
568 } 568 }
569 }); 569 });
570 } else { 570 } else {
571 $location.path('/'); 571 $location.path('/');
572 } 572 }
573 } 573 }
574 574
575 function setearHojaRuta(hojaRuta) { 575 function setearHojaRuta(hojaRuta) {
576 $scope.$broadcast('cleanCabecera'); 576 $scope.$broadcast('cleanCabecera');
577 577
578 var cabeceras = []; 578 var cabeceras = [];
579 if (hojaRuta.fechaReparto) { 579 if (hojaRuta.fechaReparto) {
580 cabeceras.push({ 580 cabeceras.push({
581 label: 'Fecha de entrega:', 581 label: 'Fecha de entrega:',
582 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 582 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
583 }); 583 });
584 } 584 }
585 if (hojaRuta.transportista.COD) { 585 if (hojaRuta.transportista.COD) {
586 cabeceras.push({ 586 cabeceras.push({
587 label: 'Transportista:', 587 label: 'Transportista:',
588 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + 588 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
589 hojaRuta.transportista.NOM 589 hojaRuta.transportista.NOM
590 }); 590 });
591 } 591 }
592 if (hojaRuta.chofer.id) { 592 if (hojaRuta.chofer.id) {
593 cabeceras.push({ 593 cabeceras.push({
594 label: 'Chofer:', 594 label: 'Chofer:',
595 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + 595 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
596 ' - ' + hojaRuta.chofer.nombre 596 ' - ' + hojaRuta.chofer.nombre
597 }); 597 });
598 } 598 }
599 if (hojaRuta.vehiculo.id) { 599 if (hojaRuta.vehiculo.id) {
600 cabeceras.push({ 600 cabeceras.push({
601 label: 'Tractor:', 601 label: 'Tractor:',
602 valor: hojaRuta.vehiculo.tractor 602 valor: hojaRuta.vehiculo.tractor
603 }); 603 });
604 cabeceras.push({ 604 cabeceras.push({
605 label: 'Semi:', 605 label: 'Semi:',
606 valor: hojaRuta.vehiculo.semi 606 valor: hojaRuta.vehiculo.semi
607 }); 607 });
608 cabeceras.push({ 608 cabeceras.push({
609 label: 'Capacidad:', 609 label: 'Capacidad:',
610 valor: hojaRuta.vehiculo.capacidad 610 valor: hojaRuta.vehiculo.capacidad
611 }); 611 });
612 } 612 }
613 if (hojaRuta.tarifario.costo) { 613 if (hojaRuta.tarifario.costo) {
614 cabeceras.push({ 614 cabeceras.push({
615 label: 'Tarifario:', 615 label: 'Tarifario:',
616 valor: hojaRuta.tarifario.costo 616 valor: hojaRuta.tarifario.costo
617 }); 617 });
618 } 618 }
619 619
620 addArrayCabecera(cabeceras); 620 addArrayCabecera(cabeceras);
621 $scope.hojaRuta = hojaRuta; 621 $scope.hojaRuta = hojaRuta;
622 } 622 }
623 623
624 function getLSHojaRuta() { 624 function getLSHojaRuta() {
625 var hojaRuta = JSON.parse($localStorage.hojaRuta || null); 625 var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
626 if (hojaRuta) { 626 if (hojaRuta) {
627 setearHojaRuta(hojaRuta); 627 setearHojaRuta(hojaRuta);
628 delete $localStorage.hojaRuta; 628 delete $localStorage.hojaRuta;
629 } 629 }
630 } 630 }
631 function addArrayCabecera(array) { 631 function addArrayCabecera(array) {
632 for(var i = 0; i < array.length; i++) { 632 for(var i = 0; i < array.length; i++) {
633 $scope.$broadcast('addCabecera', { 633 $scope.$broadcast('addCabecera', {
634 label: array[i].label, 634 label: array[i].label,
635 valor: array[i].valor 635 valor: array[i].valor
636 }); 636 });
637 } 637 }
638 } 638 }
639 } 639 }
640 ]); 640 ]);
641 641