Commit 9e8fab22206f281bba5d5fb9d3ee7d4f16a36a12

Authored by Luigi
1 parent cd6e32a184
Exists in master and in 1 other branch develop

Cambiar precio y condicion

Showing 1 changed file with 59 additions and 48 deletions   Show diff stats
src/js/controller.js
... ... @@ -574,58 +574,69 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
574 574 }
575 575 };
576 576  
  577 + function abrirModal() {
  578 + var modalInstance = $uibModal.open(
  579 + {
  580 + ariaLabelledBy: 'Busqueda de Precio Condición',
  581 + templateUrl: 'modal-precio-condicion.html',
  582 + controller: 'focaModalPrecioCondicionController',
  583 + size: 'lg',
  584 + resolve: {
  585 + idListaPrecio: function() {
  586 + return $scope.notaPedido.cliente.MOD || null;
  587 + }
  588 + }
  589 + }
  590 + );
  591 +
  592 + modalInstance.result.then(
  593 + function(precioCondicion) {
  594 + var cabecera = '';
  595 + var plazosConcat = '';
  596 + if (!Array.isArray(precioCondicion)) {
  597 + $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
  598 + $scope.notaPedido.precioCondicion = precioCondicion;
  599 + $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
  600 + $scope.idLista = precioCondicion.idListaPrecio;
  601 + for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
  602 + plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
  603 + }
  604 + cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
  605 + ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
  606 + } else { //Cuando se ingresan los plazos manualmente
  607 + $scope.notaPedido.idPrecioCondicion = 0;
  608 + //-1, el modal productos busca todos los productos
  609 + $scope.idLista = -1;
  610 + $scope.notaPedido.notaPedidoPlazo = precioCondicion;
  611 + for (var j = 0; j < precioCondicion.length; j++) {
  612 + plazosConcat += precioCondicion[j].dias + ' ';
  613 + }
  614 + cabecera = 'Ingreso manual ' + plazosConcat.trim();
  615 + }
  616 + $scope.notaPedido.articulosNotaPedido = [];
  617 + $scope.$broadcast('addCabecera', {
  618 + label: 'Precios y condiciones:',
  619 + valor: cabecera
  620 + });
  621 + }, function() {
  622 +
  623 + }
  624 + );
  625 + }
  626 +
577 627 $scope.seleccionarPreciosYCondiciones = function() {
578 628 if (!$scope.notaPedido.cliente.COD) {
579 629 focaModalService.alert('Primero seleccione un cliente');
580 630 return;
581 631 }
582   - if (validarNotaRemitada()) {
583   - var modalInstance = $uibModal.open(
584   - {
585   - ariaLabelledBy: 'Busqueda de Precio Condición',
586   - templateUrl: 'modal-precio-condicion.html',
587   - controller: 'focaModalPrecioCondicionController',
588   - size: 'lg',
589   - resolve: {
590   - idListaPrecio: function() {
591   - return $scope.notaPedido.cliente.MOD || null;
592   - }
593   - }
594   - }
595   - );
596   - modalInstance.result.then(
597   - function(precioCondicion) {
598   - var cabecera = '';
599   - var plazosConcat = '';
600   - if (!Array.isArray(precioCondicion)) {
601   - $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
602   - $scope.notaPedido.precioCondicion = precioCondicion;
603   - $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
604   - $scope.idLista = precioCondicion.idListaPrecio;
605   - for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
606   - plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
607   - }
608   - cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
609   - ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
610   - } else { //Cuando se ingresan los plazos manualmente
611   - $scope.notaPedido.idPrecioCondicion = 0;
612   - //-1, el modal productos busca todos los productos
613   - $scope.idLista = -1;
614   - $scope.notaPedido.notaPedidoPlazo = precioCondicion;
615   - for (var j = 0; j < precioCondicion.length; j++) {
616   - plazosConcat += precioCondicion[j].dias + ' ';
617   - }
618   - cabecera = 'Ingreso manual ' + plazosConcat.trim();
  632 + if ($scope.notaPedido.articulosNotaPedido.length !== 0) {
  633 + focaModalService.confirm('Se perderan los datos ingresados').then(function(data) {
  634 + if (data) {
  635 + abrirModal();
619 636 }
620   - $scope.notaPedido.articulosNotaPedido = [];
621   - $scope.$broadcast('addCabecera', {
622   - label: 'Precios y condiciones:',
623   - valor: cabecera
624   - });
625   - }, function() {
626   -
627   - }
628   - );
  637 + });
  638 + } else if (validarNotaRemitada()) {
  639 + abrirModal();
629 640 }
630 641 };
631 642  
... ... @@ -901,8 +912,8 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
901 912 notaPedido.numeroNotaPedido, 8
902 913 );
903 914  
904   - if (notaPedido.notaPedidoPuntoDescarga) {
905   - var puntosDescarga = notaPedido.notaPedidoPuntoDescarga
  915 + if (notaPedido.notaPedidoPuntoDescarga) {
  916 + var puntosDescarga = notaPedido.notaPedidoPuntoDescarga;
906 917 cabeceras.push({
907 918 label: 'Puntos de descarga: ',
908 919 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))