summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Seguros/Repasse.cs
blob: 4beadaf86be7ae1dc8eddd64852679b2173227ec (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Gestor.Model.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 Repasse : DomainBase, IDomain
{
	private string _incidenciaVendedor = "";

	private string _pgtoVendedor = "";

	public Vendedor Vendedor { get; set; }

	public long? Seguradora { get; set; }

	public Ramo Ramo { get; set; }

	public decimal ValorNovo { get; set; }

	public decimal ValorRenovacao { get; set; }

	public TipoRepasse? Tipo { get; set; }

	public TipoIncidencia? Incidencia { get; set; }

	public FormaRepasse? Forma { get; set; }

	public BaseRepasse? Base { get; set; }

	public bool Ativo { get; set; }

	public List<VinculoRepasse> Vinculo { get; set; }

	public string IncidenciaVendedor => _incidenciaVendedor = Incidencia.GetDescription();

	public string PagtoVendedor => _pgtoVendedor = Forma.GetDescription();

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

	public List<KeyValuePair<string, string>> Validate()
	{
		List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
		if (Vendedor == null)
		{
			list.AddValue("Vendedor", Messages.Obrigatorio);
		}
		if (TipoRepasse.CoCorretagem != Tipo.GetValueOrDefault() && ValorNovo == 0m)
		{
			list.AddValue("ValorNovo", Messages.Obrigatorio);
		}
		if (TipoRepasse.CoCorretagem != Tipo.GetValueOrDefault() && ValorRenovacao == 0m)
		{
			list.AddValue("ValorRenovacao", Messages.Obrigatorio);
		}
		if (!Tipo.HasValue)
		{
			list.AddValue("Tipo", Messages.Obrigatorio);
		}
		if (!Incidencia.HasValue && Forma.HasValue && Forma.GetValueOrDefault() == FormaRepasse.Recebimento)
		{
			list.AddValue("Incidencia", Messages.Obrigatorio);
		}
		if (!Forma.HasValue)
		{
			list.AddValue("Forma", Messages.Obrigatorio);
		}
		if (Forma.HasValue && Forma.GetValueOrDefault() != FormaRepasse.Recebimento)
		{
			if (!Base.HasValue)
			{
				list.AddValue("Base", Messages.Obrigatorio);
			}
			if (Forma.GetValueOrDefault() == FormaRepasse.Prazo && Base.GetValueOrDefault() != BaseRepasse.Vencimento)
			{
				list.AddValue("Base", Messages.Invalido);
			}
		}
		if (Forma.HasValue && Forma.GetValueOrDefault() == FormaRepasse.Recebimento && Base.HasValue)
		{
			list.AddValue("Base", Messages.Invalido);
		}
		return list;
	}

	public List<TupleList> Log()
	{
		return new List<TupleList>
		{
			new TupleList
			{
				Tuples = new ObservableCollection<Tuple<string, string, string>>
				{
					new Tuple<string, string, string>("TIPO", Tipo.GetDescription(), ""),
					new Tuple<string, string, string>("VALOR NOVO", $"{ValorNovo:##.00}", ""),
					new Tuple<string, string, string>("VALOR RENOVAÇÃO", $"{ValorRenovacao:##.00}", ""),
					new Tuple<string, string, string>("INCIDÊNCIA", Incidencia.GetDescription(), ""),
					new Tuple<string, string, string>("FORMA PAGAMENTO", Forma.GetDescription(), ""),
					new Tuple<string, string, string>("BASE PAGAMENTO", Base.GetDescription(), ""),
					new Tuple<string, string, string>("ATIVO", Ativo ? "SIM" : "NÃO", "")
				}
			}
		};
	}
}