diff --git a/ReportImp/DiakoniewerkEssen/Export/DiamantExporter.cs b/ReportImp/DiakoniewerkEssen/Export/DiamantExporter.cs index 74a1b179e..57e8bbd7a 100644 --- a/ReportImp/DiakoniewerkEssen/Export/DiamantExporter.cs +++ b/ReportImp/DiakoniewerkEssen/Export/DiamantExporter.cs @@ -10,7 +10,6 @@ namespace DiakonieWerkEssen.Export { public class DiamantExporter { - public static QueryDC CreateQuery(QueryDC query) { DateTime dt = DateTime.Now; @@ -41,35 +40,33 @@ namespace DiakonieWerkEssen.Export { sb.Append(s); } - if (sb.Length > 0) - sb.AppendLine(); - s = GetMonatlicheAbrechnungString(date); if (!String.IsNullOrWhiteSpace(s)) { + if (sb.Length > 0) + { + sb.AppendLine(); + } sb.Append(s); } - if (sb.Length > 0) - { - sb.AppendLine(); - } - return sb.ToString(); } public static String GetMonatlicheAbrechnungString(DateTime date) { - // Export enthält Rechnungsangaben Zeilen (Zeile F) und Kostenstellen/Rechnungspositionsangaben (Zeile K) in zwei Zeilen - // Kommen aus Export in einer Zeile und werden hier getrennt, aber nur falls die Rechnung mehrere Positionen hat - int startIdx = 1; - int stopIdx1 = 34; - int stopIdx2 = 42; // ab da beginnen Angaben zu Kostenstelle -> zweite Zeile oder auch mehr falls mehrere Positionen - String sql; - sql = GetMonatlicheAbrechnungenSqlNeu(); - var dt = ExecuteQuery(sql, date); + var dt = ExecuteQuery(GetMonatlicheRechnungenSql(), date); + return ProcessAbrechnungRows(dt); + } + + private static String ProcessAbrechnungRows(DataTable dt) + { + // F-Zeile: Rechnungs-/Buchungsangaben, G-Zeile: Gegenbuchung Erlöskonto, + // K-Zeile: Kostenstelle/Position (kann mehrfach vorkommen bei mehreren Positionen) + const int startIdx = 1; + const int stopIdx1 = 34; // G-Zeile beginnt hier + const int stopIdx2 = 42; // K-Zeile beginnt hier StringBuilder sb = new StringBuilder(); - List mergedRows = new List(); Dictionary oid2Row = new Dictionary(); foreach (DataRow row in dt.Rows) { @@ -81,9 +78,7 @@ namespace DiakonieWerkEssen.Export oid2Row.Add(oid, row); if (sb.Length > 0) - { sb.AppendLine(); - } for (int i = startIdx; i < row.ItemArray.Length; i++) { @@ -94,9 +89,7 @@ namespace DiakonieWerkEssen.Export if (betrag != 0) { if (betrag < 0) - { storno = true; - } sb.Append(String.Format("{0:0.00}", betrag)); sb.Append(";"); } @@ -113,6 +106,11 @@ namespace DiakonieWerkEssen.Export sb.Append(item); sb.Append(";"); } + else if (i == 36) + { + sb.Append(GetErloeskonto(item.ToString())); + sb.Append(";"); + } else if (i == 39) { decimal betrag = ErzeugeBetrag(item); @@ -143,18 +141,6 @@ namespace DiakonieWerkEssen.Export sb.Append(";"); } } - else if (i == 44) - { - var position = item.ToString(); - if (position.Contains("Wohngruppenzuschlag") || position.Contains("Assistenz")) - { - sb.Append("610915;"); - } - else - { - sb.Append("610905;"); - } - } else { sb.Append(item); @@ -165,9 +151,8 @@ namespace DiakonieWerkEssen.Export else { if (sb.Length > 0) - { sb.AppendLine(); - } + for (int i = startIdx; i < row.ItemArray.Length; i++) { var item = row[i]; @@ -186,18 +171,6 @@ namespace DiakonieWerkEssen.Export sb.Append(";"); } } - else if (i == 44) - { - var position = item.ToString(); - if (position.Contains("Wohngruppenzuschlag") || position.Contains("Assistenz")) - { - sb.Append("610915;"); - } - else - { - sb.Append("610905;"); - } - } else if (i > stopIdx2) { sb.Append(item); @@ -210,24 +183,16 @@ namespace DiakonieWerkEssen.Export return sb.ToString(); } - private static Dictionary CreateDictionaryKrankenkassen(DataTable dt) + private static String GetErloeskonto(String orgName) { - 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 (orgName.Contains("Jugendamt") || orgName.Contains("Essen")) + return "42425"; + if (orgName.Contains("FLS")) + return "42405"; + if (orgName.Contains("DLS")) + return "42450"; - if (oid.HasValue && betrag.HasValue) - { - dict.Add(oid.Value, betrag.Value); - } - } - } - - return dict; + return "42405"; } public static decimal ErzeugeBetrag(object betragObj) @@ -241,787 +206,141 @@ namespace DiakonieWerkEssen.Export return betrag; } - private static String GetMonatlicheAbrechnungenSqlNeu() - { - String sql = @" - -SELECT -CONCAT(cb2sc.Oid, ib.InvoiceNumber, Round(sip.Claim, 0)) AS OID, -'F', -'0', -'114', -null, -'BEWO', -'AR', -':Abrechnungsmonat', -':Periode', -null, -ib.InvoiceNumber, -c.DebitorNumber, -null, -null, -null, -Round(sip.Claim, 2) AS 'Betrag', -CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung', -null, null, null, 'EUR', -null, null, null, null, null, null, null, null, null, null, null, null, null, -'G', '0', '49100000', null, null, -Round(sip.Claim * -1, 2) AS 'Betrag2', -CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung2', null, -'K', 0, ii.ItemDescription, null, null, null, null, null, Round(ii.AmountTotal * -1, 2) - FROM - person p - INNER JOIN customer c on c.personoid = p.oid - INNER JOIN supportconcept sc on sc.customeroid = c.oid - INNER JOIN costbearer2supportconcept cb2sc on cb2sc.supportconceptoid = sc.oid - INNER JOIN costbearer cb on cb2sc.costbeareroid = cb.oid - INNER JOIN organisation org on org.costbeareroid = cb.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.InvoiceId = 'RechnungSoziotherapie' -and ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End' - -ORDER BY ib.invoicenumber -"; - return sql; - } - public static String GetMonatlicheAbrechnungLvrString(DateTime date) { - int startIdx = 0; - - DataTable dtAssi = null; - DataTable dtZuschlag = null; - DataTable dtOffenerTreff = null; - DataTable dtSoziTreff = null; - String sql; - - if (date < new DateTime(2019, 1, 1)) - { - sql = GetMonatlicheAbrechnungLvrSqlAlt(date); - } - else - { - startIdx = 1; - sql = GetMonatlicheAbrechnungLvrSqlNeu(date); - - List cats = new List(); - cats.Add(33); // Assistenzleistung nach § 45 b SGB XI - cats.Add(49); // Assistenzleistung - cats.Add(54); // Assistenzleistung nach § 45 a SGB XI - var assiSql = GetMonatlicheAbrechnungStringForCatsSql(date, cats, null); // erstellt monatliche Abgrenzung und zieht daraus die Teilbeträge - dtAssi = ExecuteQuery(assiSql, date); - - cats = new List(); - cats.Add(13); // Offener Treff - var otSql = GetMonatlicheAbrechnungStringForCatsSql(date, cats, null); - dtOffenerTreff = ExecuteQuery(otSql, date); - - //cats = new List(); - //cats.Add(50); // Soziotherapie - //var soziSql = GetMonatlicheAbrechnungStringForCatsSql(date, cats, null); - //dtSoziTreff = ExecuteQuery(soziSql, date); - - //// cats.Add(38); Wohngruppenzuschlag nach §38a SGB11 - //var zuschlagSql = GetMonatlicheZuschlaegeStringSql(date); // hier gehts nur über die InvoiceItems - //dtZuschlag = ExecuteQuery(zuschlagSql, date); - } - - var dt = ExecuteQuery(sql, date); - - Dictionary c2sOid2AssiBetrag = CreateDictionary(dtAssi); - Dictionary c2sOid2OtBetrag = CreateDictionary(dtOffenerTreff); - //Dictionary c2sOid2SoziBetrag = CreateDictionary(dtSoziTreff); - //Dictionary c2sOid2ZuschlagBetrag = CreateDictionary(dtZuschlag); - - - StringBuilder sb = new StringBuilder(); - List mergedRows = new List(); - Dictionary oid2Row = new Dictionary(); - foreach (DataRow row in dt.Rows) - { - long oid = (long)row[0]; - - if (!oid2Row.ContainsKey(oid)) - { - oid2Row.Add(oid, row); - mergedRows.Add(row); - } - //Nach Änderung der Rechnungslogik - Aushebeln des Merge für Soziotherapie und verwandte Leistungen - else if (oid2Row.ContainsKey(oid) && c2sOid2AssiBetrag.ContainsKey(oid)) - { - mergedRows.Add(row); - } - else - { - var firstRow = oid2Row[oid]; - - decimal? betrag1Obj = firstRow[15] as decimal?; - decimal? betrag2Obj = firstRow[38] as decimal?; - - decimal? betragNeu1Obj = row[15] as decimal?; - decimal? betragNeu2Obj = row[38] as decimal?; - - firstRow[15] = (betrag1Obj ?? 0) + (betragNeu1Obj ?? 0); - firstRow[38] = (betrag2Obj ?? 0) + (betragNeu2Obj ?? 0); - } - } - - foreach (DataRow row in mergedRows) - { - if (sb.Length > 0) - { - sb.AppendLine(); - } - - for (int i = startIdx; i < row.ItemArray.Length; i++) - { - if (i > startIdx) - { - sb.Append(";"); - } - if (i == (32 + startIdx)) - { - sb.AppendLine(); - } - var item = row[i]; - bool quote = i == (15 + startIdx) || i == (38 + startIdx); - - if (quote) - { - sb.Append('"'); - sb.Append(item); - sb.Append('"'); - } - else - { - sb.Append(item); - } - } - - if (date < new DateTime(2019, 1, 1)) - { - ErstelleKostenstellenZeilenAlt(row, sb); - } - else - { - ErstelleKostenstellenZeilenNeu(row, sb, c2sOid2AssiBetrag, c2sOid2OtBetrag); - } - } -//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", - - return sb.ToString(); - } - - - 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) - { - if (!dict.ContainsKey(oid.Value)) - { - dict.Add(oid.Value, betrag.Value); - } - dict[oid.Value] += betrag.Value; - } - } - } - - return dict; + var dt = ExecuteQuery(GetMonatlicheAbrechnungLvrSql(), date); + return ProcessAbrechnungRows(dt); } - 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) - { - 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); - - 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; - } - //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 (betragZuschlag > 0) - //{ - // sb.AppendLine(); - // sb.Append("K;0;610915;;;;;;"); - // sb.Append(String.Format("{0:0.##}", betragZuschlag * -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) + private static String GetMonatlicheAbrechnungLvrSql() { 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` -"; - + SELECT + qry.Oid AS OID, + 'F', '0', '204', null, '', 'ARBW', ':Abrechnungsmonat', ':Periode', null, + '', + qry.DebitorNumber, + null, null, null, + Round(SUM(qry.Betrag), 2) AS 'Betrag', + CONCAT(qry.Verwendung, ' Abgrenzung :PeriodePunkt ', qry.Kostentraeger) as 'Verwendung', + null, null, null, 'EUR', + null, null, null, null, null, null, null, null, null, null, null, null, null, + 'G', '0',qry.Kostentraeger, null, null, + Round(SUM(qry.Betrag) * -1, 2) AS 'Betrag2', + CONCAT(qry.Verwendung, ' Abgrenzung :PeriodePunkt ', qry.Kostentraeger) as 'Verwendung2', + null, + 'K', 0, '206222', null, null, null, null, null, Round(SUM(qry.Betrag) * -1, 2) AS 'AmountTotal' + 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, + 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.Oid = 1 OR org.Oid = 2) AND c.`IsActive` <> 0 AND sc.`IsActive` <> 0 AND (sr.`GeleisteteFLM` is not null)) + UNION ALL + (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, + 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.Oid = 1 OR org.Oid = 2) AND c.`IsActive` <> 0 AND sc.`IsActive` <> 0 AND (sr.`GeleisteteFLM` is not null)) + ) qry + GROUP BY qry.Oid, qry.DebitorNumber, qry.Verwendung, qry.Kostentraeger + ORDER BY qry.Verwendung + "; return sql; } - private static String GetMonatlicheAbrechnungLvrSqlNeu(DateTime date) + private static String GetMonatlicheRechnungenSql() { String sql = @" -SELECT -cb2sc.Oid, -'F', -'0', -'114', -null, -'BEWO', -'AR', -':Abrechnungsmonat', -':Periode', -null, -ib.InvoiceNumber, -c.DebitorNumber, -null, -null, -null, -Round(sip.Claim, 2) AS 'Betrag', -CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodePunkt ', 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, -Round(sip.Claim * -1, 2) AS 'Betrag2', -CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :PeriodePunkt ', 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` -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 -WHERE c.`IsActive` = 1 AND sc.`IsActive` = 1 and ib.isactive = 1 and ib.type <> 1 and isnull(InvoiceId) -and ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End' -ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` + SELECT + CONCAT(cb2sc.Oid, ib.InvoiceNumber, Round(sip.Claim, 0)) AS OID, + 'F', '0', '204', null, '', 'ARBW', ':Abrechnungsmonat', ':Periode', null, + ib.InvoiceNumber, + c.DebitorNumber, + null, null, null, + Round(sip.Claim, 2) AS 'Betrag', + CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung', + null, null, null, 'EUR', + null, null, null, null, null, null, null, null, null, null, null, null, null, + 'G', '0', org.Name, null, null, + Round(sip.Claim * -1, 2) AS 'Betrag2', + CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung2', null, + 'K', 0, '206222', null, null, null, null, null, Round(ii.AmountTotal * -1, 2) + FROM + person p + INNER JOIN customer c on c.personoid = p.oid + INNER JOIN supportconcept sc on sc.customeroid = c.oid + INNER JOIN costbearer2supportconcept cb2sc on cb2sc.supportconceptoid = sc.oid + INNER JOIN costbearer cb on cb2sc.costbeareroid = cb.oid + INNER JOIN organisation org on org.costbeareroid = cb.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.`IsExported` = 0 + and ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End' + UNION + SELECT + CONCAT(cb2sc.Oid, ib.InvoiceNumber, Round(si.Claim, 0)) AS OID, + 'F', '0', '204', null, '', 'ARBW', ':Abrechnungsmonat', ':Periode', null, + ib.InvoiceNumber, + c.DebitorNumber, + null, null, null, + Round(si.Claim, 2) AS 'Betrag', + CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung', + null, null, null, 'EUR', + null, null, null, null, null, null, null, null, null, null, null, null, null, + 'G', '0', org.Name, null, null, + Round(si.Claim * -1, 2) AS 'Betrag2', + CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', ' Abrechnung :PeriodePunkt ', org.Name) as 'Verwendung2', null, + 'K', 0, '206222', null, null, null, null, null, Round(si.Claim * -1, 2) + FROM invoicebase ib + INNER JOIN settlementinvoice si on si.invoicebaseoid = ib.oid + INNER JOIN supportconcept sc on sc.oid = ib.supportconceptoid + INNER JOIN costbearer2supportconcept cb2sc on cb2sc.supportconceptoid = sc.oid + INNER JOIN costbearer cb on cb2sc.costbeareroid = cb.oid + INNER JOIN organisation org on org.costbeareroid = cb.oid + INNER JOIN customer c on c.oid = sc.customeroid + INNER JOIN person p on c.`PersonOid` = p.`Oid` + WHERE ib.type = 1 AND ib.isactive = 1 AND c.isactive <> 0 AND ib.`IsExported` = 0 + AND ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End' + ORDER BY 11 "; - - 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; - } - - private static String GetMonatlicheZuschlaegeStringSql(DateTime dt) - { - String sql = @" - -SELECT -cb2sc.oid, -c.oid, -sc.oid, -ib.InvoiceNumber, -c.DebitorNumber, -Round(ii.AmountTotal, 2) AS 'Forderung', -'1' as 'PauschalerFaktor', -ii.UnitCount AS`GeleisteteFLM` -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 ii.ItemDescription like 'Wohngruppenzuschlag%' -and ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End' -ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` -"; - return sql; } @@ -1039,31 +358,5 @@ ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate` 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 - - } } \ No newline at end of file