summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Seguros/Vendedor.cs
blob: b9de3b443216226902a1f1e9f469464683922952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using Gestor.Model.Attributes;
using Gestor.Model.Common;
using Gestor.Model.Domain.Common;
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 Vendedor : EnderecoBase, IDomain, INotifyPropertyChanged
{
	private bool _selecionado;

	private string _nome;

	private string _documento;

	private string _conta;

	private string _agencia;

	private string _observacao;

	private string _titularConta;

	private string _documentoTitular;

	public bool Selecionado
	{
		get
		{
			return _selecionado;
		}
		set
		{
			if (value != _selecionado)
			{
				_selecionado = value;
				OnPropertyChanged("Selecionado");
			}
		}
	}

	public Controle Controle { get; set; }

	public long IdEmpresa { get; set; }

	[Log(true)]
	[Name(true)]
	public string Nome
	{
		get
		{
			return _nome?.ToUpper();
		}
		set
		{
			_nome = value;
		}
	}

	public TipoIncidenciaDesconto TipoIncidenciaDesconto { get; set; }

	public decimal? Desconto { get; set; }

	public string Documento
	{
		get
		{
			return _documento?.ToUpper().Trim();
		}
		set
		{
			_documento = value;
		}
	}

	public string TitularConta
	{
		get
		{
			return _titularConta?.ToUpper();
		}
		set
		{
			_titularConta = value;
		}
	}

	public string TitularDocumento
	{
		get
		{
			return _documentoTitular?.ToUpper().Trim();
		}
		set
		{
			_documentoTitular = value;
		}
	}

	public Banco Banco { get; set; }

	public TipoConta TipoConta { get; set; }

	public string Conta
	{
		get
		{
			return _conta?.ToUpper().Trim();
		}
		set
		{
			_conta = value;
		}
	}

	public string Agencia
	{
		get
		{
			return _agencia?.ToUpper().Trim();
		}
		set
		{
			_agencia = value;
		}
	}

	public bool Corretora { get; set; }

	public bool Ativo { get; set; }

	public string Observacao
	{
		get
		{
			return _observacao?.ToUpper();
		}
		set
		{
			_observacao = value;
		}
	}

	public List<VendedorTelefone> Telefones { get; set; }

	[JsonIgnore]
	public Func<List<KeyValuePair<string, string>>> ValidationEvent => Validate;

	public event PropertyChangedEventHandler PropertyChanged;

	protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
	{
		this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
	}

	public List<KeyValuePair<string, string>> Validate()
	{
		List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
		if (string.IsNullOrEmpty(Nome))
		{
			list.AddValue("Nome", Messages.Obrigatorio);
		}
		if (!string.IsNullOrWhiteSpace(Documento) && !Documento.ValidacaoDocumento())
		{
			list.AddValue("Documento", Messages.Invalido);
		}
		if (!string.IsNullOrWhiteSpace(TitularDocumento) && !TitularDocumento.ValidacaoDocumento())
		{
			list.AddValue("TitularDocumento", Messages.Invalido);
		}
		if (Telefones == null)
		{
			return list;
		}
		foreach (VendedorTelefone telefone in Telefones)
		{
			list.AddRange(telefone.Validate());
		}
		return list;
	}

	public List<TupleList> Log()
	{
		List<TupleList> list = new List<TupleList>
		{
			new TupleList
			{
				Tuples = new ObservableCollection<Tuple<string, string, string>>
				{
					new Tuple<string, string, string>("NOME", string.IsNullOrWhiteSpace(Nome) ? "" : Nome, ""),
					new Tuple<string, string, string>("CPF", string.IsNullOrWhiteSpace(Documento) ? "" : Documento, ""),
					new Tuple<string, string, string>("ATIVO", Ativo ? "SIM" : "NÃO", ""),
					new Tuple<string, string, string>("BANCO", (Banco == null) ? "" : Banco.Nome, ""),
					new Tuple<string, string, string>("AGÊNCIA", string.IsNullOrWhiteSpace(Agencia) ? "" : Agencia, ""),
					new Tuple<string, string, string>("CONTA CORRENTE/POUPANÇA", string.IsNullOrWhiteSpace(Conta) ? "" : Conta, ""),
					new Tuple<string, string, string>("TITULAR DA CONTA", string.IsNullOrWhiteSpace(TitularConta) ? "" : TitularConta, ""),
					new Tuple<string, string, string>("DOCUMENTO TITULAR DA CONTA", string.IsNullOrWhiteSpace(TitularDocumento) ? "" : TitularDocumento, ""),
					new Tuple<string, string, string>("TIPO CONTA", string.IsNullOrWhiteSpace(TipoConta.GetDescription()) ? "" : TipoConta.GetDescription(), ""),
					new Tuple<string, string, string>("DESCONTO", (!Desconto.HasValue) ? "" : (Desconto / (decimal?)100)?.ToString("P", new CultureInfo("pt-BR", useUserOverride: false)), "")
				}
			}
		};
		ObservableCollection<Tuple<string, string, string>> observableCollection = new ObservableCollection<Tuple<string, string, string>>
		{
			new Tuple<string, string, string>("CONTATOS$", "", "")
		};
		if (Telefones != null && Telefones.Count != 0)
		{
			foreach (VendedorTelefone telefone in Telefones)
			{
				observableCollection.Add(new Tuple<string, string, string>($"   CONTATO {Telefones.IndexOf(telefone) + 1}$", "", ""));
				observableCollection.Add(new Tuple<string, string, string>("      NOME", string.IsNullOrWhiteSpace(telefone.Nome) ? "" : telefone.Nome, ""));
				object item;
				if (telefone.Tipo.HasValue)
				{
					TipoTelefone? tipo = telefone.Tipo;
					item = (tipo.HasValue ? tipo.GetValueOrDefault().GetDescription() : null);
				}
				else
				{
					item = "";
				}
				observableCollection.Add(new Tuple<string, string, string>("      TIPO DE TELEFONE", (string)item, ""));
				observableCollection.Add(new Tuple<string, string, string>("      PREFIXO", string.IsNullOrWhiteSpace(telefone.Prefixo) ? "" : telefone.Prefixo, ""));
				observableCollection.Add(new Tuple<string, string, string>("      NÚMERO DE TELEFONE", string.IsNullOrWhiteSpace(telefone.Numero) ? "" : telefone.Numero, ""));
				observableCollection.Add(new Tuple<string, string, string>("      E-MAIL", string.IsNullOrWhiteSpace(telefone.Email) ? "" : telefone.Email, ""));
			}
			list.Add(new TupleList
			{
				Tuples = observableCollection
			});
		}
		return list;
	}
}