Files
BeWoPlaner/ReportImp/PraxisPusteblume/IfsEingangsdiagnostikRechnung.cs
Christian dbed05ccb2 cb
2018-11-22 14:05:45 +01:00

272 lines
8.9 KiB
C#

using System;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.ServiceImplementations;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using DevExpress.XtraReports.UI;
using PraxisPusteblume.Invoicing;
namespace PraxisPusteblume
{
[IDSpecificClass(Identifier = "Eingangsdiagnostik")]
public partial class IfsEingangsdiagnostikRechnung : XtraReport, IBeWoReport<ServiceInvoiceRO>
{
public IfsEingangsdiagnostikRechnung()
{
this.InitializeComponent();
}
public void SetReportDataSource(ServiceInvoiceRO pRO)
{
StringBuilder sb = new StringBuilder();
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
{
if (pRO.RecipientOrganisation.EndsWith(" - IFS"))
{
pRO.RecipientOrganisation = pRO.RecipientOrganisation.Replace(" - IFS", "").Trim();
}
sb.AppendLine(pRO.RecipientOrganisation);
}
if (!String.IsNullOrEmpty(pRO.RecipientDivision))
{
sb.AppendLine(pRO.RecipientDivision);
}
if (!String.IsNullOrEmpty(pRO.RecipientStreet))
{
sb.AppendLine(pRO.RecipientStreet);
}
if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown))
{
sb.AppendLine(pRO.RecipientPostCodeAndTown);
}
lblAdresse.Text = sb.ToString();
lblNachweisFuer.Text = String.Format("Klient/in: {0}, geb. am {1:dd.MM.yyyy}",
pRO.CustomerName, pRO.CustomerBirthdate);
lblMonatJahr.Text = String.Format("Abrechnungsmonat:: {0:MM}/{0:yyyy}", pRO.AccountingPeriodStart);
//var stats = GetStatistics(pRO);
//if (stats != null)
//{
// lblReststunden.Text = String.Format("Reststunden: {0:0.##}",
// (stats.MinutesApprovedTotal - stats.MinutesProvidedTotal) / 60);
//}
//lblAZ.Text = pRO.CustomerReferenceNumber;
//if (pRO.InvoiceDateTime.HasValue)
// pRO.Notice = String.Format("{0:dd.MM.yyyy}", pRO.InvoiceDateTime.Value.AddDays(30));
// if (pRO.ServiceInvoicePeriods != null)
// {
// foreach (var sip in pRO.ServiceInvoicePeriods)
// {
// if (sip.ServiceInvoiceItems != null)
// {
// foreach (var ii in sip.ServiceInvoiceItems)
// {
// ii.ServiceDescription = String.Format("{0}\n{1}", ii.ServiceDescription, ii.Notice);
// ii.CustomerFirstname = String.Format("{0:c}", ii.AmountPerUnit);
// if (!String.IsNullOrEmpty(ii.RateFactor))
// {
//var rfStr = ii.RateFactor.Replace("%", "").Replace(",00", "").Trim();
//int rfInt = 0;
//Int32.TryParse(rfStr, out rfInt);
//if (rateFactor > 1)
//{
// ii.CustomerFirstname = String.Format("{0} x {1:0.##}", ii.CustomerFirstname, rateFactor);
//}
//else
//{
// ii.CustomerFirstname = String.Format("{0}", ii.CustomerFirstname);
//}
// }
// }
// }
// }
// }
//SetCustomerInfos(pRO);
//cellDesription.Text = String.Format("Fachleistungsstunden {0:MM}/{0:yyyy}", pRO.AccountingPeriodStart);
decimal hourlyRateMobil = 0;
decimal hourlyRateAmbulant = 0;
decimal rateFactor = 1;
decimal hoursMobil = 0;
decimal hoursAmbulant = 0;
bool ismobil = false;
if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
{
foreach (var p in pRO.ServiceInvoicePeriods)
{
if (p.ServiceInvoiceItems != null && p.ServiceInvoiceItems.Count > 0)
{
foreach (var i in p.ServiceInvoiceItems)
{
i.CustomerFirstname = "";
i.CustomerLastname = "";
i.ServiceDescription = "";
if (i.ServiceRecord != null)
{
i.ServiceDescription = i.ServiceRecord.ServiceDescription.CategoryName;
if (i.ServiceRecord.ServiceDescription.Name.ToLower().Contains("mobil"))
{
ismobil = true;
i.CustomerFirstname = "x";
}
else if (i.ServiceRecord.ServiceDescription.Name.ToLower().Contains("ambulant"))
{
i.CustomerLastname = "x";
}
}
if (i.UnitCount.HasValue)
{
i.UnitCountString = InvoiceHelper.GetUnitString(i.UnitCount);
}
if (i.HourlyRate.HasValue)
{
if (ismobil)
{
hourlyRateMobil = i.HourlyRate.Value;
}
else
{
hourlyRateAmbulant = i.HourlyRate.Value;
}
if (!String.IsNullOrEmpty(i.RateFactor))
{
var rfStr = i.RateFactor.Replace("%", "").Replace(",00", "").Trim();
int rfInt = 0;
Int32.TryParse(rfStr, out rfInt);
rateFactor = (100m + rfInt) / 100m;
}
}
if (i.Hours.HasValue)
{
if (ismobil)
{
hoursMobil += i.Hours.Value;
}
else
{
hoursAmbulant += i.Hours.Value;
}
}
}
}
}
}
hoursMobil *= rateFactor;
hoursAmbulant *= rateFactor;
cellClaimGesamt.Text = String.Format("{0} Euro", pRO.NetClaim.Replace("€", "").Trim());
this.bindingSource1.DataSource = pRO;
}
private SupportConceptStatisticsDC GetStatistics(ServiceInvoiceRO ro)
{
if (ro.InvoiceBase.SupportConceptCostBearerRelDc != null)
{
var service = new OperationsServiceImp();
long cb2scOid = ro.InvoiceBase.SupportConceptCostBearerRelDc.CostBearer2SupportConceptOid.Value;
return service.CreateSupportConceptStatistics(cb2scOid, ro.AccountingPeriodEnd);
//if (stats.PeriodStatistics != null && stats.PeriodStatistics.Count > 0)
//{
// foreach (var ps in stats.PeriodStatistics)
// {
// if (ps.SupportConceptApprovalPeriod != null &&
// ps.SupportConceptApprovalPeriod.ServiceCategory != null &&
// (ps.SupportConceptApprovalPeriod.ServiceCategory.Name.StartsWith("Verhinderung") ||
// ps.SupportConceptApprovalPeriod.ServiceCategory.Name.StartsWith("Betreuungsleistungen")))
// {
// return ps;
// }
// }
//}
//return null;
}
return null;
}
private void SetCustomerInfos(ServiceInvoiceRO pRO)
{
String mnr = String.Empty;
Customer c = null;
if (pRO.CustomerOid.HasValue)
{
c = DAOFactory.GenericDAO.LoadByID<Customer>(pRO.CustomerOid.Value);
}
if (c == null)
{
if (pRO.ServiceInvoicePeriods.Count > 0)
{
var c2s = pRO.ServiceInvoicePeriods[0].CostBearer2SupportConcept;
c = c2s.SupportConcept.Customer;
}
}
if (c != null)
{
foreach (var vv in c.VarFieldValueList)
{
if (vv.VarFieldDefOid.Value == 2)
{
var varFieldValue = Utils.XMLDeserializeFromString(vv.SerializedValue, Type.GetType(vv.TypeName));
if (varFieldValue != null)
{
mnr = varFieldValue.ToString();
}
}
}
}
//txtMittelbindungsnr.Text = mnr;
}
}
}