Commit a824859b6d0ce91599676413c3b2488202c1bc56
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master See merge request !1
Showing
9 changed files
Show diff stats
.gitignore
.jshintrc
| ... | ... | @@ -0,0 +1,64 @@ |
| 1 | +{ | |
| 2 | + /* | |
| 3 | + * ENVIRONMENTS | |
| 4 | + * ================= | |
| 5 | + */ | |
| 6 | + | |
| 7 | + // Define globals exposed by modern browsers. | |
| 8 | + "browser": true, | |
| 9 | + | |
| 10 | + // Define globals exposed by jQuery. | |
| 11 | + "jquery": true, | |
| 12 | + | |
| 13 | + // Define globals exposed by Node.js. | |
| 14 | + "node": true, | |
| 15 | + | |
| 16 | + // Allow ES6. | |
| 17 | + "esversion": 6, | |
| 18 | + | |
| 19 | + /* | |
| 20 | + * ENFORCING OPTIONS | |
| 21 | + * ================= | |
| 22 | + */ | |
| 23 | + | |
| 24 | + // Force all variable names to use either camelCase style or UPPER_CASE | |
| 25 | + // with underscores. | |
| 26 | + "camelcase": true, | |
| 27 | + | |
| 28 | + // Prohibit use of == and != in favor of === and !==. | |
| 29 | + "eqeqeq": true, | |
| 30 | + | |
| 31 | + // Enforce tab width of 2 spaces. | |
| 32 | + "indent": 4, | |
| 33 | + | |
| 34 | + // Prohibit use of a variable before it is defined. | |
| 35 | + "latedef": false, | |
| 36 | + | |
| 37 | + // Enforce line length to 100 characters | |
| 38 | + "maxlen": 100, | |
| 39 | + | |
| 40 | + // Require capitalized names for constructor functions. | |
| 41 | + "newcap": true, | |
| 42 | + | |
| 43 | + // Enforce use of single quotation marks for strings. | |
| 44 | + "quotmark": "single", | |
| 45 | + | |
| 46 | + // Enforce placing 'use strict' at the top function scope | |
| 47 | + "strict": false, | |
| 48 | + | |
| 49 | + // Prohibit use of explicitly undeclared variables. | |
| 50 | + "undef": true, | |
| 51 | + | |
| 52 | + // Warn when variables are defined but never used. | |
| 53 | + "unused": true, | |
| 54 | + | |
| 55 | + // Para que funcione en angular | |
| 56 | + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | |
| 57 | + /* | |
| 58 | + * RELAXING OPTIONS | |
| 59 | + * ================= | |
| 60 | + */ | |
| 61 | + | |
| 62 | + // Suppress warnings about == null comparisons. | |
| 63 | + "eqnull": true | |
| 64 | +} |
gulpfile.js
| ... | ... | @@ -0,0 +1,82 @@ |
| 1 | +const templateCache = require('gulp-angular-templatecache'); | |
| 2 | +const concat = require('gulp-concat'); | |
| 3 | +const htmlmin = require('gulp-htmlmin'); | |
| 4 | +const rename = require('gulp-rename'); | |
| 5 | +const uglify = require('gulp-uglify'); | |
| 6 | +const gulp = require('gulp'); | |
| 7 | +const pump = require('pump'); | |
| 8 | +const jshint = require('gulp-jshint'); | |
| 9 | +const replace = require('gulp-replace'); | |
| 10 | +const connect = require('gulp-connect'); | |
| 11 | +const clean = require('gulp-clean'); | |
| 12 | + | |
| 13 | +var paths = { | |
| 14 | + srcJS: 'src/js/*.js', | |
| 15 | + srcViews: 'src/views/*.html', | |
| 16 | + tmp: 'tmp', | |
| 17 | + dist: 'dist/' | |
| 18 | +}; | |
| 19 | + | |
| 20 | +gulp.task('templates', function() { | |
| 21 | + return pump( | |
| 22 | + [ | |
| 23 | + gulp.src(paths.srcViews), | |
| 24 | + replace('views/', ''), | |
| 25 | + htmlmin(), | |
| 26 | + templateCache('views.js', { | |
| 27 | + module: 'focaModalResumenCuenta', | |
| 28 | + root: '' | |
| 29 | + }), | |
| 30 | + gulp.dest(paths.tmp) | |
| 31 | + ] | |
| 32 | + ); | |
| 33 | +}); | |
| 34 | + | |
| 35 | +gulp.task('uglify', ['templates'], function() { | |
| 36 | + return pump( | |
| 37 | + [ | |
| 38 | + gulp.src([ | |
| 39 | + paths.srcJS, | |
| 40 | + 'tmp/views.js' | |
| 41 | + ]), | |
| 42 | + concat('foca-modal-resumen-cuenta.js'), | |
| 43 | + replace('src/views/', ''), | |
| 44 | + replace("['ui.bootstrap']", '[]'), | |
| 45 | + gulp.dest(paths.tmp), | |
| 46 | + rename('foca-modal-resumen-cuenta.min.js'), | |
| 47 | + uglify(), | |
| 48 | + gulp.dest(paths.dist) | |
| 49 | + ] | |
| 50 | + ); | |
| 51 | +}); | |
| 52 | + | |
| 53 | +gulp.task('pre-commit', function() { | |
| 54 | + return pump( | |
| 55 | + [ | |
| 56 | + gulp.src(paths.srcJS), | |
| 57 | + jshint('.jshintrc'), | |
| 58 | + jshint.reporter('default'), | |
| 59 | + jshint.reporter('fail') | |
| 60 | + ] | |
| 61 | + ); | |
| 62 | + | |
| 63 | + gulp.start('uglify'); | |
| 64 | +}); | |
| 65 | + | |
| 66 | +gulp.task('webserver', function() { | |
| 67 | + pump [ | |
| 68 | + connect.server({port: 3000}) | |
| 69 | + ] | |
| 70 | +}); | |
| 71 | + | |
| 72 | +gulp.task('clean-post-install', function(){ | |
| 73 | + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | |
| 74 | + 'index.html'], {read: false}) | |
| 75 | + .pipe(clean()); | |
| 76 | +}); | |
| 77 | + | |
| 78 | +gulp.task('default', ['webserver']); | |
| 79 | + | |
| 80 | +gulp.task('watch', function() { | |
| 81 | + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) | |
| 82 | +}); |
package.json
| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | +{ | |
| 2 | + "name": "foca-modal-resumen-cuenta", | |
| 3 | + "version": "0.0.1", | |
| 4 | + "description": "Modal para resumen de cuenta en cobranzas", | |
| 5 | + "main": "index.js", | |
| 6 | + "scripts": { | |
| 7 | + "test": "echo \"Error: no test specified\" && exit 1", | |
| 8 | + "gulp-pre-commit": "gulp pre-commit", | |
| 9 | + "compile": "gulp uglify", | |
| 10 | + "postinstall": "npm run compile && gulp clean-post-install", | |
| 11 | + "install-dev": "npm install --ignore-scripts" | |
| 12 | + }, | |
| 13 | + "pre-commit": [ | |
| 14 | + "gulp-pre-commit" | |
| 15 | + ], | |
| 16 | + "repository": { | |
| 17 | + "type": "git", | |
| 18 | + "url": "http://git.focasoftware.com/npm/foca-modal-resumen-cuenta" | |
| 19 | + }, | |
| 20 | + "author": "Foca Software", | |
| 21 | + "license": "ISC", | |
| 22 | + "peerDependencies": { | |
| 23 | + "angular": "^1.7.4", | |
| 24 | + "bootstrap": "^4.1.3", | |
| 25 | + "font-awesome": "^4.7.0", | |
| 26 | + "ui-bootstrap4": "^3.0.4", | |
| 27 | + "gulp": "^3.9.1", | |
| 28 | + "gulp-angular-templatecache": "^2.2.1", | |
| 29 | + "gulp-concat": "^2.6.1", | |
| 30 | + "gulp-connect": "^5.6.1", | |
| 31 | + "gulp-htmlmin": "^5.0.1", | |
| 32 | + "gulp-rename": "^1.4.0", | |
| 33 | + "gulp-replace": "^1.0.0", | |
| 34 | + "gulp-uglify": "^3.0.1", | |
| 35 | + "jquery": "^3.3.1", | |
| 36 | + "pump": "^3.0.0", | |
| 37 | + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" | |
| 38 | + }, | |
| 39 | + "devDependencies": { | |
| 40 | + "angular": "1.7.5", | |
| 41 | + "angular-ladda": "0.4.3", | |
| 42 | + "bootstrap": "4.1.3", | |
| 43 | + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", | |
| 44 | + "font-awesome": "4.7.0", | |
| 45 | + "gulp": "3.9.1", | |
| 46 | + "gulp-angular-templatecache": "2.2.5", | |
| 47 | + "gulp-clean": "0.4.0", | |
| 48 | + "gulp-concat": "2.6.1", | |
| 49 | + "gulp-connect": "5.6.1", | |
| 50 | + "gulp-htmlmin": "5.0.1", | |
| 51 | + "gulp-jshint": "2.1.0", | |
| 52 | + "gulp-rename": "1.4.0", | |
| 53 | + "gulp-replace": "1.0.0", | |
| 54 | + "gulp-uglify": "3.0.1", | |
| 55 | + "jasmine-core": "3.3.0", | |
| 56 | + "jquery": "3.3.1", | |
| 57 | + "jshint": "2.9.6", | |
| 58 | + "ladda": "1.0.6", | |
| 59 | + "pre-commit": "1.2.2", | |
| 60 | + "pump": "3.0.0", | |
| 61 | + "ui-bootstrap4": "3.0.5" | |
| 62 | + } | |
| 63 | +} |
src/etc/develop.js.ejemplo
src/js/app.js
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +angular.module('focaModalResumenCuenta', ['ui.bootstrap']); |
src/js/controller.js
| ... | ... | @@ -0,0 +1,155 @@ |
| 1 | +angular.module('focaModalResumenCuenta') | |
| 2 | + .controller('focaModalResumenCuentaController', [ | |
| 3 | + '$timeout', | |
| 4 | + '$filter', | |
| 5 | + '$scope', | |
| 6 | + '$uibModalInstance', | |
| 7 | + 'focaModalResumenCuentaService', | |
| 8 | + 'idCliente', | |
| 9 | + '$uibModal', | |
| 10 | + 'focaModalService', | |
| 11 | + function($timeout, $filter, $scope, $uibModalInstance, | |
| 12 | + focaModalResumenCuentaService, idCliente, $uibModal, focaModalService) { | |
| 13 | + var fecha = new Date(); | |
| 14 | + $scope.generado = false; | |
| 15 | + $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | |
| 16 | + $scope.currentPageFacturas = []; | |
| 17 | + $scope.currentPage = 1; | |
| 18 | + $scope.numPerPage = 10; | |
| 19 | + $scope.selectedFactura = -1; | |
| 20 | + | |
| 21 | + $scope.generar = function() { | |
| 22 | + focaModalResumenCuentaService | |
| 23 | + .getResumenCuenta(idCliente, $scope.fechaDesde) | |
| 24 | + .then(function(res) { | |
| 25 | + res.data.facturas = calcularSaldos(res.data.facturas); | |
| 26 | + $scope.generado = true; | |
| 27 | + $scope.results = res.data; | |
| 28 | + $scope.results.fechaDesde = $scope.fechaDesde; | |
| 29 | + $scope.search(); | |
| 30 | + }); | |
| 31 | + }; | |
| 32 | + | |
| 33 | + $scope.cancel = function() { | |
| 34 | + if ($scope.generado) { | |
| 35 | + $scope.generado = false; | |
| 36 | + } else { | |
| 37 | + $uibModalInstance.dismiss('cancel'); | |
| 38 | + } | |
| 39 | + }; | |
| 40 | + | |
| 41 | + $scope.enviarMail = function(factura) { | |
| 42 | + focaModalService | |
| 43 | + .prompt('Ingrese los emails separados por coma para enviar comprobante', | |
| 44 | + factura.cliente.MAIL) | |
| 45 | + .then(function(res) { | |
| 46 | + return focaModalResumenCuentaService.enviarFacturaPorMail(res, factura); | |
| 47 | + }) | |
| 48 | + .then(function() { | |
| 49 | + focaModalService.alert('Mensaje enviado correctamente'); | |
| 50 | + }); | |
| 51 | + }; | |
| 52 | + | |
| 53 | + $scope.enviarResumen = function() { | |
| 54 | + focaModalService | |
| 55 | + .prompt('Ingrese los emails separados por coma para enviar comprobante', | |
| 56 | + $scope.results.facturas[0].cliente.MAIL) | |
| 57 | + .then(function(res) { | |
| 58 | + return focaModalResumenCuentaService.enviarResumenPorMail(res, | |
| 59 | + $scope.results); | |
| 60 | + }) | |
| 61 | + .then(function() { | |
| 62 | + focaModalService.alert('Mensaje enviado correctamente'); | |
| 63 | + }); | |
| 64 | + }; | |
| 65 | + | |
| 66 | + $scope.verFactura = function(factura) { | |
| 67 | + var modalInstance = $uibModal.open( | |
| 68 | + { | |
| 69 | + ariaLabelledBy: 'Detalle de factura', | |
| 70 | + templateUrl: 'foca-modal-factura-detalle.html', | |
| 71 | + controller: 'focaModalFacturaDetalleController', | |
| 72 | + size: 'md', | |
| 73 | + resolve: { | |
| 74 | + factura: factura | |
| 75 | + } | |
| 76 | + } | |
| 77 | + ); | |
| 78 | + modalInstance.result.then(); | |
| 79 | + }; | |
| 80 | + | |
| 81 | + | |
| 82 | + $scope.search = function() { | |
| 83 | + if ($scope.results.facturas.length) { | |
| 84 | + $scope.lastPage = Math.ceil( | |
| 85 | + $scope.results.facturas.length / $scope.numPerPage | |
| 86 | + ); | |
| 87 | + $scope.resetPage(); | |
| 88 | + } | |
| 89 | + }; | |
| 90 | + | |
| 91 | + $scope.resetPage = function() { | |
| 92 | + $scope.currentPage = 1; | |
| 93 | + $scope.selectPage(1); | |
| 94 | + }; | |
| 95 | + | |
| 96 | + $scope.selectPage = function(page) { | |
| 97 | + var start = (page - 1) * $scope.numPerPage; | |
| 98 | + var end = start + $scope.numPerPage; | |
| 99 | + $scope.paginas = []; | |
| 100 | + $scope.paginas = calcularPages(page); | |
| 101 | + $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); | |
| 102 | + $scope.currentPage = page; | |
| 103 | + }; | |
| 104 | + | |
| 105 | + function calcularPages(paginaActual) { | |
| 106 | + var paginas = []; | |
| 107 | + paginas.push(paginaActual); | |
| 108 | + | |
| 109 | + if (paginaActual - 1 > 1) { | |
| 110 | + | |
| 111 | + paginas.unshift(paginaActual - 1); | |
| 112 | + if (paginaActual - 2 > 1) { | |
| 113 | + paginas.unshift(paginaActual - 2); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + if (paginaActual + 1 < $scope.lastPage) { | |
| 118 | + paginas.push(paginaActual + 1); | |
| 119 | + if (paginaActual + 2 < $scope.lastPage) { | |
| 120 | + paginas.push(paginaActual + 2); | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 124 | + if (paginaActual !== 1) { | |
| 125 | + paginas.unshift(1); | |
| 126 | + } | |
| 127 | + | |
| 128 | + if (paginaActual !== $scope.lastPage) { | |
| 129 | + paginas.push($scope.lastPage); | |
| 130 | + } | |
| 131 | + | |
| 132 | + return paginas; | |
| 133 | + } | |
| 134 | + | |
| 135 | + function calcularSaldos(facturas) { | |
| 136 | + var saldo = 0; | |
| 137 | + | |
| 138 | + facturas.forEach(function(factura) { | |
| 139 | + if (factura.TCO === 'CI' || | |
| 140 | + factura.TCO === 'FT' || | |
| 141 | + factura.TCO === 'ND'){ | |
| 142 | + factura.IPA = factura.IPA * -1; | |
| 143 | + } else { | |
| 144 | + factura.IPA = factura.IPA; | |
| 145 | + } | |
| 146 | + saldo += factura.IPA; | |
| 147 | + factura.saldo = saldo; | |
| 148 | + factura.saldo_show = Math.abs(saldo); | |
| 149 | + factura.IPA_SHOW = Math.abs(factura.IPA); | |
| 150 | + }); | |
| 151 | + | |
| 152 | + return facturas; | |
| 153 | + } | |
| 154 | + }] | |
| 155 | + ); |
src/js/service.js
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +angular.module('focaModalResumenCuenta') | |
| 2 | + .service('focaModalResumenCuentaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | |
| 3 | + return { | |
| 4 | + getResumenCuenta: function(idCliente, fechaDesde) { | |
| 5 | + return $http.get(API_ENDPOINT.URL + | |
| 6 | + '/factura/resumen/' + idCliente + '/' + fechaDesde); | |
| 7 | + }, | |
| 8 | + enviarFacturaPorMail: function(receiver, factura) { | |
| 9 | + return $http.post(API_ENDPOINT.URL + '/mail', | |
| 10 | + {receiver: receiver, factura: factura}); | |
| 11 | + }, | |
| 12 | + enviarResumenPorMail: function(receiver, resumen) { | |
| 13 | + return $http.post(API_ENDPOINT.URL + '/mail/resumen-cuenta', | |
| 14 | + {receiver: receiver, resumen: resumen}); | |
| 15 | + } | |
| 16 | + }; | |
| 17 | + }]); |
src/views/modal-resumen-cuenta.html
| ... | ... | @@ -0,0 +1,114 @@ |
| 1 | +<div class="modal-header py-1"> | |
| 2 | + <div class="row w-100"> | |
| 3 | + <div class="col-lg-6"> | |
| 4 | + <h5 class="modal-title my-1">Resumen de cuenta</h5> | |
| 5 | + </div> | |
| 6 | + <div class="col-lg-6 text-right" ng-show="generado"> | |
| 7 | + <h6 class="modal-title my-1">Saldo hasta la fecha: {{results.saldo | number: 2}}</h6> | |
| 8 | + </div> | |
| 9 | + </div> | |
| 10 | +</div> | |
| 11 | +<div class="modal-body" id="modal-body"> | |
| 12 | + <div class="input-group row" | |
| 13 | + ng-hide="generado"> | |
| 14 | + <small class="col-md-2 col-4 text-left my-1">Fecha Desde</small> | |
| 15 | + <div class="col-md-4 col-8 input-group mb-2"> | |
| 16 | + <div class="input-group-prepend"> | |
| 17 | + <div class="input-group-text form-control-sm"> | |
| 18 | + <i class="fa fa-calendar"></i> | |
| 19 | + </div> | |
| 20 | + </div> | |
| 21 | + <input | |
| 22 | + class="form-control form-control-sm" | |
| 23 | + id="inlineFormInputGroup" | |
| 24 | + ladda="searchLoading" | |
| 25 | + type="text" | |
| 26 | + ng-model="fechaDesde" | |
| 27 | + ng-required="true" | |
| 28 | + uib-datepicker-popup="dd/MM/yyyy" | |
| 29 | + show-button-bar="false" | |
| 30 | + is-open="datepickerOpen" | |
| 31 | + on-open-focus="false" | |
| 32 | + ng-focus="datepickerOpen = true" | |
| 33 | + /> | |
| 34 | + </div> | |
| 35 | + </div> | |
| 36 | + <table class="table table-striped table-sm" ng-show="generado"> | |
| 37 | + <thead> | |
| 38 | + <tr> | |
| 39 | + <th>Comprobante</th> | |
| 40 | + <th>Vencimiento</th> | |
| 41 | + <th class="text-right">Importe</th> | |
| 42 | + <th class="text-right">Saldo</th> | |
| 43 | + <th class="text-right"></th> | |
| 44 | + <th class="text-right"></th> | |
| 45 | + </tr> | |
| 46 | + </thead> | |
| 47 | + <tbody> | |
| 48 | + <tr class="selectable" | |
| 49 | + ng-repeat="(key, factura) in currentPageFacturas"> | |
| 50 | + <td>{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td> | |
| 51 | + <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> | |
| 52 | + <td class="text-right"> | |
| 53 | + {{ factura.IPA_SHOW | number:2 }} | |
| 54 | + <span ng-class="{'invisible': factura.IPA >= 0}">-</span> | |
| 55 | + </td> | |
| 56 | + <td class="text-right"> | |
| 57 | + {{ factura.saldo_show | number:2 }} | |
| 58 | + <span ng-class="{'invisible': factura.saldo >= 0}">-</span> | |
| 59 | + </td> | |
| 60 | + <td> | |
| 61 | + <button | |
| 62 | + class="btn p-1" | |
| 63 | + ng-click="verFactura(factura)" | |
| 64 | + title="Ver comprobante" | |
| 65 | + > | |
| 66 | + <i class="fa fa-eye" aria-hidden="true"></i> | |
| 67 | + </button> | |
| 68 | + </td> | |
| 69 | + <td> | |
| 70 | + <button | |
| 71 | + class="btn p-1" | |
| 72 | + ng-click="enviarMail(factura)" | |
| 73 | + title="Enviar comprobante por mail" | |
| 74 | + > | |
| 75 | + <i class="fa fa-envelope-o" aria-hidden="true"></i> | |
| 76 | + </button> | |
| 77 | + </td> | |
| 78 | + </tr> | |
| 79 | + </tbody> | |
| 80 | + </table> | |
| 81 | +</div> | |
| 82 | +<div class="modal-footer py-1"> | |
| 83 | + <nav ng-show="currentPageFacturas.length" class="mr-auto"> | |
| 84 | + <ul class="pagination pagination-sm justify-content mb-0"> | |
| 85 | + <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | |
| 86 | + <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> | |
| 87 | + <span aria-hidden="true">«</span> | |
| 88 | + <span class="sr-only">Anterior</span> | |
| 89 | + </a> | |
| 90 | + </li> | |
| 91 | + <li | |
| 92 | + class="page-item" | |
| 93 | + ng-repeat="pagina in paginas" | |
| 94 | + ng-class="{'active': pagina == currentPage}" | |
| 95 | + > | |
| 96 | + <a | |
| 97 | + class="page-link" | |
| 98 | + href="javascript:void();" | |
| 99 | + ng-click="selectPage(pagina)" | |
| 100 | + ng-bind="pagina" | |
| 101 | + ></a> | |
| 102 | + </li> | |
| 103 | + <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | |
| 104 | + <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> | |
| 105 | + <span aria-hidden="true">»</span> | |
| 106 | + <span class="sr-only">Siguiente</span> | |
| 107 | + </a> | |
| 108 | + </li> | |
| 109 | + </ul> | |
| 110 | + </nav> | |
| 111 | + <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="generar()" ng-hide="generado">Generar</button> | |
| 112 | + <button class="btn btn-sm btn-primary my-1" type="button" ng-click="enviarResumen()" ng-show="generado">Enviar</button> | |
| 113 | + <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="cancel()">Cancelar</button> | |
| 114 | +</div> |