diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e6901b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/dist +package-lock\.json +/src/etc/develop.js +tmp/ 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/README.md b/README.md new file mode 100644 index 0000000..6d0ec16 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +foca-crear-cobranza diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..a79cb57 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,87 @@ +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: 'focaCrearCobranza', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-crear-cobranza.js'), + replace('src/views/', ''), + gulp.dest(paths.tmp), + rename('foca-crear-cobranza.min.js'), + uglify(), + replace('"ngRoute","ui.bootstrap","focaModal","focaModalFactura","focaBusquedaCliente",'+ + '"focaDirectivas","focaModalMoneda","focaModalCotizacion"', ''), + 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/index.html b/index.html new file mode 100644 index 0000000..171415f --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..79fd0af --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "foca-crear-cobranza", + "version": "0.0.1", + "description": "sistema de cobranzas a partir de facturas", + "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 angular-ladda ladda@1.0.6 angular-route 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 git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-factura.git git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git git+http://git.focasoftware.com/npm/foca-directivas.git" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "repository": { + "type": "git", + "url": "http://git.focasoftware.com/npm/foca-crear-cobranza.git" + }, + "author": "Foca Software", + "license": "ISC", + "devDependencies": { + "angular": "^1.7.5", + "angular-ladda": "^0.4.3", + "angular-route": "^1.7.5", + "bootstrap": "^4.1.3", + "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", + "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", + "foca-modal-factura": "git+http://git.focasoftware.com/npm/foca-modal-factura.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-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.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..ab24384 --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaCrearCobranza') + .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..4a5e997 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,10 @@ +angular.module('focaCrearCobranza', [ + 'ngRoute', + 'ui.bootstrap', + 'focaModal', + 'focaModalFactura', + 'focaBusquedaCliente', + 'focaDirectivas', + 'focaModalMoneda', + 'focaModalCotizacion' +]); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..513da0e --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,335 @@ +angular.module('focaCrearCobranza') .controller('cobranzaController', + [ + '$scope', + '$uibModal', + '$location', + '$filter', + 'focaCrearCobranzaService', + 'focaModalService', + function($scope, $uibModal, $location, $filter, focaCrearCobranzaService, focaModalService) + { + $scope.botonera = [ + {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, + {texto: 'Cobrador', accion: function() {$scope.seleccionarCobrador();}}, + {texto: 'Deuda', accion: function() {$scope.swichDeuda();}}, + {texto: 'Cobros', accion: function() {$scope.swichCobro();}}, + {texto: 'Moneda', accion: function() {$scope.seleccionarMoneda();}}, + {texto: '', accion: function() {}}, + {texto: '', accion: function() {}}, + {texto: '', accion: function() {}} + ]; + $scope.datepickerAbierto = false; + $scope.cobroDeuda = true; + $scope.show = false; + $scope.cargando = true; + $scope.dateOptions = { + maxDate: new Date(), + minDate: new Date(2010, 0, 1) + }; + + $scope.cobranza = { + fecha: new Date() + }; + + $scope.cabecera = []; + $scope.showCabecera = true; + + $scope.now = new Date(); + $scope.puntoVenta = '0000'; + $scope.comprobante = '00000000'; + $scope.facturaTabla = []; + $scope.cobrosTabla = []; + + var monedaPorDefecto; + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' + focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { + monedaPorDefecto = res.data[0]; + addCabecera('Moneda:', monedaPorDefecto.DETALLE); + addCabecera('Fecha cotizacion:', + new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); + addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); + $scope.cobranza.moneda = monedaPorDefecto; + $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0]; + }); + + focaCrearCobranzaService.getNumeroRecibo().then( + function(res) { + $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); + $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8); + }, + function(err) { + focaModalService.alert('La terminal no esta configurada correctamente'); + console.info(err); + } + ); + $scope.crearCobranza = function() { + if(!$scope.cliente.COD) { + focaModalService.alert('Ingrese Cliente'); + return; + }else if($scope.facturaTabla.length < 1) { + focaModalService.alert('Ingrese al menos una factura'); + return; + } + //TODO: Guarda cobranza + // var date = new Date(); + // var cobranza = { + // }; + }; + + $scope.swichCobro = function() { + $scope.cobroDeuda = false; + }; + + $scope.swichDeuda = function() { + $scope.cobroDeuda = true; + }; + + $scope.seleccionarCliente = function() { + + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cliente', + templateUrl: 'foca-busqueda-cliente-modal.html', + controller: 'focaBusquedaClienteModalController', + size: 'lg' + } + ); + modalInstance.result.then( + function(cliente) { + addCabecera('Cliente:', cliente.nom); + $scope.cobranza.cliente = { + COD: cliente.cod, + CUIT: cliente.cuit, + NOM: cliente.nom + }; + }, function() { + + } + ); + }; + + $scope.seleccionarFactura = function() { + if(!$scope.cobranza.cliente) { + focaModalService.alert('Seleccione primero un cliente'); + return; + } + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Facturas', + templateUrl: 'foca-modal-factura.html', + controller: 'focaModalFacturaController', + size: 'lg', + resolve: { + cliente: function() {return $scope.cobranza.cliente.COD;} + } + } + ); + modalInstance.result.then( + function(facturas) { + $scope.facturaTabla = $scope.facturaTabla.concat(facturas); + }, function() { + + } + ); + }; + + $scope.seleccionarCheque = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Carga de cheques', + templateUrl: 'modal-cheque.html', + controller: 'focaModalChequeController', + size: 'lg' + } + ); + modalInstance.result.then( + function(cheque) { + var cobro = { + tipo: 'Cheque', + fecha: cheque.fechaValor, + importe: cheque.importe + }; + $scope.cobrosTabla.push(cobro); + }, function() { + + } + ); + }; + + $scope.seleccionarEfectivo = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Carga de cheques', + templateUrl: 'modal-efectivo.html', + controller: 'focaModalEfectivoController', + size: 'sm' + } + ); + modalInstance.result.then( + function(efectivo) { + var cobro = { + tipo: 'Efectivo', + fecha: new Date(), + importe: efectivo + }; + $scope.cobrosTabla.push(cobro); + }, function() { + + } + ); + }; + + $scope.seleccionarMoneda = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Moneda', + templateUrl: 'modal-moneda.html', + controller: 'focaModalMonedaController', + size: 'lg' + } + ); + modalInstance.result.then( + function(moneda) { + $scope.seleccionarCotizacion(moneda); + }, function() { + + } + ); + }; + + $scope.seleccionarCobrador = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cobradores', + templateUrl: 'modal-cobradores.html', + controller: 'focaModalCobradoresController', + size: 'lg' + } + ); + modalInstance.result.then( + function(cobrador) { + addCabecera('Cobrador:', cobrador.nombre); + $scope.cobranza.cobrador = cobrador; + }, function() { + + } + ); + }; + + $scope.seleccionarCotizacion = function(moneda) { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cotización', + templateUrl: 'modal-cotizacion.html', + controller: 'focaModalCotizacionController', + size: 'lg', + resolve: {idMoneda: function() {return moneda.ID;}} + } + ); + modalInstance.result.then( + function(cotizacion) { + $scope.cobranza.moneda = moneda; + $scope.cobranza.cotizacion = cotizacion; + addCabecera('Moneda:', moneda.DETALLE); + addCabecera( + 'Fecha cotizacion:', + $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') + ); + addCabecera('Cotizacion:', cotizacion.VENDEDOR); + }, function() { + + } + ); + }; + + $scope.agregarCobro = function(key) { + if(key === 13) { + var cobro = { + cobro: 'Efectivo', + fecha: new Date(), + importe: $scope.cobroEfectivo + }; + $scope.cobrosTabla.push(cobro); + } + }; + + $scope.getTotalDeuda = function() { + var total = 0; + for (var i = 0; i < $scope.facturaTabla.length; i++) { + total += $scope.facturaTabla[i].IPA; + } + return parseFloat(total.toFixed(2)); + }; + + $scope.getTotalCobrado = function() { + var total = 0; + for (var i = 0; i < $scope.cobrosTabla.length; i++) { + total += $scope.cobrosTabla[i].importe; + } + return parseFloat(total.toFixed(2)); + }; + + $scope.getSubTotal = function() { + if($scope.articuloACargar) { + return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; + } + }; + //Recibe aviso si el teclado está en uso + // $rootScope.$on('usarTeclado', function(event, data) { + // if(data) { + // $scope.mostrarTeclado = true; + // return; + // } + // $scope.mostrarTeclado = false; + // }) + $scope.selectFocus = function($event) { + //Si el teclado esta en uso no selecciona el valor + // if($scope.mostrarTeclado) { + // return; + // } + $event.target.select(); + }; + + $scope.salir = function() { + $location.path('/'); + }; + + $scope.parsearATexto = function(articulo) { + articulo.cantidad = parseFloat(articulo.cantidad); + articulo.precio = parseFloat(articulo.precio); + }; + + $scope.rellenar = function(relleno, longitud) { + relleno = '' + relleno; + while (relleno.length < longitud) { + relleno = '0' + relleno; + } + + return relleno; + }; + + $scope.quitarFactura = function(key) { + $scope.facturaTabla.splice(key, 1); + }; + + $scope.quitarCobro = function(key) { + $scope.cobrosTabla.splice(key, 1); + }; + + function addCabecera(label, valor) { + var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); + if(propiedad.length === 1) { + propiedad[0].valor = valor; + } else { + $scope.cabecera.push({label: label, valor: valor}); + } + } + // TODO: descomentar cuando se use + /*function removeCabecera(label) { + var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); + if(propiedad.length === 1){ + $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); + } + }*/ + } + ]); diff --git a/src/js/route.js b/src/js/route.js new file mode 100644 index 0000000..2cbffc4 --- /dev/null +++ b/src/js/route.js @@ -0,0 +1,7 @@ +angular.module('focaCrearCobranza') + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/cobranza/crear', { + controller: 'cobranzaController', + templateUrl: 'src/views/cobranza.html' + }); + }]); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..701cfb0 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,11 @@ +angular.module('focaCrearCobranza') + .service('focaCrearCobranzaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + return { + getNumeroRecibo: function() { + return $http.get(API_ENDPOINT.URL + '/cobranza/numero-siguiente'); + }, + getCotizacionByIdMoneda: function(id) { + return $http.get(API_ENDPOINT.URL + '/moneda/' + id); + } + }; + }]); diff --git a/src/views/cobranza.html b/src/views/cobranza.html new file mode 100644 index 0000000..9f031ff --- /dev/null +++ b/src/views/cobranza.html @@ -0,0 +1,535 @@ +# | +Factura | +Cliente | +Fecha | +Importe | ++ + | + +|
---|---|---|---|---|---|---|
+ | + | + | + | + | + + | +|
+ Factura + | +||||||
+ Comprobantes: + + | ++ Total Deuda: + | ++ {{(getTotalDeuda() / cobranza.cotizacion.VENDEDOR) | + currency: cobranza.moneda.SIMBOLO}} + | ++ Total Cobrado: + | ++ {{(getTotalCobrado() / cobranza.cotizacion.VENDEDOR) | + currency: cobranza.moneda.SIMBOLO}} + | ++ DF: + | ++ {{((getTotalCobrado() - getTotalDeuda()) / + cobranza.cotizacion.VENDEDOR) | currency: cobranza.moneda.SIMBOLO}} + + | +
# | +Cobro | +Fecha | +Importe | ++ + | + +||
---|---|---|---|---|---|---|
+ | + | + | + | + + | +||
+ Cheque + | ++ Efectivo + | +|||||
+ Cobros: + + | ++ Total Deuda: + | ++ {{(getTotalDeuda() / cobranza.cotizacion.VENDEDOR) | + currency: cobranza.moneda.SIMBOLO}} + | ++ Total Cobrado: + | ++ {{(getTotalCobrado() / cobranza.cotizacion.VENDEDOR) | + currency: cobranza.moneda.SIMBOLO}} + | ++ DF: + | ++ {{((getTotalCobrado() - getTotalDeuda()) / + cobranza.cotizacion.VENDEDOR) | currency: cobranza.moneda.SIMBOLO}} + + | +
# | +
+
+
+ Factura
+ Fecha
+ Importe
+ |
+ + + | +
---|---|---|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ ||
+ + | +||
+ + | +||
+ Cantidad Items: + + | +
# | +
+
+
+ Cobro
+ Fecha
+ Importe
+ |
+ + + | +
---|---|---|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ ||
+ + | ++ + | +|
+ + | +||
+ Cantidad Items: + + | +
+ Deuda: + | ++ Cobrado: + | ++ Diferencia: + | ++ {{(getTotalDeuda() / cobranza.cotizacion.VENDEDOR) | currency: cobranza.moneda.SIMBOLO}} + | ++ {{(getTotalCobrado() / cobranza.cotizacion.VENDEDOR) | currency: cobranza.moneda.SIMBOLO}} + | ++ {{((getTotalCobrado() - getTotalDeuda()) / cobranza.cotizacion.VENDEDOR) | currency: cobranza.moneda.SIMBOLO}} + | +