VSDHammReports/Import/CustomDataImporter.cs - LWL Zahlungen aus csv
This commit is contained in:
153
ReportImp/VSDHammReports/Import/CustomDataImporter.cs
Normal file
153
ReportImp/VSDHammReports/Import/CustomDataImporter.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.Core;
|
||||
using BeWo.Service.Import.AvisImport;
|
||||
using BeWo.Service.Plugins;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts;
|
||||
using Utils = BS.Shared.Core.Utils;
|
||||
|
||||
namespace VSDHammReports.Import
|
||||
{
|
||||
public class CustomLvrAviseImporter : LvrAviseImporter
|
||||
{
|
||||
public override String ImportCsvAvise(String csv)
|
||||
{
|
||||
var reader = new LvrAvisCsvReader();
|
||||
var avise = LeseEinzelAviseLWL(csv);
|
||||
var hilfeplaene = CreateHilfeplanInfos();
|
||||
|
||||
return ImportAvise(avise, hilfeplaene);
|
||||
}
|
||||
|
||||
private List<Avis> LeseEinzelAviseLWL(string importfile)
|
||||
{
|
||||
List<Avis> liste = new List<Avis>();
|
||||
String[] lines = importfile.Split('\n');
|
||||
|
||||
for (int i = 0; i < lines.Count(); i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
var fields = line.Split(';');
|
||||
if (fields.Length >= 5)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(fields[3]) && !String.IsNullOrEmpty(fields[4]) && !String.IsNullOrEmpty(fields[5])
|
||||
&& (fields[3].ToString().Contains("Westfale") || fields[3].ToString().Contains("LWL")))
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime gueltigkeitsTag = DateTime.Now;
|
||||
decimal betrag = 0m;
|
||||
|
||||
var neuerAvis = new Avis();
|
||||
decimal.TryParse(fields[5], out betrag);
|
||||
neuerAvis.Betrag = betrag;
|
||||
if (!String.IsNullOrEmpty(fields[4]))
|
||||
{
|
||||
var zweck = fields[4];
|
||||
var matches = Regex.Matches(zweck, "/");
|
||||
if (matches.Count >= 5)
|
||||
{
|
||||
int startIndex = matches[4].Index + 1;
|
||||
var kurzString = zweck.Substring(startIndex);
|
||||
neuerAvis.Klient = kurzString.Substring(8).Trim();
|
||||
neuerAvis.Verwendungszweck = kurzString.Substring(8).Trim();
|
||||
neuerAvis.Aktenzeichen = kurzString.Substring(0, 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
neuerAvis.Klient = zweck;
|
||||
neuerAvis.Verwendungszweck = zweck;
|
||||
neuerAvis.Aktenzeichen = zweck;
|
||||
}
|
||||
|
||||
var date = zweck.Substring(23, 10);
|
||||
if (int.TryParse(date, out int resultMonat) && int.TryParse(date, out int resultJahr))
|
||||
{
|
||||
gueltigkeitsTag = new DateTime(resultJahr, resultMonat, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DateTime.TryParse(date, out DateTime resultHp))
|
||||
{
|
||||
gueltigkeitsTag = resultHp;
|
||||
}
|
||||
else
|
||||
{
|
||||
var datumMonat = fields[4].Substring(fields[4].Length - 7, 2);
|
||||
var datumJahr = fields[4].Substring(fields[4].Length - 4, 4);
|
||||
if (int.TryParse(datumMonat, out int resultMonth) && int.TryParse(datumJahr, out int resultYear))
|
||||
{
|
||||
gueltigkeitsTag = new DateTime(resultYear, resultMonth, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DateTime.TryParse(fields[4], out DateTime resultDate))
|
||||
{
|
||||
gueltigkeitsTag = resultDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
neuerAvis.GueltigkeitsDatum = gueltigkeitsTag;
|
||||
}
|
||||
else
|
||||
{
|
||||
neuerAvis.Verwendungszweck = "kein Text";
|
||||
neuerAvis.Aktenzeichen = "kein Text";
|
||||
}
|
||||
neuerAvis.BuchungsDatum = DateTime.Now;
|
||||
//neuerAvis.Sachbearbeiter = fields[13] + ", " + fields[14];
|
||||
if (neuerAvis.Betrag != 0)
|
||||
{
|
||||
liste.Add(neuerAvis);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return liste;
|
||||
}
|
||||
|
||||
public override List<HilfeplanInfo> CreateHilfeplanInfos()
|
||||
{
|
||||
List<HilfeplanInfo> liste = new List<HilfeplanInfo>();
|
||||
var scList = DAOFactory.GenericDAO.GetAllActiveAndArchived<SupportConcept>();
|
||||
|
||||
foreach (var supportConcept in scList)
|
||||
{
|
||||
foreach (var cb2sc in supportConcept.CostBearer2SupportConceptList)
|
||||
{
|
||||
HilfeplanInfo hi = new HilfeplanInfo();
|
||||
hi.Start = cb2sc.StartDate;
|
||||
hi.Ende = cb2sc.EndDate;
|
||||
var reference = cb2sc.CustomerReferenceNumber;
|
||||
if (!String.IsNullOrEmpty(reference))
|
||||
{
|
||||
reference = reference.Replace("-", "");
|
||||
reference = reference.Replace("/", "").Trim();
|
||||
}
|
||||
hi.Aktenzeichen = reference;
|
||||
hi.CostBearer2SupportConcept = cb2sc;
|
||||
hi.CustomerFirstName = cb2sc.SupportConcept.Customer.Person.FirstName;
|
||||
hi.CustomerLastName = cb2sc.SupportConcept.Customer.Person.LastName;
|
||||
|
||||
if (hi.Start.HasValue && hi.Ende.HasValue && !String.IsNullOrEmpty(hi.Aktenzeichen))
|
||||
{
|
||||
liste.Add(hi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return liste;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@
|
||||
<Compile Include="Forderungen.designer.cs">
|
||||
<DependentUpon>Forderungen.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Import\CustomDataImporter.cs" />
|
||||
<Compile Include="InvoiceCustomerReport.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user