LebenshilfeRemscheid/Export/CustomDataExporter - soweit fertig
This commit is contained in:
21
ReportImp/LebenshilfeRemscheid/Export/CustomDataExporter.cs
Normal file
21
ReportImp/LebenshilfeRemscheid/Export/CustomDataExporter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LebenshilfeRemscheid.Export;
|
||||
using BeWo.Service.Plugins;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts;
|
||||
using Utils = BS.Shared.Core.Utils;
|
||||
|
||||
namespace LebenshilfeRemscheid.Export
|
||||
{
|
||||
public class CustomDataExporter : DataExporter
|
||||
{
|
||||
|
||||
public override QueryDC CreateQuery(QueryDC query)
|
||||
{
|
||||
QueryDC q = FibuExport.CreateQuery(query);
|
||||
CreateBuchungsExportProtokollEintrag(q);
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
181
ReportImp/LebenshilfeRemscheid/Export/DatevExporter.cs
Normal file
181
ReportImp/LebenshilfeRemscheid/Export/DatevExporter.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
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.Report.ReportObjects;
|
||||
using BeWo.Service.DCEntityMapper;
|
||||
using BS.Shared.DataContracts;
|
||||
using DevExpress.XtraPrinting;
|
||||
using DevExpress.XtraReports.UI;
|
||||
|
||||
namespace LebenshilfeRemscheid.Export
|
||||
{
|
||||
public class FibuExport
|
||||
{
|
||||
List<FileAttachmentDC> liste = new List<FileAttachmentDC>();
|
||||
public static QueryDC CreateQuery(QueryDC query)
|
||||
{
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime.TryParse(query.Parameter[0].Value.ToString(), out dt);
|
||||
var table = ExecuteQuery(GetMonatlicheRechnungenSql(dt), dt);
|
||||
query.FileName = String.Format("Datev Export {0:yyyyMM}.csv", dt);
|
||||
query.QueryResult = GetAbrechnungenString(dt, table);
|
||||
query.Attachments = CreateInvoiceFiles(table);
|
||||
return query;
|
||||
}
|
||||
|
||||
public static String GetAbrechnungenString(DateTime dt, DataTable table)
|
||||
{
|
||||
DateTime lastDate = new DateTime(dt.Year, dt.Month, 1);
|
||||
lastDate = lastDate.AddMonths(1).AddDays(-1);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("EXTF;210;21;Buchungsstapel;7;");
|
||||
sb.Append(String.Format("{0:yyyyMM}00000000000", new DateTime(dt.Year, dt.Month, 1)));
|
||||
sb.Append(";;MASHERP;;Thomas;40593;960;");
|
||||
sb.Append(String.Format("{0:yyyyMMdd}", new DateTime(dt.Year, 1, 1)));
|
||||
sb.Append(";6;");
|
||||
sb.Append(String.Format("{0:yyyyMMdd}", new DateTime(dt.Year, dt.Month, 1)));
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:yyyyMMdd}", lastDate));
|
||||
sb.AppendLine(";;;1;0;0;EUR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
|
||||
sb.AppendLine("Umsatz (ohne Soll/Haben-Kz);Soll/Haben-Kennzeichen;WKZ Umsatz;Kurs;Basis-Umsatz;WKZ Basis-Umsatz;Konto;Gegenkonto (ohne BU-Schlüssel);" +
|
||||
"BU-Schlüssel;Belegdatum;Belegfeld 1;Belegfeld 2;Skonto;Buchungstext;Postensperre;Diverse Adressnummer;Geschäftspartnerbank;Sachverhalt;Zinssperre;" +
|
||||
"Beleglink;Beleginfo - Art 1;Beleginfo - Inhalt 1;Beleginfo - Art 2;Beleginfo - Inhalt 2;Beleginfo - Art 3;Beleginfo - Inhalt 3;Beleginfo - Art 4;" +
|
||||
"Beleginfo - Inhalt 4;Beleginfo - Art 5;Beleginfo - Inhalt 5;Beleginfo - Art 6;Beleginfo - Inhalt 6;Beleginfo - Art 7;Beleginfo - Inhalt 7;" +
|
||||
"Beleginfo - Art 8;Beleginfo - Inhalt 8;KOST1 - Kostenstelle;KOST2 - Kostenstelle;Kost-Menge;EU-Land u. UStID;EU-Steuersatz;Abw. Versteuerungsart;" +
|
||||
"Sachverhalt L+L;Funktionsergänzung L+L;BU 49 Hauptfunktionstyp;BU 49 Hauptfunktionsnummer;BU 49 Funktionsergänzung;Zusatzinformation - Art 1;" +
|
||||
"Zusatzinformation- Inhalt 1;Zusatzinformation - Art 2;Zusatzinformation- Inhalt 2;Zusatzinformation - Art 3;Zusatzinformation- Inhalt 3;" +
|
||||
"Zusatzinformation - Art 4;Zusatzinformation- Inhalt 4;Zusatzinformation - Art 5;Zusatzinformation- Inhalt 5;Zusatzinformation - Art 6;" +
|
||||
"Zusatzinformation- Inhalt 6;Zusatzinformation - Art 7;Zusatzinformation- Inhalt 7;Zusatzinformation - Art 8;Zusatzinformation- Inhalt 8;" +
|
||||
"Zusatzinformation - Art 9;Zusatzinformation- Inhalt 9;Zusatzinformation - Art 10;Zusatzinformation- Inhalt 10;Zusatzinformation - Art 11;" +
|
||||
"Zusatzinformation- Inhalt 11;Zusatzinformation - Art 12;Zusatzinformation- Inhalt 12;Zusatzinformation - Art 13;Zusatzinformation- Inhalt 13;" +
|
||||
"Zusatzinformation - Art 14;Zusatzinformation- Inhalt 14;Zusatzinformation - Art 15;Zusatzinformation- Inhalt 15;Zusatzinformation - Art 16;" +
|
||||
"Zusatzinformation- Inhalt 16;Zusatzinformation - Art 17;Zusatzinformation- Inhalt 17;Zusatzinformation - Art 18;Zusatzinformation- Inhalt 18;" +
|
||||
"Zusatzinformation - Art 19;Zusatzinformation- Inhalt 19;Zusatzinformation - Art 20;Zusatzinformation- Inhalt 20;Stück;Gewicht");
|
||||
var s = GetMonatlicheRechnungenString(dt, table);
|
||||
if (!String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
sb.Append(s);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static String GetMonatlicheRechnungenString(DateTime date, DataTable dt)
|
||||
{
|
||||
// select sip.Claim, ib.InvoiceDate, ib.Invoicenumber, Concat(ib.invoicnumber, ', ', org.Name, ', ', p.FirstName, ', ', p.LastName) AS Verwendung, ib.Oid
|
||||
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])); //Betrag
|
||||
sb.Append(";S;EUR;1;");
|
||||
sb.Append(String.Format("{0:0.00}", row[0])); //Betrag Basiswährung
|
||||
sb.Append(";EUR;");
|
||||
sb.Append("30150;"); //Konto
|
||||
sb.Append("4001;"); // Erlöskonto
|
||||
sb.Append(";"); //AB: Achtung falls Einführung Storno hier 20; und Soll wird zu Haben
|
||||
sb.Append(String.Format("{0:ddMM}", row[1]));
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0}", row[2])); //Belegfeld 1
|
||||
sb.Append(";");
|
||||
sb.Append(String.Format("{0:ddMMyy}", row[1])); //Belegfeld 2
|
||||
sb.Append(";;");
|
||||
sb.Append(String.Format("{0}", row[3])); // Buchungstext
|
||||
sb.Append(";;;;;;;;;;;;;;;;;;;;;;;5000;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static List<FileAttachmentDC> CreateInvoiceFiles(DataTable dt)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<FileAttachmentDC> liste = new List<FileAttachmentDC>();
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
var pdf = new FileAttachmentDC();
|
||||
|
||||
var invoiceOid = row[4].ToString();
|
||||
if (!String.IsNullOrEmpty(invoiceOid))
|
||||
{
|
||||
var oid = long.Parse(invoiceOid);
|
||||
var invoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(oid);
|
||||
//var invoice = DAOFactory.GenericDAO.LoadByID<ServiceInvoice>(oid);
|
||||
var idc = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(invoice);
|
||||
|
||||
var anhang = new RechnungFF();
|
||||
var ro = ServiceInvoiceRO.Create(idc);
|
||||
anhang.SetReportDataSource(ro);
|
||||
anhang.CreateDocument();
|
||||
|
||||
pdf.FileName = anhang.PrintingSystem.Document.Name + ".pdf";
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
anhang.ExportToPdf(ms);
|
||||
pdf.BinaryData = ms.ToArray();
|
||||
}
|
||||
liste.Add(pdf);
|
||||
//string name = anhang.PrintingSystem.Document.Name;
|
||||
//string path = @"C:\Temp\FiBuExport\";
|
||||
//anhang.ExportToPdf(path + name + ".pdf");
|
||||
}
|
||||
}
|
||||
return liste;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// continue - auch wenn gar nichts stimmt
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String GetMonatlicheRechnungenSql(DateTime date)
|
||||
{
|
||||
String sql = @"
|
||||
select
|
||||
sip.Claim,
|
||||
ib.InvoiceDate,
|
||||
ib.Invoicenumber,
|
||||
Concat(ib.invoicenumber,', ', org.Name, ', ', p.FirstName, ', ', p.LastName) AS Verwendung,
|
||||
ib.Oid
|
||||
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 costbearer cb on c2s.costbeareroid = cb.oid
|
||||
inner join organisation org on org.costbeareroid = cb.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
|
||||
order by ib.Invoicenumber
|
||||
";
|
||||
|
||||
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_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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CustomHomeContentGenerator.cs" />
|
||||
<Compile Include="Export\CustomDataExporter.cs" />
|
||||
<Compile Include="Export\DatevExporter.cs" />
|
||||
<Compile Include="Invoicing\CustomInvoiceFactory.cs" />
|
||||
<Compile Include="Invoicing\CustomInvoiceCreation.cs" />
|
||||
<Compile Include="LHRemscheidReportCreator.cs" />
|
||||
|
||||
Reference in New Issue
Block a user