155 lines
6.9 KiB
C#
155 lines
6.9 KiB
C#
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 HalteStelle.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 >= 11)
|
|
{
|
|
if (!String.IsNullOrEmpty(fields[6]) && !String.IsNullOrEmpty(fields[10]) && !String.IsNullOrEmpty(fields[11])
|
|
&& (fields[6].ToString().Contains("Westfalen-Lippe") || fields[6].ToString().Contains("LWL")))
|
|
{
|
|
try
|
|
{
|
|
DateTime gueltigkeitsTag = DateTime.Now;
|
|
decimal betrag = 0m;
|
|
|
|
var neuerAvis = new Avis();
|
|
decimal.TryParse(fields[11], out betrag);
|
|
neuerAvis.Betrag = betrag;
|
|
fields[10] = fields[10].Trim();
|
|
if (!String.IsNullOrEmpty(fields[10]))
|
|
{
|
|
var zweck = fields[10];
|
|
string pattern = @"^(?:[^/]*/){5}([^/]*)(?=/?EREF)";
|
|
Match matchVerwendung = Regex.Match(zweck, pattern);
|
|
if (matchVerwendung.Success)
|
|
{
|
|
neuerAvis.Klient = matchVerwendung.Groups[1].Value.Substring(8).Trim();
|
|
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[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;
|
|
}
|
|
}
|
|
}
|