AutismusKoelnBonn/Export/DatevExporter - NEU
This commit is contained in:
@@ -61,6 +61,8 @@
|
||||
<Compile Include="BudgetnachweisAnhang.Designer.cs">
|
||||
<DependentUpon>BudgetnachweisAnhang.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Export\CustomDataExporter.cs" />
|
||||
<Compile Include="Export\DatevExporter.cs" />
|
||||
<Compile Include="Finanzauswertung.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
19
ReportImp/AutismusKoelnBonn/Export/CustomDataExporter.cs
Normal file
19
ReportImp/AutismusKoelnBonn/Export/CustomDataExporter.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BeWo.Service.Core;
|
||||
using BeWo.Service.Plugins;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts;
|
||||
using Utils = BS.Shared.Core.Utils;
|
||||
|
||||
namespace AutismusKoelnBonn.Export
|
||||
{
|
||||
public class CustomDataExporter : DataExporter
|
||||
{
|
||||
public override QueryDC CreateQuery(QueryDC query)
|
||||
{
|
||||
|
||||
return DatevExporter.CreateQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
283
ReportImp/AutismusKoelnBonn/Export/DatevExporter.cs
Normal file
283
ReportImp/AutismusKoelnBonn/Export/DatevExporter.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.DCEntityMapper;
|
||||
using BS.Shared;
|
||||
using BS.Shared.DataContracts;
|
||||
using BS.Shared.Extensions;
|
||||
|
||||
namespace AutismusKoelnBonn.Export
|
||||
{
|
||||
public class DatevExporter
|
||||
{
|
||||
public static QueryDC CreateQuery(QueryDC query)
|
||||
{
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime.TryParse(query.Parameter[0].Value.ToString(), out dt);
|
||||
|
||||
if (query.Oid == 100)
|
||||
{
|
||||
query.FileName = String.Format("Datev Export LVR {0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, "LVR");
|
||||
}
|
||||
else
|
||||
{
|
||||
query.FileName = String.Format("Datev Export Rechnungen {0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, "Rechnungen");
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
public static String GetAbrechnungenString(DateTime date, String typ)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//sb.AppendLine("Belegdatum;Belegnummer;Debitorennummer;Kontonummer;Betrag;Buchungstext;Kostenstelle;SH KZN;F KZN;W KZN");
|
||||
sb.AppendLine("Betrag;SH KZN;Kontonummer;Gegenkonto;Belegdatum;Belegfeld1;Belegfeld2;Buchungstext;Kost1");
|
||||
string s = "";
|
||||
if (typ == "LVR")
|
||||
{
|
||||
s = GetMonatlicheBetraegeString(date);
|
||||
if (!String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
sb.Append(s);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s = GetMonatlicheRechnungenString(date, typ);
|
||||
if (!String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
sb.Append(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static String GetMonatlicheRechnungenString(DateTime date, string typ)
|
||||
{
|
||||
string sql = "";
|
||||
sql = GetMonatlicheRechnungenSql(date);
|
||||
|
||||
|
||||
/*
|
||||
sip.Claim,
|
||||
c.DebitorNumber,
|
||||
ib.InvoiceDate,
|
||||
ib.invoicenumber,
|
||||
c.CostCenter,
|
||||
c2s.KontoHilfeplan,
|
||||
ib.RecipientOrganisation,
|
||||
c2s.Oid,
|
||||
ib.InvoiceId
|
||||
*/
|
||||
|
||||
//sb.AppendLine("Belegdatum;Belegnummer;Debitorennummer;Kontonummer;Betrag;Buchungstext;Kostenstelle");
|
||||
//sb.AppendLine("Betrag;SH KZN;Kontonummer;Gegenkonto;Belegdatum;Belegfeld1;Belegfeld2;Buchungstext;Kost1");
|
||||
var dt = ExecuteQuery(sql, date);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
}
|
||||
DateTime lastDate = new DateTime(date.Year, date.Month, 1);
|
||||
lastDate = lastDate.AddMonths(1).AddDays(-1);
|
||||
sb.Append(String.Format("{0:0.00}", row[0]));
|
||||
sb.Append(";H;");
|
||||
sb.Append(String.Format("{0}", row[5].ToString().Trim())); // Erlöskonto
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[1].ToString().Trim())); //Debitor
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:dd}{0:MM}", lastDate)); // Belegdatum
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[3])); //Belegnummer
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:dd}{0:MM}{0:yyyy}", row[2])); // Belegdatum als Beleg2
|
||||
sb.Append(";");
|
||||
String buchungstext = "";
|
||||
if (row[6].ToString().IsNotNullOrEmpty())
|
||||
{
|
||||
buchungstext = String.Format("{0}", row[6]);
|
||||
}
|
||||
sb.Append(buchungstext);
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[4].ToString().Trim())); //Kostenstelle
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static String GetMonatlicheBetraegeString(DateTime date)
|
||||
{
|
||||
var sql = GetMonatlicheBetraegeLvrSql(date);
|
||||
|
||||
/*
|
||||
sum(qry.Betrag),
|
||||
qry.DebitorNumber,
|
||||
qry.CostCenter,
|
||||
qry.KontoHilfeplan,
|
||||
qry.Verwendung,
|
||||
qry.Kostentraeger,
|
||||
qry.Oid
|
||||
*/
|
||||
|
||||
//"Datum;Konto;Gegenkonto;Buchungstext;Belegfeld1;Umsatz Soll;Kostenstelle"
|
||||
//sb.AppendLine("Betrag;SH KZN;;Kontonummer;Gegenkonto;Belegdatum;Belegfeld1;Belegfeld2;Buchungstext;Kost1");
|
||||
var dt = ExecuteQuery(sql, date);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
}
|
||||
DateTime lastDate = new DateTime(date.Year, date.Month, 1);
|
||||
lastDate = lastDate.AddMonths(1).AddDays(-1);
|
||||
sb.Append(String.Format("{0:0.00}", row[0]));
|
||||
sb.Append(";H;");
|
||||
sb.Append(String.Format("{0}", row[3].ToString().Trim())); // Erlöskonto
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[1].ToString().Trim())); //Debitor
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:dd}{0:MM}", lastDate)); // Belegdatum
|
||||
sb.Append(";");
|
||||
//Belegnummer
|
||||
sb.Append(";");
|
||||
// Belegdatum als Beleg2
|
||||
sb.Append(";");
|
||||
String buchungstext = "FL ";
|
||||
if (row[4].ToString().IsNotNullOrEmpty())
|
||||
{
|
||||
buchungstext += String.Format("{0}", row[4]);
|
||||
}
|
||||
sb.Append(buchungstext);
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[2].ToString().Trim())); //Kostenstelle
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static String GetMonatlicheRechnungenSql(DateTime date)
|
||||
{
|
||||
|
||||
String sql = @"
|
||||
select
|
||||
sip.Claim,
|
||||
c.DebitorNumber,
|
||||
ib.InvoiceDate,
|
||||
ib.invoicenumber,
|
||||
c.CostCenter,
|
||||
c2s.KontoHilfeplan,
|
||||
ib.RecipientOrganisation,
|
||||
c2s.Oid,
|
||||
ib.InvoiceId
|
||||
from
|
||||
person p
|
||||
inner join customer c on c.personoid = p.oid
|
||||
inner join supportconcept sc on sc.customeroid = c.oid
|
||||
inner join costbearer2supportconcept c2s on c2s.supportconceptoid = sc.oid
|
||||
inner join invoicebase ib on ib.costbearer2supportconceptoid = c2s.oid
|
||||
inner join serviceinvoice si on si.invoicebaseoid = ib.oid
|
||||
inner join serviceinvoiceperiod sip on sip.serviceinvoiceoid = si.oid
|
||||
WHERE ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodEnd` < ':Monat_End' and ib.IsActive = 1 AND ib.`IsExported` = 0
|
||||
order by ib.invoicenumber
|
||||
";
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
private static String GetMonatlicheBetraegeLvrSql(DateTime date)
|
||||
{
|
||||
String sql = @"
|
||||
SELECT
|
||||
sum(qry.Betrag),
|
||||
qry.DebitorNumber,
|
||||
qry.CostCenter,
|
||||
qry.KontoHilfeplan,
|
||||
qry.Verwendung,
|
||||
qry.Kostentraeger,
|
||||
qry.Oid
|
||||
FROM
|
||||
(
|
||||
(SELECT
|
||||
IF(crpRateFactor.`CostRateValue` is null, ROUND((sr.`GeleisteteFLM` / 60) * (SELECT crp.`CostRateValue` FROM `costrateperiod` crp WHERE crp.`ObjectTid` = 22 AND crp.`CostRateType` = 0 AND crp.`ObjectOid` = cb2sc.`CostBearerOid` AND (crp.`EndDate` is null or crp.`EndDate` > ':Monat_Start') order by IF(crp.`EndDate` is null, MAKEDATE(9999,365),crp.`EndDate`) LIMIT 1 )),
|
||||
ROUND(ROUND((sr.`GeleisteteFLM` / 60), 2) * (SELECT crp.`CostRateValue` FROM `costrateperiod` crp WHERE crp.`ObjectTid` = 22 AND crp.`CostRateType` = 0 AND crp.`ObjectOid` = cb2sc.`CostBearerOid` AND (crp.`EndDate` is null or crp.`EndDate` > ':Monat_Start') order by IF(crp.`EndDate` is null, MAKEDATE(9999,365),crp.`EndDate`) LIMIT 1 ) * ((100 + crpRateFactor.`CostRateValue`)/100), 2)) AS 'Betrag',
|
||||
c.DebitorNumber,
|
||||
c.CostCenter,
|
||||
cb2sc.KontoHilfeplan,
|
||||
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'Verwendung',
|
||||
org.Name AS Kostentraeger,
|
||||
cb2sc.Oid
|
||||
FROM `supportconcept` sc
|
||||
INNER JOIN `costbearer2supportconcept` cb2sc ON sc.`Oid` = cb2sc.`SupportConceptOid`
|
||||
INNER JOIN `costbearer` cb ON cb2sc.`CostBearerOid` = cb.`Oid`
|
||||
LEFT JOIN
|
||||
(SELECT crp.`ObjectOid`, crp.`CostRateValue` FROM `costrateperiod` crp
|
||||
WHERE crp.`ObjectTid` = 22 AND crp.`CostRateType` = 2 AND(crp.`EndDate` is null or crp.`EndDate` > NOW()))
|
||||
AS crpRateFactor ON crpRateFactor.`ObjectOid` = cb.`Oid`
|
||||
INNER JOIN `organisation` org ON org.`CostBearerOid` = cb.`Oid`
|
||||
INNER JOIN `customer` c ON sc.`CustomerOid` = c.`Oid`
|
||||
INNER JOIN `person` p on c.`PersonOid` = p.`Oid`
|
||||
LEFT JOIN
|
||||
(SELECT sr2.`CostBearer2SupportConceptOid`, SUM(sr2.`roundedduration` / IF(sr2.`GroupEmployeeCount` is null, 1, sr2.`GroupEmployeeCount`)) AS GeleisteteFLM FROM `servicerecord` sr2
|
||||
INNER JOIN `servicedescription` sd ON sr2.`ServiceDescriptionOid` = sd.`Oid`
|
||||
INNER JOIN `servicecategory` sc ON sd.`ServiceCategoryOid` = sc.`Oid`
|
||||
WHERE sr2.`StartDate` >= ':Monat_Start' AND sr2.`StartDate` < ':Monat_End' AND sc.`Billable` = 1 AND sd.Name <> 'Fehlkontakt' GROUP BY sr2.`CostBearer2SupportConceptOid`)
|
||||
AS sr ON sr.`CostBearer2SupportConceptOid` = cb2sc.`Oid`
|
||||
WHERE org.Name LIKE 'LVR%' AND c.`IsActive` <> 0 AND sc.`IsActive` <> 0 AND (sr.`GeleisteteFLM` is not null))
|
||||
UNION
|
||||
(SELECT
|
||||
ROUND(0.8 * (sr.`GeleisteteFLM` / 60) * (SELECT crp.`CostRateValue` FROM `costrateperiod` crp WHERE crp.`ObjectTid` = 22 AND crp.`CostRateType` = 0 AND crp.`ObjectOid` = cb2sc.`CostBearerOid` AND (crp.`EndDate` is null or crp.`EndDate` > ':Monat_Start') order by IF(crp.`EndDate` is null, MAKEDATE(9999,365),crp.`EndDate`) LIMIT 1 ),2) AS 'Betrag',
|
||||
c.DebitorNumber,
|
||||
c.CostCenter,
|
||||
cb2sc.KontoHilfeplan,
|
||||
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'Verwendung',
|
||||
org.Name AS Kostentraeger,
|
||||
cb2sc.Oid
|
||||
FROM `supportconcept` sc
|
||||
INNER JOIN `costbearer2supportconcept` cb2sc ON sc.`Oid` = cb2sc.`SupportConceptOid`
|
||||
INNER JOIN `costbearer` cb ON cb2sc.`CostBearerOid` = cb.`Oid`
|
||||
INNER JOIN `organisation` org ON org.`CostBearerOid` = cb.`Oid`
|
||||
INNER JOIN `customer` c ON sc.`CustomerOid` = c.`Oid`
|
||||
INNER JOIN `person` p on c.`PersonOid` = p.`Oid`
|
||||
LEFT JOIN
|
||||
(SELECT sr2.`CostBearer2SupportConceptOid`, SUM(sr2.`roundedduration` / IF(sr2.`GroupEmployeeCount` is null, 1, sr2.`GroupEmployeeCount`)) AS GeleisteteFLM FROM `servicerecord` sr2
|
||||
INNER JOIN `servicedescription` sd ON sr2.`ServiceDescriptionOid` = sd.`Oid`
|
||||
INNER JOIN `servicecategory` sc ON sd.`ServiceCategoryOid` = sc.`Oid`
|
||||
WHERE sr2.`StartDate` >= ':Monat_Start' AND sr2.`StartDate` < ':Monat_End' AND sc.`Billable` = 1 and sd.Name = 'Fehlkontakt' GROUP BY sr2.`CostBearer2SupportConceptOid`)
|
||||
AS sr ON sr.`CostBearer2SupportConceptOid` = cb2sc.`Oid`
|
||||
WHERE org.Name LIKE 'LVR%' AND c.`IsActive` <> 0 AND sc.`IsActive` <> 0 AND (sr.`GeleisteteFLM` is not null))
|
||||
)qry
|
||||
GROUP BY qry.OID
|
||||
ORDER BY qry.Verwendung
|
||||
";
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
public static DataTable ExecuteQuery(String sql, DateTime dt)
|
||||
{
|
||||
var newsql = sql;
|
||||
newsql = newsql.Replace(":Abrechnungsmonat", String.Format("{0:dd.MM.yyyy}", dt));
|
||||
newsql = newsql.Replace(":Belegnr", String.Format("{0:yyMM}", dt));
|
||||
newsql = newsql.Replace(":Monat_MM", String.Format("{0:MM}", dt));
|
||||
newsql = newsql.Replace(":Monat_Start", String.Format("{0:yyyy-MM}-01", dt));
|
||||
dt = dt.AddMonths(1);
|
||||
newsql = newsql.Replace(":Monat_End", String.Format("{0:yyyy-MM}-01", dt));
|
||||
|
||||
return DAOFactory.AdoDAO.ExecuteQuery(newsql).Tables[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,8 @@ namespace AutismusKoelnBonn.Translation
|
||||
public override Dictionary<String, String> GetTranslationDictionary()
|
||||
{
|
||||
var dict = base.GetTranslationDictionary();
|
||||
|
||||
AddOrReplaceTranslation(dict, "OrganisationVarFieldsTitle", "Abrechnungsregeln");
|
||||
|
||||
|
||||
AddOrReplaceTranslation(dict, "OrganisationVarFieldsTitle", "Abrechnungsregeln");
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user