summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Model/Model.Domain.Ferramentas/Recibo.cs
blob: c598a0705814ee8bb0b3be681afc6f03bc1b9aa4 (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
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;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace Gestor.Model.Domain.Ferramentas
{
	public class Recibo : DomainBase, IDomain
	{
		[Description("DATA DO RECIBO")]
		[Log(true)]
		public DateTime? DataRecibo
		{
			get;
			set;
		}

		[Description("DOCUMENTO PAGANTE")]
		[Log(true)]
		public string DocumentoPagante
		{
			get;
			set;
		}

		[Description("DOCUMENTO RECEBEDOR")]
		[Log(true)]
		public string DocumentoRecebedor
		{
			get;
			set;
		}

		[Log(true)]
		public TipoPagamento? Pagamento
		{
			get;
			set;
		}

		[Log(true)]
		public string Pagante
		{
			get;
			set;
		}

		[Log(true)]
		public string Recebedor
		{
			get;
			set;
		}

		[Log(true)]
		public string Referente
		{
			get;
			set;
		}

		[Log(true)]
		public TipoRecibo? Tipo
		{
			get;
			set;
		}

		[JsonIgnore]
		public Func<List<KeyValuePair<string, string>>> ValidationEvent
		{
			get
			{
				Recibo recibo = this;
				return new Func<List<KeyValuePair<string, string>>>(recibo.Validate);
			}
		}

		[Log(true)]
		public decimal Valor
		{
			get;
			set;
		}

		public Recibo()
		{
		}

		public List<TupleList> Log()
		{
			string description;
			string shortDateString;
			List<TupleList> tupleLists = new List<TupleList>();
			TupleList tupleList = new TupleList();
			ObservableCollection<Tuple<string, string, string>> observableCollection = new ObservableCollection<Tuple<string, string, string>>()
			{
				new Tuple<string, string, string>("PAGANTE", (string.IsNullOrWhiteSpace(this.Pagante) ? "" : this.Pagante), ""),
				new Tuple<string, string, string>("DOCUMENTO PAGANTE", (string.IsNullOrWhiteSpace(this.DocumentoPagante) ? "" : this.DocumentoPagante), ""),
				new Tuple<string, string, string>("RECEBEDOR", (string.IsNullOrWhiteSpace(this.Recebedor) ? "" : this.Recebedor), ""),
				new Tuple<string, string, string>("DOCUMENTO", (string.IsNullOrWhiteSpace(this.DocumentoRecebedor) ? "" : this.DocumentoRecebedor), ""),
				new Tuple<string, string, string>("TIPO DO RECIBO", this.Tipo.GetDescription(), "")
			};
			TipoPagamento? pagamento = this.Pagamento;
			if (!pagamento.HasValue)
			{
				description = "";
			}
			else
			{
				pagamento = this.Pagamento;
				if (pagamento.HasValue)
				{
					description = pagamento.GetValueOrDefault().GetDescription();
				}
				else
				{
					description = null;
				}
			}
			observableCollection.Add(new Tuple<string, string, string>("PAGAMENTO", description, ""));
			decimal valor = this.Valor;
			observableCollection.Add(new Tuple<string, string, string>("VALOR", valor.ToString(new CultureInfo("pt-BR")), ""));
			DateTime? dataRecibo = this.DataRecibo;
			if (dataRecibo.HasValue)
			{
				shortDateString = dataRecibo.GetValueOrDefault().ToShortDateString();
			}
			else
			{
				shortDateString = null;
			}
			observableCollection.Add(new Tuple<string, string, string>("DATA DO RECIBO", shortDateString, ""));
			observableCollection.Add(new Tuple<string, string, string>("PAGANTE", (string.IsNullOrWhiteSpace(this.Pagante) ? "" : this.Pagante), ""));
			observableCollection.Add(new Tuple<string, string, string>("RECEBEDOR", (string.IsNullOrWhiteSpace(this.Recebedor) ? "" : this.Recebedor), ""));
			observableCollection.Add(new Tuple<string, string, string>("REFERENTE", (string.IsNullOrWhiteSpace(this.Referente) ? "" : this.Referente), ""));
			tupleList.Tuples = observableCollection;
			tupleLists.Add(tupleList);
			return tupleLists;
		}

		public List<KeyValuePair<string, string>> Validate()
		{
			List<KeyValuePair<string, string>> keyValuePairs = ValidationHelper.AddValue();
			if (string.IsNullOrWhiteSpace(this.Referente))
			{
				keyValuePairs.AddValue<string, string>("Referente|REFERENTE À(AO)", Messages.Obrigatorio, true);
			}
			if (this.DataRecibo.HasValue && (DateTime.Compare(this.DataRecibo.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.DataRecibo.Value, new DateTime(9999, 12, 31)) > 0))
			{
				keyValuePairs.AddValue<string, string>("DataRecibo|DATA DO RECIBO", Messages.Obrigatorio, true);
			}
			if (!this.DataRecibo.HasValue)
			{
				keyValuePairs.AddValue<string, string>("DataRecibo|DATA DO RECIBO", Messages.Obrigatorio, true);
			}
			if (string.IsNullOrWhiteSpace(this.DocumentoPagante))
			{
				keyValuePairs.AddValue<string, string>("DocumentoPagante|DOCUMENTO DO PAGANTE", Messages.Obrigatorio, true);
			}
			else if (!this.DocumentoPagante.ValidacaoDocumento())
			{
				keyValuePairs.AddValue<string, string>("DocumentoPagante|DOCUMENTO DO PAGANTE", Messages.Invalido, true);
			}
			if (string.IsNullOrWhiteSpace(this.DocumentoRecebedor))
			{
				keyValuePairs.AddValue<string, string>("DocumentoRecebedor|DOCUMENTO DO RECEBEDOR", Messages.Obrigatorio, true);
			}
			else if (!this.DocumentoRecebedor.ValidacaoDocumento())
			{
				keyValuePairs.AddValue<string, string>("DocumentoRecebedor|DOCUMENTO DO RECEBEDOR", Messages.Invalido, true);
			}
			if (string.IsNullOrWhiteSpace(this.Recebedor))
			{
				keyValuePairs.AddValue<string, string>("Recebedor", Messages.Obrigatorio, true);
			}
			if (string.IsNullOrWhiteSpace(this.Pagante))
			{
				keyValuePairs.AddValue<string, string>("Pagante", Messages.Obrigatorio, true);
			}
			if (!this.Pagamento.HasValue)
			{
				keyValuePairs.AddValue<string, string>("Pagamento|FORMA DE PAGAMENTO", Messages.Obrigatorio, true);
			}
			if (!string.IsNullOrWhiteSpace(this.Referente) && this.Referente.Length >= 255)
			{
				keyValuePairs.AddValue<string, string>("Referente|REFERENTE À(AO)", string.Format(Messages.MaiorQueLimite, 255), true);
			}
			return keyValuePairs;
		}
	}
}