CaritasverbandDuerenJuelichEV/Export/DiamantExporter.cs - 1.0 - warte noch auf Angaben aus Buchhaltung

This commit is contained in:
2024-08-19 17:12:17 +02:00
parent a03d30883e
commit c4b947e776
4 changed files with 231 additions and 476 deletions

View File

@@ -58,6 +58,8 @@
<Compile Include="Calculations\CustomServiceRecordStatisticFactory.cs" />
<Compile Include="Export\CustomDataExporter.cs" />
<Compile Include="Export\DiamantExporter.cs" />
<Compile Include="Invoicing\CustomInvoiceCreation.cs" />
<Compile Include="Invoicing\CustomInvoiceFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View File

@@ -15,12 +15,9 @@ namespace CaritasverbandDuerenJuelichEV.Export
public static QueryDC CreateQuery(QueryDC query)
{
DateTime dt = DateTime.Now;
DateTime.TryParse(query.Parameter[0].Value.ToString(), out dt);
if (query.Title == "Diamant Export Stammdaten")
{
query.FileName = String.Format("005S{0:yyMM}.er2", dt);
@@ -157,7 +154,7 @@ namespace CaritasverbandDuerenJuelichEV.Export
public static String GetAbrechnungenString(DateTime date, long? customerOid)
{
StringBuilder sb = new StringBuilder();
var s = GetMonatlicheAbrechnungLvrString(date, customerOid);
var s = GetMonatlicheAbrechnungString(date, customerOid);
if (!String.IsNullOrWhiteSpace(s))
{
sb.Append(s);
@@ -165,173 +162,187 @@ namespace CaritasverbandDuerenJuelichEV.Export
if (sb.Length > 0)
sb.AppendLine();
//s = GetAbschlagszahlungenString(date);
//if (!String.IsNullOrWhiteSpace(s))
//{
// sb.Append(s);
//}
//if (sb.Length > 0)
// sb.AppendLine();
//s = GetSelbstzahlerString(date);
//if (!String.IsNullOrWhiteSpace(s))
//{
// sb.Append(s);
//}
return sb.ToString();
}
public static String GetMonatlicheAbrechnungLvrString(DateTime date, long? customerOid)
public static String GetMonatlicheAbrechnungString(DateTime date, long? customerOid)
{
var dt = ExecuteQuery(GetMonatlicheAbrechnungLvrSql(date, customerOid), 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 - 1; i++)
{
if (i > 0)
{
sb.Append(",");
}
//if (i == 32)
//{
// sb.AppendLine();
//}
var item = row[i];
bool quote = i == 15 || i == 35;
// 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 = GetMonatlicheAbrechnungSql();
var dt = ExecuteQuery(sql, date);
if (quote)
StringBuilder sb = new StringBuilder();
List<DataRow> mergedRows = new List<DataRow>();
Dictionary<string, DataRow> oid2Row = new Dictionary<string, DataRow>();
foreach (DataRow row in dt.Rows)
{
string oid = row[0].ToString();
bool storno = false;
if (!oid2Row.ContainsKey(oid))
{
sb.Append('"');
sb.Append(item);
sb.Append('"');
oid2Row.Add(oid, row);
if (sb.Length > 0)
{
sb.AppendLine();
}
for (int i = startIdx; i < row.ItemArray.Length; i++)
{
var item = row[i];
if (i == 15 || i == 39 || i == 50)
{
decimal betrag = ErzeugeBetrag(item);
if (betrag != 0)
{
if (betrag < 0)
{
storno = true;
}
sb.Append(String.Format("{0:0.00}", betrag));
sb.Append(";");
}
}
else if (i == 16)
{
sb.Append('"');
sb.Append(item);
sb.Append('"');
}
else if (i == stopIdx1)
{
sb.AppendLine();
sb.Append(item);
sb.Append(";");
}
else if (i == 36)
{
string konto = SetKonto(item);
sb.Append(String.Format("{0}", konto));
sb.Append(";");
}
else if (i == 40)
{
sb.Append('"');
sb.Append(item);
sb.Append('"');
}
else if (i == stopIdx2)
{
sb.AppendLine();
sb.Append(item);
sb.Append(";");
}
else if (i == 44)
{
var position = item.ToString();
if (position.ToLower().Contains("ufh") || position.ToLower().Contains("kasse"))
{
sb.Append("20072;");
}
else
{
sb.Append("20002;");
}
}
else
{
sb.Append(item);
sb.Append(";");
}
}
}
else
{
sb.Append(item);
if (sb.Length > 0)
{
sb.AppendLine();
}
for (int i = startIdx; i < row.ItemArray.Length; i++)
{
var item = row[i];
// mach nichts mit den ersten Spalten -> erstelle nur Kostenstellen
if (i == stopIdx2)
{
sb.Append(item);
sb.Append(";");
}
else if (i == 50)
{
decimal betrag = ErzeugeBetrag(item);
if (betrag != 0)
{
sb.Append(String.Format("{0:0.00}", betrag * -1));
sb.Append(";");
}
}
else if (i == 44)
{
var position = item.ToString();
if (position.ToLower().Contains("ufh") || position.ToLower().Contains("kasse"))
{
sb.Append("20072;");
}
else
{
sb.Append("20002;");
}
}
else if (i > stopIdx2)
{
sb.Append(item);
sb.Append(";");
}
}
}
}
ErstelleKostenstellenZeilen(row, sb);
}
//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 void ErstelleKostenstellenZeilen(DataRow row, StringBuilder sb)
{
if (row.ItemArray.Length > 15)
{
var betragObj = row[14];
decimal gesamtbetrag = 0;
if (betragObj != null)
{
Decimal.TryParse(betragObj.ToString().Replace(".", ","), out gesamtbetrag);
}
var kstItem = row[row.ItemArray.Length - 1];
String kst = "";
if (kstItem != null)
kst = kstItem.ToString();
sb.AppendLine();
sb.Append(String.Format("K,0,{0},,v,,,,", kst));
sb.Append(String.Format("{0:0.00}", gesamtbetrag).Replace(",", "."));
sb.Append(",,4419,,,,,,");
return sb.ToString();
}
}
public static String GetAbschlagszahlungenString(DateTime date)
private static string SetKonto(object item)
{
var dt = ExecuteQuery(GetAbschlagszahlungenSql(date), date);
StringBuilder sb = new StringBuilder();
foreach (DataRow row in dt.Rows)
string konto = "84290"; // Default SPFH Kreis
if (item != null)
{
if (sb.Length > 0)
if (item.ToString().ToLower().Contains("spfh") && item.ToString().ToLower().Contains("stadt"))
{
sb.AppendLine();
konto = "84291";
}
for (int i = 0; i < row.ItemArray.Length; i++)
else if (item.ToString().ToLower().Contains("ufh") && item.ToString().ToLower().Contains("aok")) //derzeit nur ein Einzelfall
{
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);
}
konto = "84281";
}
else if (item.ToString().ToLower().Contains("ufh") && item.ToString().ToLower().Contains("selbstzahler"))
{
konto = "84283";
}
if (item.ToString().ToLower().Contains("ufh")) // Standard für UFH
{
konto = "84282";
}
}
//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();
return konto;
}
public static String GetSelbstzahlerString(DateTime date)
public static decimal ErzeugeBetrag(object betragObj)
{
var dt = ExecuteQuery(GetSelbstzahlerSql(date), date);
StringBuilder sb = new StringBuilder();
foreach (DataRow row in dt.Rows)
decimal gesamtbetrag = 0;
if (betragObj != null)
{
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);
}
}
Decimal.TryParse(betragObj.ToString().Replace(".", ","), out gesamtbetrag);
}
return sb.ToString();
decimal betrag = Math.Round(gesamtbetrag, 2, MidpointRounding.AwayFromZero);
return betrag;
}
private static String GetDebitorenSql(DateTime date)
@@ -382,330 +393,53 @@ order by p.`LastName`, p.FirstName
return sql;
}
private static String GetMonatlicheAbrechnungLvrSql(DateTime date, long? customerOid)
private static String GetMonatlicheAbrechnungSql()
{
//REPLACE(Round(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)) -IF(etbl.eigenanteil is null, 0, etbl.eigenanteil), 2), ',', '.') AS 'Betrag',
String sql = @"
(SELECT
SELECT
CONCAT(cb2sc.Oid, ib.InvoiceNumber, Round(sip.Claim, 0)) AS OID,
'F',
'0',
'005',
null,
'114',
null,
'BEWO',
'AR',
':Abrechnungsmonat',
':Periode',
null,
null,
c.DebitorNumber,
'4419',
null,
'0%',
REPLACE(
Round(
Round(
IF (crpRateFactor.`CostRateValue` is null, 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),
ROUND(ROUND((sr.`GeleisteteFLM` / 60), 2) * ((100 + crpRateFactor.`CostRateValue`)/100), 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 ))
, 2)
- IF(etbl.eigenanteil is null, 0, etbl.eigenanteil)
, 2)
, ',', '.') AS 'Betrag',
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'Verwendung',
null,
null,
'EUR',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
'R',
null,
null,
null,
null,
null,
CONCAT(p.`LastName`, ', ', p.`FirstName`) as 'Verwendung2',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
c.CostCenter
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`
LEFT JOIN
(select ib.supportconceptoid, sum(ii.Amounttotal) as eigenanteil
from invoicebase ib
inner join invoiceitem ii on ii.invoicebaseoid = ib.oid
WHERE ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End'
and ib.type = 0 and ib.isactive = 1 GROUP BY ib.supportconceptoid) as etbl on etbl.supportconceptoid = sc.oid
WHERE c.`IsActive` <> 0 AND sc.`IsActive` <> 0
and (sr.`GeleisteteFLM` is not null)#ReplaceCustomerOid#)
UNION
(SELECT
'F',
'0',
'005',
null,
null,
'AR',
':Abrechnungsmonat',
':Periode',
null,
null,
(select SUBSTRING(vv.`SerializedValue`, 50, LENGTH(vv.`SerializedValue`) - 58) from `varfieldvalue` vv where vv.`VarFieldDefOid` = 1 and vv.`ObjectOid` = c.`Oid` and vv.`ObjectTid` = 8),
'4419',
null,
'0%',
REPLACE(Round(IF(etbl.eigenanteil is null, 0, etbl.eigenanteil), 2), ',', '.') AS 'Betrag',
CONCAT(p.`LastName`, ', ', p.`FirstName`, ', Eigenanteil') as 'Verwendung',
null,
null,
'EUR',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
'R',
null,
null,
null,
null,
null,
CONCAT(p.`LastName`, ', ', p.`FirstName`, ', Eigenanteil') as 'Verwendung2',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
c.CostCenter
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`
INNER JOIN
(select ib.supportconceptoid, sum(ii.Amounttotal) as eigenanteil
from invoicebase ib
inner join invoiceitem ii on ii.invoicebaseoid = ib.oid
WHERE ib.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End'
and ib.type = 0 and ib.isactive = 1 GROUP BY ib.supportconceptoid) as etbl on etbl.supportconceptoid = sc.oid
WHERE c.`IsActive` <> 0 AND sc.`IsActive` <> 0
and (sr.`GeleisteteFLM` is not null)#ReplaceCustomerOid#) ORDER BY Verwendung";
if (customerOid.HasValue)
{
sql = sql.Replace("#ReplaceCustomerOid#", String.Format(" and c.Oid = {0}", customerOid));
}
else
{
sql = sql.Replace("#ReplaceCustomerOid#", "");
}
//ORDER BY p.`LastName`, p.`FirstName`, cb2sc.`ApprovedStartDate`
return sql;
}
private static String GetAbschlagszahlungenSql(DateTime date)
{
String sql = @"
SELECT
'F',
'0',
'005',
null,
'BEWO',
'DA',
':Abrechnungsmonat',
':Periode',
null,
null,
ib.InvoiceNumber,
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,
'R',
null,
null,
'G',
'0',
'xxxx',
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`
Round(sip.Claim, 2) AS 'Betrag',
CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :Periode ', org.Name) as 'Verwendung',
null, null, null, 'EUR',
null, null, null, null, null, null, null, null, null, null, null, null, null,
'G', '0', CONCAT(ii.ItemDescription, ' ', org.Name), null, null,
Round(sip.Claim * -1, 2) AS 'Betrag2',
CONCAT(p.`LastName`, ', ', p.`FirstName`, ' ', IF(cb2sc.CustomerRefenrenceNumber is null, '', cb2sc.CustomerRefenrenceNumber), ' Abrechnung :Periode ', 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.`AccountingPeriodEnd` >= ':Monat_Start' AND ib.`AccountingPeriodStart` < ':Monat_End'
ORDER BY ib.invoicenumber
";
return sql;
}
private static String GetSelbstzahlerSql(DateTime date)
{
String sql = @"
SELECT
'F',
'0',
'005',
null,
'BEWO',
'DA',
':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,
'R',
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;
}
public static DataTable ExecuteQuery(String sql, DateTime dt)
{
var newsql = sql;
@@ -718,31 +452,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
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Invoicing;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Services;
namespace CaritasverbandDuerenJuelichEV.Invoicing
{
public class CustomInvoiceCreation : InvoiceCreation
{
public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, BS.Shared.Services.Calculations calc)
{
var ii = base.CreateInvoiceItem(iServiceRecord, scap, calc);
ii.ItemDescription = iServiceRecord.ServiceDescription.CategoryName;
return ii;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using BeWo.Service.Invoicing;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
namespace CaritasverbandDuerenJuelichEV.Invoicing
{
public class CustomInvoiceFactory : InvoiceFactory
{
public override InvoiceCreation CreateInvoiceCreator(string specificId, string tenant, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
{
return new CustomInvoiceCreation();
}
}
}