Files
BeWoPlaner/ReportImp/SozialeDienstleistungenBeckerReports/Export/DatevExporter.cs

122 lines
4.4 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Invoicing.FibuExport;
using BeWo.Service.Invoicing.FiBuExport;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace SozialeDienstleistungenBeckerReports.Export
{
public class DatevExporter : TempFiBuExport
{
public DatevExporter(QueryDC query) : base(query)
{
}
public override List<KeyValuePair<String, String>> GetHeader()
{
return new List<KeyValuePair<String, String>>
{
new KeyValuePair<string, string> ("UMSATZ", "Betrag"),
new KeyValuePair<string, string> ("GEGENKONTO", "DebitorNummer"),
new KeyValuePair<string, string> ("BELEG1", "Belegnummer"),
new KeyValuePair<string, string> ("DATUM", "Datum"),
new KeyValuePair<string, string> ("KONTO", "KontoHilfeplan"),
new KeyValuePair<string, string> ("KOST1", "KostenstelleKlient"),
new KeyValuePair<string, string> ("KOST2", "KostenstelleHilfeplan"),
new KeyValuePair<string, string> ("BUCHUNGSTEXT", "Buchungstext")
};
}
public override FiBuDatensatz CreateFibuDatensatz(DataRow row)
{
var fd = base.CreateFibuDatensatz(row);
SetzeFehlendeKontenUndKostenstellen(fd);
fd.Buchungstext = String.Format("{0}, {1}", fd.CustomerLastName, fd.CustomerFirstName);
return fd;
}
private void SetzeFehlendeKontenUndKostenstellen(FiBuDatensatz fd)
{
if (String.IsNullOrEmpty(fd.KostenstelleHilfeplan) || String.IsNullOrEmpty(fd.KontoHilfeplan) || String.IsNullOrEmpty(fd.KostenstelleKlient))
{
if (fd.CustomerOid.HasValue)
{
var c = DAOFactory.GenericDAO.LoadByID<Customer>(fd.CustomerOid.Value);
fd.KostenstelleKlient = GetMitarbeiterKostenstelle(c);
var bereich = GetBereich(c);
if ("BEWO".Equals(bereich))
{
fd.KostenstelleHilfeplan = "40000";
fd.KontoHilfeplan = "4000";
}
else if ("JH".Equals(bereich))
{
fd.KostenstelleHilfeplan = "40020";
fd.KontoHilfeplan = "4002";
}
else if ("IB".Equals(bereich))
{
fd.KostenstelleHilfeplan = "40010";
fd.KontoHilfeplan = "4001";
}
}
}
}
private string GetMitarbeiterKostenstelle(Customer customer)
{
var hauptbetreuer = customer.Employee2CustomerList.FirstOrDefault(e2c => e2c.IsActive == ActivationTypeId.Active &&
(!e2c.StartDate.HasValue || e2c.StartDate.Value.Date <= Datum) && (!e2c.EndDate.HasValue || e2c.EndDate.Value.Date >= Datum) &&
e2c.ValueList.Any(b => b.Entry.Type.Equals(ValueListEntryType.StaffRoleType) && b.Entry.Value.ToLower().Equals("hauptbetreuung")))?.Employee;
if (hauptbetreuer != null)
{
return hauptbetreuer.PersonnelNumber;
}
return "";
}
private String GetBereich(Customer customer)
{
foreach (var t2c in customer.Team2CustomerList)
{
if (t2c.Team.Name.ToLower().Contains("bewo"))
{
return "BEWO";
}
else if (t2c.Team.Name.ToLower().Contains("jugendhilfe"))
{
return "JH";
}
else if (t2c.Team.Name.ToLower().Contains("inklusion"))
{
return "IB";
}
}
return "BEWO";
}
public override IList<FiBuDatensatz> CreateDatensaetze(bool holeSammelRechnungen, bool holeSpitzabrechnungen, bool holeStundenBetraege, bool holeAbschlagszahlungen)
{
return base.CreateDatensaetze(true, false, false, true);
}
}
}