diff --git a/src/js/app.js b/src/js/app.js index d27f735..cd3f456 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,5 +1,6 @@ angular.module('focaOrdenCarga', [ 'ui.bootstrap', 'focaDirectivas', - 'angular-ladda' + 'angular-ladda', + 'chart.js' ]); diff --git a/src/js/controller.js b/src/js/controller.js index 5ec54fc..f42bab2 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,55 +1,32 @@ angular.module('focaOrdenCarga') .controller('focaOrdenCargaController', [ '$scope', - '$uibModal', '$location', '$filter', '$timeout', 'focaOrdenCargaService', 'focaBotoneraLateralService', 'focaModalService', - 'notaPedidoBusinessService', - '$rootScope', - 'focaSeguimientoService', - 'APP', - 'focaLoginService', - '$localStorage', + '$uibModal', function ( - $scope, $uibModal, $location, $filter, $timeout, focaOrdenCargaService, - focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, - $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) { - config(); + $scope, $location, $filter, $timeout, focaOrdenCargaService, + focaBotoneraLateralService, focaModalService, $uibModal) { - function config() { + init(); + + function init() { // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA - $scope.tmpCantidad = Number; - $scope.tmpPrecio = Number; + $scope.fecha = new Date(); $scope.isNumber = angular.isNumber; - $scope.datepickerAbierto = false; $scope.show = false; $scope.cargando = true; $scope.cabeceras = []; $scope.botonera = focaOrdenCargaService.getBotonera(); - $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); - $scope.comprobante = $filter('rellenarDigitos')(0, 8); $scope.dateOptions = { maxDate: new Date(), minDate: new Date(2010, 0, 1) }; - //SETEO BOTONERA LATERAL - $timeout(function () { - focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(true); - focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); - focaBotoneraLateralService.addCustomButton('Salir', salir); - }); - - init(); - - } - - function init() { $scope.ordenCarga = { id: 0, cliente: {}, @@ -62,7 +39,241 @@ angular.module('focaOrdenCarga') notaPedidoPlazo: [], notaPedidoPuntoDescarga: [] }; + $scope.hojaRuta = { + fecha: new Date(), + litros: 0, + chofer: {}, + vehiculo: { + capacidad: 0, + cisternas: [] + }, + transportista: {}, + remitosTabla: [] + }; + } + + //SETEO BOTONERA LATERAL + $timeout(function () { + focaBotoneraLateralService.showSalir(false); + focaBotoneraLateralService.showPausar(true); + focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); + focaBotoneraLateralService.addCustomButton('Salir', salir); + }); + + function seleccionarTransportista() { + var parametrosModal = { + titulo: 'Búsqueda de Transportista', + query: '/transportista', + columnas: [ + { + nombre: 'Código', + propiedad: 'COD' + }, + { + nombre: 'Nombre', + propiedad: 'NOM' + }, + { + nombre: 'CUIT', + propiedad: 'CUIT' + } + ] + }; + return focaModalService.modal(parametrosModal); + }; + + $scope.seleccionarVehiculo = function () { + + seleccionarTransportista().then( + + function (transportista) { + elegirTransportista(transportista); + + var parametrosModal = { + columnas: [ + { + propiedad: 'codigo', + nombre: 'Código' + }, + { + propiedad: 'tractor', + nombre: 'tractor' + }, + { + propiedad: 'semi', + nombre: 'Semi' + }, + { + propiedad: 'capacidadTotalCisternas', + nombre: 'Capacidad' + } + ], + query: '/vehiculo/transportista/' + transportista.COD, + titulo: 'Búsqueda de vehiculos', + subTitulo: transportista.COD + '-' + transportista.NOM + }; + + focaModalService.modal(parametrosModal).then( + function (vehiculo) { + $scope.$broadcast('addCabecera', { + label: 'Vehículo:', + valor: vehiculo.codigo + }); + $scope.hojaRuta.vehiculo = vehiculo; + $scope.hojaRuta.transportista = transportista; + $scope.hojaRuta.vehiculo.cisternas = vehiculo.cisternas; + getEstadosCisternas($scope.hojaRuta.vehiculo.cisternas); + }, function () { + seleccionarTransportista(); + }); + }); + }; + + $scope.seleccionarVerCisternas = function () { + if (!$scope.hojaRuta.vehiculo.cisternas.length) { + focaModalService.alert('Primero seleccione un vehículo con cisternas'); + return; + } + console.log($scope.hojaRuta.vehiculo); + $uibModal.open( + { + ariaLabelledBy: 'Grafico de cisternas', + templateUrl: 'modal-grafico-cisternas.html', + controller: 'focaModalGraficoCisternasController', + size: 'md', + resolve: { + filters: { + cisternas: $scope.hojaRuta.vehiculo.cisternas + } + } + } + ); + }; + + $scope.seleccionarFechaDeReparto = function () { + focaModalService.modalFecha('Fecha').then(function (fecha) { + $scope.$broadcast('addCabecera', { + label: 'Fecha:', + valor: fecha.toLocaleDateString() + }); + $scope.fecha = fecha; + if ($scope.hojaRuta.vehiculo.cisternas) + getEstadosCisternas($scope.hojaRuta.vehiculo.cisternas); + }); + }; + + $scope.seleccionarRemitoAbierto = function () { + if ($scope.hojaRuta.vehiculo.capacidad === 0) { + focaModalService.alert('Debe ingresar vehiculo'); + return; + } else { + mostrarDetalle($scope.hojaRuta); + } + }; + + $scope.seleccionarChofer = function () { + var parametrosModal = { + titulo: 'Búsqueda de Chofer', + query: '/chofer', + columnas: [ + { + propiedad: 'id', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'nombre', + nombre: 'Nombre' + }, + { + propiedad: 'dni', + nombre: 'DNI' + }, + { + propiedad: 'telefono', + nombre: 'Teléfono' + } + ] + }; + focaModalService.modal(parametrosModal).then( + function (chofer) { + $scope.ordenCarga.chofer = chofer; + $scope.$broadcast('addCabecera', { + 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 + } + ); + }; + + function getEstadosCisternas(cisternas) { + cisternas.forEach(function (cisterna) { + focaOrdenCargaService + .getEstadoCisterna(cisterna.id, $scope.fecha) + .then(function (res) { + cisterna.estado = res.data; + }) + .catch(function (err) { console.error(err) }); + }); + } + + function elegirTransportista(transportista) { + var codigo = ('00000' + transportista.COD).slice(-5); + $scope.idTransportista = transportista.COD; + $scope.filtros = transportista.NOM.trim(); + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + transportista.NOM + }); + } + + function mostrarDetalle(hojasRutas) { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: '', + templateUrl: 'modal-detalle-carga.html', + controller: 'focaModalDetalleController', + resolve: { + parametrosModal: function () { + return { + hojasRutas: hojasRutas, + orden: $scope.hojaRuta.orden + }; + } + }, + size: 'lg', + backdrop: false + } + ); + return modalInstance.result + .then(function (res) { + res.cisternas.forEach(function (cisterna) { + $scope.cisternaCargas.push(cisterna.cisternaCarga); + }); + $scope.cisternaMovimientos = res.movimientos; + $scope.articulosRecibidos = res.articulos; + $scope.articulos = res.articulos; + $filter('filter')($scope.botonera, { + label: 'Detalle de Carga', + })[0].checked = true; + }) + .catch(function (e) { console.error(e); }); + }; + + function crearOrdenCarga() { + + focaBotoneraLateralService.startGuardar(); + $scope.saveLoading = true; } $scope.$watch('ordenCarga', function (newValue) { @@ -83,13 +294,6 @@ angular.module('focaOrdenCarga') }); }, true); - $scope.crearOrdenCarga = function () { - - focaBotoneraLateralService.startGuardar(); - $scope.saveLoading = true; - - } - $scope.salir = function () { $location.path('/'); }; diff --git a/src/js/controllerDetalle.js b/src/js/controllerDetalle.js new file mode 100644 index 0000000..70a1e34 --- /dev/null +++ b/src/js/controllerDetalle.js @@ -0,0 +1,171 @@ +angular.module('focaOrdenCarga') + .controller('focaModalDetalleController', [ + '$scope', '$timeout', '$uibModalInstance', 'focaModalService', + 'focaCrearHojaRutaService', 'parametrosModal', + function ($scope, $timeout, $uibModalInstance, focaModalService, + focaCrearHojaRutaService, parametrosModal) { + + $scope.mostrar = false; + $scope.orden = parametrosModal.orden; + $scope.articulos = []; + $scope.cisternaMovimientos = []; + + init(); + + function init() { + + $scope.hojasRutas = parametrosModal.hojasRutas; + $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( + function (cisterna) { + return !cisterna.desactivado; + } + ); + focaCrearHojaRutaService.getArticulos() + .then(function (articulos) { + $scope.articulos = articulos.data; + }); + } + + $scope.validarCisternaDisponible = function (cisterna) { + if (parseInt(cisterna.disponible) > cisterna.capacidad) { + focaModalService.alert('No se puede ingresar una capacidad disponible ' + + 'superior a la ' + 'capacidad del vehiculo '); + cisterna.disponible = cisterna.capacidad; + return; + } + }; + + $scope.seleccionarProductos = function (key, cisterna) { + focaModalService.modal({ + titulo: 'Productos', + data: $scope.articulos, + size: 'md', + columnas: [ + { + propiedad: 'CodRub', + nombre: 'Codigo' + }, + { + propiedad: 'descripcion', + nombre: 'Nombre' + }, + ], + }).then(function (res) { + cisterna.disponible = cisterna.capacidad; + var newArt = + { + id: 0, + idRemito: 0, + codigo: res.codigo, + sector: res.sector, + sectorCodigo: res.sector + '-' + res.codigo, + descripcion: res.descripcion, + item: key + 1, + nombre: res.descripcion, + precio: parseFloat(res.precio).toFixed(4), + costoUnitario: res.costo, + editCantidad: false, + editPrecio: false, + rubro: res.CodRub, + ivaUnitario: res.IMPIVA, + impuestoInternoUnitario: res.ImpInt, + impuestoInterno1Unitario: res.ImpInt2, + impuestoInterno2Unitario: res.ImpInt3, + precioLista: res.precio, + combustible: 1, + facturado: 0, + idArticulo: res.id, + tasaIva: res.tasaIVA + }; + + newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; + newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; + + cisterna.articuloSeleccionado = newArt; + cisterna.nombreArticulo = res.descripcion; + }).catch(function (e) { + console.log(e); + }); + }; + + $scope.guardar = function () { + + var cisternasFilter = validarArticulos(); + + var articulos = []; + if (cisternasFilter === undefined) { + return; + } + cisternasFilter.forEach(function (cisterna) { + + var fechaReparto = $scope.hojasRutas.fechaReparto; + + // var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { + // return carga.fechaReparto === fechaReparto; + // }); + + // if (filtroCisternaCarga.length) { + // cisterna.cisternaCarga = filtroCisternaCarga[0]; + // } else { + cisterna.cisternaCarga = { + confirmado: null, + fechaReparto: fechaReparto, + idCisterna: cisterna.id, + orden: $scope.orden + }; + // } + + //cargar + if (cisterna.cisternaCarga.cantidad) { + cisterna.cisternaCarga.cantidad += cisterna.disponible; + } else { + cisterna.cisternaCarga.cantidad = cisterna.disponible; + cisterna.cisternaCarga.idProducto = + cisterna.articuloSeleccionado.idArticulo; + } + + //Guardar + var now = new Date(); + var cisternaMovimiento = { + fecha: now.toISOString().slice(0, 19).replace('T', ' '), + cantidad: cisterna.disponible, + metodo: 'carga', + idCisternaCarga: cisterna.cisternaCarga.id, + }; + + cisterna.cisternaCarga.fechaReparto = fechaReparto; + cisterna.articuloSeleccionado.cantidad = cisterna.disponible; + articulos.push(cisterna.articuloSeleccionado); + $scope.cisternaMovimientos.push(cisternaMovimiento); + }); + + $uibModalInstance.close({ + cisternas: cisternasFilter, + movimientos: $scope.cisternaMovimientos, + articulos: articulos + }); + }; + + $scope.cancel = function () { + $uibModalInstance.dismiss(null); + }; + + function validarArticulos() { + var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas + .filter(function (cisterna) { + return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; + }); + + var cisternasIncompletas = cisternasFilter.filter(function (cisterna) { + return (cisterna.articuloSeleccionado && !cisterna.disponible) || + (!cisterna.articuloSeleccionado && cisterna.disponible); + }); + + if (cisternasIncompletas.length > 0 && cisternasFilter.length > 0) { + focaModalService.alert('Ingrese todos los campos para completar el remito'); + cisternasFilter = undefined; + } + return cisternasFilter; + } + } + ]); diff --git a/src/js/service.js b/src/js/service.js index fe2ad21..3f72b05 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,35 +1,60 @@ angular.module('focaOrdenCarga') - .factory('focaOrdenCargaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { - var route = API_ENDPOINT.URL; + .factory('focaOrdenCargaService', ['$http', 'API_ENDPOINT', function ($http, API_ENDPOINT) { return { - getBotonera: function() { - var result = [ - { - label: 'Vehiculo', - image: 'vehiculo_secundario.png' - }, - { - label: 'Fecha de Reparto', - image: 'fechaDeEntrega.png' - }, - { - label: 'Hojas de Ruta', - image: 'hojaDeRuta.png' - }, - { - label: 'Remito Abierto', - image: 'remito_abierto.png' - }, - { - label: 'Chofer', - image: 'chofer_secundario.png' - }, - { - label: 'Ver Cisternas', - image: 'verCisterna.png' - } - ]; - return result; - }, - }; - }]); + getVehiculos: function () { + return $http.get(API_ENDPOINT.URL + '/vehiculo'); + }, + getTransportistas: function () { + return $http.get(API_ENDPOINT.URL + '/transportista'); + }, + getCisternadoPorVehiculo: function (idVehiculo) { + return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo); + }, + getCisterna: function (id) { + return $http.get(API_ENDPOINT.URL + '/cisterna/obtener/' + id); + }, + guardarCisterna: function (cisterna) { + return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', { cisterna: cisterna }); + }, + deleteCisterna: function (id) { + return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); + }, + getVehiculosPorTransportista: function (id) { + return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); + }, + getEstadoCisterna: function (id, fecha) { + console.log(id, " ", fecha); + return $http.post(API_ENDPOINT.URL + '/cisterna/stock', + { idCisterna: id, fecha: fecha }); + }, + getBotonera: function () { + var result = [ + { + label: 'Vehiculo', + image: 'vehiculo_secundario.png' + }, + { + label: 'Fecha de Reparto', + image: 'fechaDeEntrega.png' + }, + { + label: 'Hojas de Ruta', + image: 'hojaDeRuta.png' + }, + { + label: 'Remito Abierto', + image: 'remito_abierto.png' + }, + { + label: 'Chofer', + image: 'chofer_secundario.png' + }, + { + label: 'Ver Cisternas', + image: 'verCisterna.png' + } + ]; + return result; + }, + }; + }]); diff --git a/src/views/modal-detalle-carga.html b/src/views/modal-detalle-carga.html new file mode 100644 index 0000000..c2ad43b --- /dev/null +++ b/src/views/modal-detalle-carga.html @@ -0,0 +1,76 @@ +
Cisterna | +Capacidad | +Disponibles | +Articulo Cargado | +
---|---|---|---|
+ | + | + + | +
+
+
+
+
+
+
+ |
+