diff --git a/gulpfile.js b/gulpfile.js index 0aa5bc2..4c51124 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,7 +21,9 @@ var paths = { dist: 'dist/' }; -gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app')); +gulp.task('uglify', function(callback) { + gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app')(callback); +}); gulp.task('templates', function() { diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js index d1c8fbb..df7cdd9 100644 --- a/spec/controllerSpec.js +++ b/spec/controllerSpec.js @@ -254,8 +254,8 @@ describe('controladores módulo crear cobranza', function() { cobrador: { NUM: true }, - cotizacion: { - moneda: { SIMBOLO: '' }, + moneda: { + SIMBOLO: '' }, facturas: [1] }; @@ -319,15 +319,12 @@ describe('controladores módulo crear cobranza', function() { cobrador: { NUM: true }, - cotizacion: { - moneda: { - ID: true, - SIMBOLO: '' - } + moneda: { + cotizacion: {} }, facturas: [1], cobros: [{ - fecha: new Date(), + FEC: new Date(), fechaPresentacion: new Date(), fechaEmision: new Date(), tipo: true, @@ -342,7 +339,7 @@ describe('controladores módulo crear cobranza', function() { ID: true } }], - fecha: new Date() + FEC: new Date() }; //act @@ -479,7 +476,14 @@ describe('controladores módulo crear cobranza', function() { focaLoginService: {}, $localStorage: true }); - var respuesta = { facturas: 1, cobros: 2, cliente: { } }; + var respuesta = { + facturas: 1, + cobros: 2, + cliente: { }, + moneda: { + cotizaciones: [] + } + }; var promesa = { result: Promise.resolve(respuesta) }; //act @@ -717,7 +721,9 @@ describe('controladores módulo crear cobranza', function() { $localStorage: true }); scope.cobranza = { - cliente: { } + cliente: { }, + facturas: [], + cobros: [] }; var respuesta = { result: { then: function() { } } }; @@ -768,7 +774,8 @@ describe('controladores módulo crear cobranza', function() { $localStorage: true }); scope.cobranza = { - cliente: { } + cliente: { }, + cobros: [] }; var respuesta = { result: { then: function() { } } }; @@ -819,7 +826,9 @@ describe('controladores módulo crear cobranza', function() { $localStorage: true }); scope.cobranza = { - cliente: { } + cliente: { }, + facturas: [], + cobros: [] }; var respuesta = { result: { then: function() { } } }; @@ -1077,7 +1086,7 @@ describe('controladores módulo crear cobranza', function() { $localStorage: true }); scope.cobranza = { - cobros: [{ importe: 1 }] + cobros: [{ IMP: 1 }] }; //act diff --git a/spec/serviceSpec.js b/spec/serviceSpec.js index 53a4731..30efcb6 100644 --- a/spec/serviceSpec.js +++ b/spec/serviceSpec.js @@ -104,26 +104,6 @@ describe('Servicios módulo crear cobranza', function() { expect(result).toEqual(responseFake); }); - it('enviarComprobantePorMail llama a ruta correcta', function() { - - //arrange - var responseFake = 'responseFake'; - var result; - var paramFake = 1; - - httpBackend.expectPOST('localhost/mail/comprobante', - {receiver: paramFake}).respond(responseFake); - - //act - servicio.enviarComprobantePorMail(paramFake).then(function(data) { - result = data.data; - }); - httpBackend.flush(); - - //assert - expect(result).toEqual(responseFake); - }); - it('actualizarEmail llama a ruta correcta', function() { //arrange diff --git a/src/js/controller.js b/src/js/controller.js index 31644ad..3117d25 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -112,7 +112,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', focaModalService.alert('Ingrese al menos una factura'); return; } - if ($scope.getTotalCobrado() + (Math.abs($scope.getTotalDeuda()) * -1) !== 0) { + if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { focaModalService.alert('La diferencia debe ser ' + $scope.cobranza.moneda.SIMBOLO + '0,00'); return; @@ -206,7 +206,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', REC_CAJ: 'D', TIPO_C: 0,//?? SALDO_CAJ: 'S', - FECHA_INGRESO: new Date($scope.cobranza.fecha) + FECHA_INGRESO: new Date($scope.cobranza.FEC) .toISOString().slice(0, 19).replace('T', ' '), Vendedor_valor: 0, FAMILIA: 0, @@ -481,7 +481,20 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', ); }; - $scope.seleccionarCheque = function() { + $scope.seleccionarCheque = function(cheque) { + + var parametros; + + if(!cheque) { + parametros = { + importe: getSugerido(), + esNuevo : true + }; + } else { + parametros = cheque; + parametros.importe = cheque.IMP; + } + var modalInstance = $uibModal.open( { ariaLabelledBy: 'Carga de cheques', @@ -489,9 +502,8 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', controller: 'focaModalChequeController', size: 'lg', resolve: { - sugerido: function() { - var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); - return sugerido < 0 ? sugerido : null; + cheque: function() { + return parametros; } } } @@ -506,14 +518,14 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', cheque.fechaPresentacion.toLocaleDateString(), fechaPresentacion: cheque.fechaPresentacion, fechaEmision: cheque.fechaEmision, - IMP: cheque.importe * $scope.cobranza.moneda.cotizacion.VENDEDOR, + IMP: cheque.importe, localidad: cheque.localidad, librador: cheque.librador, provincia: cheque.provincia, observaciones: cheque.observaciones, TIL: 'EF' }; - $scope.cobranza.cobros.push(cobro); + pushearCobro(cobro, cheque.$$hashKey); }, function() { } @@ -521,6 +533,15 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', }; $scope.seleccionarEfectivo = function() { + + var importe = 0; + $scope.cobranza.cobros.filter(function(a) { + if(a.COM === 'Efectivo') { + importe = a.IMP; + } + }); + + var modalInstance = $uibModal.open( { ariaLabelledBy: 'Carga de cheques', @@ -529,23 +550,25 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', size: 'sm', resolve: { sugerido: function() { - var sugerido = $scope.getTotalDeuda() - $scope.getTotalCobrado(); - return sugerido < 0 ? sugerido : null; + return parseFloat(getSugerido()) + parseFloat(importe); } } } ); modalInstance.result.then( function(efectivo) { + var cobro = { COM: 'Efectivo', FEC: new Date(), - IMP: efectivo * $scope.cobranza.moneda.cotizacion.VENDEDOR, + IMP: efectivo, TIL: 'EF' }; + $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { - return a.tipo !== 'Efectivo'; + return a.COM !== 'Efectivo'; }); + $scope.cobranza.cobros.push(cobro); }, function() { @@ -553,7 +576,21 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', ); }; - $scope.seleccionarDetalles = function() { + $scope.seleccionarDetalles = function(detalle) { + + var parametro = {}; + + if(!detalle) { + parametro = { + importe: getSugerido(), + files: [] + }; + } else { + parametro = detalle; + parametro.importe = detalle.IMP; + parametro.files= detalle.imgs; + } + var modalInstance = $uibModal.open( { ariaLabelledBy: 'Carga de detalles', @@ -561,34 +598,24 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', controller: 'focaModalDetallesController', size: 'lg', resolve: { - sugerido: function() { - var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); - return sugerido < 0 ? sugerido : null; + parametros: function() { + return parametro; } } } ); modalInstance.result.then( function(detalles) { + var cobro = { COM: 'de(COBRO POR DETALLES)', FEC: new Date(), - IMP: detalles.monto * $scope.cobranza.moneda.cotizacion.VENDEDOR, - imgs: detalles.imgs, + IMP: detalles.importe, + imgs: detalles.files, TIL: 'DE', observacion: detalles.observacion }; - var existe = false; - - $scope.cobranza.cobros.forEach(function(c, idx) { - if (c.til === 'DE') { - $scope.cobranza.cobros[idx] = cobro; - existe = true; - } - }); - if (!existe) { - $scope.cobranza.cobros.push(cobro); - } + pushearCobro(cobro, detalles.$$hashKey); }, function() {} ); }; @@ -711,6 +738,30 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', $scope.cobranza.cobros.splice(key, 1); }; + $scope.editarCobro = function(cobro) { + if(cobro.COM === 'Efectivo') { + $scope.seleccionarEfectivo(); + } else if(cobro.COM.substring(0, 2) === 'de') { + $scope.seleccionarDetalles(cobro); + } else if(cobro.COM.substring(0, 2) === 'ch') { + $scope.seleccionarCheque(cobro); + } + }; + + function pushearCobro(cobro, hashKey) { + var existe; + + $scope.cobranza.cobros.forEach(function(c, idx) { + if(c.$$hashKey === hashKey) { + $scope.cobranza.cobros[idx] = cobro; + existe = true; + } + }); + if (!existe) { + $scope.cobranza.cobros.push(cobro); + } + } + function salir() { var confirmacion = false; @@ -781,5 +832,17 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', } ); } + + function getSugerido() { + var result; + + var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); + + if (valor < 0) { + result = Math.abs(valor).toFixed(4); + } + + return result; + } } ]); diff --git a/src/views/cobranza.html b/src/views/cobranza.html index 37a8276..183cc4b 100644 --- a/src/views/cobranza.html +++ b/src/views/cobranza.html @@ -153,6 +153,12 @@