LebenshilfeBadKreuznachFUD/Export/SageExporter.cs - Teil 1 für Team Integration
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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 LebenshilfeBadKreuznachFUD.Export
|
||||
{
|
||||
public class CustomDataExporter : DataExporter
|
||||
{
|
||||
public override QueryDC CreateQuery(QueryDC query)
|
||||
{
|
||||
return SageExporter.CreateQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
166
ReportImp/LebenshilfeBadKreuznachFUD/Export/SageExporter.cs
Normal file
166
ReportImp/LebenshilfeBadKreuznachFUD/Export/SageExporter.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
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 LebenshilfeBadKreuznachFUD.Export
|
||||
{
|
||||
public class SageExporter
|
||||
{
|
||||
private String teamname = "Integration";
|
||||
|
||||
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("SageExportIntegration{0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, "Integration");
|
||||
}
|
||||
else if (query.Oid == 101)
|
||||
{
|
||||
query.FileName = String.Format("SageExportEntlastung{0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, "Entlastung");
|
||||
}
|
||||
else if (query.Oid == 102)
|
||||
{
|
||||
query.FileName = String.Format("SageExportAutismus{0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, "Autismus");
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public static String GetAbrechnungenString(DateTime date, String teamname)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Buchungsdatum; Belegdatum; Belegnummer; Buchungstext; Sollkonto; Habenkonto; Umsatz; Währung; Steuerart; Steuercode; " +
|
||||
"Kostenstelle Soll; Kostenstelle Haben; Kostenträger Soll; Kostenträger Haben; Kostenart; Buchungskreis");
|
||||
|
||||
var s = GetMonatlicheRechnungenString(date, teamname);
|
||||
if (!String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
sb.Append(s);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static String GetMonatlicheRechnungenString(DateTime date, String teamname)
|
||||
{
|
||||
var sql = GetMonatlicheRechnungenSql(date);
|
||||
|
||||
/*
|
||||
cb2sc.Oid,
|
||||
ib.InvoiceNumber,
|
||||
c.DebitorNumber,
|
||||
Round(ii.AmountTotal, 2) AS 'Betrag',
|
||||
ib.InvoiceDate,
|
||||
org.Name AS 'VerwendungOrg'
|
||||
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'VerwendungPerson',
|
||||
org.DebitorNumber,
|
||||
ii.ItemDescription,
|
||||
c.CostCenter,
|
||||
ib.Oid,
|
||||
ib.AccountingPeriodEnd,
|
||||
*/
|
||||
|
||||
//sb.AppendLine("Belegdatum;Belegnummer;Debitorennummer;Kontonummer;Betrag;Buchungstext;Kostenstelle");
|
||||
//sb.AppendLine("Buchungsdatum; Belegdatum; Belegnummer; Buchungstext; Sollkonto; Habenkonto; Umsatz; Währung; Steuerart; Steuercode; " +
|
||||
// "Kostenstelle Soll; Kostenstelle Haben; Kostenträger Soll; Kostenträger Haben; Kostenart; Buchungskreis");
|
||||
var dt = ExecuteQuery(sql, date, teamname);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
}
|
||||
sb.Append(String.Format("{0:dd.MM.yyyy}", row[4]));
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:dd.MM.yyyy}", row[4]));
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[1]));
|
||||
sb.Append(";");
|
||||
String buchungstext = String.Format("AR-SI {0:MM}/{0:yyyy} {1} - {2}", row[11], row[5], row[6]);
|
||||
sb.Append(buchungstext);
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[7])); // Sollkonto - Kundennr. Kostenträger
|
||||
sb.Append(";");
|
||||
String hbnKto = "S82035"; // Habenkonto für 1. Halbjahr
|
||||
if (date.Month > 6)
|
||||
{
|
||||
hbnKto = "S82025";
|
||||
}
|
||||
sb.Append(String.Format("{0}", hbnKto)); // Habenkonto
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:0.00}", row[3]));
|
||||
sb.Append(";EUR;;;");
|
||||
sb.Append("T70400"); // Kostenstelle (String.Format("{0}", row[9]));
|
||||
sb.Append(";;;;;12"); // Buchungskreis
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static String GetMonatlicheRechnungenSql(DateTime date)
|
||||
{
|
||||
|
||||
String sql = @"
|
||||
SELECT * FROM
|
||||
(SELECT
|
||||
cb2sc.Oid AS cb2scOid,
|
||||
ib.InvoiceNumber,
|
||||
c.DebitorNumber,
|
||||
Round(ii.GrossAmountTotal, 2) AS 'Betrag',
|
||||
ib.InvoiceDate,
|
||||
org.Name AS 'VerwendungOrg',
|
||||
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'VerwendungPerson',
|
||||
org.DebitorNumber AS OrgDebitorNumber,
|
||||
ii.ItemDescription,
|
||||
c.CostCenter,
|
||||
ib.Oid AS ibOid,
|
||||
ib.AccountingPeriodEnd,
|
||||
(select t.name from team t inner join team2customer t2c on t2c.teamoid = t.oid where t2c.customeroid = c.Oid limit 1) AS Team
|
||||
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`
|
||||
INNER JOIN invoicebase ib on ib.costbearer2supportconceptoid = cb2sc.oid
|
||||
inner join serviceinvoice si on si.invoicebaseoid = ib.oid
|
||||
inner join serviceinvoiceperiod sip on sip.serviceinvoiceoid = si.oid
|
||||
inner join invoiceitem ii on ii.serviceinvoiceperiodoid = sip.oid
|
||||
WHERE ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodEnd` < ':Monat_End' and ib.IsActive = 1
|
||||
ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate`) AS sqry
|
||||
WHERE Team = ':teamname'
|
||||
";
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
public static DataTable ExecuteQuery(String sql, DateTime dt, String teamname)
|
||||
{
|
||||
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));
|
||||
newsql = newsql.Replace(":teamname", String.Format("{0}", teamname));
|
||||
|
||||
return DAOFactory.AdoDAO.ExecuteQuery(newsql).Tables[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Calculations\DefaultCalculations.cs" />
|
||||
<Compile Include="Calculations\CustomGroupDurationCalculator.cs" />
|
||||
<Compile Include="Export\CustomDataExporter.cs" />
|
||||
<Compile Include="Export\SageExporter.cs" />
|
||||
<Compile Include="Invoicing\CustomInvoiceCreation.cs" />
|
||||
<Compile Include="Invoicing\CustomInvoiceFactory.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -110,7 +112,6 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Export\" />
|
||||
<Folder Include="Import\" />
|
||||
<Folder Include="Validation\" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user