diff --git a/src/js/controller.js b/src/js/controller.js index fa30cc0..a462305 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -33,8 +33,22 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaBotoneraLateralService.addCustomButton('Salir', salir); }); + focaCrearHojaRutaService.getParametros().then(function(res) { + + var parametros = JSON.parse(res.data[0].jsonText); + + if ($localStorage.hojaRuta) { + $timeout(function() {getLSHojaRuta();}); + } else { + + for(var property in parametros) { + $scope.hojaRuta[property] = parametros[property]; + } + + setearHojaRuta($scope.hojaRuta); + } + }); init(); - $timeout(function() {getLSHojaRuta();}); } function init() { @@ -48,9 +62,6 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', capacidad: 0 }, transportista: {}, - tarifario: { - costo: null - }, remitosTabla: [] }; $scope.idLista = undefined; @@ -70,6 +81,19 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } $scope.$watch('hojaRuta', function(newValue) { + + // Seteo checked en remitos + if ($scope.hojaRuta.remitosTabla.length) { + + $filter('filter')($scope.botonera, { + label: 'Remitos', + })[0].checked = true; + } else { + $filter('filter')($scope.botonera, { + label: 'Remitos', + })[0].checked = false; + } + focaBotoneraLateralService.setPausarData({ label: 'hojaRuta', val: newValue @@ -93,7 +117,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaModalService.alert('Ingrese Transportista'); return; } - if (!$scope.hojaRuta.tarifario.costo) { + if (!$scope.hojaRuta.tarifario) { focaModalService.alert('Ingrese Tarifario'); return; } @@ -110,7 +134,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', idTransportista: $scope.hojaRuta.transportista.COD, idChofer: $scope.hojaRuta.chofer.id, idVehiculo: $scope.hojaRuta.vehiculo.id, - tarifaFlete: $scope.hojaRuta.tarifario.costo, + tarifaFlete: $scope.hojaRuta.tarifario, fechaReparto: new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), estado: 0 @@ -126,7 +150,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) ); - init(); + config(); }, function(error) { focaModalService.alert('Hubo un error al crear la hoja de ruta'); @@ -163,6 +187,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + proveedor.NOM }); + + $filter('filter')($scope.botonera, { + label: 'Transportista', + })[0].checked = true; }, function() { } @@ -203,6 +231,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Chofer:', valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre }); + + $filter('filter')($scope.botonera, { + label: 'Chofer', + })[0].checked = true; }, function() { // funcion ejecutada cuando se cancela el modal } @@ -218,7 +250,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaModalService .prompt({ titulo: 'Tarifa flete', - value: $scope.hojaRuta.tarifario.costo + value: $scope.hojaRuta.tarifario }) .then(function(costo) { if (isNaN(costo)) { @@ -231,11 +263,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', return; } - $scope.hojaRuta.tarifario.costo = costo; + $scope.hojaRuta.tarifario = costo; $scope.$broadcast('addCabecera', { label: 'Tarifario:', valor: costo }); + + $filter('filter')($scope.botonera, { + label: 'Tarifario', + })[0].checked = true; }); }; @@ -372,6 +408,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } ); return modalInstance.result.then(function(datosExtra) { + + $filter('filter')($scope.botonera, { + label: 'Datos extra', + })[0].checked = true; + $scope.hojaRuta.datosExtra = datosExtra; }, function() { //se ejecuta cuando se cancela el modal @@ -420,10 +461,16 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', minDate: new Date() }; focaModalService.modalFecha(fechaEntrega).then(function(fecha) { + $scope.$broadcast('addCabecera', { label: 'Fecha de entrega: ', valor: fecha.toLocaleDateString() }); + + $filter('filter')($scope.botonera, { + label: 'Fecha Entrega', + })[0].checked = true; + $scope.hojaRuta.fechaReparto = fecha; }); } @@ -491,12 +538,22 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaCrearHojaRutaService .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) .then(function(res) { + + $filter('filter')($scope.botonera, { + label: 'Vehiculos precargados', + })[0].checked = true; + $scope.hojaRuta.remitosTabla = res.data; }); } else { focaCrearHojaRutaService .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) .then(function(res) { + + $filter('filter')($scope.botonera, { + label: 'Vehiculo', + })[0].checked = true; + $scope.hojaRuta.remitosTabla = res.data; }); } @@ -512,6 +569,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Capacidad:', valor: vehiculo.capacidad }); + }); } @@ -563,6 +621,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Fecha de entrega:', valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') }); + + $filter('filter')( $scope.botonera, { + label: 'Fecha Entrega' + })[0].checked = true; } if (hojaRuta.transportista.COD) { cabeceras.push({ @@ -570,6 +632,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + hojaRuta.transportista.NOM }); + + $filter('filter')( $scope.botonera, { + label: 'Transportista' + })[0].checked = true; } if (hojaRuta.chofer.id) { cabeceras.push({ @@ -577,6 +643,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + ' - ' + hojaRuta.chofer.nombre }); + + $filter('filter')( $scope.botonera, { + label: 'Chofer' + })[0].checked = true; } if (hojaRuta.vehiculo.id) { cabeceras.push({ @@ -591,12 +661,20 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Capacidad:', valor: hojaRuta.vehiculo.capacidad }); + + $filter('filter')( $scope.botonera, { + label: 'Vehiculo' + })[0].checked = true; } - if (hojaRuta.tarifario.costo) { + if (hojaRuta.tarifario) { cabeceras.push({ label: 'Tarifario:', - valor: hojaRuta.tarifario.costo + valor: hojaRuta.tarifario }); + + $filter('filter')( $scope.botonera, { + label: 'Tarifario' + })[0].checked = true; } addArrayCabecera(cabeceras); diff --git a/src/js/service.js b/src/js/service.js index 3881cbc..9d29f45 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -69,6 +69,9 @@ angular.module('focaCrearHojaRuta') vehiculoSinRemitos: sinRemitos }); }, + getParametros: function() { + return $http.get(API_ENDPOINT.URL + '/parametros/hojaRuta'); + }, getBotonera: function() { return [ {