Files
BeWoPlaner/ReportImp/MitMenschenWuppertal/Fahrtkostenauswertung.cs
Christian fd164962f2 cb
2022-12-15 23:16:04 +01:00

160 lines
4.7 KiB
C#

using System;
using System.Linq;
using BS.Shared;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Data.Entities;
using BeWo.Data.Access;
using System.Collections.Generic;
using BeWo.Service.DCEntityMapper;
using BS.Shared.Core;
using BS.Shared.Services;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
//using BeWo.Service.DCEntityMapper;
namespace MitMenschenWuppertal
{
public partial class Fahrtkostenauswertung : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<QueryRO>
{
public Fahrtkostenauswertung()
{
InitializeComponent();
}
public void SetReportDataSource(QueryRO pRO)
{
this.bindingSource1.DataSource = CreateDataSource(pRO);
}
private QueryRO CreateDataSource(QueryRO ro)
{
DateTime dt;
if (DateTime.TryParse(ro.Rows[0].Field2.ToString(), out dt))
{
lblMonat.Text = String.Format("{0:MMMM yyyy}", dt);
}
IList<Employee> empListe = new List<Employee>();
long oid;
Int64.TryParse(ro.Rows[0].Field1.ToString(), out oid);
if (oid > 0)
{
Employee emp = DAOFactory.GenericDAO.GetByID<Employee>(oid);
empListe.Add(emp);
}
else
{
empListe = DAOFactory.GenericDAO.GetAllActive<Employee>();
}
QueryRO newQueryRo = new QueryRO();
decimal? preisProKm = null;
decimal kmTotal = 0;
foreach (var e in empListe)
{
QueryRO.Row empRow = new QueryRO.Row();
empRow.ChildRows1 = new List<QueryRO.Row>();
newQueryRo.Rows.Add(empRow);
empRow.Field1 = e.Person.FirstNameLastName;
DateTimeSpan span = new DateTimeSpan();
span.StartDateTime = dt;
span.EndDateTime = dt.AddMonths(1).AddSeconds(-1);
var records = DAOFactory.SearchDAO.FindEmployeeServiceRecords(e.Oid.Value, span, null, null);
foreach (var sr in records.Where(s1 => s1.ServiceDescription.Name == "Fahrtzeit").OrderBy(s => s.Start))
{
if (!preisProKm.HasValue)
{
preisProKm = GetKmPreis(sr.ServiceDescription, dt);
}
QueryRO.Row srRow = new QueryRO.Row();
empRow.ChildRows1.Add(srRow);
srRow.Field1 = String.Format("{0:dd.MM.yyyy}", sr.Start);
if (sr.Start.Value.Second > 0)
{
srRow.Field2 = "";
}
else
{
srRow.Field2 = String.Format("{0:HH:mm}-{1:HH:mm}", sr.Start, sr.End);
}
srRow.Field3 = String.Format("{0:0.##}", sr.RoundedDuration);
srRow.Field4 = String.Format("{0}", sr.DistanceInMeter);
if (sr.DistanceInMeter.HasValue)
{
kmTotal += sr.DistanceInMeter.Value;
}
srRow.Field6 = sr.Notice;
}
empRow.Field2 = String.Format("x {0:c} = {1:c}", preisProKm, preisProKm * kmTotal);
}
foreach (var ccr in newQueryRo.Rows)
{
ccr.ChildRows1.Sort((a, b) => a.Field1.ToString().CompareTo(b.Field1));
}
return newQueryRo;
}
private decimal? GetKmPreis(ServiceDescription sd, DateTime datum)
{
if (sd.CostRatePeriods != null && sd.CostRatePeriods.Count > 0)
{
var crList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(sd.CostRatePeriods);
var cr = crList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, datum);
if (cr != null && cr.CostRateValue.HasValue)
{
return cr.CostRateValue.Value;
}
}
return null;
}
private QueryRO.Row CreateMonatsRow(DateTime dt)
{
QueryRO.Row row = new QueryRO.Row();
row.Field1 = String.Format("{0:MMM yyyy}", dt);
row.ChildRows2 = new List<QueryRO.Row>();
return row;
}
}
internal class TotalSummary
{
internal decimal flmTotal;
internal decimal amountTotal;
internal int countTotal;
internal decimal approvedMinFl;
internal decimal approvedMinAls;
internal decimal approvedMinOthers;
}
}