Commit 560b5953f770fcaf45a6fd8dc6d6b6e09b5fc4c7
1 parent
68473ec2f2
Exists in
master
and in
1 other branch
edit cobros, unit test
Showing
5 changed files
with
124 additions
and
64 deletions
 
Show diff stats
gulpfile.js
| ... | ... | @@ -21,7 +21,9 @@ var paths = { | 
| 21 | 21 | dist: 'dist/' | 
| 22 | 22 | }; | 
| 23 | 23 | |
| 24 | -gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app')); | |
| 24 | +gulp.task('uglify', function(callback) { | |
| 25 | + gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app')(callback); | |
| 26 | +}); | |
| 25 | 27 | |
| 26 | 28 | |
| 27 | 29 | gulp.task('templates', function() { | 
spec/controllerSpec.js
| ... | ... | @@ -254,8 +254,8 @@ describe('controladores módulo crear cobranza', function() { | 
| 254 | 254 | cobrador: { | 
| 255 | 255 | NUM: true | 
| 256 | 256 | }, | 
| 257 | - cotizacion: { | |
| 258 | - moneda: { SIMBOLO: '' }, | |
| 257 | + moneda: { | |
| 258 | + SIMBOLO: '' | |
| 259 | 259 | }, | 
| 260 | 260 | facturas: [1] | 
| 261 | 261 | }; | 
| ... | ... | @@ -319,15 +319,12 @@ describe('controladores módulo crear cobranza', function() { | 
| 319 | 319 | cobrador: { | 
| 320 | 320 | NUM: true | 
| 321 | 321 | }, | 
| 322 | - cotizacion: { | |
| 323 | - moneda: { | |
| 324 | - ID: true, | |
| 325 | - SIMBOLO: '' | |
| 326 | - } | |
| 322 | + moneda: { | |
| 323 | + cotizacion: {} | |
| 327 | 324 | }, | 
| 328 | 325 | facturas: [1], | 
| 329 | 326 | cobros: [{ | 
| 330 | - fecha: new Date(), | |
| 327 | + FEC: new Date(), | |
| 331 | 328 | fechaPresentacion: new Date(), | 
| 332 | 329 | fechaEmision: new Date(), | 
| 333 | 330 | tipo: true, | 
| ... | ... | @@ -342,7 +339,7 @@ describe('controladores módulo crear cobranza', function() { | 
| 342 | 339 | ID: true | 
| 343 | 340 | } | 
| 344 | 341 | }], | 
| 345 | - fecha: new Date() | |
| 342 | + FEC: new Date() | |
| 346 | 343 | }; | 
| 347 | 344 | |
| 348 | 345 | //act | 
| ... | ... | @@ -479,7 +476,14 @@ describe('controladores módulo crear cobranza', function() { | 
| 479 | 476 | focaLoginService: {}, | 
| 480 | 477 | $localStorage: true | 
| 481 | 478 | }); | 
| 482 | - var respuesta = { facturas: 1, cobros: 2, cliente: { } }; | |
| 479 | + var respuesta = { | |
| 480 | + facturas: 1, | |
| 481 | + cobros: 2, | |
| 482 | + cliente: { }, | |
| 483 | + moneda: { | |
| 484 | + cotizaciones: [] | |
| 485 | + } | |
| 486 | + }; | |
| 483 | 487 | var promesa = { result: Promise.resolve(respuesta) }; | 
| 484 | 488 | |
| 485 | 489 | //act | 
| ... | ... | @@ -717,7 +721,9 @@ describe('controladores módulo crear cobranza', function() { | 
| 717 | 721 | $localStorage: true | 
| 718 | 722 | }); | 
| 719 | 723 | scope.cobranza = { | 
| 720 | - cliente: { } | |
| 724 | + cliente: { }, | |
| 725 | + facturas: [], | |
| 726 | + cobros: [] | |
| 721 | 727 | }; | 
| 722 | 728 | |
| 723 | 729 | var respuesta = { result: { then: function() { } } }; | 
| ... | ... | @@ -768,7 +774,8 @@ describe('controladores módulo crear cobranza', function() { | 
| 768 | 774 | $localStorage: true | 
| 769 | 775 | }); | 
| 770 | 776 | scope.cobranza = { | 
| 771 | - cliente: { } | |
| 777 | + cliente: { }, | |
| 778 | + cobros: [] | |
| 772 | 779 | }; | 
| 773 | 780 | |
| 774 | 781 | var respuesta = { result: { then: function() { } } }; | 
| ... | ... | @@ -819,7 +826,9 @@ describe('controladores módulo crear cobranza', function() { | 
| 819 | 826 | $localStorage: true | 
| 820 | 827 | }); | 
| 821 | 828 | scope.cobranza = { | 
| 822 | - cliente: { } | |
| 829 | + cliente: { }, | |
| 830 | + facturas: [], | |
| 831 | + cobros: [] | |
| 823 | 832 | }; | 
| 824 | 833 | |
| 825 | 834 | var respuesta = { result: { then: function() { } } }; | 
| ... | ... | @@ -1077,7 +1086,7 @@ describe('controladores módulo crear cobranza', function() { | 
| 1077 | 1086 | $localStorage: true | 
| 1078 | 1087 | }); | 
| 1079 | 1088 | scope.cobranza = { | 
| 1080 | - cobros: [{ importe: 1 }] | |
| 1089 | + cobros: [{ IMP: 1 }] | |
| 1081 | 1090 | }; | 
| 1082 | 1091 | |
| 1083 | 1092 | //act | 
spec/serviceSpec.js
| ... | ... | @@ -104,26 +104,6 @@ describe('Servicios módulo crear cobranza', function() { | 
| 104 | 104 | expect(result).toEqual(responseFake); | 
| 105 | 105 | }); | 
| 106 | 106 | |
| 107 | - it('enviarComprobantePorMail llama a ruta correcta', function() { | |
| 108 | - | |
| 109 | - //arrange | |
| 110 | - var responseFake = 'responseFake'; | |
| 111 | - var result; | |
| 112 | - var paramFake = 1; | |
| 113 | - | |
| 114 | - httpBackend.expectPOST('localhost/mail/comprobante', | |
| 115 | - {receiver: paramFake}).respond(responseFake); | |
| 116 | - | |
| 117 | - //act | |
| 118 | - servicio.enviarComprobantePorMail(paramFake).then(function(data) { | |
| 119 | - result = data.data; | |
| 120 | - }); | |
| 121 | - httpBackend.flush(); | |
| 122 | - | |
| 123 | - //assert | |
| 124 | - expect(result).toEqual(responseFake); | |
| 125 | - }); | |
| 126 | - | |
| 127 | 107 | it('actualizarEmail llama a ruta correcta', function() { | 
| 128 | 108 | |
| 129 | 109 | //arrange | 
src/js/controller.js
| ... | ... | @@ -112,7 +112,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 112 | 112 | focaModalService.alert('Ingrese al menos una factura'); | 
| 113 | 113 | return; | 
| 114 | 114 | } | 
| 115 | - if ($scope.getTotalCobrado() + (Math.abs($scope.getTotalDeuda()) * -1) !== 0) { | |
| 115 | + if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) { | |
| 116 | 116 | focaModalService.alert('La diferencia debe ser ' + | 
| 117 | 117 | $scope.cobranza.moneda.SIMBOLO + '0,00'); | 
| 118 | 118 | return; | 
| ... | ... | @@ -206,7 +206,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 206 | 206 | REC_CAJ: 'D', | 
| 207 | 207 | TIPO_C: 0,//?? | 
| 208 | 208 | SALDO_CAJ: 'S', | 
| 209 | - FECHA_INGRESO: new Date($scope.cobranza.fecha) | |
| 209 | + FECHA_INGRESO: new Date($scope.cobranza.FEC) | |
| 210 | 210 | .toISOString().slice(0, 19).replace('T', ' '), | 
| 211 | 211 | Vendedor_valor: 0, | 
| 212 | 212 | FAMILIA: 0, | 
| ... | ... | @@ -481,7 +481,20 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 481 | 481 | ); | 
| 482 | 482 | }; | 
| 483 | 483 | |
| 484 | - $scope.seleccionarCheque = function() { | |
| 484 | + $scope.seleccionarCheque = function(cheque) { | |
| 485 | + | |
| 486 | + var parametros; | |
| 487 | + | |
| 488 | + if(!cheque) { | |
| 489 | + parametros = { | |
| 490 | + importe: getSugerido(), | |
| 491 | + esNuevo : true | |
| 492 | + }; | |
| 493 | + } else { | |
| 494 | + parametros = cheque; | |
| 495 | + parametros.importe = cheque.IMP; | |
| 496 | + } | |
| 497 | + | |
| 485 | 498 | var modalInstance = $uibModal.open( | 
| 486 | 499 | { | 
| 487 | 500 | ariaLabelledBy: 'Carga de cheques', | 
| ... | ... | @@ -489,9 +502,8 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 489 | 502 | controller: 'focaModalChequeController', | 
| 490 | 503 | size: 'lg', | 
| 491 | 504 | resolve: { | 
| 492 | - sugerido: function() { | |
| 493 | - var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | |
| 494 | - return sugerido < 0 ? sugerido : null; | |
| 505 | + cheque: function() { | |
| 506 | + return parametros; | |
| 495 | 507 | } | 
| 496 | 508 | } | 
| 497 | 509 | } | 
| ... | ... | @@ -506,14 +518,14 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 506 | 518 | cheque.fechaPresentacion.toLocaleDateString(), | 
| 507 | 519 | fechaPresentacion: cheque.fechaPresentacion, | 
| 508 | 520 | fechaEmision: cheque.fechaEmision, | 
| 509 | - IMP: cheque.importe * $scope.cobranza.moneda.cotizacion.VENDEDOR, | |
| 521 | + IMP: cheque.importe, | |
| 510 | 522 | localidad: cheque.localidad, | 
| 511 | 523 | librador: cheque.librador, | 
| 512 | 524 | provincia: cheque.provincia, | 
| 513 | 525 | observaciones: cheque.observaciones, | 
| 514 | 526 | TIL: 'EF' | 
| 515 | 527 | }; | 
| 516 | - $scope.cobranza.cobros.push(cobro); | |
| 528 | + pushearCobro(cobro, cheque.$$hashKey); | |
| 517 | 529 | }, function() { | 
| 518 | 530 | |
| 519 | 531 | } | 
| ... | ... | @@ -521,6 +533,15 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 521 | 533 | }; | 
| 522 | 534 | |
| 523 | 535 | $scope.seleccionarEfectivo = function() { | 
| 536 | + | |
| 537 | + var importe = 0; | |
| 538 | + $scope.cobranza.cobros.filter(function(a) { | |
| 539 | + if(a.COM === 'Efectivo') { | |
| 540 | + importe = a.IMP; | |
| 541 | + } | |
| 542 | + }); | |
| 543 | + | |
| 544 | + | |
| 524 | 545 | var modalInstance = $uibModal.open( | 
| 525 | 546 | { | 
| 526 | 547 | ariaLabelledBy: 'Carga de cheques', | 
| ... | ... | @@ -529,23 +550,25 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 529 | 550 | size: 'sm', | 
| 530 | 551 | resolve: { | 
| 531 | 552 | sugerido: function() { | 
| 532 | - var sugerido = $scope.getTotalDeuda() - $scope.getTotalCobrado(); | |
| 533 | - return sugerido < 0 ? sugerido : null; | |
| 553 | + return parseFloat(getSugerido()) + parseFloat(importe); | |
| 534 | 554 | } | 
| 535 | 555 | } | 
| 536 | 556 | } | 
| 537 | 557 | ); | 
| 538 | 558 | modalInstance.result.then( | 
| 539 | 559 | function(efectivo) { | 
| 560 | + | |
| 540 | 561 | var cobro = { | 
| 541 | 562 | COM: 'Efectivo', | 
| 542 | 563 | FEC: new Date(), | 
| 543 | - IMP: efectivo * $scope.cobranza.moneda.cotizacion.VENDEDOR, | |
| 564 | + IMP: efectivo, | |
| 544 | 565 | TIL: 'EF' | 
| 545 | 566 | }; | 
| 567 | + | |
| 546 | 568 | $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | 
| 547 | - return a.tipo !== 'Efectivo'; | |
| 569 | + return a.COM !== 'Efectivo'; | |
| 548 | 570 | }); | 
| 571 | + | |
| 549 | 572 | $scope.cobranza.cobros.push(cobro); | 
| 550 | 573 | }, function() { | 
| 551 | 574 | |
| ... | ... | @@ -553,7 +576,21 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 553 | 576 | ); | 
| 554 | 577 | }; | 
| 555 | 578 | |
| 556 | - $scope.seleccionarDetalles = function() { | |
| 579 | + $scope.seleccionarDetalles = function(detalle) { | |
| 580 | + | |
| 581 | + var parametro = {}; | |
| 582 | + | |
| 583 | + if(!detalle) { | |
| 584 | + parametro = { | |
| 585 | + importe: getSugerido(), | |
| 586 | + files: [] | |
| 587 | + }; | |
| 588 | + } else { | |
| 589 | + parametro = detalle; | |
| 590 | + parametro.importe = detalle.IMP; | |
| 591 | + parametro.files= detalle.imgs; | |
| 592 | + } | |
| 593 | + | |
| 557 | 594 | var modalInstance = $uibModal.open( | 
| 558 | 595 | { | 
| 559 | 596 | ariaLabelledBy: 'Carga de detalles', | 
| ... | ... | @@ -561,34 +598,24 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 561 | 598 | controller: 'focaModalDetallesController', | 
| 562 | 599 | size: 'lg', | 
| 563 | 600 | resolve: { | 
| 564 | - sugerido: function() { | |
| 565 | - var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | |
| 566 | - return sugerido < 0 ? sugerido : null; | |
| 601 | + parametros: function() { | |
| 602 | + return parametro; | |
| 567 | 603 | } | 
| 568 | 604 | } | 
| 569 | 605 | } | 
| 570 | 606 | ); | 
| 571 | 607 | modalInstance.result.then( | 
| 572 | 608 | function(detalles) { | 
| 609 | + | |
| 573 | 610 | var cobro = { | 
| 574 | 611 | COM: 'de(COBRO POR DETALLES)', | 
| 575 | 612 | FEC: new Date(), | 
| 576 | - IMP: detalles.monto * $scope.cobranza.moneda.cotizacion.VENDEDOR, | |
| 577 | - imgs: detalles.imgs, | |
| 613 | + IMP: detalles.importe, | |
| 614 | + imgs: detalles.files, | |
| 578 | 615 | TIL: 'DE', | 
| 579 | 616 | observacion: detalles.observacion | 
| 580 | 617 | }; | 
| 581 | - var existe = false; | |
| 582 | - | |
| 583 | - $scope.cobranza.cobros.forEach(function(c, idx) { | |
| 584 | - if (c.til === 'DE') { | |
| 585 | - $scope.cobranza.cobros[idx] = cobro; | |
| 586 | - existe = true; | |
| 587 | - } | |
| 588 | - }); | |
| 589 | - if (!existe) { | |
| 590 | - $scope.cobranza.cobros.push(cobro); | |
| 591 | - } | |
| 618 | + pushearCobro(cobro, detalles.$$hashKey); | |
| 592 | 619 | }, function() {} | 
| 593 | 620 | ); | 
| 594 | 621 | }; | 
| ... | ... | @@ -711,6 +738,30 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 711 | 738 | $scope.cobranza.cobros.splice(key, 1); | 
| 712 | 739 | }; | 
| 713 | 740 | |
| 741 | + $scope.editarCobro = function(cobro) { | |
| 742 | + if(cobro.COM === 'Efectivo') { | |
| 743 | + $scope.seleccionarEfectivo(); | |
| 744 | + } else if(cobro.COM.substring(0, 2) === 'de') { | |
| 745 | + $scope.seleccionarDetalles(cobro); | |
| 746 | + } else if(cobro.COM.substring(0, 2) === 'ch') { | |
| 747 | + $scope.seleccionarCheque(cobro); | |
| 748 | + } | |
| 749 | + }; | |
| 750 | + | |
| 751 | + function pushearCobro(cobro, hashKey) { | |
| 752 | + var existe; | |
| 753 | + | |
| 754 | + $scope.cobranza.cobros.forEach(function(c, idx) { | |
| 755 | + if(c.$$hashKey === hashKey) { | |
| 756 | + $scope.cobranza.cobros[idx] = cobro; | |
| 757 | + existe = true; | |
| 758 | + } | |
| 759 | + }); | |
| 760 | + if (!existe) { | |
| 761 | + $scope.cobranza.cobros.push(cobro); | |
| 762 | + } | |
| 763 | + } | |
| 764 | + | |
| 714 | 765 | function salir() { | 
| 715 | 766 | var confirmacion = false; | 
| 716 | 767 | |
| ... | ... | @@ -781,5 +832,17 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', | 
| 781 | 832 | } | 
| 782 | 833 | ); | 
| 783 | 834 | } | 
| 835 | + | |
| 836 | + function getSugerido() { | |
| 837 | + var result; | |
| 838 | + | |
| 839 | + var valor = $scope.getTotalDeuda() + $scope.getTotalCobrado(); | |
| 840 | + | |
| 841 | + if (valor < 0) { | |
| 842 | + result = Math.abs(valor).toFixed(4); | |
| 843 | + } | |
| 844 | + | |
| 845 | + return result; | |
| 846 | + } | |
| 784 | 847 | } | 
| 785 | 848 | ]); | 
src/views/cobranza.html
| ... | ... | @@ -153,6 +153,12 @@ | 
| 153 | 153 | <td class="text-center col-auto"> | 
| 154 | 154 | <button | 
| 155 | 155 | class="btn btn-outline-light" | 
| 156 | + ng-click="editarCobro(cobro)" | |
| 157 | + > | |
| 158 | + <i class="fa fa-edit"></i> | |
| 159 | + </button> | |
| 160 | + <button | |
| 161 | + class="btn btn-outline-light" | |
| 156 | 162 | ng-click="quitarCobro(key)" | 
| 157 | 163 | > | 
| 158 | 164 | <i class="fa fa-trash"></i> |