diff --git a/src/js/controller.js b/src/js/controller.js index a0e0f91..bea37e1 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -9,17 +9,20 @@ angular.module('focaBusquedaCliente') $scope.vendedor = vendedor ? vendedor : {}; $scope.filters = ''; $scope.primerBusqueda = false; - // pagination + + //#region pagination $scope.numPerPage = 10; $scope.currentPage = 1; $scope.filteredClientes = []; $scope.currentPageClientes = []; $scope.selectedClientes = -1; $scope.ingreso = false; + $scope.accion = ''; $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/); $scope.focused = 1; + //#endregion - $scope.cliente = { + $scope.clienteTemplate = { COD: 0, ES_MAY: true, cuit1: '', @@ -50,10 +53,10 @@ angular.module('focaBusquedaCliente') NOMBRE: '' }, cobrador: { - NomVen: '' + NOM: '' } - }; - + }; + $scope.cliente = angular.copy($scope.clienteTemplate); $scope.busquedaPress = function (key) { if (key === 13) { var funcion; @@ -127,6 +130,56 @@ angular.module('focaBusquedaCliente') } }; + $scope.crearCliente = function () { + $scope.cliente = angular.copy($scope.clienteTemplate); + $scope.vendedor.NOM = ''; + $scope.vendedor.id = undefined; + $scope.cliente.cobrador.NOM = ''; + $scope.cliente.cobrador.ID = undefined; + $scope.accion = "Crear Cliente"; + $scope.ingreso = true; + } + + $scope.openModal = function (cliente) { + focaBusquedaClienteService.obtenerClientePorCodigo(cliente.cod) + .then(function (res) { + var data = res.data[0]; + $scope.cliente.codigo = res.data[0].COD; + $scope.cliente.NOM = data.NOM; + $scope.cliente.DOM = data.DOM; + $scope.cliente.CPO = data.CPO; + $scope.cliente.provincia.ID = data.PCX; + $scope.cliente.provincia.NOMBRE = data.PCI; + $scope.cliente.localidad.ID = data.LOX; + $scope.cliente.localidad.NOMBRE = data.LOC; + $scope.cliente.zona.ID = data.zona.ID; + $scope.cliente.zona.NOM = data.zona.NOM; + $scope.cliente.actividad.NOM = data.ACT; + $scope.cliente.cobrador.NOM = data.cobrador ? data.cobrador.NOM : ''; + $scope.cliente.cobrador.ID = data.cobrador ? data.cobrador.id : undefined; + $scope.vendedor.NOM = data.vendedor.NOM; + $scope.vendedor.id = data.vendedor.id; + $scope.cliente.MAIL = data.MAIL; + $scope.cliente.TEL = data.TEL; + $scope.cliente.iva.NOMBRE = data.iva.NOMBRE; + $scope.cliente.tipoFactura.NOMBRE = data.tipoFactura.NOMBRE; + $scope.cliente.tipoFactura.ID = data.tipoFactura.ID; + var cuit = data.CUIT.split('-'); + $scope.cliente.cuit1 = cuit[0]; + $scope.cliente.cuit2 = cuit[1]; + $scope.cliente.cuit3 = cuit[2]; + $scope.cliente.tipoComprobante.NOMBRE = data.tipoComprobante.NOMBRE; + $scope.cliente.tipoComprobante.ID = data.tipoComprobante.ID; + $scope.cliente.formaPago.NOMBRE = data.formaPago.NOMBRE; + $scope.cliente.formaPago.ID = data.formaPago.ID; + $scope.cliente.ES_PROS = data.ES_PROS; + $scope.cliente.ES_MAY = data.ES_MAY; + $scope.accion = "Cliente"; + $scope.ingreso = true; + }) + .catch(function (e) { console.log(e); }) + } + $scope.busquedaDown = function (key) { if (key === 40) { primera(key); @@ -492,6 +545,7 @@ angular.module('focaBusquedaCliente') }; focaModalService.modal(parametrosModal).then( function (vendedor) { + console.log("vendedor seleccionado => ", vendedor); $scope.vendedor = vendedor; }, function () { // funcion ejecutada cuando se cancela el modal @@ -564,6 +618,8 @@ angular.module('focaBusquedaCliente') return; } + $scope.cliente.actividad.ID = parseInt($scope.cliente.actividad.ID); + var cliente = crearCopia(); focaBusquedaClienteService @@ -590,7 +646,7 @@ angular.module('focaBusquedaCliente') cliente.TIP = cliente.tipoFactura.ID; cliente.TCO = cliente.tipoComprobante.ID; cliente.FPA = cliente.formaPago.ID; - cliente.VEN = vendedor.ID; + cliente.VEN = $scope.vendedor.id; cliente.CUIT = cliente.cuit1 + cliente.cuit2 + cliente.cuit3; cliente.idCobrador = cliente.cobrador.ID; @@ -610,6 +666,7 @@ angular.module('focaBusquedaCliente') return cliente; } + //#region PAGINADOR function calcularPages(paginaActual) { var paginas = []; paginas.push(paginaActual); @@ -673,6 +730,8 @@ angular.module('focaBusquedaCliente') $scope.selectedClientes = 0; } } + //#endregion + function validateEmails(emails) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var arr = emails.split(','); diff --git a/src/js/service.js b/src/js/service.js index 83106ba..65277e7 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -13,6 +13,9 @@ angular.module('focaBusquedaCliente') return $http.post(API_ENDPOINT.URL + '/cliente/listar', { nombreOCuit: nombreOCuit }); }, + obtenerClientePorCodigo: function (cod) { + return $http.get(API_ENDPOINT.URL + '/cliente-codigo/' + cod ); + }, guardarCliente: function (cliente) { return $http.post(API_ENDPOINT.URL + '/cliente', { cliente: cliente }); } diff --git a/src/views/foca-busqueda-cliente-modal.html b/src/views/foca-busqueda-cliente-modal.html index 7ded284..b6467bb 100644 --- a/src/views/foca-busqueda-cliente-modal.html +++ b/src/views/foca-busqueda-cliente-modal.html @@ -2,11 +2,12 @@