327 lines
10 KiB
C#
327 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.XtraPrinting;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace BloemelingUndTeckhaus
|
|
{
|
|
public partial class SoziotherapieRechnung : XtraReport, IBeWoReport<ServiceInvoiceRO>
|
|
{
|
|
private decimal mEinheitenTotal = 0;
|
|
|
|
public List<SoziotherapieRow> SoziotherapieRowList { get; set; }
|
|
|
|
public SoziotherapieRechnung()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(ServiceInvoiceRO pRO)
|
|
{
|
|
var allServiceInvoiceItems = new List<ServiceInvoiceItemRO>();
|
|
pRO.ServiceInvoicePeriods.ForEach(f => allServiceInvoiceItems.AddRange(f.ServiceInvoiceItems));
|
|
|
|
var index = 0;
|
|
decimal? pauschale = 0m;
|
|
foreach (var item in allServiceInvoiceItems)
|
|
{
|
|
if (item.ServiceRecord == null && item.GrossAmount.IsNullOrEmpty())
|
|
{
|
|
pauschale = item.AmountPerUnit;
|
|
break;
|
|
}
|
|
index++;
|
|
}
|
|
if (pauschale != null && pauschale != 0)
|
|
{
|
|
allServiceInvoiceItems.RemoveAt(index);
|
|
}
|
|
int anzHausbesuche = 0;
|
|
if (allServiceInvoiceItems.Any(s => s.ServiceDescription != null && s.ServiceDescription.Contains("hausbesuch") || s.ServiceDescription != null && s.ServiceDescription.Contains("Hausbesuch")))
|
|
{
|
|
anzHausbesuche = allServiceInvoiceItems.Where(s => s.ServiceDescription != null && s.ServiceDescription.ToLower().Contains("hausbesuch")).Count();
|
|
tc_AnzHausbesuche.Text = anzHausbesuche.ToString();
|
|
tc_Fahrtkostenpauschale.Text = string.Format("{0:c}", pauschale.Value);
|
|
}
|
|
else
|
|
{
|
|
tc_AnzHausbesuche.Text = anzHausbesuche.ToString();
|
|
tc_Fahrtkostenpauschale.Text = "keine";
|
|
}
|
|
|
|
|
|
var gc = pRO.GrossClaim.Split(' ');
|
|
var gcAsDecimal = Convert.ToDecimal(gc[0]);
|
|
tc_GesamtOhnePauschale.Text = string.Format("{0:c}", (gcAsDecimal - pauschale.Value * anzHausbesuche));
|
|
tc_PauschaleGesamt.Text = string.Format("{0:c}", pauschale.Value * anzHausbesuche);
|
|
|
|
//decimal? unitSum = 0;
|
|
//pRO.ServiceInvoicePeriods.ForEach(fe => fe.ServiceInvoiceItems.ForEach(f => unitSum += f.UnitCount));
|
|
|
|
//xrTableCell123.Text = unitSum.ToString();
|
|
|
|
BuildSoziotherapieRow(pRO, allServiceInvoiceItems);
|
|
|
|
var firstRow = SoziotherapieRowList.FirstOrDefault();
|
|
|
|
if (firstRow != null)
|
|
{
|
|
var fr = xrTable3.Rows[0];
|
|
fr.Cells[0].Text = firstRow.Title;
|
|
for (var i = 1; i <= firstRow.Days.Length; i++)
|
|
{
|
|
var units = firstRow.Days[i - 1];
|
|
xrTable3.Rows[0].Cells[i].Text = units == 0 ? String.Empty : "X";
|
|
xrTable3.Rows[1].Cells[i].Text = units == 0 ? String.Empty : string.Format("{0:0.0}", units);
|
|
}
|
|
|
|
if (SoziotherapieRowList.Count > 1)
|
|
{
|
|
for (var j = 1; j < SoziotherapieRowList.Count; j++)
|
|
{
|
|
var obj = SoziotherapieRowList[j];
|
|
|
|
var newRow1 = xrTable3.InsertRowBelow(xrTable3.Rows[xrTable3.Rows.Count - 1]);
|
|
var newRow2 = xrTable3.InsertRowBelow(newRow1);
|
|
|
|
newRow1.Height = xrTable3.Rows[0].Height;
|
|
newRow2.Height = xrTable3.Rows[1].Height;
|
|
|
|
newRow1.Cells[0].Text = obj.Title;
|
|
newRow1.Cells[0].TextAlignment = TextAlignment.MiddleLeft;
|
|
newRow1.Cells[0].Padding = xrTable3.Rows[1].Cells[0].Padding;
|
|
newRow2.Cells[0].Text = "Therapieeinheit";
|
|
newRow2.Cells[0].TextAlignment = TextAlignment.MiddleLeft;
|
|
newRow2.Cells[0].Padding = xrTable3.Rows[1].Cells[0].Padding;
|
|
|
|
|
|
// 0 -> Therapieeinh.
|
|
// 1 -> 1.
|
|
for (var i = 1; i <= obj.Days.Length; i++)
|
|
{
|
|
var units = obj.Days[i - 1];
|
|
|
|
newRow1.Cells[i].Text = units == 0 ? String.Empty : "X";
|
|
newRow1.Cells[i].TextAlignment = TextAlignment.MiddleCenter;
|
|
newRow1.Cells[i].Padding = xrTable3.Rows[0].Cells[1].Padding;
|
|
|
|
newRow2.Cells[i].Text = units == 0 ? String.Empty : string.Format("{0:0.0}", units);
|
|
newRow2.Cells[i].TextAlignment = TextAlignment.MiddleCenter;
|
|
newRow2.Cells[i].Padding = xrTable3.Rows[0].Cells[1].Padding;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var period = pRO.ServiceInvoicePeriods.FirstOrDefault(f => f.Customer != null && f.Customer.Oid != null);
|
|
|
|
if (period != null && period.Customer != null && period.Customer.Oid != null)
|
|
{
|
|
if (pauschale != null && pauschale != 0)
|
|
{
|
|
period.ServiceInvoiceItems.RemoveAt(index);
|
|
}
|
|
var fod = period.ServiceInvoiceItems.FirstOrDefault();
|
|
if (fod != null && fod.AmountPerUnit != null)
|
|
{
|
|
cellBetragJeStunden.Text = fod.AmountPerUnit.Value.ToString("0.00 €");
|
|
}
|
|
|
|
|
|
}
|
|
cellAnzahlEinheitenGesamt.Text = String.Format("{0:0.0}", mEinheitenTotal);
|
|
|
|
SetAnbieterFields(pRO);
|
|
SetVarFields(pRO);
|
|
SetZwischenEndabrechnung(pRO);
|
|
|
|
var customer = GetCustomer(pRO);
|
|
var hauptbetreuer =
|
|
customer.Employee2CustomerList.FirstOrDefault(
|
|
e2c => e2c.ValueList.Any(ve => ve.Entry.SystemEntryID.HasValue && ve.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant));
|
|
if (hauptbetreuer != null && hauptbetreuer.Employee.Person.LastName.ToLower() == "blömeling" || hauptbetreuer != null && hauptbetreuer.Employee.Person.LastName.ToLower() == "bloemeling")
|
|
lblBuchungsnummer.Text = "8111";
|
|
else if (hauptbetreuer != null && hauptbetreuer.Employee.Person.LastName.ToLower() == "teckhaus")
|
|
lblBuchungsnummer.Text = "8112";
|
|
|
|
bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private void SetZwischenEndabrechnung(ServiceInvoiceRO pRO)
|
|
{
|
|
bool isZwischen = true;
|
|
if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
var sip = pRO.ServiceInvoicePeriods[0];
|
|
if (sip.CostBearer2SupportConcept != null)
|
|
{
|
|
if (pRO.AccountingPeriodEnd >= sip.CostBearer2SupportConcept.EndDate)
|
|
{
|
|
isZwischen = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
zwischenabrechnungsCB.Checked = isZwischen;
|
|
endabrechnungsCB.Checked = !isZwischen;
|
|
}
|
|
|
|
private void SetAnbieterFields(ServiceInvoiceRO pRO)
|
|
{
|
|
var cust = GetCustomer(pRO);
|
|
if (cust != null)
|
|
{
|
|
//foreach (var valueEntry in item.ValueList)
|
|
// {
|
|
// if (valueEntry.Entry.SystemEntryID != null && valueEntry.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant)
|
|
// {
|
|
var hauptbetreuer =
|
|
cust.Employee2CustomerList.FirstOrDefault(
|
|
e2c => e2c.ValueList.Any(ve => ve.Entry.SystemEntryID.HasValue && ve.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant));
|
|
|
|
//if (pRO.SenderContactPerson.Contains("Teckhaus"))
|
|
// cellIKNr.Text = "490 534 390";
|
|
//else if (pRO.SenderContactPerson.Contains("Blömeling"))
|
|
// cellIKNr.Text = "490 534 083";
|
|
}
|
|
}
|
|
|
|
private void SetVarFields(ServiceInvoiceRO pRO)
|
|
{
|
|
var c = GetCustomer(pRO);
|
|
if (c == null)
|
|
{
|
|
return;
|
|
}
|
|
foreach (var vv in c.VarFieldValueList)
|
|
{
|
|
var varFieldValue = Utils.XMLDeserializeFromString(vv.SerializedValue, Type.GetType(vv.TypeName));
|
|
if (varFieldValue != null)
|
|
{
|
|
var vValue = varFieldValue.ToString();
|
|
|
|
switch (vv.VarFieldDefOid)
|
|
{
|
|
case 1:
|
|
kassennrLabel.Text = vValue;
|
|
break;
|
|
case 2:
|
|
versichertennrLabel.Text = vValue;
|
|
break;
|
|
case 3:
|
|
statusLabel.Text = vValue;
|
|
break;
|
|
case 4:
|
|
vertragsarztNrLabel.Text = vValue;
|
|
break;
|
|
case 5:
|
|
vkGueltigBisLabel.Text = ((DateTime)varFieldValue).ToShortDateString();
|
|
break;
|
|
//case 6:
|
|
// cellBeginn.Text = ((DateTime)varFieldValue).ToShortDateString();
|
|
// break;
|
|
//case 7:
|
|
// cellBeendigung.Text = ((DateTime)varFieldValue).ToShortDateString();
|
|
// break;
|
|
case 8:
|
|
chkPlanmaessig.Checked = (bool)varFieldValue;
|
|
break;
|
|
case 9:
|
|
if (!String.IsNullOrEmpty(vValue))
|
|
{
|
|
chkAbbruch.Checked = true;
|
|
chkAbbruch.Text = vValue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private Customer GetCustomer(ServiceInvoiceRO pRO)
|
|
{
|
|
if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
var sip = pRO.ServiceInvoicePeriods[0];
|
|
if (sip.Customer != null)
|
|
{
|
|
return DAOFactory.GenericDAO.LoadByID<Customer>(sip.Customer.CustomerOid);
|
|
}
|
|
else
|
|
{
|
|
if (pRO.InvoiceBase.SupportConceptOid.HasValue)
|
|
{
|
|
var sc = DAOFactory.GenericDAO.LoadByID<SupportConcept>(pRO.InvoiceBase.SupportConceptOid.Value);
|
|
return sc.Customer;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return null;
|
|
}
|
|
|
|
public void BuildSoziotherapieRow(ServiceInvoiceRO pRO, IEnumerable<ServiceInvoiceItemRO> serviceItems)
|
|
{
|
|
SoziotherapieRowList = new List<SoziotherapieRow>();
|
|
|
|
DateTime start = pRO.AccountingPeriodStart;
|
|
|
|
while (start < pRO.AccountingPeriodEnd)
|
|
{
|
|
var title = String.Format("{0}. {1}", start.ToString("MMM"), start.ToString("yy"));
|
|
SoziotherapieRowList.Add(new SoziotherapieRow { Title = title });
|
|
start = start.AddMonths(1);
|
|
}
|
|
|
|
foreach (var item in serviceItems)
|
|
{
|
|
if (!item.AccountingPeriodStart.HasValue)
|
|
continue;
|
|
|
|
var date = item.AccountingPeriodStart.Value;
|
|
var title = String.Format("{0}. {1}", date.ToString("MMM"), date.ToString("yy"));
|
|
|
|
if (!SoziotherapieRowList.Any(a => a.Title.Equals(title)))
|
|
{
|
|
SoziotherapieRowList.Add(new SoziotherapieRow { Title = title });
|
|
}
|
|
|
|
var row = SoziotherapieRowList.First(f => f.Title.Equals(title));
|
|
|
|
decimal stunden = 0;
|
|
if (item.Hours.HasValue)
|
|
{
|
|
stunden = item.Hours.Value;
|
|
}
|
|
|
|
row.Days[item.AccountingPeriodStart.Value.Day - 1] += stunden;
|
|
|
|
mEinheitenTotal += stunden;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SoziotherapieRow
|
|
{
|
|
public String Title { get; set; }
|
|
|
|
public decimal[] Days { get; set; }
|
|
|
|
public SoziotherapieRow()
|
|
{
|
|
Title = string.Empty;
|
|
Days = new decimal[31];
|
|
}
|
|
}
|
|
} |