fcs-virk/VrVatInfoMapper.cs

114 lines
4.7 KiB
C#
Raw Normal View History

// ***********************************************************************
2022-02-24 11:55:50 +01:00
// Assembly : FCS.Lib.Virk
// Author : FH
// Created : 02-21-2022
//
// Last Modified By : FH
// Last Modified On : 02-24-2022
// ***********************************************************************
// <copyright file="VrCvrMapper.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
2022-03-14 14:19:34 +01:00
// it under the terms of the Affero GNU 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
2022-03-14 14:19:34 +01:00
// Affero GNU General Public License for more details.
//
2022-03-14 14:19:34 +01:00
// You should have received a copy of the Affero GNU General Public License
2022-02-24 14:00:43 +01:00
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
// </copyright>
// <summary></summary>
// ***********************************************************************
2022-02-21 18:08:26 +01:00
2022-04-03 11:20:22 +02:00
using FCS.Lib.Common;
2022-02-24 11:40:19 +01:00
namespace FCS.Lib.Virk
2022-02-21 18:08:26 +01:00
{
2022-11-16 11:34:36 +01:00
/// <summary>
/// Vr Vat Info Mapper
/// </summary>
2022-04-03 11:20:22 +02:00
public class VrVatInfoMapper
2022-02-21 18:08:26 +01:00
{
2022-11-16 11:34:36 +01:00
/// <summary>
/// Vr to CRM mapper
/// </summary>
/// <param name="vrVirk"></param>
/// <returns>Vat Info Data Transfer Object</returns>
/// <see cref="VatInfoDto"/>
/// <see cref="VrVirksomhed"/>
/// <see cref="VatState"/>
/// <see cref="LifeCycle"/>
/// <see cref="TimeFrame"/>
2022-04-03 11:34:21 +02:00
public VatInfoDto MapVrToCrm(VrVirksomhed vrVirk)
2022-02-21 18:08:26 +01:00
{
2022-04-03 11:20:22 +02:00
var c = new VatInfoDto
2022-02-21 18:08:26 +01:00
{
Name = vrVirk.VirksomhedMetadata.NyesteNavn.Navn,
Address =
$"{vrVirk.VirksomhedMetadata.NyesteBeliggenhedsadresse.Vejnavn} {vrVirk.VirksomhedMetadata.NyesteBeliggenhedsadresse.HusnummerFra}",
CoName = vrVirk.VirksomhedMetadata.NyesteBeliggenhedsadresse.CoNavn,
ZipCode = vrVirk.VirksomhedMetadata.NyesteBeliggenhedsadresse.Postnummer.ToString(),
City = vrVirk.VirksomhedMetadata.NyesteBeliggenhedsadresse.PostDistrikt,
2022-04-03 11:20:22 +02:00
VatNumber = vrVirk.CvrNummer,
2022-04-07 17:39:35 +02:00
RequestDate = $"{DateTime.Now:yyyy-MM-dd}"
2022-02-21 18:08:26 +01:00
};
if (vrVirk.VirksomhedsStatus.Any())
{
2022-04-03 11:20:22 +02:00
foreach (var cs in vrVirk.VirksomhedsStatus.Select(vrStatus => new VatState
2022-02-21 18:08:26 +01:00
{
State = vrStatus.Status,
LastUpdate = vrStatus.SidstOpdateret,
TimeFrame = new TimeFrame
{
StartDate = vrStatus.Periode.GyldigFra,
2022-04-01 12:13:56 +02:00
EndDate = !string.IsNullOrWhiteSpace(vrStatus.Periode.GyldigTil) ? vrStatus.Periode.GyldigTil : ""
}
}))
{
c.States.Add(cs);
}
}
else
2022-02-21 18:08:26 +01:00
{
2022-04-03 11:20:22 +02:00
c.States.Add(new VatState());
2022-02-21 18:08:26 +01:00
}
2022-04-01 12:13:56 +02:00
if (vrVirk.Livsforloeb.Any())
{
foreach (var lc in vrVirk.Livsforloeb.Select(
vrCourse => new LifeCycle
{
LastUpdate = vrCourse.SidstOpdateret,
TimeFrame = new TimeFrame
{
StartDate = vrCourse.Periode.GyldigFra,
EndDate = !string.IsNullOrWhiteSpace(vrCourse.Periode.GyldigTil) ? vrCourse.Periode.GyldigTil : ""
}
}
))
{
c.LifeCycles.Add(lc);
}
}
else
{
c.LifeCycles.Add(new LifeCycle());
}
if (!string.IsNullOrWhiteSpace(c.States[c.States.Count - 1].State)) return c;
var sc = c.States.Count - 1;
var lcc = c.LifeCycles.Count - 1;
c.States[sc].LastUpdate = c.LifeCycles[lcc].LastUpdate;
c.States[sc].TimeFrame.StartDate = c.LifeCycles[lcc].TimeFrame.StartDate;
c.States[sc].TimeFrame.EndDate = c.LifeCycles[lcc].TimeFrame.EndDate;
c.States[sc].State = string.IsNullOrWhiteSpace(c.LifeCycles[c.LifeCycles.Count - 1].TimeFrame.EndDate) ? "NORMAL" : "LUKKET";
2022-02-21 18:08:26 +01:00
return c;
}
}
}