From ba72cea3808ad4dbbe20d56fec89890a7300a70f Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Thu, 14 Mar 2019 12:29:03 -0300 Subject: [PATCH] seleccionar vendedor al seleccionar cliente --- src/js/controller.js | 95 ++++++++++++++++++++++++++++++---------------------- src/js/service.js | 12 +------ 2 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index a291707..e134d52 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -28,6 +28,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $scope.datepickerAbierto = false; $scope.show = false; $scope.cargando = true; + $scope.botonera = crearNotaPedidoService.getBotonera(); $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); $scope.comprobante = $filter('rellenarDigitos')(0, 8); $scope.dateOptions = { @@ -46,9 +47,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR if (APP === 'distribuidor') { $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; - $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); - } else { - $scope.botonera = crearNotaPedidoService.getBotonera(); } //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' @@ -125,10 +123,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', }, true); $scope.crearNotaPedido = function() { - if (!$scope.notaPedido.vendedor.id) { - focaModalService.alert('Ingrese Vendedor'); - return; - } else if (!$scope.notaPedido.cliente.COD) { + if (!$scope.notaPedido.cliente.COD) { focaModalService.alert('Ingrese Cliente'); return; } else if (!$scope.notaPedido.proveedor.COD) { @@ -346,7 +341,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } }; - $scope.seleccionarVendedor = function() { + $scope.seleccionarVendedor = function(callback, ocultarVendedor) { + if(APP === 'distribuidor' || ocultarVendedor) { + callback(); + return; + } + if(validarNotaRemitada()) { var parametrosModal = { titulo: 'Búsqueda vendedores', @@ -375,13 +375,43 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', vendedor.NOM }); $scope.notaPedido.vendedor = vendedor; - }, function() { - - } + deleteCliente(); + callback(); + }, function() {} ); } }; + $scope.seleccionarCliente = function(ocultarVendedor) { + $scope.seleccionarVendedor(function() { + if (!$scope.notaPedido.vendedor.NUM) { + focaModalService.alert('Primero seleccione un vendedor'); + return; + } + if (validarNotaRemitada()) { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cliente', + templateUrl: 'foca-busqueda-cliente-modal.html', + controller: 'focaBusquedaClienteModalController', + resolve: { + vendedor: function() { return $scope.notaPedido.vendedor; } + }, + size: 'lg' + } + ); + modalInstance.result.then( + function(cliente) { + $scope.abrirModalDomicilios(cliente); + $scope.cliente = cliente; + }, function() { + if (APP !== 'distribuidor') $scope.seleccionarCliente(); + } + ); + } + }, ocultarVendedor); + }; + $scope.seleccionarProveedor = function() { if(validarNotaRemitada()) { var parametrosModal = { @@ -423,32 +453,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } }; - $scope.seleccionarCliente = function() { - if(!$scope.notaPedido.vendedor.NUM) { - focaModalService.alert('Primero seleccione un vendedor'); - return; - } - if(validarNotaRemitada()) { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Cliente', - templateUrl: 'foca-busqueda-cliente-modal.html', - controller: 'focaBusquedaClienteModalController', - resolve: { - vendedor: function() { return $scope.notaPedido.vendedor; } - }, - size: 'lg' - } - ); - modalInstance.result.then( - function(cliente) { - $scope.abrirModalDomicilios(cliente); - $scope.cliente = cliente; - }, function() {} - ); - } - }; - $scope.abrirModalDomicilios = function(cliente) { var modalInstanceDomicilio = $uibModal.open( { @@ -464,6 +468,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); modalInstanceDomicilio.result.then( function(domicilio) { + $scope.notaPedido.domicilio = domicilio; $scope.notaPedido.cliente = { COD: cliente.cod, @@ -485,10 +490,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', label: 'Domicilio:', valor: domicilioStamp }); - if(domicilio.verPuntos) { + if (domicilio.verPuntos) { delete $scope.notaPedido.domicilio.verPuntos; $scope.seleccionarPuntosDeDescarga(); - }else { + } else { crearNotaPedidoService .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) .then(function(res) { @@ -496,7 +501,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', }); } }, function() { - $scope.seleccionarCliente(); + $scope.seleccionarCliente(true); return; } ); @@ -970,5 +975,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', delete $localStorage.notaPedido; } } + + function deleteCliente() { + delete $scope.notaPedido.domicilioStamp; + delete $scope.notaPedido.notaPedidoPuntoDescarga; + $scope.notaPedido.domicilio = {dom: ''}; + $scope.notaPedido.cliente = {}; + $scope.$broadcast('removeCabecera', 'Cliente:'); + $scope.$broadcast('removeCabecera', 'Domicilio:'); + $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); + } } ]); diff --git a/src/js/service.js b/src/js/service.js index 3f5e412..a1eee0a 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -55,7 +55,7 @@ angular.module('focaCrearNotaPedido') getNumeroNotaPedido: function() { return $http.get(route + '/nota-pedido/numero-siguiente'); }, - getBotonera: function(vendedor) { + getBotonera: function() { var result = [ { label: 'Cliente', @@ -86,16 +86,6 @@ angular.module('focaCrearNotaPedido') image: 'productos.png' } ]; - - if(!vendedor) { - var botonVendedor = { - label: 'Vendedor', - image: 'vendedor.png' - }; - - result.unshift(botonVendedor); - } - return result; }, crearPuntosDescarga: function(puntosDescarga) { -- 1.9.1