using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using Gestor.Model.Attributes; using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using Gestor.Model.Helper; using Gestor.Model.Resources; using Gestor.Model.Validation; using Newtonsoft.Json; namespace Gestor.Model.Domain.Financeiro; public class Fornecedor : EnderecoBase, IDomain { private string _nome; private string _documento; private string _email; private string _observacao; public new long Id { get; set; } public long IdEmpresa { get; set; } public long? IdConta { get; set; } public long? IdCentro { get; set; } public long? IdPlano { get; set; } public TipoPagamento? TipoPagamento { get; set; } [Log(true)] [Name(true)] public string Nome { get { return _nome?.ToUpper(); } set { _nome = value; NomeSocial = $"{value?.ToUpper()} - {Id}"; } } [Log(true)] [Description("NOME SOCIAL")] public string NomeSocial { get; set; } [Log(true)] public string Documento { get { return _documento?.ToUpper().Trim(); } set { _documento = value; } } [Log(true)] [Description("TIPO TELEFONE")] public TipoTelefone? TipoTelefone1 { get; set; } [Log(true)] [Description("PREFIXO 1")] public string Prefixo1 { get; set; } [Log(true)] [Description("TELEFONE 1")] public string Telefone1 { get; set; } [Log(true)] [Description("TIPO TELEFONE 2")] public TipoTelefone? TipoTelefone2 { get; set; } [Log(true)] [Description("PREFIXO 2")] public string Prefixo2 { get; set; } [Log(true)] [Description("TELEFONE 2")] public string Telefone2 { get; set; } [Log(true)] [Description("E-MAIL")] public string Email { get { return _email?.ToLower(); } set { _email = value; } } [Log(true)] [Description("OBSERVAÇÃO")] public string Observacao { get { return _observacao?.ToUpper(); } set { _observacao = value; } } [Log(true)] [Description("ATIVO")] public bool Ativo { get; set; } [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 (!string.IsNullOrWhiteSpace(Nome) && Nome.Length > 60) { list.AddValue("Nome", string.Format(Messages.MaiorQueLimite, 60)); } if (!string.IsNullOrWhiteSpace(Documento) && !Documento.ValidacaoDocumento()) { list.AddValue("Documento", Messages.Invalido); } if (!string.IsNullOrWhiteSpace(Prefixo1) && !Prefixo1.ValidacaoPrefixo()) { list.AddValue("Prefixo1", Messages.Obrigatorio); } if (!string.IsNullOrWhiteSpace(Telefone1) && !Telefone1.ValidacaoTelefone()) { list.AddValue("Telefone1", Messages.Obrigatorio); } if (!string.IsNullOrWhiteSpace(Email) && !Email.ValidacaoEmail()) { list.AddValue("Email", Messages.Obrigatorio); } if (!string.IsNullOrWhiteSpace(base.Cidade) && base.Cidade.Length > 30) { list.AddValue("Cidade", string.Format(Messages.MaiorQueLimite, 30)); } if (!string.IsNullOrWhiteSpace(base.Bairro) && base.Bairro.Length > 60) { list.AddValue("Bairro", string.Format(Messages.MaiorQueLimite, 60)); } if (!string.IsNullOrWhiteSpace(base.Complemento) && base.Complemento.Length > 40) { list.AddValue("Complemento", string.Format(Messages.MaiorQueLimite, 40)); } return list; } public List Log() { List list = new List(); TupleList tupleList = new TupleList(); ObservableCollection> obj = new ObservableCollection> { new Tuple("NOME DO FORNECEDOR", string.IsNullOrWhiteSpace(Nome) ? "" : Nome, ""), new Tuple("DOCUMENTO", string.IsNullOrWhiteSpace(Documento) ? "" : Documento, ""), new Tuple("CEP", string.IsNullOrWhiteSpace(base.Cep) ? "" : base.Cep, ""), new Tuple("ENDEREÇO", string.IsNullOrWhiteSpace(base.Endereco) ? "" : base.Endereco, ""), new Tuple("NÚMERO", string.IsNullOrWhiteSpace(base.Numero) ? "" : base.Numero, ""), new Tuple("COMPLEMENTO", string.IsNullOrWhiteSpace(base.Complemento) ? "" : base.Complemento, ""), new Tuple("BAIRRO", string.IsNullOrWhiteSpace(base.Bairro) ? "" : base.Bairro, ""), new Tuple("CIDADE", string.IsNullOrWhiteSpace(base.Cidade) ? "" : base.Cidade, ""), new Tuple("ESTADO", string.IsNullOrWhiteSpace(base.Estado) ? "" : base.Estado, "") }; object item; if (TipoTelefone1.HasValue) { TipoTelefone? tipoTelefone = TipoTelefone1; item = (tipoTelefone.HasValue ? tipoTelefone.GetValueOrDefault().GetDescription() : null); } else { item = ""; } obj.Add(new Tuple("TIPO DO PRIMEIRO TELEFONE", (string)item, "")); obj.Add(new Tuple("PRIMEIRO PREFIXO", string.IsNullOrWhiteSpace(Prefixo1) ? "" : Prefixo1, "")); obj.Add(new Tuple("PRIMEIRO TELEFONE", string.IsNullOrWhiteSpace(Telefone1) ? "" : Telefone1, "")); object item2; if (TipoTelefone2.HasValue) { TipoTelefone? tipoTelefone = TipoTelefone2; item2 = (tipoTelefone.HasValue ? tipoTelefone.GetValueOrDefault().GetDescription() : null); } else { item2 = ""; } obj.Add(new Tuple("TIPO DO SEGUNDO TELEFONE", (string)item2, "")); obj.Add(new Tuple("SEGUNDO PREFIXO", string.IsNullOrWhiteSpace(Prefixo2) ? "" : Prefixo2, "")); obj.Add(new Tuple("SEGUNDO TELEFONE", string.IsNullOrWhiteSpace(Telefone2) ? "" : Telefone2, "")); obj.Add(new Tuple("E-MAIL", string.IsNullOrWhiteSpace(Email) ? "" : Email, "")); obj.Add(new Tuple("PLANO DE CONTAS", (!IdPlano.HasValue) ? "" : IdPlano?.ToString(), "")); obj.Add(new Tuple("CENTRO DE CUSTO", (!IdCentro.HasValue) ? "" : IdCentro?.ToString(), "")); obj.Add(new Tuple("CONTA CORRENTE", (!IdConta.HasValue) ? "" : IdConta?.ToString(), "")); object item3; if (TipoPagamento.HasValue) { TipoPagamento? tipoPagamento = TipoPagamento; item3 = (tipoPagamento.HasValue ? tipoPagamento.GetValueOrDefault().GetDescription() : null); } else { item3 = ""; } obj.Add(new Tuple("TIPO DE PAGAMENTO", (string)item3, "")); obj.Add(new Tuple("OBSERVAÇÕES", string.IsNullOrWhiteSpace(Observacao) ? "" : Observacao, "")); tupleList.Tuples = obj; list.Add(tupleList); return list; } }