diff --git a/src/js/controller.js b/src/js/controller.js index f07a54d..bb071b2 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -9,9 +9,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', 'focaModalService', 'focaBotoneraLateralService', 'focaLoginService', + '$localStorage', function($scope, $uibModal, $location, $filter, $timeout, focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, - focaLoginSrv) + focaLoginSrv, $localStorage) { config(); @@ -33,6 +34,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); init(); + $timeout(function() {getLSHojaRuta();}); } function init() { @@ -48,10 +50,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', transportista: {}, tarifario: { costo: null - } + }, + remitosTabla: [] }; - $scope.remitosTabla = []; $scope.idLista = undefined; focaCrearHojaRutaService.getNumeroHojaRuta().then( @@ -65,15 +67,18 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } ); - $scope.inicial = { - hojaRuta: angular.copy($scope.hojaRuta), - remitosTabla: angular.copy($scope.remitosTabla), - idLista: angular.copy($scope.idLista) - }; + $scope.inicial = angular.copy($scope.hojaRuta); } + $scope.$watch('hojaRuta', function(newValue, oldValue) { + focaBotoneraLateralService.setPausarData({ + label: 'hojaRuta', + val: newValue + }); + }, true); + $scope.crearHojaRuta = function() { - if(!$scope.remitosTabla.length) { + if(!$scope.hojaRuta.remitosTabla.length) { focaModalService.alert('Ingrese Remitos'); return; } @@ -107,10 +112,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', idChofer: $scope.hojaRuta.chofer.id, idVehiculo: $scope.hojaRuta.vehiculo.id, tarifaFlete: $scope.hojaRuta.tarifario.costo, - fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), + fechaReparto: new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), estado: 0 }, - remitos: $scope.remitosTabla + remitos: $scope.hojaRuta.remitosTabla }; save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); focaCrearHojaRutaService.crearHojaRuta(save).then( @@ -251,8 +256,8 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', modalInstance.result.then( function(remito) { // TODO: borrar cuando no se use definitivamente - // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { - // if ($scope.remitosTabla[i].id === remito.id) { + // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { + // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { // focaModalService.alert('Remito ya incluido'); // return; // } @@ -283,7 +288,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', // remito.litros = litros; // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; $scope.cargarCisterna(remito.id).then(function() { - $scope.remitosTabla.push(remito); + $scope.hojaRuta.remitosTabla.push(remito); $scope.seleccionarRemitos(); }, function() { $scope.seleccionarRemitos(); @@ -310,7 +315,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', resolve: { idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, idRemito: function() {return idRemito;}, - fechaReparto: function() {return $scope.fechaReparto;} + fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} } } ); @@ -318,7 +323,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }; $scope.seleccionarFechaEntrega = function() { - if(!$scope.fechaReparto) { + if(!$scope.hojaRuta.fechaReparto) { elegirFecha(); return; } @@ -359,9 +364,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + ' vehículo?').then(function() { focaCrearHojaRutaService.desasociarRemitos(idsRemito, - $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( + $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1).then( function() { - $scope.remitosTabla.splice(key, 1); + $scope.hojaRuta.remitosTabla.splice(key, 1); focaModalService.alert('Remito desasociado con éxito'); } ); @@ -374,7 +379,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Fecha de entrega:', valor: fecha.toLocaleDateString() }); - $scope.fechaReparto = fecha; + $scope.hojaRuta.fechaReparto = fecha; }); } @@ -387,7 +392,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } function eligioFecha() { - if(!$scope.fechaReparto) { + if(!$scope.hojaRuta.fechaReparto) { focaModalService.alert('Primero seleccione fecha de reparto'); return false; } @@ -406,7 +411,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', var parametrosModal = {}; if(preCargados) { parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + - $scope.fechaReparto.toISOString().substring(0, 10); + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; }else { parametrosModal.query = '/vehiculo'; @@ -439,15 +444,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', ' - ' + vehiculo.transportista.NOM }); focaCrearHojaRutaService - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) .then(function(res) { - $scope.remitosTabla = res.data; + $scope.hojaRuta.remitosTabla = res.data; }); }else { focaCrearHojaRutaService - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) .then(function(res) { - $scope.remitosTabla = res.data; + $scope.hojaRuta.remitosTabla = res.data; }); } $scope.$broadcast('addCabecera', { @@ -470,8 +475,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', for(var i = 0; i < vehiculo.cisternas.length; i++) { for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; - if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto - .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && + if(cisternaCarga.fechaReparto.substring(0, 10) === + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && + cisternaCarga.idUsuarioProceso && cisternaCarga.idUsuarioProceso !== idUsuario) { focaModalService.alert('El vehículo está siendo usado por otro' + @@ -486,11 +492,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', function salir() { var confirmacion = false; - angular.forEach($scope.inicial, function(valor, key) { - if (!angular.equals($scope[key], $scope.inicial[key])) { - confirmacion = true; - } - }); + if (!angular.equals($scope.hojaRuta, $scope.inicial)) { + confirmacion = true; + } if (confirmacion) { focaModalService.confirm( @@ -504,5 +508,70 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', $location.path('/'); } } + + function setearHojaRuta(hojaRuta) { + $scope.$broadcast('cleanCabecera'); + + var cabeceras = []; + if (hojaRuta.fechaReparto) { + cabeceras.push({ + label: 'Fecha de entrega:', + valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') + }); + } + if (hojaRuta.transportista.COD) { + cabeceras.push({ + label: 'Transportista:', + valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + + hojaRuta.transportista.NOM + }); + } + if (hojaRuta.chofer.id) { + cabeceras.push({ + label: 'Chofer:', + valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + + ' - ' + hojaRuta.chofer.nombre + }); + } + if (hojaRuta.vehiculo.id) { + cabeceras.push({ + label: 'Tractor:', + valor: hojaRuta.vehiculo.tractor + }); + cabeceras.push({ + label: 'Semi:', + valor: hojaRuta.vehiculo.semi + }); + cabeceras.push({ + label: 'Capacidad:', + valor: hojaRuta.vehiculo.capacidad + }); + } + if (hojaRuta.tarifario.costo) { + cabeceras.push({ + label: 'Tarifario:', + valor: hojaRuta.tarifario.costo + }); + } + + addArrayCabecera(cabeceras); + $scope.hojaRuta = hojaRuta; + } + + function getLSHojaRuta() { + var hojaRuta = JSON.parse($localStorage.hojaRuta || null); + if (hojaRuta) { + setearHojaRuta(hojaRuta); + delete $localStorage.hojaRuta; + } + } + function addArrayCabecera(array) { + for(var i = 0; i < array.length; i++) { + $scope.$broadcast('addCabecera', { + label: array[i].label, + valor: array[i].valor + }); + } + } } ]); diff --git a/src/js/service.js b/src/js/service.js index 92e5720..3881cbc 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,5 +1,6 @@ angular.module('focaCrearHojaRuta') - .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', + function($http, API_ENDPOINT) { var route = API_ENDPOINT.URL; return { crearHojaRuta: function(hojaRuta) { diff --git a/src/views/hoja-ruta.html b/src/views/hoja-ruta.html index 189a8ed..1edfc9f 100644 --- a/src/views/hoja-ruta.html +++ b/src/views/hoja-ruta.html @@ -45,9 +45,9 @@ Remitos: - +