diff --git a/src/js/arrastrar.js b/src/js/arrastrar.js new file mode 100644 index 0000000..1f17c02 --- /dev/null +++ b/src/js/arrastrar.js @@ -0,0 +1,25 @@ +function allowDrop(ev) { + ev.preventDefault(); +} +function drag(ev, marcador) { + marcador = JSON.stringify(marcador); + ev.dataTransfer.setData('marcador', marcador); + var elementoDom = document.getElementById('test'); + var scope = angular.element(elementoDom).scope(); + scope.arrastra(); +} +function drop(ev) { + ev.preventDefault(); + var data = ev.dataTransfer.getData('marcador'); + var elementoDom = document.getElementById(ev.target.id); + var elementoAngular = angular.element(elementoDom); + var elementoScope = elementoAngular.scope(); + elementoScope.cargar(ev.target.id, data); + elementoScope.$digest(); +} +function dropEnd() { + console.log('drop'); + var elementoDom = document.getElementById('test'); + var scope = angular.element(elementoDom).scope(); + scope.noArrastra(); +} \ No newline at end of file diff --git a/src/js/controller.js b/src/js/controller.js index 8e90f98..981cc26 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,10 +1,17 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [ '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', - function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter) { - $scope.actividad = ''; - + 'focaModalService', 'focaBotoneraLateralService', + function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, + focaModalService, focaBotoneraLateralService + ) { $scope.now = new Date(); - $scope.actividad = 'Nota de pedido'; + $scope.actividad = 'Logistica'; + + //Datos Pantalla + $scope.titulo = 'Logistica de Pedidos'; + $scope.botonera = ['Vehiculo']; + var cabecera = ''; + $scope.idUsuario = 0; $scope.marcadores = []; $scope.vehiculos = []; @@ -15,9 +22,23 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo getSeguimiento(); }; + //SETEO BOTONERA LATERAL + focaBotoneraLateralService.showSalir(true); + focaBotoneraLateralService.showPausar(false); + focaBotoneraLateralService.showGuardar(false); + + $scope.general = function() { + $scope.idUsuario = 0; + getSeguimiento(); + $scope.$broadcast('removeCabecera', cabecera); + $scope.$broadcast('addCabecera',{ + label: 'General', + valor: '' + }); + }; + $scope.cargar = function(id, punto) { - var marcador = JSON.parse(punto); - var vehiculo = $filter('filter')($scope.vehiculos, {id: parseInt(id)})[0]; + var idRemito = JSON.parse(punto).notaPedido.remito.id; var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Vehiculo', @@ -25,18 +46,29 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo controller: 'focaDetalleVehiculo', size: 'lg', resolve: { - vehiculo: function() {return vehiculo;}, - marcador: function() {return marcador;} + idVehiculo: function() {return id;}, + idRemito: function() {return idRemito;} } } ); - modalInstance.result.then(function() { + modalInstance.result.then(function() { }, function() { - //run when cancel modal }); }; - $scope.arrastra = function() { + $scope.quitarVehiculo = function(vehiculo) { + focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + + vehiculo.codigo + '?').then(function() { + $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); + }); + }; + + $scope.informacionVehiculo = function(vehiculo) { + focaModalService.alert('EN DESARROLLO : \n información del vehículo ' + + JSON.stringify(vehiculo)); + }; + + $scope.arrastra = function() { $scope.arrastrando = true; $scope.$digest(); }; @@ -62,6 +94,11 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo if (key === 13) { $scope.idUsuario = $scope.idUsuarioInput; getSeguimiento(); + $scope.$broadcast('removeCabecera', 'General'); + $scope.$broadcast('addCabecera', { + label: cabecera, + valor: $scope.idUsuarioInput + }); } }; @@ -81,14 +118,17 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo modalInstance.result.then( function(vehiculo) { + var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); + if(existe.length > 0){ + focaModalService.alert('El vehiculo que intenta cargar ya ha sido cargado'); + return; + } $scope.vehiculos.push(vehiculo); }, function() { // funcion ejecutada cuando se cancela el modal } ); }; - - function getSeguimiento() { var now = $scope.now; @@ -108,7 +148,6 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo }; focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { - $scope.marcadores = datos.data; }); } diff --git a/src/js/controllerDetalleVehiculo.js b/src/js/controllerDetalleVehiculo.js index 5b32ddf..8e61934 100644 --- a/src/js/controllerDetalleVehiculo.js +++ b/src/js/controllerDetalleVehiculo.js @@ -2,30 +2,74 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaDetalleVehiculo', ['$scope', '$uibModalInstance', - 'vehiculo', - 'marcador', - function($scope, $uibModalInstance, vehiculo, marcador) { - $scope.articulos = marcador.notaPedido.articulosNotaPedido; - $scope.articuloSeleccionado = {}; - $scope.vehiculo = vehiculo; + 'idVehiculo', + 'idRemito', + 'focaModalService', + '$filter', + 'focaLogisticaPedidoRutaService', + function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, + focaLogisticaPedidoRutaService + ) { + $scope.articulos = []; + $scope.vehiculo = {}; + $scope.remito = {}; + focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( + function(res) { + $scope.vehiculo = res.data; + } + ); + focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( + function(res) { + $scope.remito = res.data; + $scope.articulos = res.data.articulosRemito; + } + ); + $scope.aCargar = []; $scope.aceptar = function() { $uibModalInstance.close(); }; - $scope.cargarACisterna = function(cisterna) { - if(!$scope.articuloSeleccionado.id) { - //TODO: usar modal de foca - alert('Debe seleccionar un articulo'); - return; - } - if(cisterna.cisternaCarga.cantidad) { - cisterna.cisternaCarga.cantidad += parseFloat(cisterna.aCargar); - }else { - cisterna.cisternaCarga.cantidad = parseFloat(cisterna.aCargar); - cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.id; - } - cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; - cisterna.aCargar = ''; + $scope.cancelar = function() { + $uibModalInstance.close(); + }; + + $scope.cargarACisternas = function(vehiculo) { + for (var i = 0; i < vehiculo.cisternas.length; i++) { + var cisterna = vehiculo.cisternas[i]; + var aCargar = parseFloat($scope.aCargar[i]); + if(!aCargar) { + continue; + } + if(aCargar > cisterna.disponible) { + focaModalService.alert('La cantidad cargada supera la capacidad de la' + + 'cisterna ' + cisterna.codigo); + return; + } + if(cisterna.cisternaCarga.cantidad) { + cisterna.cisternaCarga.cantidad += aCargar; + }else { + cisterna.cisternaCarga.cantidad = aCargar; + cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; + } + cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; + + cisterna.cisternaCarga.articulo = { + DetArt: $scope.articuloSeleccionado.descripcion + }; + $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] + .cargado = true; + + $scope.calcularPorcentaje(cisterna); + } + var articuloSiguiente = $scope.articulos.filter( + function(filter) { + return filter.cargado !== true; + } + ); + if(articuloSiguiente.length > 0){ + $scope.cambioArticulo(articuloSiguiente[0]); + } + $scope.aCargar = []; }; $scope.calcularPorcentaje = function(cisterna) { if(!cisterna.cisternaCarga.cantidad) { @@ -33,9 +77,29 @@ angular.module('focaLogisticaPedidoRuta') } var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / cisterna.capacidad) + '%'; - document.getElementById(cisterna.id).style.width = porcentaje; + var elementHtml = document.getElementById(cisterna.id); + if(elementHtml) { + elementHtml.style.width = porcentaje; + } }; $scope.cambioArticulo = function(articulo) { + articulo.checked = true; $scope.articuloSeleccionado = articulo; }; + $scope.actualizarArticulo = function () { + $scope.articuloSeleccionado.cantidadCargada = 0; + for (var i = 0; i < $scope.aCargar.length; i++) { + $scope.articuloSeleccionado.cantidadCargada += + parseFloat($scope.aCargar[i]) || 0; + } + }; + $scope.tieneArticulosPendientes = function() { + var articulosDescargados = $scope.articulos.filter(function(filter) { + return filter.cargado === true; + }); + if(articulosDescargados.length === $scope.articulos.length) { + return false; + } + return true; + }; }]); diff --git a/src/js/osm-directive.js b/src/js/osm-directive.js index 6a4bb40..7b0b4d3 100644 --- a/src/js/osm-directive.js +++ b/src/js/osm-directive.js @@ -51,7 +51,7 @@ angular.module('focaLogisticaPedidoRuta').directive('foca', function() { observacion += '
'; observacion += ''; + JSON.stringify(marcador)+')\' draggable="true">(Arrastrar icono)'; $scope.markers.push( L.marker([marcador.latitud, marcador.longitud]).addTo($scope.map) .bindPopup(observacion) diff --git a/src/js/service.js b/src/js/service.js index c6e00f6..4c0196a 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -5,6 +5,12 @@ angular.module('focaLogisticaPedidoRuta') return { obtenerActividad: function(parametros) { return $http.post(API_ENDPOINT.URL + '/seguimiento/filtros', parametros); + }, + obtenerVehiculoById: function(idVehiculo) { + return $http.get(API_ENDPOINT.URL + '/vehiculo/' + idVehiculo); + }, + obtenerRemitoById: function(idRemito) { + return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito); } }; }]); diff --git a/src/views/foca-detalle-vehiculo.html b/src/views/foca-detalle-vehiculo.html index 6c4f61f..f2901f7 100644 --- a/src/views/foca-detalle-vehiculo.html +++ b/src/views/foca-detalle-vehiculo.html @@ -1,45 +1,47 @@