Files
BeWoPlaner/ReportImp/SawoReports/ServicesOverviewReport.cs
Christian b76d6ea7d1 Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/BeWo
# Conflicts:
#	Data/Access/SearchDAO.cs
2018-03-02 16:24:55 +01:00

327 lines
12 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared.Core;
using DevExpress.XtraReports.UI;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using BeWo.Service.DCEntityMapper;
namespace SawoReports
{
public partial class Stundenzettel : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
{
private Dictionary<string, decimal> key2Pflegeeinheiten = new Dictionary<string, decimal>();
private Dictionary<string, decimal> key2Wegepauschale = new Dictionary<string, decimal>();
private decimal totalEinheiten1 = 0;
private decimal totalEinheiten2 = 0;
private decimal totalWegepWochentags1 = 0;
private decimal totalWegepWochentags2 = 0;
private decimal totalWegepWochenende1 = 0;
private decimal totalWegepWochenende2 = 0;
public Stundenzettel()
{
InitializeComponent();
}
public void SetReportDataSource(ServicesOverviewRO ro)
{
//cellMonat1.Text = String.Format("{0:MMM yy}", ro.StartDate);
lblZeitraum.Text = String.Format("Zeitraum {0:dd.MM.yyyy} - {1:dd.MM.yyyy}", ro.StartDate, ro.EndDate);
InitRows(ro);
if (ro.Services != null)
{
foreach (ServicesOverviewRO.ServiceDetail s in ro.Services)
{
AddDetailToTable(ro, s);
}
}
lblCustomer.Text = String.Format("Klient: {0}, {1}, {2}, {3} {4}, {5}", ro.CustomerLastName,
ro.CustomerFirstName, ro.CustomerStreet, ro.CustomerPostalCode, ro.CustomerCity, ro.ReferenceNumber);
if (String.IsNullOrEmpty(ro.Costbearer))
{
ro.Costbearer = HoleErstenKostentraeger(ro);
}
//cellPreis1.Text = String.Format("{0:c}", totalEuro1);
//cellPreis2.Text = String.Format("{0:c}", totalEuro2);
//cellPreis3.Text = String.Format("{0:c}", totalEuro3);
//lblSummeEinheiten1.Text = String.Format("{0:0}", totalEinheiten1);
//lblSummeWegepWochentags1.Text = String.Format("{0:0}", totalWegepWochentags1);
//lblSummeWegepWochenende1.Text = String.Format("{0:0}", totalWegepWochenende1);
//lblPflegeeinheitenTotal.Text = String.Format("Anzahl Pflegeeinheiten:{0:0}", totalEinheiten1 + totalEinheiten2);
//cellStunden1.Text = String.Format("{0:0.00}", totalStunden1 / 60);
//cellStunden2.Text = String.Format("{0:0.00}", totalStunden2 / 60);
//cellStunden3.Text = String.Format("{0:0.00}", totalStunden3 / 60);
//Customer c = GetCustomer(ro);
//if (c != null)
//{
// var dcList = MapperFactory.CustomerPersonRelationDC_Customer2Person.MapToNewDCs(c.Customer2PersonList);
// var x =
// dcList.FirstOrDefault(
// f => f.RelationRole.TypeDescription.ToLower().Equals("facharzt (psychiater)"));
// if (x != null)
// {
// lblArzt.Text = x.Person.TitleFirstNameLastNameToString();
// }
//}
this.bindingSource1.DataSource = ro;
}
private string HoleErstenKostentraeger(ServicesOverviewRO ro)
{
if (ro.CostBearer2SupportConceptList == null || ro.CostBearer2SupportConceptList.Count == 0)
{
if (ro.SupportConceptCostBearer == null)
{
if (ro.CustomerOid > 0)
{
var c = DAOFactory.GenericDAO.LoadByID<Customer>(ro.CustomerOid);
foreach (var sc in c.SupportConcepts)
{
foreach (var c2s in sc.CostBearer2SupportConceptList)
{
if (c2s.StartDate.HasValue && c2s.EndDate.HasValue && c2s.StartDate <= ro.EndDate &&
c2s.EndDate >= ro.StartDate)
{
return c2s.CostBearer.Organisation.Name;
}
}
}
}
}
}
return ro.Costbearer;
}
private void InitRows(ServicesOverviewRO ro)
{
DateTime start = ro.StartDate;
int idx = 0;
while (start < ro.StartDate.AddMonths(1))
{
var cellIdx = 2 + idx++;
rowWochentage.Cells[cellIdx].Text = String.Format("{0:dd\nddd}", start);
if (IstWochentagOderFeiertag(start))
{
rowWochentage.Cells[cellIdx].BackColor = Color.LightGray;
tableRowPflegeeinheiten1.Cells[cellIdx].BackColor = Color.LightGray;
row2.Cells[cellIdx].BackColor = Color.LightGray;
row3.Cells[cellIdx].BackColor = Color.LightGray;
}
start = start.AddDays(1);
}
while (idx < 31)
{
rowWochentage.Cells[2 + idx++].Text = "";
}
}
private Customer GetCustomer(ServicesOverviewRO ro)
{
if (ro.CostBearer2SupportConceptList != null && ro.CostBearer2SupportConceptList.Count > 0)
{
return ro.CostBearer2SupportConceptList[0].SupportConcept.Customer;
}
return null;
}
private void AddDetailToTable(ServicesOverviewRO ro, ServicesOverviewRO.ServiceDetail sd)
{
var table = tableMonat1;
SetTableText(table, sd);
}
private void SetTableText(XRTable table, ServicesOverviewRO.ServiceDetail sd)
{
XRTableCell cell = null;
int column = 1 + sd.StartDate.Day;
XRTableRow row = null;
XRTableRow wegepauschaleRow = null;
XRTableRow uhrzeitRow = null;
String text = "";
String key = String.Format("{0}_{1}", table.Name, column);
decimal decimalValue = 0;
bool firstValue = true;
if (key2Pflegeeinheiten.ContainsKey(key))
{
decimalValue = key2Pflegeeinheiten[key];
if (decimalValue > 0)
{
firstValue = false;
}
}
if (sd.ServiceCategory == "Entlastungsleistung § 45 b")
{
//int einheiten = (int)Math.Floor(sd.Minutes/60);
decimal einheiten = (decimal)sd.Minutes / 60m;
bool wegepauschale = false;
if (!key2Wegepauschale.ContainsKey(key))
{
wegepauschale = true;
key2Wegepauschale.Add(key, 1);
}
row = tableRowPflegeeinheiten1;
uhrzeitRow = tableRowUhrzeit1;
totalEinheiten1 += einheiten;
//if (wegepauschale)
//{
// if (IstWochentagOderFeiertag(sd.StartDate))
// {
// totalWegepWochenende1++;
// wegepauschaleRow = tableRowWegepWochenende1;
// }
// else
// {
// totalWegepWochentags1++;
// wegepauschaleRow = tableRowWegepWochentags1;
// }
//}
decimalValue += einheiten;
text = String.Format("{0:0.#}", decimalValue);
row.Cells[column].Text = text;
if (wegepauschaleRow != null)
{
wegepauschaleRow.Cells[column].Text = "1";
}
if (uhrzeitRow != null && firstValue)
{
uhrzeitRow.Cells[column].Text = String.Format("{0:HH:mm}", sd.StartDate);
}
}
key2Pflegeeinheiten[key] = decimalValue;
}
private bool IstWochentagOderFeiertag(DateTime dt)
{
if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
{
return true;
}
return false;
}
public virtual bool IstFeiertag(DateTime start)
{
List<DateTime> feiertage = GetFeiertage(start.Year);
foreach (var ft in feiertage)
{
if (start.Date == ft)
return true;
}
return false;
}
public virtual List<DateTime> GetFeiertage(int year)
{
List<DateTime> list = new List<DateTime>();
list.Add(new DateTime(year, 1, 1)); // "Neujahr"));
//list.Add(new DateTime(year, 1, 6)); // , "Heilige Drei Könige"));
list.Add(new DateTime(year, 5, 1)); // , "Tag der Arbeit"));
//list.Add(new DateTime(year, 8, 15)); // , "Mariä Himmelfahrt"));
list.Add(new DateTime(year, 10, 3)); // , "Tag der dt. Einheit"));
//list.Add(new DateTime(year, 11, 1)); // , "Allerheiligen "));
//list.Add(new DateTime(year, 12, 24)); // , "Heilig Abend"));
list.Add(new DateTime(year, 12, 25)); // , "1. Weihnachtstag"));
list.Add(new DateTime(year, 12, 26)); // , "2. Weihnachtstag"));
if (year == 2017)
{
list.Add(new DateTime(year, 10, 31)); // , "Reformationstag"));
}
DateTime osterSonntag = GetOsterSonntag(year);
//list.Add(osterSonntag); // , "Ostersonntag"));
//list.Add(osterSonntag.AddDays(-3)); // , "Gründonnerstag")); q
//list.Add(osterSonntag.AddDays(-48)); // , "Rosenmontag"));
list.Add(osterSonntag.AddDays(-2)); // , "Karfreitag"));
list.Add(osterSonntag.AddDays(1)); // , "Ostermontag"));
list.Add(osterSonntag.AddDays(39)); // , "Christi Himmelfahrt"));
//list.Add(osterSonntag.AddDays(49)); // , "Pfingstsonntag"));
list.Add(osterSonntag.AddDays(50)); // , "Pfingstmontag"));
//list.Add(osterSonntag.AddDays(60)); // , "Fronleichnam"));
//01.01. Neujahr
//01.05. Tag der Arbeit
//03.10. Tag der Deutschen Einheit
//01.11. Allerheiligen
//25.12. 1. Weihnachtstag
//26.12. 2. Weihnachtstag
//Karfreitag
//Ostermontag
//Christi Himmelfahrt (39 Tage nach Ostersonntag)
//Pfingstmontag (50 Tage nach Ostersonntag)
//Fronleichnam (60 Tage nach Ostersonntag)
//24.12. Heilig Abend
return list;
}
protected DateTime GetOsterSonntag(int year)
{
int g, h, c, j, l, i;
g = year % 19;
c = year / 100;
h = ((c - (c / 4)) - (((8 * c) + 13) / 25) + (19 * g) + 15) % 30;
i = h - (h / 28) * (1 - (29 / (h + 1)) * ((21 - g) / 11));
j = (year + (year / 4) + i + 2 - c + (c / 4)) % 7;
l = i - j;
int month = (int)(3 + ((l + 40) / 44));
int day = (int)(l + 28 - 31 * (month / 4));
return new DateTime(year, month, day);
}
}
}