-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViesVatInfoMapper.cs
executable file
·134 lines (125 loc) · 4.52 KB
/
ViesVatInfoMapper.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
133
134
// ***********************************************************************
// Solution : Inno.Api.v2
// Assembly : FCS.Lib.Vies
// Filename : ViesVatInfoMapper.cs
// Created : 2025-01-03 14:01
// Last Modified By : dev
// Last Modified On : 2025-01-08 13: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.Globalization;
using FCS.Lib.Common;
namespace FCS.Lib.Vies;
/// <summary>
/// Provides functionality to map VAT information from a <see cref="ViesEntityModel" /> to a <see cref="VatInfoDto" />.
/// </summary>
/// <remarks>
/// This class is responsible for transforming VAT-related data from the VIES system into a structured format
/// suitable for further processing or consumption by other components.
/// </remarks>
public class ViesVatInfoMapper
{
/// <summary>
/// Maps a <see cref="ViesEntityModel" /> to a <see cref="VatInfoDto" /> object.
/// </summary>
/// <param name="viesEntity">The source entity containing VAT information to be mapped.</param>
/// <returns>
/// A <see cref="VatInfoDto" /> object populated with the mapped data from the provided
/// <see cref="ViesEntityModel" />.
/// </returns>
public VatInfoDto MapViesVatInfoDto(ViesEntityModel viesEntity)
{
var addressBlock = viesEntity.Address.Split('\n');
string address;
var zip = "";
var city = "";
var i = 0;
if (viesEntity.CountryCode == "SE" && addressBlock.Length > 0)
{
if (addressBlock.Length > 1) i++;
try
{
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
if (addressBlock.Length > 2)
{
i++;
zip = addressBlock[i].Normalize().Substring(0, 6).Replace(" ", "");
city = addressBlock[i].Normalize().Substring(7).Trim();
}
}
else
{
if (addressBlock.Length > 1)
{
addressBlock[i].Normalize();
i++;
}
try
{
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
if (addressBlock.Length > 1)
{
i++;
zip = addressBlock[i].Substring(0, 5).Replace(" ", "");
city = addressBlock[i].Substring(5).Trim();
}
}
// generate return object
var c = new VatInfoDto
{
Name = viesEntity.Name.Normalize(),
Address = address,
VatNumber = viesEntity.VatNumber,
City = city,
ZipCode = zip,
RequestDate = DateTime.Now.ToString(CultureInfo.InvariantCulture)
};
c.States.Add(new VatState
{
State = viesEntity.Valid ? "NORMAL" : "LUKKET",
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
EndDate = "NA",
StartDate = "NA"
}
});
c.LifeCycles.Add(new LifeCycle
{
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
StartDate = "NN",
EndDate = "NN"
}
});
return c;
}
}