From d907dd8e071649be6b18169316205a912680d197 Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Wed, 13 Mar 2019 10:06:18 -0300 Subject: [PATCH] Primera version --- .gitignore | 6 ++ .jshintrc | 64 +++++++++++++++ gulpfile.js | 82 +++++++++++++++++++ package.json | 63 +++++++++++++++ src/etc/develop.js.ejemplo | 4 + src/js/app.js | 1 + src/js/controller.js | 155 ++++++++++++++++++++++++++++++++++++ src/js/service.js | 17 ++++ src/views/modal-resumen-cuenta.html | 114 ++++++++++++++++++++++++++ 9 files changed, 506 insertions(+) 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/js/service.js create mode 100644 src/views/modal-resumen-cuenta.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09dcb46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist +/tmp +package-lock\.json +src/etc/develop\.js +yarn.lock diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d8cbb07 --- /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": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..0a371ed --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,82 @@ +const templateCache = require('gulp-angular-templatecache'); +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'); +const clean = require('gulp-clean'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('templates', function() { + return pump( + [ + gulp.src(paths.srcViews), + replace('views/', ''), + htmlmin(), + templateCache('views.js', { + module: 'focaModalResumenCuenta', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-modal-resumen-cuenta.js'), + replace('src/views/', ''), + replace("['ui.bootstrap']", '[]'), + gulp.dest(paths.tmp), + rename('foca-modal-resumen-cuenta.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +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: 3000}) + ] +}); + +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..244a431 --- /dev/null +++ b/package.json @@ -0,0 +1,63 @@ +{ + "name": "foca-modal-resumen-cuenta", + "version": "0.0.1", + "description": "Modal para resumen de cuenta en cobranzas", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "gulp-pre-commit": "gulp pre-commit", + "compile": "gulp uglify", + "postinstall": "npm run compile && gulp clean-post-install", + "install-dev": "npm install --ignore-scripts" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "repository": { + "type": "git", + "url": "http://git.focasoftware.com/npm/foca-modal-resumen-cuenta" + }, + "author": "Foca Software", + "license": "ISC", + "peerDependencies": { + "angular": "^1.7.4", + "bootstrap": "^4.1.3", + "font-awesome": "^4.7.0", + "ui-bootstrap4": "^3.0.4", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.1", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "gulp-htmlmin": "^5.0.1", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "pump": "^3.0.0", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" + }, + "devDependencies": { + "angular": "1.7.5", + "angular-ladda": "0.4.3", + "bootstrap": "4.1.3", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", + "font-awesome": "4.7.0", + "gulp": "3.9.1", + "gulp-angular-templatecache": "2.2.5", + "gulp-clean": "0.4.0", + "gulp-concat": "2.6.1", + "gulp-connect": "5.6.1", + "gulp-htmlmin": "5.0.1", + "gulp-jshint": "2.1.0", + "gulp-rename": "1.4.0", + "gulp-replace": "1.0.0", + "gulp-uglify": "3.0.1", + "jasmine-core": "3.3.0", + "jquery": "3.3.1", + "jshint": "2.9.6", + "ladda": "1.0.6", + "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..af02be7 --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaModalResumenCuenta') + .constant("API_ENDPOINT", { + 'URL': '//127.0.0.1:9000' + }); diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..8e65c74 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1 @@ +angular.module('focaModalResumenCuenta', ['ui.bootstrap']); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..016cdec --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,155 @@ +angular.module('focaModalResumenCuenta') + .controller('focaModalResumenCuentaController', [ + '$timeout', + '$filter', + '$scope', + '$uibModalInstance', + 'focaModalResumenCuentaService', + 'idCliente', + '$uibModal', + 'focaModalService', + function($timeout, $filter, $scope, $uibModalInstance, + focaModalResumenCuentaService, idCliente, $uibModal, focaModalService) { + var fecha = new Date(); + $scope.generado = false; + $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); + $scope.currentPageFacturas = []; + $scope.currentPage = 1; + $scope.numPerPage = 10; + $scope.selectedFactura = -1; + + $scope.generar = function() { + focaModalResumenCuentaService + .getResumenCuenta(idCliente, $scope.fechaDesde) + .then(function(res) { + res.data.facturas = calcularSaldos(res.data.facturas); + $scope.generado = true; + $scope.results = res.data; + $scope.results.fechaDesde = $scope.fechaDesde; + $scope.search(); + }); + }; + + $scope.cancel = function() { + if ($scope.generado) { + $scope.generado = false; + } else { + $uibModalInstance.dismiss('cancel'); + } + }; + + $scope.enviarMail = function(factura) { + focaModalService + .prompt('Ingrese los emails separados por coma para enviar comprobante', + factura.cliente.MAIL) + .then(function(res) { + return focaModalResumenCuentaService.enviarFacturaPorMail(res, factura); + }) + .then(function() { + focaModalService.alert('Mensaje enviado correctamente'); + }); + }; + + $scope.enviarResumen = function() { + focaModalService + .prompt('Ingrese los emails separados por coma para enviar comprobante', + $scope.results.facturas[0].cliente.MAIL) + .then(function(res) { + return focaModalResumenCuentaService.enviarResumenPorMail(res, + $scope.results); + }) + .then(function() { + focaModalService.alert('Mensaje enviado correctamente'); + }); + }; + + $scope.verFactura = function(factura) { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Detalle de factura', + templateUrl: 'foca-modal-factura-detalle.html', + controller: 'focaModalFacturaDetalleController', + size: 'md', + resolve: { + factura: factura + } + } + ); + modalInstance.result.then(); + }; + + + $scope.search = function() { + if ($scope.results.facturas.length) { + $scope.lastPage = Math.ceil( + $scope.results.facturas.length / $scope.numPerPage + ); + $scope.resetPage(); + } + }; + + $scope.resetPage = function() { + $scope.currentPage = 1; + $scope.selectPage(1); + }; + + $scope.selectPage = function(page) { + var start = (page - 1) * $scope.numPerPage; + var end = start + $scope.numPerPage; + $scope.paginas = []; + $scope.paginas = calcularPages(page); + $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); + $scope.currentPage = page; + }; + + function calcularPages(paginaActual) { + var paginas = []; + paginas.push(paginaActual); + + if (paginaActual - 1 > 1) { + + paginas.unshift(paginaActual - 1); + if (paginaActual - 2 > 1) { + paginas.unshift(paginaActual - 2); + } + } + + if (paginaActual + 1 < $scope.lastPage) { + paginas.push(paginaActual + 1); + if (paginaActual + 2 < $scope.lastPage) { + paginas.push(paginaActual + 2); + } + } + + if (paginaActual !== 1) { + paginas.unshift(1); + } + + if (paginaActual !== $scope.lastPage) { + paginas.push($scope.lastPage); + } + + return paginas; + } + + function calcularSaldos(facturas) { + var saldo = 0; + + facturas.forEach(function(factura) { + if (factura.TCO === 'CI' || + factura.TCO === 'FT' || + factura.TCO === 'ND'){ + factura.IPA = factura.IPA * -1; + } else { + factura.IPA = factura.IPA; + } + saldo += factura.IPA; + factura.saldo = saldo; + factura.saldo_show = Math.abs(saldo); + factura.IPA_SHOW = Math.abs(factura.IPA); + }); + + return facturas; + } + }] + ); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..aaae67c --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,17 @@ +angular.module('focaModalResumenCuenta') + .service('focaModalResumenCuentaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + return { + getResumenCuenta: function(idCliente, fechaDesde) { + return $http.get(API_ENDPOINT.URL + + '/factura/resumen/' + idCliente + '/' + fechaDesde); + }, + enviarFacturaPorMail: function(receiver, factura) { + return $http.post(API_ENDPOINT.URL + '/mail', + {receiver: receiver, factura: factura}); + }, + enviarResumenPorMail: function(receiver, resumen) { + return $http.post(API_ENDPOINT.URL + '/mail/resumen-cuenta', + {receiver: receiver, resumen: resumen}); + } + }; + }]); diff --git a/src/views/modal-resumen-cuenta.html b/src/views/modal-resumen-cuenta.html new file mode 100644 index 0000000..1ec3311 --- /dev/null +++ b/src/views/modal-resumen-cuenta.html @@ -0,0 +1,114 @@ + + + -- 1.9.1