diff --git a/ReportImp/HPHBersenbrueck/Export/CustomDataExporter.cs b/ReportImp/HPHBersenbrueck/Export/CustomDataExporter.cs new file mode 100644 index 000000000..721504116 --- /dev/null +++ b/ReportImp/HPHBersenbrueck/Export/CustomDataExporter.cs @@ -0,0 +1,31 @@ +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 HphBersenbrueck.Export +{ + public class CustomDataExporter : DataExporter + { + public override string CreateExportString(string pFileID, string[] pHeaderCaption, string[][] pContent) + { + + if (pHeaderCaption != null && pHeaderCaption.Length > 0 && pHeaderCaption[0].Contains("Micos")) + { + return MicosExporter.CreateExportString(pHeaderCaption, pContent); + } + return base.CreateExportString(pFileID, pHeaderCaption, pContent); + } + + public override QueryDC CreateQuery(QueryDC query) + { + var q = MicosExporter.CreateQuery(query); + CreateBuchungsExportProtokollEintrag(q); + + return q; + } + } +} diff --git a/ReportImp/HPHBersenbrueck/Export/MicosExporter.cs b/ReportImp/HPHBersenbrueck/Export/MicosExporter.cs new file mode 100644 index 000000000..10a26f9cd --- /dev/null +++ b/ReportImp/HPHBersenbrueck/Export/MicosExporter.cs @@ -0,0 +1,921 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Text; +using BeWo.Data.Access; +using BS.Shared.Core; +using BS.Shared.DataContracts; + +namespace HphBersenbrueck.Export +{ + public class MicosExporter + { + + public static QueryDC CreateQuery(QueryDC query) + { + DateTime dt = DateTime.Now; + DateTime.TryParse(query.Parameter[0].Value.ToString(), out dt); + + query.FileName = String.Format("Micos Export {0:yyyyMM}.txt", dt); + + DateTime dtStart = DateTime.MinValue; + DateTime dtEnd = DateTime.MaxValue; + + if (query.Parameter.Count > 1) + { + DateTimeSpan span = query.Parameter[1].Value as DateTimeSpan; + + dtStart = span.StartDate; + dtEnd = span.EndDate; + } + + if (dtStart == DateTime.MinValue) + { + dtStart = new DateTime(1900, 1, 1); + } + query.QueryResult = GetAbrechnungenString(dt, dtStart, dtEnd); + + + return query; + } + + public static string CreateExportString(string[] pHeaderCaption, string[][] pContent) + { + if (pHeaderCaption != null && pHeaderCaption.Length > 1 && pHeaderCaption[0].Contains("Micos")) + { + DateTime dt = DateTime.Now; + + DateTime.TryParse(pHeaderCaption[1], out dt); + + return GetAbrechnungenString(dt, dt, dt); + } + return null; + } + + public static String GetAbrechnungenString(DateTime date, DateTime rechnungsDatumVon, DateTime rechnungsDatumBis) + { + StringBuilder sb = new StringBuilder(); + var s = GetMonatlicheAbrechnungString(date, rechnungsDatumVon, rechnungsDatumBis); + if (!String.IsNullOrWhiteSpace(s)) + { + sb.Append(s); + } + if (sb.Length > 0) + sb.AppendLine(); + + return sb.ToString(); + } + + public static String GetMonatlicheAbrechnungString(DateTime date, DateTime rechnungsDatumVon, DateTime rechnungsDatumBis) + { + + + var sql = GetRechnungenSql(date, rechnungsDatumVon, rechnungsDatumBis); + + /* + * SELECT +cb2sc.Oid, +ib.InvoiceNumber, +c.DebitorNumber, +Round(sip.Claim, 2) AS 'Betrag', +ib.InvoiceDate, +CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung', + */ + + var dt = ExecuteQuery(sql, date); + + var datensaetze = CreateMicosDatensaetze(dt, date); + + StringBuilder sb = new StringBuilder(); + + + foreach (var data in datensaetze) + { + + if (sb.Length > 0) + { + sb.AppendLine(); + } + + //03002022021500070EURO990037107S000001767690004050 15022200037810037200 RE R03-781 DAK-Gesundhei 00000000 + sb.Append("0300"); + sb.Append(String.Format("{0:yyyyMMdd}", data.Datum)); + sb.Append("00070"); + sb.Append("EURO99"); + + String debitornr = data.Debitor; + + while (debitornr.Length < 7) + { + debitornr = "0" + debitornr; + } + sb.Append(debitornr); + sb.Append("S"); + + String betrag = String.Format("{0:0.00}", data.Betrag).Replace(",", ""); // Betrag + while (betrag.Length < 11) + { + betrag = "0" + betrag; + } + sb.Append(betrag); + sb.Append("0004040"); + sb.Append(" "); + sb.Append(String.Format("{0:ddMMyy}", data.RechnungsDatum)); // Belegdatum + + String belegnummer = data.Belegnummer; // Belegnummer + + while (belegnummer.Length < 7) + { + belegnummer = "0" + belegnummer; + } + sb.Append(belegnummer); + + String kostenstelle = data.Kostenstelle; + while (kostenstelle.Length < 7) + { + kostenstelle = "0" + kostenstelle; + } + sb.Append(kostenstelle); + + sb.Append(" "); // Skonto 9 Leerzeichen + sb.Append(" "); // Textschlüssel 2 Leerzeichen + sb.Append(" "); // Zusatz-Schlüssel 1 Leerzeichen + + String buchungstext = data.Buchungstext; // Verwendungszweck + if (buchungstext.Length > 25) + { + buchungstext = buchungstext.Substring(0, 25); + } + while (buchungstext.Length < 25) + { + buchungstext = buchungstext + " "; + } + sb.Append(buchungstext); + sb.Append(" "); // Steuerbetrag 9 Leerzeichen + sb.Append(" "); // Wechselfälligkeitsdatum 8 Leerzeichen + sb.Append(" "); // Wechsel-Nr. 7 Leerzeichen + sb.Append(" "); // Valutadatum 8 Leerzeichen + sb.Append(" "); // Fremdbelegdatum 8 Leerzeichen + sb.Append(" "); // Fremdbeleg-Nr. 12 Leerzeichen + sb.Append(" "); // Absolutes Zahlungsdatum 8 Leerzeichen + sb.Append(" "); // Skontotage 2 Leerzeichen + sb.Append(" "); // Skontoprozent 2 Leerzeichen + sb.Append(" "); // Kennzeichen Mahnung 1 Leerzeichen + sb.Append(" "); // Kennzeichen Bankeinzug 1 Leerzeichen + sb.Append("000000"); + sb.Append("00"); + + //sb.Append(data.Artikelbezeichnung); + } + + return sb.ToString(); + } + + + private static IList CreateMicosDatensaetze(DataTable dt, DateTime date) + { + var list = new List(); + var key2Datensatz = new Dictionary(); + + foreach (DataRow row in dt.Rows) + { + + //date = letzter Tag des Monats () + long oid = 0; + if (row[7] != null) + { + Int64.TryParse(row[7].ToString(), out oid); + } + + String debitornr = String.Format("{0}", row[2]); // Debitor + + decimal betrag = 0; + + if (row[3] != null) + { + Decimal.TryParse(row[3].ToString(), out betrag); + } + + DateTime rd = date; + + if (row[4] != null) + { + DateTime.TryParse(row[4].ToString(), out rd); + } + + DateTime abrechnungsEnddatum = date; + + if (row[8] != null) + { + DateTime.TryParse(row[8].ToString(), out abrechnungsEnddatum); + } + + String belegnummer = String.Format("{0}", row[1]); // Belegnummer + + String kostenstelle = GetKostenstelle(row); + String buchungstext = String.Format("{0}", row[5]); // Verwendungszweck + + String artikel = String.Format("{0}", row[6]); // Verwendungszweck + + MicosDatensatz md = null; + String key = String.Format("{0}_{1}", oid, artikel); + + if (key2Datensatz.ContainsKey(key)) + { + md = key2Datensatz[key]; + } + else + { + md = new MicosDatensatz(); + md.InvoiceBaseOid = oid; + md.Artikelbezeichnung = artikel; + md.Belegnummer = belegnummer; + md.Buchungstext = buchungstext; + md.Kostenstelle = kostenstelle; + md.Debitor = debitornr; + md.Datum = abrechnungsEnddatum; + md.RechnungsDatum = rd; + + key2Datensatz.Add(key, md); + list.Add(md); + + } + md.Betrag += betrag; + + + } + + return list; + } + + private static string GetKostenstelle(DataRow row) + { + /* + * + * folgende Kostenstellen gehören zu den Leistungsarten: + 35701 Betreuungseinheiten FUD KST: 35700 + 35702 Kostenbeteiligung Betreuung KST: 35700 + + 35703 Kilometerpauschale KST 35700 + + 35801 Niedrigschwellige Betreuung KST: 35800 + + 35831 Verhinderungspflege nach § 39 KST: 35800 + + 35901 Sachkosten Reise KST 35900 + + 35904 Betreuungskosten o. Pflegegrad KST: 35900 + + 35911 Betreuungskosten mit Pflegegrad KST: 35900 + + 35956 Sachkosten Kurzurlaub KST: 35955 + */ + + if (row[6] != null) + { + String verwendungszweck = row[6].ToString(); + + if (verwendungszweck.Contains("Niederschwellig")) + { + return "35800"; + } + if (verwendungszweck.Contains("Verhinderungspflege")) + { + return "35800"; + } + if (verwendungszweck.Contains("Kurzurlaub")) + { + return "35955"; + } + if (verwendungszweck.Contains("Reise")) + { + return "35550"; + } + } + return "35540"; + + } + + private static Dictionary CreateDictionary(DataTable dt) + { + Dictionary dict = new Dictionary(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + { + long? oid = row.ItemArray[0] as long?; + decimal? betrag = row.ItemArray[4] as decimal?; + + if (oid.HasValue && betrag.HasValue) + { + dict.Add(oid.Value, betrag.Value); + } + } + } + + return dict; + } + + //private static void ErstelleKostenstellenZeilenAlt(DataRow row, StringBuilder sb) + //{ + // if (row.ItemArray.Length > 14) + // { + // var betragObj = row[14]; + + // decimal gesamtbetrag = 0; + // if (betragObj != null) + // { + // Decimal.TryParse(betragObj.ToString().Replace(".", ","), out gesamtbetrag); + // } + // decimal betrag1 = Math.Round(gesamtbetrag * 0.1643m, 2, MidpointRounding.AwayFromZero); + // decimal betrag2 = Math.Round(gesamtbetrag * 0.8213m, 2, MidpointRounding.AwayFromZero); + // decimal betrag3 = gesamtbetrag - betrag1 - betrag2; + + + + // sb.AppendLine(); + // sb.Append("K;0;610900;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betrag1 * -1).Replace(",", ".")); + // sb.AppendLine(";"); + // sb.Append("K;0;610901;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betrag2 * -1).Replace(",", ".")); + // sb.AppendLine(";"); + // sb.Append("K;0;610902;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betrag3 * -1).Replace(",", ".")); + // sb.Append(";"); + // } + //} + + //private static void ErstelleKostenstellenZeilenNeu(DataRow row, StringBuilder sb, Dictionary c2sOid2AssiBetrag, Dictionary c2sOid2OtBetrag, Dictionary c2sOid2SoziBetrag) + //{ + // if (row.ItemArray.Length > 15) + // { + // long? oid = row[0] as long?; + + // var betragObj = row[15]; + + // decimal gesamtbetrag = 0; + // if (betragObj != null) + // { + // Decimal.TryParse(betragObj.ToString().Replace(".", ","), out gesamtbetrag); + // } + // decimal betragBewo = Math.Round(gesamtbetrag, 2, MidpointRounding.AwayFromZero); + // decimal betragGruppen = 0;//Math.Round(gesamtbetrag, 2, MidpointRounding.AwayFromZero); + // decimal betragAssistenz = 0;//Math.Round(gesamtbetrag, 2, MidpointRounding.AwayFromZero); + // decimal betragSozi = 0; + + // if (oid.HasValue && c2sOid2AssiBetrag.ContainsKey(oid.Value)) + // { + // betragAssistenz = c2sOid2AssiBetrag[oid.Value]; + // betragAssistenz = Math.Round(betragAssistenz, 2, MidpointRounding.AwayFromZero); + // betragBewo -= betragAssistenz; + // } + + // if (oid.HasValue && c2sOid2OtBetrag.ContainsKey(oid.Value)) + // { + // betragGruppen = c2sOid2OtBetrag[oid.Value]; + // betragGruppen = Math.Round(betragGruppen, 2, MidpointRounding.AwayFromZero); + // betragBewo -= betragGruppen; + // } + // if (oid.HasValue && c2sOid2SoziBetrag.ContainsKey(oid.Value)) + // { + // betragSozi = c2sOid2SoziBetrag[oid.Value]; + // betragSozi = Math.Round(betragSozi, 2, MidpointRounding.AwayFromZero); + // betragBewo -= betragSozi; + // } + // //bewo 610900 + // //offener Treff 610910 Leistungskategorie Gruppenbuchung + // //Assistenzleistungen 610915 Leistungskategorien Assistenz (Kategorie Assistenzleistungen) + + // //Bei Finanzauswertungen nach diesen drei Kategorien trennen + + // //Rechnungen als AWO Vorlage + + // if (betragBewo != 0) + // { + // sb.AppendLine(); + // sb.Append("K;0;610900;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betragBewo * -1).Replace(",", ".")); + // sb.Append(";"); + // } + + // if (betragGruppen > 0) + // { + // sb.AppendLine(); + // sb.Append("K;0;610910;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betragGruppen * -1).Replace(",", ".")); + // sb.Append(";"); + // } + + // if (betragAssistenz > 0) + // { + // sb.AppendLine(); + // sb.Append("K;0;610915;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betragAssistenz * -1).Replace(",", ".")); + // sb.Append(";"); + // } + + // if (betragSozi > 0) + // { + // sb.AppendLine(); + // sb.Append("K;0;610905;;;;;;"); + // sb.Append(String.Format("{0:0.##}", betragSozi * -1).Replace(",", ".")); + // sb.Append(";"); + // } + // } + //} + + //public static String GetAbschlagszahlungenString(DateTime date) + //{ + // var dt = ExecuteQuery(GetAbschlagszahlungenSql(date), date); + + // StringBuilder sb = new StringBuilder(); + // foreach (DataRow row in dt.Rows) + // { + // if (sb.Length > 0) + // { + // sb.AppendLine(); + // } + // for (int i = 0; i < row.ItemArray.Length; i++) + // { + // if (i > 0) + // { + // sb.Append(";"); + // } + // if (i == 32) + // { + // sb.AppendLine(); + // } + // var item = row[i]; + // bool quote = i == 15 || i == 38; + + // if (quote) + // { + // sb.Append('"'); + // sb.Append(item); + // sb.Append('"'); + // } + // else + // { + // sb.Append(item); + // } + // } + + // } + // //F,0,050,,BEWO,DA,02012016,012016,iBelegNr2,Belegnr2,220001,,,,-888.88, "Name AZ Abschlagszahlung LVR 01/2016",,,EUR,,,,,,,,,,,R,,, + // //G,0,4473,,,888.88,"Name AZ Abschlagszahlung LVR 05/2016", + + // return sb.ToString(); + //} + + //public static String GetSelbstzahlerString(DateTime date) + //{ + // var dt = ExecuteQuery(GetSelbstzahlerSql(date), date); + + // StringBuilder sb = new StringBuilder(); + // foreach (DataRow row in dt.Rows) + // { + // if (sb.Length > 0) + // { + // sb.AppendLine(); + // } + // for (int i = 0; i < row.ItemArray.Length; i++) + // { + // if (i > 0) + // { + // sb.Append(";"); + // } + // if (i == 32) + // { + // sb.AppendLine(); + // } + + // var item = row[i]; + // bool quote = i == 15 || i == 38; + + // if (quote) + // { + // sb.Append('"'); + // sb.Append(item); + // sb.Append('"'); + // } + // else + // { + // sb.Append(item); + // } + // } + + // } + // return sb.ToString(); + //} + + + +// private static String GetMonatlicheAbrechnungLvrSqlAlt(DateTime date) +// { +// String sql = @" +//SELECT +//'F', +//'0', +//'114', +//null, +//'BEWO', +//'AR', +//':Abrechnungsmonat', +//':Periode', +//null, +//GetNextBelegnr(1), +//c.DebitorNumber, +//null, +//null, +//null, +//REPLACE(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', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodeSlash ', org.Name) as 'Verwendung', +//null, +//null, +//'EUR', +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//'G', +//'0', +//'49100000', +//null, +//null, +//REPLACE(-1 * 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 'Betrag2', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodeSlash ', org.Name) as 'Verwendung2', +//null +//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 GROUP BY sr2.`CostBearer2SupportConceptOid`) +// AS sr ON sr.`CostBearer2SupportConceptOid` = cb2sc.`Oid` +//WHERE c.`IsActive` = 1 AND sc.`IsActive` = 1 +//and (sr.`GeleisteteFLM` is not null) +//ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` +//"; + +// return sql; +// } + + private static String GetRechnungenSql(DateTime date, DateTime rechnungsDatumVon, DateTime rechnungsDatumBis) + { + if (rechnungsDatumVon <= new DateTime(1900, 1, 1)) + { + rechnungsDatumVon = new DateTime(date.Year, date.Month, 1); + } + if (rechnungsDatumBis.Year > 9000) + { + rechnungsDatumBis = new DateTime(date.Year, date.Month, 1).AddMonths(1); + } + else + { + rechnungsDatumBis = rechnungsDatumBis.AddDays(1); + } + + String sql = @" + +SELECT +cb2sc.Oid, +ib.InvoiceNumber, +c.DebitorNumber, +Round(ii.AmountTotal, 2) AS 'Betrag', +ib.InvoiceDate, +CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', org.Name) as 'Verwendung', +ii.ItemDescription, +ib.Oid, +ib.AccountingPeriodEnd +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 c.`IsActive` = 1 AND sc.`IsActive` = 1 and ib.isactive = 1 and ib.type <> 1 +and ib.`InvoiceDate` >= ':Monat_Start' AND ib.`InvoiceDate` < ':Monat_End' +ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` +"; + + sql = sql.Replace(":Monat_Start", String.Format("{0:yyyy-MM-dd}", rechnungsDatumVon)); + sql = sql.Replace(":Monat_End", String.Format("{0:yyyy-MM-dd}", rechnungsDatumBis)); + return sql; + } + +// private static String GetAbschlagszahlungenSql(DateTime date) +// { +// String sql = @" +//SELECT +//'F', +//'0', +//'114', +//null, +//'BEWO', +//'AR', +//':Abrechnungsmonat', +//':Periode', +//GetNextBelegnr(0), +//GetNextBelegnr(1), +//c.DebitorNumber, +//null, +//null, +//null, +//REPLACE(-1 * ROUND(at.`GesamtBetrag`, 2), ',', '.') as 'Abschlagszahlungen', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abschlagszahlung :PeriodeSlash ', org.Name) as 'Verwendung', +//null, +//null, +//'EUR', +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//'G', +//'0', +//'48301000', +//null, +//null, +//REPLACE(ROUND(at.`GesamtBetrag`, 2), ',', '.') as 'Abschlagszahlungen2', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abschlagszahlung :PeriodeSlash ', org.Name) as 'Verwendung2', +//null +//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 at2.`CostBearer2SupportConceptOid`, SUM(at2.`Amount`) AS GesamtBetrag FROM `accountingtransaction` at2 +// WHERE at2.`BookingDate` >= ':Monat_Start' AND at2.`BookingDate` < ':Monat_End' GROUP BY at2.`CostBearer2SupportConceptOid`) +// AS at ON at.`CostBearer2SupportConceptOid` = cb2sc.`Oid` +//WHERE c.`IsActive` = 1 AND sc.`IsActive` = 1 +//and (at.`GesamtBetrag` is not null) +//ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` +//"; +// return sql; +// } + +// private static String GetSelbstzahlerSql(DateTime date) +// { +// String sql = @" +//SELECT +//'F', +//'0', +//'114', +//null, +//'BEWO', +//'AR', +//':Abrechnungsmonat', +//':Periode', +//GetNextBelegnr(0), +//GetNextBelegnr(1), +//c.DebitorNumber, +//null, +//null, +//null, +//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', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodeSlash ', org.Name) as 'Verwendung', +//null, +//null, +//'EUR', +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//null, +//'G', +//'0', +//'xxxx', +//null, +//null, +//-1 * 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 'Betrag2', +//CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodeSlash ', org.Name) as 'Verwendung2', +//null +//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 GROUP BY sr2.`CostBearer2SupportConceptOid`) +// AS sr ON sr.`CostBearer2SupportConceptOid` = cb2sc.`Oid` +//WHERE c.`IsActive` = 1 AND sc.`IsActive` = 1 +//and (sr.`GeleisteteFLM` is not null) +//ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` +//"; + +// return sql; +// } + +// private static String GetMonatlicheAbrechnungStringForCatsSql(DateTime date, IList includeCatOids, IList excludeOids) +// { + +// String sql = @" +//SELECT distinct +//cb2sc.oid, +//c.oid, +//sc.oid, +//c.DebitorNumber, +//IF(crpRateFactor.`CostRateValue` is null, ROUND((sr.`GeleisteteFLM` / 60) * crpHourlyRate.`CostRateValue`, 2),ROUND(ROUND((sr.`GeleisteteFLM` / 60), 2) * crpHourlyRate.`CostRateValue` * ((100 + crpRateFactor.`CostRateValue`)/100), 2)) AS 'Forderung', +//ROUND(crpHourlyRate.`CostRateValue`,2) as 'Stundensatz', ROUND(crpRateFactor.`CostRateValue`,2) as 'PauschalerFaktor', +//sr.`GeleisteteFLM` +//FROM `supportconcept` sc +//INNER JOIN `costbearer2supportconcept` cb2sc ON sc.`Oid` = cb2sc.`SupportConceptOid` +//INNER JOIN `costbearer` cb ON cb2sc.`CostBearerOid` = cb.`Oid` +//INNER JOIN +// (SELECT crp.`ObjectOid`, crp.costratetype, crp.`CostRateValue`, If(crp.Enddate is null, '9999-01-01', crp.enddate) as aenddatum, crptemp.enddatum FROM `costrateperiod` crp +// inner join (SELECT crpi.`ObjectOid`, Min(If(crpi.Enddate is null, '9999-01-01', crpi.enddate)) as enddatum FROM `costrateperiod` crpi +// WHERE crpi.`ObjectTid` = 22 AND crpi.`CostRateType` = 0 AND (crpi.`EndDate` is null or crpi.`EndDate` > ':Monat_Start') +// group by crpi.objectoid) as crptemp on crptemp.objectoid = crp.objectoid +// WHERE crp.`ObjectTid` = 22 and crp.costratetype = 0 +// having aenddatum = crptemp.enddatum) +// AS crpHourlyRate ON crpHourlyRate.`ObjectOid` = cb.`Oid` +//LEFT JOIN +// (SELECT crp.`ObjectOid`, crp.costratetype, crp.`CostRateValue`, If(crp.Enddate is null, '9999-01-01', crp.enddate) as aenddatum, crptemp.enddatum FROM `costrateperiod` crp +// inner join (SELECT crpi.`ObjectOid`, Min(If(crpi.Enddate is null, '9999-01-01', crpi.enddate)) as enddatum FROM `costrateperiod` crpi +// WHERE crpi.`ObjectTid` = 22 AND crpi.`CostRateType` = 2 AND (crpi.`EndDate` is null or crpi.`EndDate` > ':Monat_Start') +// group by crpi.objectoid) as crptemp on crptemp.objectoid = crp.objectoid +// WHERE crp.`ObjectTid` = 22 and crp.costratetype = 2 +// having aenddatum = crptemp.enddatum) +// 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` +//INNER 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:IncludeCatOidList:ExcludeCatOidList GROUP BY sr2.`CostBearer2SupportConceptOid`) +// AS sr ON sr.`CostBearer2SupportConceptOid` = cb2sc.`Oid` +//WHERE c.`IsActive` <> 0 AND sc.`IsActive` <> 0 and (sr.`GeleisteteFLM` is not null) +//ORDER BY p.`LastName` +//"; + +// String includeString = ""; +// String excludeString = ""; +// if (includeCatOids != null && includeCatOids.Count > 0) +// { +// StringBuilder oidList = new StringBuilder(); + +// foreach (var catOid in includeCatOids) +// { +// if (oidList.Length > 0) +// oidList.Append(","); +// oidList.Append(catOid); +// } + +// includeString = String.Format(" AND sc.oid in ({0})", oidList.ToString()); +// } + +// if (excludeOids != null && excludeOids.Count > 0) +// { +// StringBuilder notoidList = new StringBuilder(); + +// foreach (var catOid in excludeOids) +// { +// if (notoidList.Length > 0) +// notoidList.Append(","); +// notoidList.Append(catOid); +// } +// excludeString = String.Format(" AND sc.oid not in ({0})", notoidList.ToString()); +// } + +// String gruppenfilter = ""; + +// //if (!holeEinzel || !holeGruppen) +// //{ +// // if (holeGruppen) +// // { +// // gruppenfilter = "AND sr2.GroupOid is not null"; +// // } +// // else +// // { +// // gruppenfilter = "AND sr2.GroupOid is null"; +// // } +// //} +// sql = sql.Replace(":Gruppenfilter", gruppenfilter); +// sql = sql.Replace(":IncludeCatOidList", includeString); +// sql = sql.Replace(":ExcludeCatOidList", excludeString); +// return sql; +// } + + public static DataTable ExecuteQuery(String sql, DateTime dt) + { + var newsql = sql; + newsql = newsql.Replace(":PeriodePunkt", String.Format("{0:MM.yyyy}", dt)); + newsql = newsql.Replace(":PeriodeSlash", String.Format("{0:MM/yyyy}", dt)); + newsql = newsql.Replace(":Periode", String.Format("{0:MMyyyy}", dt)); + newsql = newsql.Replace(":Abrechnungsmonat", String.Format("{0:ddMMyyyy}", dt)); + newsql = newsql.Replace(":Abrechnungsmonat", String.Format("{0:ddMMyyyy}", 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]; + } + + + + + //Buchung Abrechnung Stundenzettel + //F,0,050,, BEWO, DA,01012016,012016, iBelegNr1, Belegnr1,220001,,,,999.99, "Name AZ Abrechnung 01/2016 LVR",,, EUR,,,,,,,,,,, R,,, + //G,0,1695,,,-999.99,"Name AZ Abrechnung 01/2016 LVR", + + + + //Buchung Abschlagszahlung + //F,0,050,, BEWO, DA,02012016,012016, iBelegNr2, Belegnr2,220001,,,,-888.88, "Name AZ Abschlagszahlung LVR 01/2016",,, EUR,,,,,,,,,,, R,,, + //G,0,4473,,,888.88,"Name AZ Abschlagszahlung LVR 05/2016", + + + //Buchung Abrechnung LVR / Selbstzahler + //F,0,050,, BEWO, DA,01022016,022016, iBelegNr3, Belegnr3,220001,,,,900.00, "Name AZ Abrechnung LVR + SZ 02/2016",,, EUR,,,,,,,,,,, R,,, + //G,0,1695,,,-800.00,"Name AZ Abrechnung 05/2016 LVR", + //G,0,1695,,,-100.00,"Name AZ Abrechnung 05/2016 SZ", + + + + //schwarz = konstant + //rot = variabel + + + } + class MicosDatensatz + { + public long InvoiceBaseOid { get; set; } + + public DateTime Datum { get; set; } + + public DateTime RechnungsDatum { get; set; } + + public String Debitor { get; set; } + + public decimal Betrag { get; set; } + + public String Belegnummer { get; set; } + + public String Kostenstelle { get; set; } + + public String Buchungstext { get; set; } + + public String Artikelbezeichnung { get; set; } + + } +} \ No newline at end of file diff --git a/ReportImp/HPHBersenbrueck/HPHBersenbrueck.csproj b/ReportImp/HPHBersenbrueck/HPHBersenbrueck.csproj index 65c674a1b..1785680f4 100644 --- a/ReportImp/HPHBersenbrueck/HPHBersenbrueck.csproj +++ b/ReportImp/HPHBersenbrueck/HPHBersenbrueck.csproj @@ -69,6 +69,8 @@ CustomerDataReport.cs + +