184 lines
8.7 KiB
C#
184 lines
8.7 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using DevExpress.XtraReports.UI;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Report;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BS.Shared.Core;
|
|
using System.Collections.Generic;
|
|
using BS.Shared.DataContracts;
|
|
using System.Linq;
|
|
using BS.Shared.Extensions;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace AutismusLeben
|
|
{
|
|
public partial class Spitzabrechnung2 : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<Settlement2RO>
|
|
{
|
|
public Spitzabrechnung2()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(Settlement2RO pRO)
|
|
{
|
|
if (pRO.InvoiceNumber.Length > 2)
|
|
pRO.InvoiceNumber = String.Format("3{0:MM}{0:yy}0{1}", pRO.AccountingEndDate, pRO.InvoiceNumber);
|
|
else
|
|
pRO.InvoiceNumber = String.Format("3{0:MM}{0:yy}00{1}", pRO.AccountingEndDate, pRO.InvoiceNumber);
|
|
|
|
decimal rateFactor = 1;
|
|
|
|
foreach (var ii in pRO.InvoiceItems)
|
|
{
|
|
if (ii.RateFactor.HasValue)
|
|
{
|
|
rateFactor = (100 + ii.RateFactor.Value) / 100;
|
|
}
|
|
|
|
if (pRO.FehlkontakteString != null && ii.RateFactor == 0)
|
|
{
|
|
Zwischensumme.Visible = true;
|
|
if (!ii.ItemDescription.IsNullOrEmpty())
|
|
{
|
|
ii.DetailDescription = Regex.Replace(ii.DetailDescription, ii.ItemDescription, "Fehlkontakte");
|
|
}
|
|
ii.ItemDescription = "Fehlkontakte";
|
|
}
|
|
else
|
|
{
|
|
ii.DetailDescription = string.Format("Fachleistungsstunden x {0:0.00} ({1:dd.MM.yyyy} - {2:dd.MM.yyyy})", rateFactor, ii.PeriodStartDate, ii.PeriodEndDate);
|
|
ii.ItemDescription = "Fachleistungsstunden";
|
|
}
|
|
}
|
|
|
|
pRO.RateFactor = (double)rateFactor;
|
|
|
|
var os = new OperationsServiceImp();
|
|
var accs = new AccountingServiceImp();
|
|
var span = new DateTimeSpan(pRO.AccountingStartDate, pRO.AccountingEndDate);
|
|
|
|
var invoiceBase = accs.GetSettlementByInvoiceBaseOid(pRO.InvoiceBaseOid.Value);
|
|
|
|
var abschlagszahlungen = os.GetAccountingTransactions(span, invoiceBase.SupportConceptOid, invoiceBase.CostBearer2SupportConceptOid); // ES FEHLEN BEIDE OIDs
|
|
Dictionary<string, decimal> gruppierteAbschlagszahlungen = GruppiereAbschlagszahlungen(pRO.InvoiceItems, abschlagszahlungen, pRO.AccountingStartDate, pRO.AccountingEndDate);
|
|
|
|
|
|
var rowCounter = 0;
|
|
while (rowCounter < gruppierteAbschlagszahlungen.Count)
|
|
{
|
|
if (rowCounter == 0)
|
|
{
|
|
table_Abschlagszahlungen.Rows.RemoveAt(0);
|
|
var row = new XRTableRow();
|
|
var baseCell0 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 51.75f };
|
|
var baseCell1 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 546.08f };
|
|
var baseCell2 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 99.17f };
|
|
|
|
baseCell0.Text = (rowCounter + 1).ToString();
|
|
baseCell1.Text = gruppierteAbschlagszahlungen.ElementAt(0).Key;
|
|
baseCell2.Text = string.Format("{0:c}", gruppierteAbschlagszahlungen.ElementAt(0).Value);
|
|
row.Cells.Add(baseCell0);
|
|
row.Cells.Add(baseCell1);
|
|
row.Cells.Add(baseCell2);
|
|
|
|
table_Abschlagszahlungen.Rows.Add(row);
|
|
rowCounter++;
|
|
}
|
|
else
|
|
{
|
|
for (rowCounter = rowCounter; rowCounter < gruppierteAbschlagszahlungen.Count; rowCounter++)
|
|
{
|
|
var row = new XRTableRow();
|
|
|
|
var baseCell0 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 51.75f };
|
|
var baseCell1 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 548.08f };
|
|
var baseCell2 = new XRTableCell() { Padding = 2, TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight, BorderColor = Color.Black, Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom, WidthF = 99.17f };
|
|
|
|
baseCell0.Text = (rowCounter + 1).ToString();
|
|
baseCell1.Text = gruppierteAbschlagszahlungen.ElementAt(rowCounter).Key;
|
|
baseCell2.Text = string.Format("{0:c}", gruppierteAbschlagszahlungen.ElementAt(rowCounter).Value);
|
|
|
|
row.Cells.Add(baseCell0);
|
|
row.Cells.Add(baseCell1);
|
|
row.Cells.Add(baseCell2);
|
|
|
|
table_Abschlagszahlungen.Rows.Add(row);
|
|
}
|
|
}
|
|
}
|
|
if (pRO.Claim >= 0)
|
|
tc_RueckzahlungOderRestbetrag.Text = "Restbetrag";
|
|
else
|
|
tc_RueckzahlungOderRestbetrag.Text = "Rückzahlung";
|
|
|
|
|
|
lblSchlusssatz.Text = string.Format("Zahlbar bis {0:dd.MM.yyyy} ohne Abzug.\nUmsatzsteuerfrei gemäß §4 Nr. 18 UStG.", pRO.InvoiceDate.AddDays(14));
|
|
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private Dictionary<string, decimal> GruppiereAbschlagszahlungen(List<Settlement2RO.SettlementInvoiceItemRO> invoiceItems, List<AccountingTransactionDC> abschlagszahlungen, DateTime accountingStartDate, DateTime accountingEndDate)
|
|
{
|
|
DateTime? letztesEnde = null;
|
|
Dictionary<string, decimal> gruppierteAbschlagszahlungen = new Dictionary<string, decimal>();
|
|
|
|
for (int i = 0; i < invoiceItems.Count; i++)
|
|
{
|
|
var item = invoiceItems[i];
|
|
if (item.ItemDescription.ToLower().Contains("fehlkontakt"))
|
|
continue;
|
|
|
|
// Wenn es das erste Item ist, also auch der erste Stundensatz, dann ist in der description das Ende ausgewiesen.
|
|
if (letztesEnde == null)
|
|
{
|
|
DateTime? ende = item.PeriodEndDate;
|
|
var zahlungenBisErstemStundensatzWechsel = abschlagszahlungen.Where(a => a.BookingDate <= ende.Value).ToList();
|
|
decimal summe = 0.0m;
|
|
foreach (var zahlung in zahlungenBisErstemStundensatzWechsel)
|
|
summe += zahlung.Amount;
|
|
|
|
string zeitraum = string.Format("Abschlagszahlung bis {0:dd.MM.yyyy}", ende.Value);
|
|
gruppierteAbschlagszahlungen.Add(zeitraum, summe);
|
|
letztesEnde = ende;
|
|
}
|
|
// Bei allen nachfolgenden Items muss geprüft werden, ob es noch ein nächstes Item gibt, weil in der Description nur der Anfang drin steht.
|
|
// Das Ende ist der Start - 1 des nächsten Items
|
|
else
|
|
{
|
|
DateTime? start = item.PeriodStartDate;
|
|
|
|
if (i < invoiceItems.Count - 1)
|
|
{
|
|
DateTime? ende = item.PeriodEndDate;
|
|
var zahlungenInZeitraum = abschlagszahlungen.Where(a => a.BookingDate >= start.Value && a.BookingDate <= ende.Value).ToList();
|
|
decimal summe = 0.0m;
|
|
foreach (var zahlung in zahlungenInZeitraum)
|
|
summe += zahlung.Amount;
|
|
|
|
//string zeitraum = string.Format("Abschlagszahlung {0:MMM yyyy} - {1:MMM yyyy}", start.Value, ende.Value);
|
|
string zeitraum = string.Format("Abschlagszahlung {0:dd.MM.yyyy} - {1:dd.MM.yyyy}", start.Value, ende.Value);
|
|
gruppierteAbschlagszahlungen.Add(zeitraum, summe);
|
|
letztesEnde = ende;
|
|
}
|
|
else
|
|
{
|
|
var zahlungenInZeitraum = abschlagszahlungen.Where(a => a.BookingDate >= start.Value).ToList();
|
|
decimal summe = 0.0m;
|
|
foreach (var zahlung in zahlungenInZeitraum)
|
|
summe += zahlung.Amount;
|
|
|
|
//string zeitraum = string.Format("Abschlagszahlung {0:MMM yyyy} - {1:MMM yyyy}", start.Value, accountingEndDate);
|
|
string zeitraum = string.Format("Abschlagszahlung ab {0:dd.MM.yyyy}", start.Value);
|
|
gruppierteAbschlagszahlungen.Add(zeitraum, summe);
|
|
}
|
|
}
|
|
}
|
|
|
|
return gruppierteAbschlagszahlungen;
|
|
}
|
|
}
|
|
}
|