From a3a220dda5d774fcb6c371f29fb16368efbfc905 Mon Sep 17 00:00:00 2001 From: efernandez Date: Tue, 15 Jan 2019 10:15:22 -0300 Subject: [PATCH] first version --- .gitignore | 6 + .jshintrc | 64 ++++++++++ README.md | 2 +- gulpfile.js | 86 ++++++++++++++ package.json | 46 ++++++++ src/etc/develop.js.ejemplo | 4 + src/js/app.js | 1 + src/js/controller.js | 222 +++++++++++++++++++++++++++++++++++ src/views/foca-detalle-vehiculo.html | 129 ++++++++++++++++++++ 9 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/etc/develop.js.ejemplo create mode 100644 src/js/app.js create mode 100644 src/js/controller.js create mode 100644 src/views/foca-detalle-vehiculo.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76a3502 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist +package-lock\.json +/src/etc/develop.js + +tmp/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..f7034ad --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": false, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": false, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe", "L"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/README.md b/README.md index a6f054d..208247b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# foca-modal +# foca-modal-detalle-cisternas Modal detalle, carga de cisternas diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..e3ef1ee --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,86 @@ +const templateCache = require('gulp-angular-templatecache'); +const clean = require('gulp-clean'); +const concat = require('gulp-concat'); +const htmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); +const connect = require('gulp-connect'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('templates', ['clean'], function() { + return pump( + [ + gulp.src(paths.srcViews), + htmlmin(), + templateCache('views.js', { + module: 'focaModalDetalleCisternas', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-modal-detalle-cisternas.js'), + replace('src/views/', ''), + gulp.dest(paths.tmp), + rename('foca-modal-detalle-cisternas.min.js'), + uglify(), + replace('"ui.bootstrap"', ''), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('clean', function(){ + return gulp.src(['tmp', 'dist'], {read: false}) + .pipe(clean()); +}); + +gulp.task('pre-commit', function() { + return pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); + +gulp.task('webserver', function() { + pump [ + connect.server({port: 3300, host: '0.0.0.0'}) + ] +}); + +gulp.task('clean-post-install', function() { + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', + 'index.html'], {read: false}) + .pipe(clean()); +}); + +gulp.task('default', ['webserver']); + +gulp.task('watch', function() { + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..2450cfa --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "foca-modal-detalle-cisternas", + "version": "0.0.1", + "description": "Detalle de cisternas", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "gulp uglify", + "gulp-pre-commit": "gulp pre-commit", + "postinstall": "npm run compile && gulp clean-post-install", + "install-dev": "npm install -D jasmine-core pre-commit angular bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "repository": { + "type": "git", + "url": "http://git.focasoftware.com/npm/foca-modal-detalle-cisternas.git" + }, + "author": "Foca Software", + "license": "ISC", + "devDependencies": { + "angular": "^1.7.5", + "angular-route": "^1.7.5", + "bootstrap": "^4.2.1", + "font-awesome": "^4.7.0", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.6", + "gulp-clean": "^0.4.0", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.7.0", + "gulp-htmlmin": "^5.0.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-sequence": "^1.0.0", + "gulp-uglify": "^3.0.1", + "gulp-uglify-es": "^1.0.4", + "jasmine-core": "^3.3.0", + "jquery": "^3.3.1", + "jshint": "^2.9.7", + "pre-commit": "^1.2.2", + "pump": "^3.0.0", + "ui-bootstrap4": "^3.0.5" + } +} diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo new file mode 100644 index 0000000..ed5d184 --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaModalDetalleCisternas') + .constant("API_ENDPOINT", { + 'URL': 'http://127.0.0.1:9000' + }); diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..512a559 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1 @@ +angular.module('focaModalDetalleCisternas', ['ui.bootstrap']); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..dc6861e --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,222 @@ +angular.module('focaModalDetalleCisternas') + .controller('focaDetalleVehiculo', + ['$scope', + '$uibModalInstance', + 'idVehiculo', + 'idRemito', + 'focaModalService', + '$filter', + 'focaLogisticaPedidoRutaService', + function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, + focaLogisticaPedidoRutaService + ) { + //seteo variables + $scope.cargandoDatos = true; + $scope.idRemito = idRemito; + $scope.articulos = []; + $scope.vehiculo = {}; + $scope.cisternas = []; + $scope.cisternasCarga = []; + $scope.remito = {}; + $scope.aCargar = []; + var cisternaMovimientos = []; + var promesaRemito; + var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); + var promesaCisternas = focaLogisticaPedidoRutaService + .obtenerCisternasPorFecha(idVehiculo); + if(idRemito !== -1) { + promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); + } + Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { + $scope.cargandoDatos = false; + $scope.vehiculo = res[0].data; + $scope.cisternas = res[1].data; + if(!res[2]) { + $scope.$digest(); + return; + } + $scope.remito = res[2].data; + if($scope.remito.idUsuarioProceso) { + focaModalService.alert('Remito ya asignado'); + $uibModalInstance.close(); + } + $scope.articulos = $scope.remito.articulosRemito; + $scope.seleccionarArticulo($scope.articulos[0]); + var tieneUsuario = $scope.cisternas.filter(function(cisterna) { + if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { + return cisterna.cisternaCarga.idUsuarioProceso !== + focaLogisticaPedidoRutaService.idUsuario; + } + }); + if(tieneUsuario.length) { + focaModalService.alert('Otro usario esta usando este vehículo'); + $uibModalInstance.close(); + } + $scope.$digest(); + }); + $scope.aceptar = function() { + $scope.cargando = true; + for(var i = 0; i < $scope.cisternasCarga.length; i++) { + $scope.cisternasCarga[i].idUsuarioProceso = + focaLogisticaPedidoRutaService.idUsuario; + delete $scope.cisternasCarga[i].articulo; + } + var cisterna = { + cisternaMovimientos: cisternaMovimientos, + cisternaCargas: $scope.cisternasCarga, + idVehiculo: $scope.vehiculo.id, + fechaReparto: focaLogisticaPedidoRutaService.fecha + }; + 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(); + if (error.status === 403) { + focaModalService.alert('ERROR: ' + error.data); + return; + } + focaModalService.alert('Hubo un error al cargar las cisternas'); + }); + }; + $scope.cancelar = function() { + $uibModalInstance.close(); + }; + $scope.cargarACisternas = function() { + for(var i = 0; i < $scope.cisternas.length; i++) { + var cisterna = $scope.cisternas[i]; + var aCargar = parseFloat($scope.aCargar[i]); + var fechaReparto = focaLogisticaPedidoRutaService.fecha; + //validaciones + if(!aCargar) { + continue; + } + //cargar + 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); + //Guardar + var now = new Date(); + var cisternaMovimiento = { + fecha: now.toISOString().slice(0, 19).replace('T', ' '), + cantidad: aCargar, + metodo: 'carga', + idCisternaCarga: cisterna.cisternaCarga.id, + idRemito: $scope.remito.id + }; + cisterna.cisternaCarga.fechaReparto = fechaReparto; + cisterna.cisternaCarga.idCisterna = cisterna.id; + $scope.cisternasCarga.push(cisterna.cisternaCarga); + cisternaMovimientos.push(cisternaMovimiento); + } + var articuloSiguiente = $scope.articulos.filter( + function(filter) { + return filter.cargado !== true; + } + ); + if(articuloSiguiente.length > 0) { + $scope.seleccionarArticulo(articuloSiguiente[0]); + } + }; + $scope.calcularPorcentaje = function(cisterna) { + if(!cisterna.cisternaCarga) { + cisterna.cisternaCarga = { + cantidad: 0 + }; + } + var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / + cisterna.capacidad) + '%'; + var elementHtml = document.getElementById(cisterna.id); + if(elementHtml) { + elementHtml.style.width = porcentaje; + } + }; + $scope.seleccionarArticulo = function(articulo) { + $scope.articuloSeleccionado = articulo; + $scope.cisternaDisponible(); + $scope.autoCompletar(); + $scope.actualizarArticulo(); + }; + $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.autoCompletar = function() { + $scope.aCargar = []; + var disponible = $filter('filter')($scope.cisternas, {disabled: false}); + var index = $scope.cisternas.indexOf(disponible[0]); + $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; + }; + $scope.cisternaDisponible = function() { + for(var i = 0; i < $scope.cisternas.length; i++) { + if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { + $scope.cisternas[i].disabled = true; + continue; + } + if($scope.cisternas[i].cisternaCarga && + $scope.cisternas[i].cisternaCarga.idProducto && + $scope.articuloSeleccionado.idArticulo !== + $scope.cisternas[i].cisternaCarga.idProducto) + { + $scope.cisternas[i].disabled = true; + continue; + } + $scope.cisternas[i].disabled = false; + } + }; + $scope.rellenarInput = function(input) { + if(!$scope.articuloSeleccionado) return; + if($scope.articuloSeleccionado.cantidad - + $scope.articuloSeleccionado.cantidadCargada === 0) { + return input; + } + if(!input) input = 0; + input = parseFloat(input); + input += parseFloat($scope.articuloSeleccionado.cantidad - + $scope.articuloSeleccionado.cantidadCargada); + return input; + }; + $scope.distribucionDisponible = function() { + if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - + $scope.articuloSeleccionado.cantidadCargada !== 0 || + !$scope.tieneArticulosPendientes()) { + return false; + } + return true; + }; + $scope.tieneArticulosPendientes = function() { + var algunValorNegativo = $scope.aCargar.filter(function(p) { + return p < 0; + }); + if(algunValorNegativo.length) { + return false; + } + var articulosDescargados = $scope.articulos.filter(function(filter) { + return filter.cargado === true; + }); + if(articulosDescargados.length === $scope.articulos.length) { + $scope.aCargar = []; + return false; + } + return true; + }; + }]); diff --git a/src/views/foca-detalle-vehiculo.html b/src/views/foca-detalle-vehiculo.html new file mode 100644 index 0000000..1883336 --- /dev/null +++ b/src/views/foca-detalle-vehiculo.html @@ -0,0 +1,129 @@ + + + -- 1.9.1