-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrRegVatInfoMapper.cs
executable file
·132 lines (121 loc) · 5.09 KB
/
BrRegVatInfoMapper.cs
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
// // ***********************************************************************
// // Solution : Inno.Api.v2
// // Assembly : FCS.Lib.BrReg
// // Filename : BrRegVatInfoMapper.cs
// // Created : 2025-01-03 14:01
// // Last Modified By : dev
// // Last Modified On : 2025-01-04 11:01
// // ***********************************************************************
// // <copyright company="Frede Hundewadt">
// // Copyright (C) 2010-2025 Frede Hundewadt
// // This program is free software: you can redistribute it and/or modify
// // it under the terms of the GNU Affero General Public License as
// // published by the Free Software Foundation, either version 3 of the
// // License, or (at your option) any later version.
// //
// // This program is distributed in the hope that it will be useful,
// // but WITHOUT ANY WARRANTY; without even the implied warranty of
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// // GNU Affero General Public License for more details.
// //
// // You should have received a copy of the GNU Affero General Public License
// // along with this program. If not, see [https://www.gnu.org/licenses]
// // </copyright>
// // <summary></summary>
// // ***********************************************************************
using System;
using System.Collections.Generic;
using FCS.Lib.Common;
namespace FCS.Lib.BrReg;
/// <summary>
/// Provides functionality to map Brønnøysund Register Center (BrReg) company data
/// to VAT-related data transfer objects (DTOs) and states.
/// </summary>
/// <remarks>
/// This class is responsible for transforming data from BrRegCompany models into
/// VAT-specific representations such as <see cref="VatInfoDto" /> and <see cref="TaxIdInfo" />.
/// It is utilized in services that interact with Brønnøysund Register Center data.
/// </remarks>
public class BrRegVatInfoMapper
{
/// <summary>
/// Maps a <see cref="BrRegCompany" /> object to a <see cref="VatInfoDto" /> object.
/// </summary>
/// <param name="brCompany">The <see cref="BrRegCompany" /> instance containing the source data.</param>
/// <returns>A <see cref="VatInfoDto" /> instance populated with the mapped data.</returns>
public VatInfoDto MapBrToCrm(BrRegCompany brCompany)
{
return new VatInfoDto
{
Name = brCompany.Navn,
Address = string.Join(", ", brCompany.Forretningsadresse.Adresse),
City = brCompany.Forretningsadresse.Poststed,
RequestDate = $"{DateTime.Now:yyyy-MM-dd}",
ZipCode = brCompany.Forretningsadresse.Postnummer,
VatNumber = brCompany.Organisasjonsnummer,
States = new List<VatState>
{
new()
{
LastUpdate = "",
State = MapBrVatState(brCompany).HasFolded ? "LUKKET" : "NORMAL",
TimeFrame = new TimeFrame
{
StartDate = "",
EndDate = ""
}
}
},
LifeCycles = new List<LifeCycle>
{
new()
{
TimeFrame = new TimeFrame
{
EndDate = "NN",
StartDate = "NN"
}
}
}
};
}
/// <summary>
/// Maps the VAT-related state of a Brønnøysund Register Center (BrReg) company
/// to a <see cref="TaxIdInfo" /> object.
/// </summary>
/// <param name="brCompany">
/// The <see cref="BrRegCompany" /> instance containing the company data to be mapped.
/// </param>
/// <returns>
/// A <see cref="TaxIdInfo" /> object representing the VAT-related state of the company.
/// </returns>
/// <remarks>
/// This method evaluates the company's status based on various properties, such as
/// bankruptcy, liquidation, or dissolution, and determines whether the VAT number
/// is valid or if the company has folded.
/// </remarks>
public TaxIdInfo MapBrVatState(BrRegCompany brCompany)
{
if (brCompany == null)
return new TaxIdInfo
{
RequestDate = DateTime.Now
};
var c = new TaxIdInfo
{
Name = brCompany.Navn,
VatNumber = brCompany.Organisasjonsnummer,
RequestDate = DateTime.Now,
VatNumberValid = true
};
if (brCompany.Konkurs || brCompany.UnderAvvikling || brCompany.UnderTvangsavviklingEllerTvangsopplosning)
c.HasFolded = true;
if (!string.IsNullOrWhiteSpace(brCompany.Organisasjonsform.Utgaatt))
c.HasFolded = true;
if (!string.IsNullOrWhiteSpace(brCompany.Slettedato))
c.HasFolded = true;
if (c.HasFolded)
c.VatNumberValid = false;
return c;
}
}