using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Globalization; using Gestor.Model.Attributes; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; using Gestor.Model.Helper; using Gestor.Model.Resources; using Gestor.Model.Validation; using Newtonsoft.Json; namespace Gestor.Model.Domain.Seguros; public class Cliente : DomainBase, IDomain { private string _nome; private string _documento; private string _identidade; private string _emissor; private string _estadoEmissor; private string _habilitacao; private string _categoriaHabilitacao; private string _pasta; private string _cei; private string _rne; private string _agencia; private string _tipoConta; private string _conta; private string _caepf; private bool? _malaDireta = true; private string _nomeSocialRg; public long IdEmpresa { get; set; } [Log(true)] [Name(true)] public string Nome { get { return _nome?.ToUpper(); } set { _nome = value; NomeSocial = $"{value?.ToUpper()} - {base.Id}"; } } public string NomeSocial { get; set; } [Log(true)] public DateTime? Nascimento { get; set; } [Log(true)] public Sexo? Sexo { get; set; } [Log(true)] [Description("ESTADO CIVIL")] public EstadoCivil? EstadoCivil { get; set; } [Log(true)] [Description("DOCUMENTO PRINCIPAL")] public TipoDocumento? DocumentoPrincipal { get; set; } [Log(true)] public string Documento { get { return _documento?.ToUpper().Trim(); } set { _documento = value; } } [Log(true)] public string Identidade { get { return _identidade?.ToUpper().Trim(); } set { _identidade = value; } } [Log(true)] public string Emissor { get { return _emissor?.ToUpper().Trim(); } set { _emissor = value; } } [Log(true)] [Description("ESTADO EMISSOR")] public string EstadoEmissor { get { return _estadoEmissor?.ToUpper().Trim(); } set { _estadoEmissor = value; } } [Log(true)] [Description("EXPEDIÇÃO")] public DateTime? Expedicao { get; set; } [Log(true)] [Description("HABILITAÇÃO")] public string Habilitacao { get { return _habilitacao?.ToUpper().Trim(); } set { _habilitacao = value; } } [Log(true)] [Description("PRIMEIRA HABILITAÇÃO")] public DateTime? PrimeiraHabilitacao { get; set; } [Log(true)] [Description("VENCIMENTO HABILITAÇÃO")] public DateTime? VencimentoHabilitacao { get; set; } [Log(true)] [Description("CATEGORIA HABILITAÇÃO")] public string CategoriaHabilitacao { get { return _categoriaHabilitacao?.ToUpper().Trim(); } set { _categoriaHabilitacao = value; } } [Log(true)] [Description("CLIENTE DESDE")] public DateTime? ClienteDesde { get; set; } [Log(true)] public string Pasta { get { return _pasta?.ToUpper(); } set { _pasta = value; } } [Log(true)] public string Cei { get { return _cei?.ToUpper().Trim(); } set { _cei = value; } } [Log(true)] public string Rne { get { return _rne?.ToUpper().Trim(); } set { _rne = value; } } [Log(true)] public string Caepf { get { return _caepf?.ToUpper().Trim(); } set { _caepf = value; } } public Atividade Atividade { get; set; } [Description("PROFISSÃO")] public Profissao Profissao { get; set; } public Banco Banco { get; set; } [Log(true)] [Description("AGÊNCIA")] public string Agencia { get { return _agencia?.ToUpper().Trim(); } set { _agencia = value; } } [Log(true)] [Description("TIPO CONTA")] public string TipoConta { get { return _tipoConta?.ToUpper(); } set { _tipoConta = value; } } [Log(true)] public string Conta { get { return _conta?.ToUpper().Trim(); } set { _conta = value; } } [Log(true)] [Description("RENDA MENSAL")] public decimal RendaMensal { get; set; } [Log(true)] public bool Falecido { get; set; } public ObservableCollection Telefones { get; set; } public ObservableCollection Emails { get; set; } public ObservableCollection Enderecos { get; set; } public ObservableCollection Contatos { get; set; } public ObservableCollection Vinculos { get; set; } public List Origens { get; set; } [Log(true)] [Description("OBSERVAÇÃO")] public string Observacao { get; set; } [Log(true)] public bool Excluido { get; set; } [Log(true)] public string Status { get; set; } [Log(true)] public ResponsavelAssinatura ResponsavelAssinatura { get; set; } [Log(true)] [Description("DESEJA RECEBER MALA DIRETA")] public bool? MalaDireta { get { return _malaDireta.GetValueOrDefault(true); } set { _malaDireta = value.GetValueOrDefault(true); } } public string NomeSocialRg { get { return _nomeSocialRg?.ToUpper(); } set { _nomeSocialRg = value; } } public bool EstaNaCentralSegurado { get; set; } public bool PessoaFisica => Documento.Clear().Length < 12; [JsonIgnore] public Func>> ValidationEvent => Validate; public List> Validate() { List> list = ValidationHelper.AddValue(); int? num = Nome?.Trim().Split(new char[1] { ' ' }).Length; if (!num.HasValue) { list.AddValue("Nome", Messages.Obrigatorio); } else if (num <= 1) { list.AddValue("Nome", Messages.NomeInvalido); } if (!DocumentoPrincipal.HasValue) { list.AddValue("DocumentoPrincipal|DOCUMENTO PRINCIPAL", string.Format(Messages.Obrigatorio)); } if (ClienteDesde.HasValue && (DateTime.Compare(ClienteDesde.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(ClienteDesde.Value, new DateTime(9999, 12, 31)) > 0)) { list.AddValue("ClienteDesde|CLIENTE DESDE", string.Format(Messages.DataInvalida)); } DateTime date = Funcoes.GetNetworkTime().Date; if (Nascimento.HasValue && Nascimento > date) { list.AddValue("Nascimento|" + ((Documento.OnlyNumber().Length > 11) ? "FUNDAÇÃO" : "NASCIMENTO"), Messages.Invalido); } if (Nascimento.HasValue && (DateTime.Compare(Nascimento.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Nascimento.Value, new DateTime(9999, 12, 31)) > 0)) { list.AddValue("Nascimento|" + ((Documento.OnlyNumber().Length > 11) ? "FUNDAÇÃO" : "NASCIMENTO"), string.Format(Messages.DataInvalida)); } if (string.IsNullOrWhiteSpace(Documento)) { list.AddValue("Documento", Messages.Obrigatorio); } else if (!Documento.ValidacaoDocumento()) { list.AddValue("Documento", Messages.Invalido); } switch (DocumentoPrincipal) { case TipoDocumento.Rne: if (string.IsNullOrWhiteSpace(Rne)) { list.AddValue("Rne", Messages.Obrigatorio); } else if (!Rne.ValidacaoRne()) { list.AddValue("Rne", Messages.Invalido); } break; case TipoDocumento.Cei: if (string.IsNullOrWhiteSpace(Cei)) { list.AddValue("Cei", Messages.Obrigatorio); } else if (!Cei.ValidacaoCei()) { list.AddValue("Cei", Messages.Invalido); } break; case TipoDocumento.Caepf: if (string.IsNullOrWhiteSpace(Caepf)) { list.AddValue("Caepf", Messages.Obrigatorio); } else if (!Caepf.ValidateCaepf()) { list.AddValue("Caepf", Messages.Invalido); } break; } if (Documento == null || Documento.OnlyNumber().Length <= 11) { if (PrimeiraHabilitacao.HasValue && PrimeiraHabilitacao > date) { list.AddValue("PrimeiraHabilitacao|PRIMEIRA HABILITAÇÃO", Messages.Invalido); } if (PrimeiraHabilitacao.HasValue && (DateTime.Compare(PrimeiraHabilitacao.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(PrimeiraHabilitacao.Value, new DateTime(9999, 12, 31)) > 0)) { list.AddValue("PrimeiraHabilitacao|PRIMEIRA HABILITAÇÃO", string.Format(Messages.DataInvalida)); } if (VencimentoHabilitacao.HasValue && VencimentoHabilitacao <= PrimeiraHabilitacao) { list.AddValue("VencimentoHabilitacao|VENCIMENTO HABILITAÇÃO", Messages.Invalido); } if (VencimentoHabilitacao.HasValue && (DateTime.Compare(VencimentoHabilitacao.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(VencimentoHabilitacao.Value, new DateTime(9999, 12, 31)) > 0)) { list.AddValue("VencimentoHabilitacao|VENCIMENTO HABILITAÇÃO", string.Format(Messages.DataInvalida)); } if (Expedicao.HasValue && (DateTime.Compare(Expedicao.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Expedicao.Value, new DateTime(9999, 12, 31)) > 0)) { list.AddValue("Expedicao|EXPEDIÇÃO", string.Format(Messages.DataInvalida)); } if (Expedicao.HasValue && Expedicao > date) { list.AddValue("Expedicao|EXPEDIÇÃO", Messages.Invalido); } if (!string.IsNullOrWhiteSpace(Identidade) && Identidade.Length > 14) { list.AddValue("Identidade", string.Format(Messages.MaiorQueLimite, 14)); } if (!string.IsNullOrWhiteSpace(Habilitacao) && Habilitacao.Length > 15) { list.AddValue("Habilitacao|HABILITAÇÃO", string.Format(Messages.MaiorQueLimite, 15)); } if (!string.IsNullOrWhiteSpace(CategoriaHabilitacao) && CategoriaHabilitacao.Length > 10) { list.AddValue("CategoriaHabilitacao|CATEGORIA HABILITAÇÃO", string.Format(Messages.MaiorQueLimite, 10)); } if (!string.IsNullOrWhiteSpace(Emissor) && !Emissor.ValidacaoOrgao()) { list.AddValue("Emissor|EMISSOR", string.Format(Messages.MaiorQueLimite, 6)); } if (!string.IsNullOrWhiteSpace(EstadoEmissor) && !EstadoEmissor.ValidacaoEstado()) { list.AddValue("EstadoEmissor|ESTADO EMISSOR", Messages.Invalido); } } if (!string.IsNullOrWhiteSpace(Pasta) && Pasta.Length > 8) { list.AddValue("Pasta", string.Format(Messages.MaiorQueLimite, 8)); } if (!string.IsNullOrWhiteSpace(Agencia) && Agencia.Length > 8) { list.AddValue("Agencia|AGÊNCIA", string.Format(Messages.MaiorQueLimite, 8)); } if (!string.IsNullOrWhiteSpace(TipoConta) && TipoConta.Length > 20) { list.AddValue("TipoConta|TIPO CONTA", string.Format(Messages.MaiorQueLimite, 20)); } if (!string.IsNullOrWhiteSpace(Conta) && Conta.Length > 12) { list.AddValue("Conta", string.Format(Messages.MaiorQueLimite, 12)); } if (ResponsavelAssinatura != null) { list.AddRange(ResponsavelAssinatura.Validate()); } return list; } public List Log() { List list = new List(); TupleList tupleList = new TupleList(); ObservableCollection> observableCollection = new ObservableCollection>(); object item; if (DocumentoPrincipal.HasValue) { TipoDocumento? documentoPrincipal = DocumentoPrincipal; item = (documentoPrincipal.HasValue ? documentoPrincipal.GetValueOrDefault().GetDescription() : null); } else { item = ""; } observableCollection.Add(new Tuple("TIPO DO DOCUMENTO PRINCIPAL", (string)item, "")); observableCollection.Add(new Tuple("DOCUMENTO PRINCIPAL", string.IsNullOrWhiteSpace(Documento) ? "" : Documento, "")); observableCollection.Add(new Tuple("CLIENTE", string.IsNullOrWhiteSpace(Nome) ? "" : Nome.ToUpper(), "")); observableCollection.Add(new Tuple((Documento.OnlyNumber().Length > 11) ? "FUNDAÇÃO" : "NASCIMENTO", (!Nascimento.HasValue) ? "" : Nascimento?.ToShortDateString(), "")); tupleList.Tuples = observableCollection; list.Add(tupleList); List list2 = list; if (Documento != null && Documento.OnlyNumber().Length > 11) { list2[0].Tuples.Add(new Tuple("RAMO DE ATIVIDADE", string.IsNullOrWhiteSpace(Atividade.Nome) ? "" : Atividade.Nome, "")); } else { list2[0].Tuples.Add(new Tuple("IDENTIDADE", string.IsNullOrWhiteSpace(Identidade) ? "" : Identidade, "")); list2[0].Tuples.Add(new Tuple("ÓRGÃO EMISSOR", string.IsNullOrWhiteSpace(Emissor) ? "" : Emissor.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("ESTADO EMISSOR", string.IsNullOrWhiteSpace(EstadoEmissor) ? "" : EstadoEmissor.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("DATA DE EXPEDIÇÃO", (!Expedicao.HasValue) ? "" : Expedicao?.ToShortDateString(), "")); list2[0].Tuples.Add(new Tuple("HABILITAÇÃO", string.IsNullOrWhiteSpace(Habilitacao) ? "" : Habilitacao.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("CATEGORIA", string.IsNullOrWhiteSpace(CategoriaHabilitacao) ? "" : CategoriaHabilitacao.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("PRIMEIRA HABILITAÇÃO", (!PrimeiraHabilitacao.HasValue) ? "" : PrimeiraHabilitacao?.ToShortDateString(), "")); list2[0].Tuples.Add(new Tuple("VENCIMENTO DA HABILITAÇÃO", (!VencimentoHabilitacao.HasValue) ? "" : VencimentoHabilitacao?.ToShortDateString(), "")); ObservableCollection> tuples = list2[0].Tuples; object item2; if (Sexo.HasValue) { Sexo? sexo = Sexo; item2 = (sexo.HasValue ? sexo.GetValueOrDefault().GetDescription() : null); } else { item2 = ""; } tuples.Add(new Tuple("SEXO", (string)item2, "")); ObservableCollection> tuples2 = list2[0].Tuples; object item3; if (EstadoCivil.HasValue) { EstadoCivil? estadoCivil = EstadoCivil; item3 = (estadoCivil.HasValue ? estadoCivil.GetValueOrDefault().GetDescription() : null); } else { item3 = ""; } tuples2.Add(new Tuple("ESTADO CIVIL", (string)item3, "")); list2[0].Tuples.Add(new Tuple("PROFISSÃO DO CLIENTE", (Profissao == null) ? "" : Profissao.Nome.ToUpper(), "")); } list2[0].Tuples.Add(new Tuple("CLIENTE DESDE", (!ClienteDesde.HasValue) ? "" : ClienteDesde?.ToShortDateString(), "")); list2[0].Tuples.Add(new Tuple("PASTA", string.IsNullOrWhiteSpace(Pasta) ? "" : Pasta.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("BANCO", (Banco == null) ? "" : Banco.Nome.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("AGÊNCIA", string.IsNullOrWhiteSpace(Agencia) ? "" : Agencia.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("TIPO DE CONTA", string.IsNullOrWhiteSpace(TipoConta) ? "" : TipoConta.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("NÚMERO DA CONTA", string.IsNullOrWhiteSpace(Conta) ? "" : Conta.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("FALECIDO", Falecido ? "SIM" : "NÃO", "")); list2[0].Tuples.Add(new Tuple("ÓRGÃO EMISSOR", string.IsNullOrWhiteSpace(Emissor) ? "" : Emissor.ToUpper(), "")); list2[0].Tuples.Add(new Tuple("RENDA MENSAL", RendaMensal.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), "")); ObservableCollection> observableCollection2 = new ObservableCollection> { new Tuple("TELEFONES$", "", "") }; if (Telefones != null && Telefones.Count > 0) { foreach (ClienteTelefone telefone in Telefones) { observableCollection2.Add(new Tuple($" TELEFONE {Telefones.IndexOf(telefone) + 1}$", "", "")); object item4; if (telefone.Tipo.HasValue) { TipoTelefone? tipo = telefone.Tipo; item4 = (tipo.HasValue ? tipo.GetValueOrDefault().GetDescription() : null); } else { item4 = ""; } observableCollection2.Add(new Tuple(" TIPO", (string)item4, "")); observableCollection2.Add(new Tuple(" PREFIXO", string.IsNullOrWhiteSpace(telefone.Prefixo) ? "" : telefone.Prefixo.ToUpper(), "")); observableCollection2.Add(new Tuple(" NÚMERO", string.IsNullOrWhiteSpace(telefone.Numero) ? "" : telefone.Numero, "")); observableCollection2.Add(new Tuple(" ORDEM", (!telefone.Ordem.HasValue) ? "" : telefone.Ordem.ToString(), "")); } } list2.Add(new TupleList { Tuples = observableCollection2 }); ObservableCollection> observableCollection3 = new ObservableCollection> { new Tuple("EMAILS$", "", "") }; if (Emails != null && Emails.Count > 0) { foreach (ClienteEmail email in Emails) { observableCollection3.Add(new Tuple($" EMAIL {Emails.IndexOf(email) + 1}$", "", "")); observableCollection3.Add(new Tuple(" ENDEREÇO DE EMAIL", string.IsNullOrWhiteSpace(email.Email) ? "" : email.Email, "")); observableCollection3.Add(new Tuple(" ORDEM", (!email.Ordem.HasValue) ? "" : email.Ordem.ToString(), "")); } } list2.Add(new TupleList { Tuples = observableCollection3 }); ObservableCollection> observableCollection4 = new ObservableCollection> { new Tuple("ENDEREÇOS$", "", "") }; if (Enderecos != null && Enderecos.Count > 0) { foreach (ClienteEndereco endereco in Enderecos) { observableCollection4.Add(new Tuple($" ENDEREÇO {Enderecos.IndexOf(endereco) + 1}$", "", "")); observableCollection4.Add(new Tuple(" LOGRADOURO", string.IsNullOrWhiteSpace(endereco.Endereco) ? "" : endereco.Endereco, "")); observableCollection4.Add(new Tuple(" NÚMERO", string.IsNullOrWhiteSpace(endereco.Numero) ? "" : endereco.Numero, "")); observableCollection4.Add(new Tuple(" COMPLEMENTO", string.IsNullOrWhiteSpace(endereco.Complemento) ? "" : endereco.Complemento, "")); observableCollection4.Add(new Tuple(" BAIRRO", string.IsNullOrWhiteSpace(endereco.Bairro) ? "" : endereco.Bairro, "")); observableCollection4.Add(new Tuple(" CIDADE", string.IsNullOrWhiteSpace(endereco.Cidade) ? "" : endereco.Cidade, "")); observableCollection4.Add(new Tuple(" ESTADO", string.IsNullOrWhiteSpace(endereco.Estado) ? "" : endereco.Estado, "")); observableCollection4.Add(new Tuple(" CEP", string.IsNullOrWhiteSpace(endereco.Cep) ? "" : endereco.Cep, "")); observableCollection4.Add(new Tuple(" ORDEM", (!endereco.Ordem.HasValue) ? "" : endereco.Ordem.ToString(), "")); } } list2.Add(new TupleList { Tuples = observableCollection4 }); ObservableCollection> observableCollection5 = new ObservableCollection> { new Tuple("CONTATOS$", "", "") }; if (Contatos != null && Contatos.Count > 0) { foreach (MaisContato contato in Contatos) { observableCollection5.Add(new Tuple($" CONTATO {Contatos.IndexOf(contato) + 1}$", "", "")); observableCollection5.Add(new Tuple(" DOCUMENTO", string.IsNullOrWhiteSpace(contato.Documento) ? "" : contato.Documento, "")); observableCollection5.Add(new Tuple(" NASCIMENTO", (!contato.Nascimento.HasValue) ? "" : contato.Nascimento?.ToShortDateString(), "")); object item5; if (contato.Parentesco.HasValue) { Parentesco? parentesco = contato.Parentesco; item5 = (parentesco.HasValue ? parentesco.GetValueOrDefault().GetDescription() : null); } else { item5 = ""; } observableCollection5.Add(new Tuple(" PARENTESCO", (string)item5, "")); observableCollection5.Add(new Tuple(" BANCO", string.IsNullOrWhiteSpace(contato.Banco) ? "" : contato.Banco, "")); observableCollection5.Add(new Tuple(" AGÊNCIA", string.IsNullOrWhiteSpace(contato.Agencia) ? "" : contato.Agencia, "")); observableCollection5.Add(new Tuple(" CONTA", string.IsNullOrWhiteSpace(contato.Conta) ? "" : contato.Conta, "")); object item6; if (contato.Tipo.HasValue) { TipoTelefone? tipo = contato.Tipo; item6 = (tipo.HasValue ? tipo.GetValueOrDefault().GetDescription() : null); } else { item6 = ""; } observableCollection5.Add(new Tuple(" TIPO DO TELEFONE", (string)item6, "")); observableCollection5.Add(new Tuple(" PREFIXO", string.IsNullOrWhiteSpace(contato.Prefixo) ? "" : contato.Prefixo, "")); observableCollection5.Add(new Tuple(" NÚMERO", string.IsNullOrWhiteSpace(contato.Telefone) ? "" : contato.Telefone, "")); observableCollection5.Add(new Tuple(" EMAIL", string.IsNullOrWhiteSpace(contato.Email) ? "" : contato.Email, "")); } } list2.Add(new TupleList { Tuples = observableCollection5 }); ObservableCollection> observableCollection6 = new ObservableCollection> { new Tuple("VÍNCULOS$", "", "") }; if (Vinculos == null) { Vinculos = new ObservableCollection(); } if (Vinculos != null && Vinculos.Count > 0) { foreach (ClienteVinculo vinculo in Vinculos) { observableCollection6.Add(new Tuple($" VÍNCULO {Vinculos.IndexOf(vinculo) + 1}$", "", "")); observableCollection6.Add(new Tuple(" COM CLIENTE", (vinculo.Cliente1.Id != base.Id) ? vinculo.Cliente1.Nome : vinculo.Cliente2.Nome, "")); observableCollection6.Add(new Tuple(" PARENTESCO", (vinculo.Cliente1.Id == base.Id) ? vinculo.Parentesco.GetDescription() : Funcoes.ParentescoInverso(vinculo.Parentesco).GetDescription(), "")); } } list2.Add(new TupleList { Tuples = observableCollection6 }); return list2; } }