diff --git a/src/js/controller.js b/src/js/controller.js index dac7a26..538e57c 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,18 +1,171 @@ angular.module('focaAbmCliente') .controller('focaAbmClienteController', [ - '$scope', 'focaAbmClienteService', '$location', '$uibModal', - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', - '$routeParams', '$filter', - function($scope, focaAbmClienteService, $location, $uibModal, focaModalService, - focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) { + '$scope', 'focaBotoneraLateralService', '$timeout', '$uibModal','focaModalService', + 'focaAbmClienteService','$filter', + function($scope, focaBotoneraLateralService, $timeout, $uibModal,focaModalService, + focaAbmClienteService, $filter) { + $scope.cliente= { + NOM: undefined, + COD: undefined + }; + $scope.vendedor = {}; + + $scope.botonCliente = [{ + label: 'Cliente', + image: 'cliente.png' + }]; + + $scope.botonera = [ + { + label: 'Datos Cliente', + image: 'datoscliente.png', + }, + { + label: 'Domicilios de entrega', + image: 'dimiciliodeentrega.png' + }, + { + label: 'Precio y Condiciones', + image: 'precios-condiciones.png' + } + ]; //SETEO BOTONERA LATERAL $timeout(function() { - focaBotoneraLateralService.showSalir(false); + focaBotoneraLateralService.showSalir(true); focaBotoneraLateralService.showPausar(false); focaBotoneraLateralService.showCancelar(false); - focaBotoneraLateralService.showGuardar(true); + focaBotoneraLateralService.showGuardar(false); }); - - } - ]); + + $scope.seleccionarCliente = function() { + var datos = null; + focaAbmClienteService.getAllClientes() + .then(function (res) { + datos = res.data; + focaModalService.modal({ + titulo: 'Clientes', + data: datos, + size: 'md', + columnas: [ + { + propiedad: 'COD', + nombre: 'Codigo' + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + }, + { + propiedad: 'CUIT', + nombre: 'CUIT' + } + ], + }).then(function (res) { + $scope.cliente.NOM = res.NOM; + $scope.cliente.COD = res.COD; + $scope.$broadcast('addCabecera', { + label: 'Cliente:', + valor: $filter('rellenarDigitos') + ($scope.cliente.COD, 5) + ' - ' + $scope.cliente.NOM + }); + }).catch(function (e) { + console.log(e); + }); + }); + }; + + $scope.seleccionarDatosCliente = function () { + if ($scope.cliente.NOM === undefined || $scope.cliente.COD === undefined) { + focaModalService.alert('Seleccione cliente'); + return; + } else { + var modalInstanceCliente = $uibModal.open( + { + ariaLabelledBy: '', + templateUrl: 'foca-modal-cliente.html', + controller: 'focaModalClienteController', + resolve: { + idCliente: function () { return $scope.cliente.COD; }, + }, + size: 'lg', + } + ); + modalInstanceCliente.result + .then( function(data) { + if (data) { + console.log('Data 2: ', data); + $scope.cliente.NOM = data.NOM; + $scope.$broadcast('cleanCabecera'); + $scope.$broadcast('addCabecera', { + label: 'Cliente:', + valor: $filter('rellenarDigitos')($scope.cliente.NOM) + }); + console.log('Data', data); + } + }); + } + }; + + $scope.seleccionarDomiciliosDeEntrega = function () { + if ($scope.cliente.NOM === undefined || $scope.cliente.COD === undefined) { + focaModalService.alert('Seleccione un cliente'); + return; + } + var modalInstanceDomicilio = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Domicilios', + templateUrl: 'modal-domicilio.html', + controller: 'focaModalDomicilioController', + resolve: { + idCliente: function () { return $scope.cliente.COD; }, + esNuevo: function () { return $scope.cliente.esNuevo; } + }, + size: 'lg', + } + ); + modalInstanceDomicilio.result.then( function(data) { + if (data) { + $scope.$broadcast('addCabecera', { + label: 'Domicilio:', + valor: data.Calle + ' ' + data.Numero + ' - ' + data.Localidad + + ' - ' + data.Provincia + }); + } + }); + }; + + $scope.seleccionarPrecioYCondiciones = function () { + + if ($scope.cliente.NOM === undefined || $scope.cliente.COD === undefined) { + focaModalService.alert('Seleccione cliente'); + return; + } + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Precio Condición', + templateUrl: 'modal-precio-condicion.html', + controller: 'focaModalPrecioCondicionController', + size: 'lg', + resolve: { + idListaPrecio: function () { + return $scope.cliente.MOD || null; + } + } + } + ); + + modalInstance.result.then( function (data) { + if (data) { + console.log('Data: ', data); + } + + }, function () { + + } + ); + }; + + + } +]); diff --git a/src/js/controllerCliente.js b/src/js/controllerCliente.js new file mode 100644 index 0000000..5f098eb --- /dev/null +++ b/src/js/controllerCliente.js @@ -0,0 +1,534 @@ +angular.module('focaAbmCliente') + .controller('focaModalClienteController', [ + '$scope', '$timeout', '$uibModalInstance', 'focaModalService', + 'focaAbmClienteService', 'idCliente', + + function ($scope, $timeout, $uibModalInstance, focaModalService, + focaAbmClienteService, idCliente) { + + $scope.cliente = { + provincia: {}, + localidad: {}, + zona: {}, + actividad: {}, + cobrador: {}, + vendedor: {}, + iva: {}, + tipoFactura: {}, + tipoComprobante: {}, + formaPago: {} + }; + $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/); + + $scope.vendedor = {}; + + focaAbmClienteService.obtenerClientePorCodigo(idCliente) + .then(function (res) { + var data = res.data[0]; + $scope.cliente.codigo = data.COD; + $scope.cliente.DOM = data.DOM; + $scope.cliente.NOM = data.NOM; + $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.actividad.NOM; + $scope.cliente.actividad.ID = data.actividad.ID; + $scope.cliente.cobrador.NOM = data.cobrador ? data.cobrador.NOM : ''; + $scope.cliente.cobrador.NUM = data.cobrador ? data.cobrador.NUM : undefined; + $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.editando = true; + + }) + .catch(function (e) { console.log(e); }); + + + + + $scope.cancel = function () { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.guardar = function () { + if (!$scope.cliente.NOM) { + focaModalService.alert('Ingrese Nombre'); + return; + } else if (!$scope.cliente.CPO) { + focaModalService.alert('Ingrese Codigo Postal'); + return; + } else if (!$scope.cliente.provincia.NOMBRE) { + focaModalService.alert('Seleccione una provincia'); + return; + } else if (!$scope.cliente.DOM) { + focaModalService.alert('Ingrese Domicilio'); + return; + } else if (!$scope.cliente.localidad.NOMBRE) { + focaModalService.alert('Seleccione una localidad'); + return; + } else if (!$scope.cliente.zona.NOM) { + focaModalService.alert('Seleccione una zona'); + return; + } else if (!$scope.cliente.actividad.NOM) { + focaModalService.alert('Seleccione actividad'); + return; + } else if (!$scope.cliente.cobrador.NUM) { + focaModalService.alert('Seleccione un cobrador'); + return; + } else if (!$scope.vendedor.NOM) { + focaModalService.alert('Seleccione un vendedor'); + return; + } else if ($scope.cliente.MAIL && !validateEmails($scope.cliente.MAIL)) { + focaModalService.alert('Ingrese un formato de email válido'); + return; + } else if (!$scope.cliente.TEL) { + focaModalService.alert('Ingrese un numero de telefono'); + return; + } else if (!$scope.cliente.iva.NOMBRE) { + focaModalService.alert('Seleccione responsabilidad ante el IVA'); + return; + } else if (!$scope.cliente.tipoFactura.NOMBRE) { + focaModalService.alert('Seleccione tipo de Factura'); + return; + } else if (!$scope.cliente.cuit1 && !$scope.cliente.cuit2 && !$scope.cliente.cuit3) { + focaModalService.alert('Ingrese CUIT'); + return; + } else if (!$scope.cliente.cuit1 || !$scope.cliente.cuit2 || !$scope.cliente.cuit3) { + focaModalService.alert('Ingrese CUIT válido'); + return; + } else if (!$scope.regexCuit.test($scope.cliente.cuit1 + $scope.cliente.cuit2 + $scope.cliente.cuit3)) { + focaModalService.alert('Ingrese CUIT con formato: XX-XXXXXXXX-X'); + return; + } else if (!$scope.cliente.tipoComprobante.NOMBRE) { + focaModalService.alert('Seleccione un Comprobante'); + return; + } else if (!$scope.cliente.formaPago.NOMBRE) { + focaModalService.alert('Seleccione una forma de pago'); + return; + } + + $scope.cliente.actividad.ID = parseInt($scope.cliente.actividad.ID); + + var cliente = crearCopia(); + + focaAbmClienteService + .guardarCliente(cliente) + .then(function () { + $uibModalInstance.close(cliente); + }) + .catch(function (e) { + console.log(e); + }); + }; + $scope.seleccionarProvincia = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.provincia.NOMBRE, + query: '/provincia', + columnas: [ + { + propiedad: 'ID', + nombre: 'Codigo', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOMBRE', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de provincias', + size: 'md' + }; + focaModalService.modal(parametrosModal).then(function (provincia) { + $scope.cliente.provincia = provincia; + $timeout(function () { + $scope.focused = 4; + }); + }, function () { + //TODO: función llamada cuando cancela el modal + }); + } + }; + $scope.seleccionarLocalidad = function (key) { + if ($scope.cliente.provincia.ID === undefined) { + focaModalService.alert('Seleccione una provincia'); + return; + } + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.localidad.NOMBRE, + query: '/localidad/' + parseInt($scope.cliente.provincia.ID), + columnas: [ + { + propiedad: 'ID', + nombre: 'Código', + }, + { + propiedad: 'NOMBRE', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de localidades', + size: 'md' + }; + focaModalService.modal(parametrosModal).then(function (localidad) { + $scope.cliente.localidad = localidad; + $timeout(function () { + $scope.focused = 5; + }); + }, function () { + //TODO: función llamada cuando cancela el modal + }); + } + }; + $scope.seleccionarZona = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.zona.NOM, + query: '/zona', + columnas: [ + { + propiedad: 'ID', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de zonas', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (zona) { + $scope.cliente.zona = zona; + $timeout(function () { + $scope.focused = 6; + }); + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarActividad = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.actividad.NOM, + query: '/actividad', + columnas: [ + { + propiedad: 'ID', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de actividades', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (actividad) { + $scope.cliente.actividad = actividad; + $timeout(function () { + $scope.focused = 7; + }); + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarCobrador = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.cobrador.NOM, + query: '/cobrador', + columnas: [ + { + propiedad: 'NUM', + nombre: 'Código' + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de cobradores', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (cobrador) { + $scope.cliente.cobrador = cobrador; + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarVendedor = function (key) { + if (key === 13) { + var parametrosModal = { + titulo: 'Búsqueda vendedores', + query: '/vendedor', + columnas: [ + { + propiedad: 'NUM', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + } + ], + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (vendedor) { + console.log("vendedor seleccionado => ", vendedor); + $scope.vendedor = vendedor; + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarIva = function (key) { + if (key === 13) { + var parametrosModal = { + query: '/iva', + searchText: $scope.cliente.iva.NOMBRE, + columnas: [ + { + propiedad: 'ID', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOMBRE', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de responsabilidad ante el IVA', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (iva) { + if (iva) { + delete $scope.cliente.tipoFactura.NOMBRE; + } + $scope.cliente.iva = iva; + $timeout(function () { + $scope.focused = 12; + }); + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarTipoFactura = function (key) { + + if ($scope.cliente.iva.NOMBRE == '') { + focaModalService.alert('Seleccione una responsabilidad ante el IVA'); + return; + } + + if (key === 13) { + var datos; + if ($scope.cliente.iva.ID == 1) { + datos = [ + { + ID: 'A', + NOMBRE: 'Factura A' + }, + { + ID: 'M', + NOMBRE: 'Factura M' + }, + { + ID: 'R', + NOMBRE: 'Remito' + } + ]; + } else { + datos = [ + { + ID: 'B', + NOMBRE: 'Factura B' + }, + { + ID: 'R', + NOMBRE: 'Remito' + } + ]; + } + focaModalService.modal({ + titulo: 'Seleccionar Factura', + data: datos, + size: 'md', + columnas: [ + { + propiedad: 'ID', + NOMBRE: 'Codigo' + }, + { + propiedad: 'NOMBRE', + NOMBRE: 'Factura' + } + ], + }).then(function (res) { + $scope.cliente.tipoFactura = res; + }); + } + }; + $scope.pasarCampoCuit = function (numeroCuit) { + if (numeroCuit === 1 && $scope.cliente.cuit1.length === 2) { + $scope.cuitActivo = 2; + } else if (numeroCuit === 2 && $scope.cliente.cuit2.length === 8) { + $scope.cuitActivo = 3; + } + }; + $scope.seleccionarTipoComprobante = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.tipoComprobante.NOMBRE, + query: '/tipo-comprobante', + columnas: [ + { + propiedad: 'ID', + nombre: 'Código' + }, + { + propiedad: 'NOMBRE', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de tipos de comprobante', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (tipoComprobante) { + $scope.cliente.tipoComprobante = tipoComprobante; + $timeout(function () { + $scope.focused = 17; + }); + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + $scope.seleccionarFormaPago = function (key) { + if (key === 13) { + var parametrosModal = { + searchText: $scope.cliente.formaPago.NOMBRE, + query: '/forma-pago', + columnas: [ + { + propiedad: 'ID', + nombre: 'Código', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOMBRE', + nombre: 'Nombre' + } + ], + titulo: 'Búsqueda de formas de pago', + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (formaPago) { + $scope.cliente.formaPago = formaPago; + }, function () { + // funcion ejecutada cuando se cancela el modal + }); + } + }; + + function crearCopia() { + var cliente = angular.copy($scope.cliente); + cliente.COD = cliente.codigo; + cliente.CPO = cliente.CPO; + cliente.PCX = parseInt(cliente.provincia.ID); + cliente.LOX = parseInt(cliente.localidad.ID); + cliente.LOC = cliente.localidad.NOMBRE; + cliente.PCI = cliente.provincia.NOMBRE; + cliente.IVA = cliente.iva.ID; + cliente.ACT = cliente.actividad.ID; + cliente.ZON = (parseInt(cliente.zona.ID)).toString(); + cliente.TIP = cliente.tipoFactura.ID; + cliente.TCO = cliente.tipoComprobante.ID; + cliente.FPA = cliente.formaPago.ID; + cliente.VEN = $scope.vendedor.id; + cliente.CUIT = `${cliente.cuit1}-${cliente.cuit2}-${cliente.cuit3}`; + cliente.idCobrador = cliente.cobrador.ID; + + delete cliente.codigo; + delete cliente.provincia; + delete cliente.localidad; + delete cliente.iva; + delete cliente.actividad; + delete cliente.zona; + delete cliente.tipoFactura; + delete cliente.tipoComprobante; + delete cliente.formaPago; + delete cliente.cobrador; + delete cliente.cuit1; + delete cliente.cuit2; + delete cliente.cuit3; + delete cliente.vendedor; + + return cliente; + } + 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(','); + var result = true; + arr.forEach(function (email) { + var val = String(email).trim().toLowerCase(); + if (!re.test(val)) result = false; + }); + return result; + } + + }]); \ No newline at end of file diff --git a/src/js/service.js b/src/js/service.js index daf7b66..dd2f30b 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,6 +1,14 @@ angular.module('focaAbmCliente') - .factory('focaAbmCliente', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + .factory('focaAbmClienteService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { return { - + getAllClientes: function () { + return $http.get(API_ENDPOINT.URL + '/cliente'); + }, + 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-abm-cliente.html b/src/views/foca-abm-cliente.html index 5f24335..5ed8d27 100644 --- a/src/views/foca-abm-cliente.html +++ b/src/views/foca-abm-cliente.html @@ -9,9 +9,19 @@
+ + +
+
+
+
+
-
+
- \ No newline at end of file diff --git a/src/views/foca-modal-cliente.html b/src/views/foca-modal-cliente.html new file mode 100644 index 0000000..2476ef7 --- /dev/null +++ b/src/views/foca-modal-cliente.html @@ -0,0 +1,515 @@ + + +