Commit 9bb92655ab931c2559a3a451ebcd169a9649f6ac
1 parent
7860c14c21
Exists in
master
validacion al editar cobranza seleccionada
Showing
1 changed file
with
256 additions
and
217 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -324,7 +324,6 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
| 324 | 324 | }; |
| 325 | 325 | |
| 326 | 326 | $scope.seleccionarCobranza = function() { |
| 327 | - | |
| 328 | 327 | var modalInstance = $uibModal.open( |
| 329 | 328 | { |
| 330 | 329 | ariaLabelledBy: 'Busqueda de Cobranzas', |
| ... | ... | @@ -365,48 +364,53 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
| 365 | 364 | }; |
| 366 | 365 | |
| 367 | 366 | $scope.seleccionarCliente = function() { |
| 368 | - $scope.seleccionarCobrador(function() { | |
| 369 | - var modalInstance = $uibModal.open( | |
| 370 | - { | |
| 371 | - ariaLabelledBy: 'Busqueda de Cliente', | |
| 372 | - templateUrl: 'foca-busqueda-cliente-modal.html', | |
| 373 | - controller: 'focaBusquedaClienteModalController', | |
| 374 | - resolve: { | |
| 375 | - vendedor: function() { return null; }, | |
| 376 | - cobrador: function() { return $scope.cobranza.cobrador; } | |
| 377 | - }, | |
| 378 | - size: 'lg' | |
| 379 | - } | |
| 380 | - ); | |
| 381 | - modalInstance.result.then( | |
| 382 | - function(cliente) { | |
| 383 | - | |
| 384 | - var clienteMayus = { | |
| 385 | - COD: cliente.cod, | |
| 386 | - NOM: cliente.nom, | |
| 387 | - CUIT: cliente.cuit, | |
| 388 | - MAIL: cliente.mail, | |
| 389 | - DOM: cliente.DOM, | |
| 390 | - LOC: cliente.LOC, | |
| 391 | - PCI: cliente.PCI | |
| 392 | - }; | |
| 393 | - console.log(clienteMayus); | |
| 394 | - $scope.$broadcast('addCabecera', { | |
| 395 | - label: 'Cliente:', | |
| 396 | - valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + | |
| 397 | - clienteMayus.NOM | |
| 398 | - }); | |
| 399 | - | |
| 400 | - $filter('filter')($scope.botonera, | |
| 401 | - { label: 'Cliente'})[0].checked = true; | |
| 402 | - | |
| 403 | - $scope.cobranza.cliente = clienteMayus; | |
| 404 | - $scope.cobranza.facturas = []; | |
| 405 | - }, function() { | |
| 406 | - if (APP !== 'cobranza') $scope.seleccionarCliente(); | |
| 407 | - } | |
| 408 | - ); | |
| 409 | - }); | |
| 367 | + if ($scope.cobranza.id === undefined) { | |
| 368 | + $scope.seleccionarCobrador(function() { | |
| 369 | + var modalInstance = $uibModal.open( | |
| 370 | + { | |
| 371 | + ariaLabelledBy: 'Busqueda de Cliente', | |
| 372 | + templateUrl: 'foca-busqueda-cliente-modal.html', | |
| 373 | + controller: 'focaBusquedaClienteModalController', | |
| 374 | + resolve: { | |
| 375 | + vendedor: function() { return null; }, | |
| 376 | + cobrador: function() { return $scope.cobranza.cobrador; } | |
| 377 | + }, | |
| 378 | + size: 'lg' | |
| 379 | + } | |
| 380 | + ); | |
| 381 | + modalInstance.result.then( | |
| 382 | + function(cliente) { | |
| 383 | + | |
| 384 | + var clienteMayus = { | |
| 385 | + COD: cliente.cod, | |
| 386 | + NOM: cliente.nom, | |
| 387 | + CUIT: cliente.cuit, | |
| 388 | + MAIL: cliente.mail, | |
| 389 | + DOM: cliente.DOM, | |
| 390 | + LOC: cliente.LOC, | |
| 391 | + PCI: cliente.PCI | |
| 392 | + }; | |
| 393 | + console.log(clienteMayus); | |
| 394 | + $scope.$broadcast('addCabecera', { | |
| 395 | + label: 'Cliente:', | |
| 396 | + valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + | |
| 397 | + clienteMayus.NOM | |
| 398 | + }); | |
| 399 | + | |
| 400 | + $filter('filter')($scope.botonera, | |
| 401 | + { label: 'Cliente'})[0].checked = true; | |
| 402 | + | |
| 403 | + $scope.cobranza.cliente = clienteMayus; | |
| 404 | + $scope.cobranza.facturas = []; | |
| 405 | + }, function() { | |
| 406 | + if (APP !== 'cobranza') $scope.seleccionarCliente(); | |
| 407 | + } | |
| 408 | + ); | |
| 409 | + }); | |
| 410 | + } else { | |
| 411 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 412 | + return; | |
| 413 | + } | |
| 410 | 414 | }; |
| 411 | 415 | |
| 412 | 416 | $scope.seleccionarCobrador = function(callback) { |
| ... | ... | @@ -453,206 +457,231 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
| 453 | 457 | }; |
| 454 | 458 | |
| 455 | 459 | $scope.seleccionarFactura = function() { |
| 456 | - if (!$scope.cobranza.cliente.COD) { | |
| 457 | - focaModalService.alert('Seleccione primero un cliente'); | |
| 458 | - return; | |
| 459 | - } | |
| 460 | - var modalInstance = $uibModal.open( | |
| 461 | - { | |
| 462 | - ariaLabelledBy: 'Busqueda de Facturas', | |
| 463 | - templateUrl: 'foca-modal-factura.html', | |
| 464 | - controller: 'focaModalFacturaController', | |
| 465 | - size: 'lg', | |
| 466 | - resolve: { | |
| 467 | - parametrosFactura: function() { | |
| 468 | - return { | |
| 469 | - cliente: $scope.cobranza.cliente, | |
| 470 | - simbolo: $scope.cobranza.moneda.SIMBOLO, | |
| 471 | - cotizacion: $scope.cobranza.moneda, | |
| 472 | - moneda: $scope.cobranza.moneda.ID | |
| 473 | - }; | |
| 460 | + if ($scope.cobranza.id === undefined) { | |
| 461 | + if (!$scope.cobranza.cliente.COD) { | |
| 462 | + focaModalService.alert('Seleccione primero un cliente'); | |
| 463 | + return; | |
| 464 | + } | |
| 465 | + var modalInstance = $uibModal.open( | |
| 466 | + { | |
| 467 | + ariaLabelledBy: 'Busqueda de Facturas', | |
| 468 | + templateUrl: 'foca-modal-factura.html', | |
| 469 | + controller: 'focaModalFacturaController', | |
| 470 | + size: 'lg', | |
| 471 | + resolve: { | |
| 472 | + parametrosFactura: function() { | |
| 473 | + return { | |
| 474 | + cliente: $scope.cobranza.cliente, | |
| 475 | + simbolo: $scope.cobranza.moneda.SIMBOLO, | |
| 476 | + cotizacion: $scope.cobranza.moneda, | |
| 477 | + moneda: $scope.cobranza.moneda.ID | |
| 478 | + }; | |
| 479 | + } | |
| 474 | 480 | } |
| 475 | 481 | } |
| 476 | - } | |
| 477 | - ); | |
| 478 | - modalInstance.result.then( | |
| 479 | - function(facturas) { | |
| 480 | - var facturasResult = []; | |
| 481 | - //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | |
| 482 | - facturas.forEach(function(factura) { | |
| 483 | - var existe = $scope.cobranza.facturas.filter(function(e) { | |
| 484 | - return angular.equals(factura, e); | |
| 482 | + ); | |
| 483 | + modalInstance.result.then( | |
| 484 | + function(facturas) { | |
| 485 | + var facturasResult = []; | |
| 486 | + //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | |
| 487 | + facturas.forEach(function(factura) { | |
| 488 | + var existe = $scope.cobranza.facturas.filter(function(e) { | |
| 489 | + return angular.equals(factura, e); | |
| 490 | + }); | |
| 491 | + | |
| 492 | + if (!existe.length) facturasResult.push(factura); | |
| 485 | 493 | }); |
| 486 | 494 | |
| 487 | - if (!existe.length) facturasResult.push(factura); | |
| 488 | - }); | |
| 489 | - | |
| 490 | - $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); | |
| 491 | - }, function() { } | |
| 492 | - ); | |
| 493 | - }; | |
| 494 | - | |
| 495 | - $scope.seleccionarCheque = function(cheque) { | |
| 496 | - | |
| 497 | - var parametros; | |
| 498 | - | |
| 499 | - if(!cheque) { | |
| 500 | - parametros = { | |
| 501 | - importe: getSugerido(), | |
| 502 | - esNuevo : true | |
| 503 | - }; | |
| 495 | + $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); | |
| 496 | + }, function() { } | |
| 497 | + ); | |
| 504 | 498 | } else { |
| 505 | - parametros = cheque; | |
| 506 | - parametros.importe = cheque.IMP; | |
| 499 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 500 | + return; | |
| 507 | 501 | } |
| 508 | 502 | |
| 509 | - var modalInstance = $uibModal.open( | |
| 510 | - { | |
| 511 | - ariaLabelledBy: 'Carga de cheques', | |
| 512 | - templateUrl: 'modal-cheque.html', | |
| 513 | - controller: 'focaModalChequeController', | |
| 514 | - size: 'lg', | |
| 515 | - resolve: { | |
| 516 | - cheque: function() { | |
| 517 | - return parametros; | |
| 518 | - } | |
| 519 | - } | |
| 520 | - } | |
| 521 | - ); | |
| 522 | - modalInstance.result.then( | |
| 523 | - function(cheque) { | |
| 524 | - var cobro = { | |
| 525 | - COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | |
| 526 | - numero: cheque.numero, | |
| 527 | - banco: cheque.banco, | |
| 528 | - FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | |
| 529 | - cheque.fechaPresentacion.toLocaleDateString(), | |
| 530 | - fechaPresentacion: cheque.fechaPresentacion, | |
| 531 | - fechaEmision: cheque.fechaEmision, | |
| 532 | - IMP: cheque.importe, | |
| 533 | - localidad: cheque.localidad, | |
| 534 | - librador: cheque.librador, | |
| 535 | - provincia: cheque.provincia, | |
| 536 | - observaciones: cheque.observaciones, | |
| 537 | - TIL: 'EF' | |
| 538 | - }; | |
| 539 | - pushearCobro(cobro, cheque.$$hashKey); | |
| 540 | - }, function() { | |
| 541 | - | |
| 542 | - } | |
| 543 | - ); | |
| 544 | 503 | }; |
| 545 | 504 | |
| 546 | - $scope.seleccionarEfectivo = function() { | |
| 505 | + $scope.seleccionarCheque = function(cheque) { | |
| 506 | + if ($scope.cobranza.id === undefined) { | |
| 507 | + var parametros; | |
| 547 | 508 | |
| 548 | - var importe = 0; | |
| 549 | - $scope.cobranza.cobros.filter(function(a) { | |
| 550 | - if(a.COM === 'Efectivo') { | |
| 551 | - importe = a.IMP; | |
| 509 | + if(!cheque) { | |
| 510 | + parametros = { | |
| 511 | + importe: getSugerido(), | |
| 512 | + esNuevo : true | |
| 513 | + }; | |
| 514 | + } else { | |
| 515 | + parametros = cheque; | |
| 516 | + parametros.importe = cheque.IMP; | |
| 552 | 517 | } |
| 553 | - }); | |
| 554 | 518 | |
| 555 | - var modalInstance = $uibModal.open( | |
| 556 | - { | |
| 557 | - ariaLabelledBy: 'Carga de cheques', | |
| 558 | - templateUrl: 'modal-efectivo.html', | |
| 559 | - controller: 'focaModalEfectivoController', | |
| 560 | - size: 'sm', | |
| 561 | - resolve: { | |
| 562 | - sugerido: function() { | |
| 563 | - return parseFloat(getSugerido()) + parseFloat(importe); | |
| 519 | + var modalInstance = $uibModal.open( | |
| 520 | + { | |
| 521 | + ariaLabelledBy: 'Carga de cheques', | |
| 522 | + templateUrl: 'modal-cheque.html', | |
| 523 | + controller: 'focaModalChequeController', | |
| 524 | + size: 'lg', | |
| 525 | + resolve: { | |
| 526 | + cheque: function() { | |
| 527 | + return parametros; | |
| 528 | + } | |
| 564 | 529 | } |
| 565 | 530 | } |
| 566 | - } | |
| 567 | - ); | |
| 568 | - modalInstance.result.then( | |
| 569 | - function(efectivo) { | |
| 570 | - | |
| 571 | - var cobro = { | |
| 572 | - COM: 'Efectivo', | |
| 573 | - FEC: new Date(), | |
| 574 | - IMP: efectivo, | |
| 575 | - TIL: 'EF' | |
| 576 | - }; | |
| 577 | - | |
| 578 | - $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | |
| 579 | - return a.COM !== 'Efectivo'; | |
| 580 | - }); | |
| 531 | + ); | |
| 532 | + modalInstance.result.then( | |
| 533 | + function(cheque) { | |
| 534 | + var cobro = { | |
| 535 | + COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | |
| 536 | + numero: cheque.numero, | |
| 537 | + banco: cheque.banco, | |
| 538 | + FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | |
| 539 | + cheque.fechaPresentacion.toLocaleDateString(), | |
| 540 | + fechaPresentacion: cheque.fechaPresentacion, | |
| 541 | + fechaEmision: cheque.fechaEmision, | |
| 542 | + IMP: cheque.importe, | |
| 543 | + localidad: cheque.localidad, | |
| 544 | + librador: cheque.librador, | |
| 545 | + provincia: cheque.provincia, | |
| 546 | + observaciones: cheque.observaciones, | |
| 547 | + TIL: 'EF' | |
| 548 | + }; | |
| 549 | + pushearCobro(cobro, cheque.$$hashKey); | |
| 550 | + }, function() { | |
| 581 | 551 | |
| 582 | - $scope.cobranza.cobros.push(cobro); | |
| 583 | - }, function() { | |
| 552 | + } | |
| 553 | + ); | |
| 554 | + } else { | |
| 555 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 556 | + return; | |
| 557 | + } | |
| 584 | 558 | |
| 585 | - } | |
| 586 | - ); | |
| 587 | 559 | }; |
| 588 | 560 | |
| 589 | - $scope.seleccionarDetalles = function(detalle) { | |
| 590 | - | |
| 591 | - var parametro = {}; | |
| 592 | - | |
| 593 | - if(!detalle) { | |
| 594 | - parametro = { | |
| 595 | - importe: getSugerido(), | |
| 596 | - files: [] | |
| 597 | - }; | |
| 561 | + $scope.seleccionarEfectivo = function() { | |
| 562 | + if ($scope.cobranza.id === undefined) { | |
| 563 | + var importe = 0; | |
| 564 | + $scope.cobranza.cobros.filter(function(a) { | |
| 565 | + if(a.COM === 'Efectivo') { | |
| 566 | + importe = a.IMP; | |
| 567 | + } | |
| 568 | + }); | |
| 569 | + | |
| 570 | + var modalInstance = $uibModal.open( | |
| 571 | + { | |
| 572 | + ariaLabelledBy: 'Carga de cheques', | |
| 573 | + templateUrl: 'modal-efectivo.html', | |
| 574 | + controller: 'focaModalEfectivoController', | |
| 575 | + size: 'sm', | |
| 576 | + resolve: { | |
| 577 | + sugerido: function() { | |
| 578 | + return parseFloat(getSugerido()) + parseFloat(importe); | |
| 579 | + } | |
| 580 | + } | |
| 581 | + } | |
| 582 | + ); | |
| 583 | + modalInstance.result.then( | |
| 584 | + function(efectivo) { | |
| 585 | + | |
| 586 | + var cobro = { | |
| 587 | + COM: 'Efectivo', | |
| 588 | + FEC: new Date(), | |
| 589 | + IMP: efectivo, | |
| 590 | + TIL: 'EF' | |
| 591 | + }; | |
| 592 | + | |
| 593 | + $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | |
| 594 | + return a.COM !== 'Efectivo'; | |
| 595 | + }); | |
| 596 | + | |
| 597 | + $scope.cobranza.cobros.push(cobro); | |
| 598 | + }, function() { | |
| 599 | + | |
| 600 | + } | |
| 601 | + ); | |
| 598 | 602 | } else { |
| 599 | - parametro = detalle; | |
| 600 | - parametro.importe = detalle.IMP; | |
| 601 | - parametro.files= detalle.imgs; | |
| 603 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 604 | + return; | |
| 602 | 605 | } |
| 606 | + }; | |
| 603 | 607 | |
| 604 | - var modalInstance = $uibModal.open( | |
| 605 | - { | |
| 606 | - ariaLabelledBy: 'Carga de detalles', | |
| 607 | - templateUrl: 'modal-detalles.html', | |
| 608 | - controller: 'focaModalDetallesController', | |
| 609 | - size: 'lg', | |
| 610 | - resolve: { | |
| 611 | - parametros: function() { | |
| 612 | - return parametro; | |
| 608 | + $scope.seleccionarDetalles = function(detalle) { | |
| 609 | + if ($scope.cobranza.id === undefined) { | |
| 610 | + var parametro = {}; | |
| 611 | + | |
| 612 | + if(!detalle) { | |
| 613 | + parametro = { | |
| 614 | + importe: getSugerido(), | |
| 615 | + files: [] | |
| 616 | + }; | |
| 617 | + } else { | |
| 618 | + parametro = detalle; | |
| 619 | + parametro.importe = detalle.IMP; | |
| 620 | + parametro.files= detalle.imgs; | |
| 621 | + } | |
| 622 | + | |
| 623 | + var modalInstance = $uibModal.open( | |
| 624 | + { | |
| 625 | + ariaLabelledBy: 'Carga de detalles', | |
| 626 | + templateUrl: 'modal-detalles.html', | |
| 627 | + controller: 'focaModalDetallesController', | |
| 628 | + size: 'lg', | |
| 629 | + resolve: { | |
| 630 | + parametros: function() { | |
| 631 | + return parametro; | |
| 632 | + } | |
| 613 | 633 | } |
| 614 | 634 | } |
| 615 | - } | |
| 616 | - ); | |
| 617 | - modalInstance.result.then( | |
| 618 | - function(detalles) { | |
| 619 | - | |
| 620 | - var cobro = { | |
| 621 | - COM: 'de(COBRO POR DETALLES)', | |
| 622 | - FEC: new Date(), | |
| 623 | - IMP: detalles.importe, | |
| 624 | - imgs: detalles.files, | |
| 625 | - TIL: 'DE', | |
| 626 | - observacion: detalles.observacion | |
| 627 | - }; | |
| 628 | - pushearCobro(cobro, detalles.$$hashKey); | |
| 629 | - }, function() {} | |
| 630 | - ); | |
| 635 | + ); | |
| 636 | + modalInstance.result.then( | |
| 637 | + function(detalles) { | |
| 638 | + | |
| 639 | + var cobro = { | |
| 640 | + COM: 'de(COBRO POR DETALLES)', | |
| 641 | + FEC: new Date(), | |
| 642 | + IMP: detalles.importe, | |
| 643 | + imgs: detalles.files, | |
| 644 | + TIL: 'DE', | |
| 645 | + observacion: detalles.observacion | |
| 646 | + }; | |
| 647 | + pushearCobro(cobro, detalles.$$hashKey); | |
| 648 | + }, function() {} | |
| 649 | + ); | |
| 650 | + } else { | |
| 651 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 652 | + return; | |
| 653 | + } | |
| 631 | 654 | }; |
| 632 | 655 | |
| 633 | 656 | $scope.seleccionarMoneda = function() { |
| 634 | - var parametrosModal = { | |
| 635 | - titulo: 'Búsqueda de monedas', | |
| 636 | - query: '/moneda', | |
| 637 | - columnas: [ | |
| 638 | - { | |
| 639 | - propiedad: 'DETALLE', | |
| 640 | - nombre: 'Nombre' | |
| 641 | - }, | |
| 642 | - { | |
| 643 | - propiedad: 'SIMBOLO', | |
| 644 | - nombre: 'Símbolo' | |
| 657 | + if ($scope.cobranza.id === undefined){ | |
| 658 | + var parametrosModal = { | |
| 659 | + titulo: 'Búsqueda de monedas', | |
| 660 | + query: '/moneda', | |
| 661 | + columnas: [ | |
| 662 | + { | |
| 663 | + propiedad: 'DETALLE', | |
| 664 | + nombre: 'Nombre' | |
| 665 | + }, | |
| 666 | + { | |
| 667 | + propiedad: 'SIMBOLO', | |
| 668 | + nombre: 'Símbolo' | |
| 669 | + } | |
| 670 | + ], | |
| 671 | + size: 'md' | |
| 672 | + }; | |
| 673 | + focaModalService.modal(parametrosModal).then( | |
| 674 | + function(moneda) { | |
| 675 | + $scope.seleccionarCotizacion(moneda); | |
| 676 | + }, function() { | |
| 677 | + | |
| 645 | 678 | } |
| 646 | - ], | |
| 647 | - size: 'md' | |
| 648 | - }; | |
| 649 | - focaModalService.modal(parametrosModal).then( | |
| 650 | - function(moneda) { | |
| 651 | - $scope.seleccionarCotizacion(moneda); | |
| 652 | - }, function() { | |
| 679 | + ); | |
| 680 | + } else { | |
| 681 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
| 682 | + return; | |
| 683 | + } | |
| 653 | 684 | |
| 654 | - } | |
| 655 | - ); | |
| 656 | 685 | }; |
| 657 | 686 | |
| 658 | 687 | $scope.seleccionarCotizacion = function(moneda) { |
| ... | ... | @@ -745,11 +774,21 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
| 745 | 774 | }; |
| 746 | 775 | |
| 747 | 776 | $scope.quitarFactura = function(key) { |
| 748 | - $scope.cobranza.facturas.splice(key, 1); | |
| 777 | + if ($scope.cobranza.id === undefined) { | |
| 778 | + $scope.cobranza.facturas.splice(key, 1); | |
| 779 | + } else { | |
| 780 | + focaModalService.alert('Esta comprobante no se puede eliminar'); | |
| 781 | + return; | |
| 782 | + } | |
| 749 | 783 | }; |
| 750 | 784 | |
| 751 | 785 | $scope.quitarCobro = function(key) { |
| 752 | - $scope.cobranza.cobros.splice(key, 1); | |
| 786 | + if ($scope.cobranza.id === undefined) { | |
| 787 | + $scope.cobranza.cobros.splice(key, 1); | |
| 788 | + } else { | |
| 789 | + focaModalService.alert('Esta comprobante no se puede eliminar'); | |
| 790 | + return; | |
| 791 | + } | |
| 753 | 792 | }; |
| 754 | 793 | |
| 755 | 794 | $scope.editarCobro = function(cobro) { |