diff --git a/ReportImp/SBBMainzReports/Export/CustomDataExporter.cs b/ReportImp/SBBMainzReports/Export/CustomDataExporter.cs new file mode 100644 index 000000000..bedc13d8e --- /dev/null +++ b/ReportImp/SBBMainzReports/Export/CustomDataExporter.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using SBBMainzReports.Export; +using BeWo.Service.Plugins; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using Utils = BS.Shared.Core.Utils; + +namespace SBBMainzReports.Export +{ + public class CustomDataExporter : DataExporter + { + + public override QueryDC CreateQuery(QueryDC query) + { + QueryDC q = FibuExport.CreateQuery(query); + CreateBuchungsExportProtokollEintrag(q); + return q; + } + } +} diff --git a/ReportImp/SBBMainzReports/Export/FibuExporter.cs b/ReportImp/SBBMainzReports/Export/FibuExporter.cs new file mode 100644 index 000000000..bb95c3655 --- /dev/null +++ b/ReportImp/SBBMainzReports/Export/FibuExporter.cs @@ -0,0 +1,164 @@ +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 SBBMainzReports.Export +{ + public class FibuExport + { + List liste = new List(); + 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("BeWoPlaner-FiBu-Export{0:yyyyMM}.csv", dt); + query.QueryResult = GetAbrechnungenString(dt, table); + query.Attachments = CreateInvoiceFiles(table); + return query; + } + + public static String GetAbrechnungenString(DateTime dt, DataTable table) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("Datum;Erlöskonto;Kostenstelle;ReNr;Debitor;Gesamtsumme;Kostenträger;Leistungsempfänger"); + var s = GetMonatlicheRechnungenString(dt, table); + if (!String.IsNullOrWhiteSpace(s)) + { + sb.Append(s); + } + + return sb.ToString(); + } + + public static String GetMonatlicheRechnungenString(DateTime date, DataTable dt) + { + // '8000' as 'Gegenkonto', sip.Claim, ib.invoicenumber, ib.InvoiceDate, c.DebitorNumber, c.CostCenter, org.Name, p.FirstName, p.LastName, + 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:dd.MM.yyyy}", lastDate)); + sb.Append(";"); + sb.Append(String.Format("\"{0}\"", row[0])); //Erlöskonto + sb.Append(";"); + sb.Append(String.Format("{0}", row[5])); // Kostenstelle + sb.Append(";"); + sb.Append(String.Format("{0}", row[2])); // ReNr + sb.Append(";"); + sb.Append(String.Format("{0}", row[4])); + sb.Append(";"); + sb.Append(String.Format("{0:0.00}", row[1])); + sb.Append(";"); + sb.Append(String.Format("{0}", row[6])); + sb.Append(";"); + sb.Append(String.Format("{0} {1}", row[7], row[8])); + } + return sb.ToString(); + } + + private static List CreateInvoiceFiles(DataTable dt) + { + try + { + List liste = new List(); + foreach (DataRow row in dt.Rows) + { + var pdf = new FileAttachmentDC(); + + var invoiceOid = row[9].ToString(); + if (!String.IsNullOrEmpty(invoiceOid)) + { + var oid = long.Parse(invoiceOid); + var invoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(oid); + //var invoice = DAOFactory.GenericDAO.LoadByID(oid); + var idc = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(invoice); + + var anhang = new ServiceInvoiceReport(); + 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 + '8000' as 'Gegenkonto', + SUM(sip.Claim), + ib.invoicenumber, + ib.InvoiceDate, + c.DebitorNumber, + c.CostCenter, + org.Name, + p.FirstName, + p.LastName, + 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 and ib.IsExported = 0 + GROUP BY ib.Oid + 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]; + } + } +} \ No newline at end of file diff --git a/ReportImp/SBBMainzReports/SBBMainzReports.csproj b/ReportImp/SBBMainzReports/SBBMainzReports.csproj index 348b81e39..881b5ce56 100644 --- a/ReportImp/SBBMainzReports/SBBMainzReports.csproj +++ b/ReportImp/SBBMainzReports/SBBMainzReports.csproj @@ -76,6 +76,8 @@ CustomerDataReport.cs + + diff --git a/ReportImp/SBBMainzReports/ServiceInvoiceReport.Designer.cs b/ReportImp/SBBMainzReports/ServiceInvoiceReport.Designer.cs index 3d2fafefc..31bcbb69e 100644 --- a/ReportImp/SBBMainzReports/ServiceInvoiceReport.Designer.cs +++ b/ReportImp/SBBMainzReports/ServiceInvoiceReport.Designer.cs @@ -39,6 +39,7 @@ namespace SBBMainzReports this.xrLabel5 = new DevExpress.XtraReports.UI.XRLabel(); this.bottomMarginBand1 = new DevExpress.XtraReports.UI.BottomMarginBand(); this.Page1 = new DevExpress.XtraReports.UI.GroupHeaderBand(); + this.xrRichText1 = new DevExpress.XtraReports.UI.XRRichText(); this.xrLabel3 = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel4 = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel16 = new DevExpress.XtraReports.UI.XRLabel(); @@ -48,7 +49,7 @@ namespace SBBMainzReports this.lblAbrechnungszeitraum = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel10 = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel11 = new DevExpress.XtraReports.UI.XRLabel(); - this.xrLabel8 = new DevExpress.XtraReports.UI.XRLabel(); + this.lblRechnungsnummer = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel7 = new DevExpress.XtraReports.UI.XRLabel(); this.xrTable1 = new DevExpress.XtraReports.UI.XRTable(); this.xrTableRow2 = new DevExpress.XtraReports.UI.XRTableRow(); @@ -96,12 +97,12 @@ namespace SBBMainzReports this.PageFooter = new DevExpress.XtraReports.UI.PageFooterBand(); this.xrLabel15 = new DevExpress.XtraReports.UI.XRLabel(); this.xrPictureBox2 = new DevExpress.XtraReports.UI.XRPictureBox(); - this.xrRichText1 = new DevExpress.XtraReports.UI.XRRichText(); + this.lblReName = new DevExpress.XtraReports.UI.XRLabel(); + ((System.ComponentModel.ISupportInitialize)(this.xrRichText1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable6)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.xrRichText1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); // // Detail @@ -169,7 +170,7 @@ namespace SBBMainzReports this.lblAbrechnungszeitraum, this.xrLabel10, this.xrLabel11, - this.xrLabel8, + this.lblRechnungsnummer, this.xrLabel7, this.xrTable1, this.lblAdresse, @@ -180,6 +181,15 @@ namespace SBBMainzReports this.Page1.Name = "Page1"; this.Page1.StylePriority.UseFont = false; // + // xrRichText1 + // + this.xrRichText1.Font = new DevExpress.Drawing.DXFont("Verdana", 10F); + this.xrRichText1.LocationFloat = new DevExpress.Utils.PointFloat(10.00016F, 0F); + this.xrRichText1.Name = "xrRichText1"; + this.xrRichText1.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); + this.xrRichText1.SerializableRtfString = resources.GetString("xrRichText1.SerializableRtfString"); + this.xrRichText1.SizeF = new System.Drawing.SizeF(323.2498F, 39.99996F); + // // xrLabel3 // this.xrLabel3.BackColor = System.Drawing.Color.Transparent; @@ -309,19 +319,19 @@ namespace SBBMainzReports this.xrLabel11.Text = "[DebitorNumber]"; this.xrLabel11.WordWrap = false; // - // xrLabel8 + // lblRechnungsnummer // - this.xrLabel8.BackColor = System.Drawing.Color.Transparent; - this.xrLabel8.CanShrink = true; - this.xrLabel8.Font = new DevExpress.Drawing.DXFont("arial", 11F, DevExpress.Drawing.DXFontStyle.Bold); - this.xrLabel8.LocationFloat = new DevExpress.Utils.PointFloat(122.5F, 280.1665F); - this.xrLabel8.Name = "xrLabel8"; - this.xrLabel8.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); - this.xrLabel8.SizeF = new System.Drawing.SizeF(112.5F, 20F); - this.xrLabel8.StylePriority.UseBackColor = false; - this.xrLabel8.StylePriority.UseFont = false; - this.xrLabel8.Text = "[InvoiceNumber]"; - this.xrLabel8.WordWrap = false; + this.lblRechnungsnummer.BackColor = System.Drawing.Color.Transparent; + this.lblRechnungsnummer.CanShrink = true; + this.lblRechnungsnummer.Font = new DevExpress.Drawing.DXFont("arial", 11F, DevExpress.Drawing.DXFontStyle.Bold); + this.lblRechnungsnummer.LocationFloat = new DevExpress.Utils.PointFloat(122.5F, 280.1665F); + this.lblRechnungsnummer.Name = "lblRechnungsnummer"; + this.lblRechnungsnummer.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); + this.lblRechnungsnummer.SizeF = new System.Drawing.SizeF(112.5F, 20F); + this.lblRechnungsnummer.StylePriority.UseBackColor = false; + this.lblRechnungsnummer.StylePriority.UseFont = false; + this.lblRechnungsnummer.Text = "[InvoiceNumber]"; + this.lblRechnungsnummer.WordWrap = false; // // xrLabel7 // @@ -838,6 +848,7 @@ namespace SBBMainzReports // PageFooter // this.PageFooter.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { + this.lblReName, this.xrLabel15, this.xrPictureBox2}); this.PageFooter.HeightF = 121.0002F; @@ -865,14 +876,21 @@ namespace SBBMainzReports this.xrPictureBox2.SizeF = new System.Drawing.SizeF(159.7919F, 111F); this.xrPictureBox2.Sizing = DevExpress.XtraPrinting.ImageSizeMode.ZoomImage; // - // xrRichText1 + // lblReName // - this.xrRichText1.Font = new DevExpress.Drawing.DXFont("Verdana", 10F); - this.xrRichText1.LocationFloat = new DevExpress.Utils.PointFloat(10.00016F, 0F); - this.xrRichText1.Name = "xrRichText1"; - this.xrRichText1.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 96F); - this.xrRichText1.SerializableRtfString = resources.GetString("xrRichText1.SerializableRtfString"); - this.xrRichText1.SizeF = new System.Drawing.SizeF(323.2498F, 39.99996F); + this.lblReName.BackColor = System.Drawing.Color.Transparent; + this.lblReName.CanGrow = false; + this.lblReName.CanShrink = true; + this.lblReName.Font = new DevExpress.Drawing.DXFont("Alef", 1F); + this.lblReName.ForeColor = System.Drawing.Color.Transparent; + this.lblReName.LocationFloat = new DevExpress.Utils.PointFloat(635.8747F, 91.00018F); + this.lblReName.Name = "lblReName"; + this.lblReName.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); + this.lblReName.SizeF = new System.Drawing.SizeF(18.75F, 20F); + this.lblReName.StylePriority.UseBackColor = false; + this.lblReName.StylePriority.UseFont = false; + this.lblReName.StylePriority.UseForeColor = false; + this.lblReName.WordWrap = false; // // ServiceInvoiceReport // @@ -896,11 +914,12 @@ namespace SBBMainzReports this.Version = "23.2"; xrWatermark1.Id = "Watermark1"; this.Watermarks.Add(xrWatermark1); + this.AfterPrint += new System.EventHandler(this.ChangeName); + ((System.ComponentModel.ISupportInitialize)(this.xrRichText1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.xrTable6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.xrRichText1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); } @@ -956,7 +975,7 @@ namespace SBBMainzReports private DevExpress.XtraReports.UI.XRLabel lblAbrechnungszeitraum; private DevExpress.XtraReports.UI.XRLabel xrLabel10; private DevExpress.XtraReports.UI.XRLabel xrLabel11; - private DevExpress.XtraReports.UI.XRLabel xrLabel8; + private DevExpress.XtraReports.UI.XRLabel lblRechnungsnummer; private DevExpress.XtraReports.UI.XRLabel xrLabel7; private DevExpress.XtraReports.UI.XRLabel xrLabel3; private DevExpress.XtraReports.UI.XRLabel xrLabel4; @@ -972,5 +991,6 @@ namespace SBBMainzReports private DevExpress.XtraReports.UI.XRLabel xrLabel18; private DevExpress.XtraReports.UI.XRLabel xrLabel19; private DevExpress.XtraReports.UI.XRRichText xrRichText1; + private DevExpress.XtraReports.UI.XRLabel lblReName; } } diff --git a/ReportImp/SBBMainzReports/ServiceInvoiceReport.cs b/ReportImp/SBBMainzReports/ServiceInvoiceReport.cs index add58face..3308acecc 100644 --- a/ReportImp/SBBMainzReports/ServiceInvoiceReport.cs +++ b/ReportImp/SBBMainzReports/ServiceInvoiceReport.cs @@ -19,7 +19,12 @@ namespace SBBMainzReports { DateTime start = pRO.AccountingPeriodStart; DateTime end = pRO.AccountingPeriodEnd; - if (start.Month == end.Month && start.Year == end.Year) + lblReName.Text = String.Format("{0}, {1}. - {2} -{3:MM.yy}", pRO.CustomerLastName, pRO.CustomerFirstName.Substring(0,1), pRO.InvoiceNumber, end); + if (lblReName.Text.Contains("/")) + { + lblReName.Text = lblReName.Text.Replace("/", "-"); + } + if (start.Month == end.Month && start.Year == end.Year) { lblAbrechnungszeitraum.Text = String.Format("{0:MMMM yyyy}", start); } @@ -99,5 +104,10 @@ namespace SBBMainzReports } lblAdresse.Text = sb.ToString(); } + + private void ChangeName(object sender, EventArgs e) + { + PrintingSystem.Document.Name = String.Format("{0}", lblReName.Text); + } } } \ No newline at end of file