diff --git a/ReportImp/IBAHSeV/IBAHSeV.csproj b/ReportImp/IBAHSeV/IBAHSeV.csproj index 969de4adf..24b39a1de 100644 --- a/ReportImp/IBAHSeV/IBAHSeV.csproj +++ b/ReportImp/IBAHSeV/IBAHSeV.csproj @@ -65,6 +65,7 @@ + @@ -139,7 +140,6 @@ - diff --git a/ReportImp/IBAHSeV/Import/CustomDataImporter.cs b/ReportImp/IBAHSeV/Import/CustomDataImporter.cs new file mode 100644 index 000000000..16d3dbe1b --- /dev/null +++ b/ReportImp/IBAHSeV/Import/CustomDataImporter.cs @@ -0,0 +1,155 @@ +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 IBAHS.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 LeseEinzelAviseLWL(string importfile) + { + List liste = new List(); + String[] lines = importfile.Split('\n'); + + for (int i = 0; i < lines.Count(); i++) + { + string line = lines[i]; + var fields = line.Split(';'); + if (fields.Length >= 10) + { + if (!String.IsNullOrEmpty(fields[4]) && !String.IsNullOrEmpty(fields[5]) && !String.IsNullOrEmpty(fields[8]) + && (fields[5].ToString().Contains("Westfalen-Lippe") || fields[5].ToString().Contains("LWL"))) + { + try + { + DateTime gueltigkeitsTag = DateTime.Now; + decimal betrag = 0m; + + var neuerAvis = new Avis(); + decimal.TryParse(fields[8], out betrag); + neuerAvis.Betrag = betrag; + fields[4] = fields[4].Trim(); + if (!String.IsNullOrEmpty(fields[4])) + { + var zweck = fields[4]; + string pattern = @"^(?:[^/]*/){5}([^/]*)"; // Sucht den gesamten Text nach dem 5. / -> also der Teil mit Aktenzeichen und Name + Match matchVerwendung = Regex.Match(zweck, pattern); + if (matchVerwendung.Success) + { + neuerAvis.Klient = matchVerwendung.Groups[1].Value.Substring(8).Trim(); + neuerAvis.Klient = Regex.Replace(neuerAvis.Klient, @"\b([A-ZÄÖÜ][a-zäöüß]+)\s*\1\b", "$1"); // Der Nachname kommt fast immer doppelt vor, wird hier gefiltert + neuerAvis.Verwendungszweck = matchVerwendung.Groups[1].Value.Substring(8).Trim(); + neuerAvis.Aktenzeichen = matchVerwendung.Groups[1].Value.Substring(0, 7); + } + else + { + neuerAvis.Klient = zweck; + neuerAvis.Verwendungszweck = zweck; + neuerAvis.Aktenzeichen = zweck; + } + + var teilEins = zweck.Substring(0, 50).Replace(" ", ""); + var date = teilEins.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[1].Substring(fields[1].Length - 7, 2); + var datumJahr = fields[1].Substring(fields[1].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 CreateHilfeplanInfos() + { + List liste = new List(); + var scList = DAOFactory.GenericDAO.GetAllActiveAndArchived(); + + 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; + } + } +}