Files
BeWoPlaner/Service/Reporting/Straffaelligenhilfe/StatisticBase.cs

120 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Services;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Plugins;
using Castle.Components.DictionaryAdapter;
using NHibernate.Linq;
namespace BeWo.Service.Reporting.Straffaelligenhilfe
{
public class StatisticBase
{
protected DateTime StartDate { get; set; }
protected DateTime EndDate { get; set; }
protected Dictionary<long, Customer> CustomerByOid { get; set; }
public virtual List<AnnualReportDC> CreateStatistic(DateTime startDate, DateTime endDate)
{
StartDate = startDate;
EndDate = endDate;
CustomerByOid = new Dictionary<long, Customer>();
var reports = new List<AnnualReportDC>();
LoadData();
Dictionary<long, int> customerOid2Days = new Dictionary<long, int>();
StringBuilder sb = new StringBuilder();
foreach (var customerOid in CustomerByOid.Keys)
{
Customer customer = CustomerByOid[customerOid];
ProcessCustomer(customer);
}
return reports;
}
public virtual void LoadData()
{
foreach (var customer in DAOFactory.GenericDAO.GetAllActiveAndArchived<Customer>())
{
if (ShouldProcessCustomer(customer))
{
if (!CustomerByOid.ContainsKey(customer.Oid.Value))
{
CustomerByOid.Add(customer.Oid.Value, customer);
}
}
}
}
public virtual void ProcessCustomer(Customer customer)
{
}
public virtual IList<CustomerVermittlungArbeit> GetVgaList(Customer customer, VgaTypeEnum vgaType)
{
var list = customer.CustomerVermittlungArbeiten.Where(v => v.Auftragseingang.HasValue && v.Auftragseingang >= StartDate && v.Auftragseingang.Value.Date <= EndDate);
return list.Where(v => v.VgaType == vgaType).ToList();
}
public virtual bool ShouldProcessCustomer(Customer customer)
{
if (customer .IsActive != ActivationTypeId.Deleted)
{
//if (CustomerBelongsToTeam(customer, TeamOid) &&
// IsCustomerOfCustomerCareType(customer, CustomerCareTypeValueListEntryOid))
//{
return true;
//}
}
return false;
}
public virtual bool IsCustomerOfCustomerCareType(Customer customer, long? customerCareTypeValueListEntryOid)
{
bool val = true;
if (customerCareTypeValueListEntryOid.HasValue)
{
val = false;
foreach (var v in customer.ValueList)
{
if (v.Entry.Type == ValueListEntryType.CustomerCareType && v.Entry.Oid == customerCareTypeValueListEntryOid)
return true;
}
}
return val;
}
public virtual bool CustomerBelongsToTeam(Customer customer, long? teamOid)
{
bool val = true;
if (teamOid.HasValue)
{
val = false;
foreach (var t2c in customer.Team2CustomerList)
{
if (t2c.TeamOid == teamOid)
return true;
}
}
return val;
}
}
}