208 lines
6.6 KiB
C#
208 lines
6.6 KiB
C#
using System;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Report;
|
|
using DevExpress.XtraReports.UI;
|
|
using System.Data;
|
|
using BeWo.Data.Access;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Linq;
|
|
using System.Xml.Schema;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
using DevExpress.Xpo.DB;
|
|
using HphBersenbrueckFreizeitUndReisen.Abrechnung;
|
|
|
|
namespace HphBersenbrueckFreizeitUndReisen
|
|
{
|
|
[IDSpecificClass(Identifier = "AuswertungFahrtkosten")]
|
|
public partial class AuswertungFahrtkosten : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<QueryRO>
|
|
{
|
|
public AuswertungFahrtkosten()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
public void SetReportDataSource(QueryRO queryRo)
|
|
{
|
|
|
|
var ro = CreateRo(queryRo);
|
|
|
|
this.bindingSource1.DataSource = ro;
|
|
}
|
|
|
|
|
|
|
|
private AuswertungFahrtkostenRO CreateRo(QueryRO queryRo)
|
|
{
|
|
AuswertungFahrtkostenRO result = new AuswertungFahrtkostenRO();
|
|
result.DetailList = new List<AuswertungFahrtkostenDetailRO>();
|
|
|
|
long? customerOid = null;
|
|
|
|
DateTime reportStart = new DateTime(DateTime.Now.Year, 1, 1);
|
|
|
|
|
|
|
|
if (queryRo.Rows.Count > 0)
|
|
{
|
|
if (queryRo.Rows[0].Field1 != null)
|
|
{
|
|
DateTime dtTemp = DateTime.Now;
|
|
|
|
if (DateTime.TryParse(queryRo.Rows[0].Field1.ToString(), out dtTemp) &&
|
|
dtTemp > new DateTime(1900, 1, 1))
|
|
{
|
|
reportStart = dtTemp;
|
|
}
|
|
}
|
|
|
|
//if (queryRo.Rows[0].Field4 != null)
|
|
//{
|
|
// long longTemp = 0;
|
|
// if (Int64.TryParse(queryRo.Rows[0].Field4.ToString(), out longTemp) && longTemp > 0)
|
|
// {
|
|
// customerOid = longTemp;
|
|
// }
|
|
|
|
//}
|
|
}
|
|
|
|
DateTime reportEnde = reportStart.AddYears(1).AddDays(-1);
|
|
|
|
Dictionary<String, AuswertungFahrtkostenDetailRO> rowDict =
|
|
new Dictionary<String, AuswertungFahrtkostenDetailRO>();
|
|
|
|
var scList = DAOFactory.GenericDAO.GetAllActiveAndArchived<SupportConcept>();
|
|
//var scList = new List<SupportConcept>();
|
|
//scList = scList.Where(s => s.Customer.Person.LastName.Contains("Aaa")).ToList();
|
|
|
|
|
|
foreach (var sc in scList)
|
|
{
|
|
if (!customerOid.HasValue || customerOid == sc.Customer.Oid)
|
|
{
|
|
foreach (var c2s in sc.CostBearer2SupportConceptList)
|
|
{
|
|
AddSupportConceptToRow(rowDict, sc, c2s, reportStart, reportEnde);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var row in rowDict.Values)
|
|
{
|
|
result.DetailList.Add(row);
|
|
}
|
|
result.DetailList = result.DetailList.OrderBy(d => String.Format("{0}_{1}", d.Mitarbeiter, d.KlientName)).ToList();
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
private void AddSupportConceptToRow(Dictionary<String, AuswertungFahrtkostenDetailRO> rowDict,
|
|
SupportConcept sc, CostBearer2SupportConcept c2S, DateTime reportStart, DateTime reportEnd)
|
|
{
|
|
|
|
|
|
DateTimeSpan span = new DateTimeSpan();
|
|
span.StartDate = reportStart;
|
|
span.EndDate = reportEnd.AddDays(1).AddTicks(-1);
|
|
|
|
//var serviceRecords = DAOFactory.SearchDAO.FindCustomerServiceRecords(sc.Customer.Oid.Value, span, null, null, true);
|
|
var serviceRecords = c2S.ServiceRecords;
|
|
|
|
|
|
foreach (var sr in serviceRecords)
|
|
{
|
|
if (sr.Start.HasValue && reportStart <= sr.Start && sr.Start.Value.Date <= reportEnd.Date)
|
|
{
|
|
if (sr.DistanceInMeter.HasValue && sr.DistanceInMeter.Value > 0)
|
|
{
|
|
AddKmToRow(rowDict, sr, c2S);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void AddKmToRow(Dictionary<String, AuswertungFahrtkostenDetailRO> rowDict, ServiceRecord sr,
|
|
CostBearer2SupportConcept c2s)
|
|
{
|
|
String key = String.Format("{0}_{1}", sr.Employee.Oid, c2s.Oid);
|
|
|
|
AuswertungFahrtkostenDetailRO ro = null;
|
|
if (!rowDict.ContainsKey(key))
|
|
{
|
|
ro = new AuswertungFahrtkostenDetailRO();
|
|
rowDict.Add(key, ro);
|
|
|
|
ro.Mitarbeiter = String.Format("{0}, {1}", sr.Employee.Person.LastName, sr.Employee.Person.FirstName);
|
|
ro.KlientName = String.Format("{0}, {1}", c2s.SupportConcept.Customer.Person.LastName,
|
|
c2s.SupportConcept.Customer.Person.FirstName);
|
|
}
|
|
else
|
|
{
|
|
ro = rowDict[key];
|
|
}
|
|
if (sr.Start.Value.Month == 1)
|
|
{
|
|
ro.Jan += sr.DistanceInMeter.Value;
|
|
}
|
|
else if(sr.Start.Value.Month == 2)
|
|
{
|
|
ro.Feb += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 3)
|
|
{
|
|
ro.Maer += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 4)
|
|
{
|
|
ro.Apr += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 5)
|
|
{
|
|
ro.Mai += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 6)
|
|
{
|
|
ro.Jun += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 7)
|
|
{
|
|
ro.Jul += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 8)
|
|
{
|
|
ro.Aug += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 9)
|
|
{
|
|
ro.Sep += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 10)
|
|
{
|
|
ro.Okt += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 11)
|
|
{
|
|
ro.Nov += sr.DistanceInMeter.Value;
|
|
}
|
|
else if (sr.Start.Value.Month == 12)
|
|
{
|
|
ro.Dez += sr.DistanceInMeter.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|