From 41d9bb98c31d97d24dc93fc0abc3a13feb67da48 Mon Sep 17 00:00:00 2001 From: efernandez Date: Fri, 28 Dec 2018 17:50:05 -0300 Subject: [PATCH] desarrollo --- src/js/arrastrar.js | 5 ++- src/js/controller.js | 30 +++++++++--------- src/js/controllerDetalleVehiculo.js | 31 ++++++++++++++---- src/js/controllerHojaRuta.js | 52 ++++++++++++++++++++++++------- src/js/osm-directive.js | 33 +++++++++++++++++--- src/js/service.js | 49 ++++++++++++++++++----------- src/views/foca-detalle-vehiculo.html | 3 +- src/views/foca-logistica-pedido-ruta.html | 14 ++++----- src/views/foca-modal-crear-hoja-ruta.html | 21 ++++++++----- 9 files changed, 163 insertions(+), 75 deletions(-) diff --git a/src/js/arrastrar.js b/src/js/arrastrar.js index f2ab03d..a50ef7b 100644 --- a/src/js/arrastrar.js +++ b/src/js/arrastrar.js @@ -4,7 +4,7 @@ function allowDrop(ev) { function drag(ev, marcador) { marcador = JSON.stringify(marcador); ev.dataTransfer.setData('marcador', marcador); - var elementoDom = document.getElementById('test'); + var elementoDom = document.getElementById('scope'); var scope = angular.element(elementoDom).scope(); scope.arrastra(); } @@ -18,8 +18,7 @@ function drop(ev) { elementoScope.$digest(); } function dropEnd() { - console.log('drop'); - var elementoDom = document.getElementById('test'); + var elementoDom = document.getElementById('scope'); var scope = angular.element(elementoDom).scope(); scope.noArrastra(); } diff --git a/src/js/controller.js b/src/js/controller.js index b7969a5..3cd5420 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,8 +1,8 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [ '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', - 'focaModalService', 'focaBotoneraLateralService', + 'focaModalService', 'focaBotoneraLateralService', '$cookies', function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, - focaModalService, focaBotoneraLateralService + focaModalService, focaBotoneraLateralService, $cookies ) { $scope.now = new Date(); $scope.actividad = 'Logistica'; @@ -11,15 +11,14 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo $scope.titulo = 'Logistica de Pedidos'; $scope.botonera = ['Vehiculo']; var cabecera = ''; - - $scope.idUsuario = 0; + + $scope.idVendedor = 0; $scope.marcadores = []; $scope.vehiculos = []; - var idsRemitos = []; getSeguimiento(); $scope.arrastrando = false; $scope.general = function() { - $scope.idUsuario = 0; + $scope.idVendedor = 0; getSeguimiento(); }; @@ -28,8 +27,9 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo focaBotoneraLateralService.showPausar(false); focaBotoneraLateralService.showGuardar(false); + $scope.general = function() { - $scope.idUsuario = 0; + $scope.idVendedor = 0; getSeguimiento(); $scope.$broadcast('removeCabecera', cabecera); $scope.$broadcast('addCabecera',{ @@ -52,8 +52,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo } } ); - modalInstance.result.then(function(idRemito) { - idsRemitos.push(idRemito); + modalInstance.result.then(function() { }, function() { }); }; @@ -73,8 +72,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo controller: 'focaModalCrearHojaRuta', size: 'lg', resolve: { - idVehiculo: function() {return vehiculo.id;}, - idsRemitos: function() {return idsRemitos;} + idVehiculo: function() {return vehiculo.id;} } } ); @@ -96,7 +94,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo }; $scope.individual = function() { - $scope.idUsuario = -1; + $scope.idVendedor = -1; }; $scope.mostrarDetalle = function() { @@ -109,12 +107,12 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo $scope.search = function(key) { if (key === 13) { - $scope.idUsuario = $scope.idUsuarioInput; + $scope.idVendedor = $scope.idVendedorInput; getSeguimiento(); $scope.$broadcast('removeCabecera', 'General'); $scope.$broadcast('addCabecera', { label: cabecera, - valor: $scope.idUsuarioInput + valor: $scope.idVendedorInput }); } }; @@ -158,14 +156,14 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo desde = new Date(desde); var datos = { actividad: $scope.actividad, - idUsuario: $scope.idUsuario, + idUsuario: $scope.idVendedor, fechaDesde: desde, fechaHasta: new Date(new Date(now.setHours(23)).setMinutes(59)) }; $scope.datosBuscados = { actividad: $scope.actividad, - individual: $scope.idUsuario !== 0 ? true : false + individual: $scope.idVendedor !== 0 ? true : false }; focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { diff --git a/src/js/controllerDetalleVehiculo.js b/src/js/controllerDetalleVehiculo.js index ef4079d..5d958b8 100644 --- a/src/js/controllerDetalleVehiculo.js +++ b/src/js/controllerDetalleVehiculo.js @@ -24,6 +24,11 @@ angular.module('focaLogisticaPedidoRuta') focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( function(res) { $scope.remito = res.data; + if($scope.remito.idUsuarioProceso !== focaLogisticaPedidoRutaService.idUsuario) + { + focaModalService.alert('El remito esta siendo cargado por otro usario'); + $uibModalInstance.close(); + } $scope.articulos = res.data.articulosRemito; } ); @@ -36,13 +41,26 @@ angular.module('focaLogisticaPedidoRuta') } var cisterna = { cisternaMovimientos: cisternaMovimientos, - cisternaCargas: cisternaCargas + cisternaCargas: cisternaCargas, + idVehiculo: $scope.vehiculo.id }; - focaLogisticaPedidoRutaService.guardarCisternas(cisterna).then(function() { - focaModalService.alert('Cisternas cargadas con éxito').then(function() { + focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) + .then(function() { + focaModalService.alert('Cisternas cargadas con éxito').then(function() { + $scope.cargando = false; + $uibModalInstance.close(); + }); + }).catch(function(error) { $scope.cargando = false; - $uibModalInstance.close(idRemito); - }); + $uibModalInstance.close(); + if (error.status === 403.1) { + focaModalService.alert('ERROR: El vehículo esta en uso'); + } + if(error.status === 403.2) { + focaModalService.alert('ERROR: Otro usario ya cargó este remito'); + return; + } + focaModalService.alert('Hubo un error al cargar las cisternas'); }); }; @@ -85,7 +103,8 @@ angular.module('focaLogisticaPedidoRuta') fecha: now.toISOString().slice(0, 19).replace('T', ' '), cantidad: aCargar, metodo: 'carga', - idCisternaCarga: cisterna.cisternaCarga.id + idCisternaCarga: cisterna.cisternaCarga.id, + idRemito: $scope.remito.id }; cisternaMovimientos.push(cisternaMovimiento); } diff --git a/src/js/controllerHojaRuta.js b/src/js/controllerHojaRuta.js index bb1584f..709797e 100644 --- a/src/js/controllerHojaRuta.js +++ b/src/js/controllerHojaRuta.js @@ -5,30 +5,60 @@ angular.module('focaLogisticaPedidoRuta') '$uibModal', 'focaLogisticaPedidoRutaService', 'idVehiculo', - 'idsRemitos', + 'focaModalService', + '$filter', function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, - idVehiculo, idsRemitos) { + idVehiculo, focaModalService, $filter) { $scope.vehiculo = {}; $scope.remitos = []; + $scope.now = new Date(); focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { $scope.vehiculo = res.data; }); - for (var i = 0; i < idsRemitos.length; i++) { - focaLogisticaPedidoRutaService.obtenerRemitoById(idsRemitos[i]) - .then(cargarRemito); - } - function cargarRemito(res) { - $scope.remitos.push(res.data); - } + //TODO: refactor código esta rre feo + focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) { + for (var i = 0; i < res.data.cisternas.length; i++) { + for (var j = 0; j < res.data.cisternas[i].cisternaCarga.cisternaMovimientos.length; + j++) { + if(!!res.data.cisternas[i].cisternaCarga.cisternaMovimientos[j].remito && + !res.data.cisternas[i].cisternaCarga.cisternaMovimientos[j].remito + .idHojaRuta) { + var remito = res.data.cisternas[i].cisternaCarga + .cisternaMovimientos[j].remito; + var yaEstaCargado = $filter('filter')($scope.remitos, {id: remito.id}); + if(!yaEstaCargado.length && + res.data.cisternas[i].cisternaCarga.cisternaMovimientos[j].metodo === + 'carga') { + $scope.remitos.push(remito); + } + } + } + } + }); focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { $scope.sucursal = res.data.sucursal; - $scope.numero = res.data.numeroHojaRuta; + $scope.numero = res.data.numeroHojaRuta; }); $scope.cancelar = function() { $uibModalInstance.close(); }; $scope.aceptar = function() { - $uibModalInstance.close(); + var save = { + hojaRuta: { + id: 0, + fechaCreacion: $scope.now.toISOString().slice(0, 19).replace('T', ' '), + idTransportista: $scope.vehiculo.idTransportista, + idChofer: $scope.chofer.id, + idVehiculo: $scope.vehiculo.id, + tarifaFlete: $scope.tarifaFlete + }, + remitos: $scope.remitos, + idVehiculo: $scope.vehiculo.id + }; + focaLogisticaPedidoRutaService.crearHojaRuta(save).then(function() { + $uibModalInstance.close(); + focaModalService.alert('Hoja de ruta guardada con éxito'); + }); }; $scope.seleccionarChofer = function() { var modalInstance = $uibModal.open( diff --git a/src/js/osm-directive.js b/src/js/osm-directive.js index 7b0b4d3..3924849 100644 --- a/src/js/osm-directive.js +++ b/src/js/osm-directive.js @@ -1,4 +1,4 @@ -angular.module('focaLogisticaPedidoRuta').directive('foca', function() { +angular.module('focaLogisticaPedidoRuta').directive('focaLogistica', function() { return { restrict: 'E', link: function(scope, el, attrs) { @@ -27,8 +27,8 @@ angular.module('focaLogisticaPedidoRuta').directive('foca', function() { $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') + ' ' + marcador.fecha.slice(11,19) + '
'; observacion += 'Nº: ' + $filter('comprobante')([ - marcador.notaPedido.sucursal, - marcador.notaPedido.numeroNotaPedido + marcador.notaPedido.remito.sucursal, + marcador.notaPedido.remito.numeroRemito ]) + '
'; observacion += 'Cliente: ' + marcador.notaPedido.cliente.NOM + '
'; @@ -43,7 +43,7 @@ angular.module('focaLogisticaPedidoRuta').directive('foca', function() { marcador.distancia + 'km'; } }else { - observacion += 'Cantidad de nota de pedido: ' + + observacion += 'Cantidad de nota de remitos: ' + marcador.cantidad + '
'; observacion += 'Total Vendido: ' + $filter('currency')(marcador.total, '$'); @@ -52,8 +52,31 @@ angular.module('focaLogisticaPedidoRuta').directive('foca', function() { observacion += '(Arrastrar icono)'; + var icon; + if(marcador.notaPedido.remito.idUsuarioProceso) { + //Asignado AZUL + icon = new L.Icon({ + iconUrl: 'img/marker-icon-2x-blue.png', + shadowUrl: 'img/marker-shadow.png', + iconSize: [25, 41], + iconAnchor: [12, 41], + popupAnchor: [1, -34], + shadowSize: [41, 41] + }); + }else { + //Sin asignar ROJO + icon = new L.Icon({ + iconUrl: 'img/marker-icon-2x-red.png', + shadowUrl: 'img/marker-shadow.png', + iconSize: [25, 41], + iconAnchor: [12, 41], + popupAnchor: [1, -34], + shadowSize: [41, 41] + }); + } $scope.markers.push( - L.marker([marcador.latitud, marcador.longitud]).addTo($scope.map) + L.marker([marcador.latitud, marcador.longitud], {icon: icon}) + .addTo($scope.map) .bindPopup(observacion) ); diff --git a/src/js/service.js b/src/js/service.js index cfd3c19..67e8ab7 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,22 +1,33 @@ angular.module('focaLogisticaPedidoRuta') .service( - 'focaLogisticaPedidoRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT - ) { - 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); - }, - guardarCisternas: function(cisterna) { - return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar', cisterna); - }, - numeroHojaRuta: function() { - return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente'); - } - }; + 'focaLogisticaPedidoRutaService', [ + '$http', + '$cookies', + 'API_ENDPOINT', + function($http, $cookies, API_ENDPOINT) { + return { + idUsuario: $cookies.get('idUsuario'), + 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); + }, + guardarCisternas: function(cisterna, idRemito) { + return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' + + this.idUsuario + '/' + idRemito,cisterna); + }, + numeroHojaRuta: function() { + return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente'); + }, + getRemitos: function(idVehiculo) { + return $http.get(API_ENDPOINT.URL + '/remito/sin-hoja-ruta/' +idVehiculo); + }, + crearHojaRuta: function(hojaRuta) { + return $http.post(API_ENDPOINT.URL + '/hoja-ruta', hojaRuta); + } + }; }]); diff --git a/src/views/foca-detalle-vehiculo.html b/src/views/foca-detalle-vehiculo.html index f4fc3b4..f7e763c 100644 --- a/src/views/foca-detalle-vehiculo.html +++ b/src/views/foca-detalle-vehiculo.html @@ -58,7 +58,8 @@ placeholder="A cargar..." ng-model="aCargar[key]" ng-disabled="(articuloSeleccionado.idArticulo !== cisterna.cisternaCarga.idProducto && - cisterna.cisternaCarga.idProducto) || !tieneArticulosPendientes()" + cisterna.cisternaCarga.idProducto) || !tieneArticulosPendientes() + || articuloSeleccionado.cantidad > cisterna.disponible" ng-change="actualizarArticulo()" > diff --git a/src/views/foca-logistica-pedido-ruta.html b/src/views/foca-logistica-pedido-ruta.html index 830352b..0814cbc 100644 --- a/src/views/foca-logistica-pedido-ruta.html +++ b/src/views/foca-logistica-pedido-ruta.html @@ -1,4 +1,4 @@ -
+
- -
+
diff --git a/src/views/foca-modal-crear-hoja-ruta.html b/src/views/foca-modal-crear-hoja-ruta.html index 5182440..e891772 100644 --- a/src/views/foca-modal-crear-hoja-ruta.html +++ b/src/views/foca-modal-crear-hoja-ruta.html @@ -1,7 +1,13 @@ @@ -91,6 +98,6 @@ class="btn btn-sm btn-primary" ladda="cargando" type="button" - ng-disabled="!formHojaRuta.$valid" + ng-disabled="!formHojaRuta.$valid || !remitos.length" ng-click="aceptar()">Crear hoja ruta
-- 1.9.1