172 lines
5.6 KiB
C#
172 lines
5.6 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
|
|
{
|
|
public StatisticBase(VgaTypeEnum vgaType)
|
|
{
|
|
VgaType = vgaType;
|
|
}
|
|
public DateTime StartDate { get; set; }
|
|
public DateTime EndDate { get; set; }
|
|
protected Dictionary<long, Customer> CustomerByOid { get; set; }
|
|
protected Dictionary<long, CustomerVermittlungArbeit> VgaByOid { get; set; }
|
|
protected Dictionary<long, List<CustomerVermittlungArbeit>> CustomerOid2Vgas { get; set; }
|
|
protected Dictionary<long, long> VgaOid2CustomerOid { get; set; }
|
|
public VgaTypeEnum VgaType { get; set; }
|
|
|
|
public int AnzahlAlt { get; set; } // Anzahl der aus dem vorhergehenden Berichtszeitraum übernommenen offenen Aufträge
|
|
public int AnzahlNeu { get; set; } // Anzahl der im aktuellen Berichtszeitraum erteilten Aufträge
|
|
public int AnzahlInsgesamt { get { return AnzahlAlt + AnzahlNeu; } } // Anzahl der insges. erteilten Aufträge (Summe Zeilen 0.1+ 0.2)
|
|
public int AnzahlErledigt { get; set; }
|
|
public int AnzahlAbbruchNegativ { get; set; }
|
|
public int AnzahlPositiv { get; set; }
|
|
public virtual List<AnnualReportDC> CreateStatistic(DateTime startDate, DateTime endDate)
|
|
{
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
|
|
CustomerByOid = new Dictionary<long, Customer>();
|
|
VgaByOid = new Dictionary<long, CustomerVermittlungArbeit>();
|
|
VgaOid2CustomerOid = new Dictionary<long, long>();
|
|
CustomerOid2Vgas = new Dictionary<long, List<CustomerVermittlungArbeit>>();
|
|
|
|
var reports = new List<AnnualReportDC>();
|
|
|
|
LoadData();
|
|
|
|
|
|
foreach (var vgaOid in VgaByOid.Keys)
|
|
{
|
|
CustomerVermittlungArbeit cva = VgaByOid[vgaOid];
|
|
|
|
ProcessCustomerVermittlungArbeit(cva.Customer, cva);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
if (!CustomerOid2Vgas.ContainsKey(customer.Oid.Value))
|
|
{
|
|
CustomerOid2Vgas.Add(customer.Oid.Value, new List<CustomerVermittlungArbeit>());
|
|
}
|
|
|
|
var vgaList = GetVgaList(customer);
|
|
|
|
foreach (var vga in vgaList)
|
|
{
|
|
if (!VgaOid2CustomerOid.ContainsKey(vga.Oid.Value))
|
|
{
|
|
VgaOid2CustomerOid.Add(vga.Oid.Value, customer.Oid.Value);
|
|
}
|
|
if (!VgaByOid.ContainsKey(vga.Oid.Value))
|
|
{
|
|
VgaByOid.Add(vga.Oid.Value, vga);
|
|
}
|
|
|
|
CustomerOid2Vgas[customer.Oid.Value].Add(vga);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public virtual void ProcessCustomerVermittlungArbeit(Customer customer, CustomerVermittlungArbeit cva)
|
|
{
|
|
//Anzahl der aus dem vorhergehenden Berichtszeitraum übernommenen offenen Aufträge
|
|
if (cva.Auftragseingang < StartDate && !cva.Auftragsruckgabe.HasValue)
|
|
{
|
|
AnzahlAlt++;
|
|
}
|
|
else if (cva.Auftragseingang >= StartDate && cva.Auftragseingang <= EndDate)
|
|
{
|
|
AnzahlNeu++;
|
|
}
|
|
|
|
if (cva.CustomerVermittlungBearbeitungsstatus != CustomerVermittlungBearbeitungsstatus.InProgress)
|
|
{
|
|
AnzahlErledigt++;
|
|
|
|
if (cva.Verlauf == CustomerVgaVerlauf.Abbruch || cva.CustomerVermittlungBearbeitungsstatus == CustomerVermittlungBearbeitungsstatus.Negativ)
|
|
{
|
|
AnzahlAbbruchNegativ++;
|
|
}
|
|
else if (cva.CustomerVermittlungBearbeitungsstatus == CustomerVermittlungBearbeitungsstatus.Positiv)
|
|
{
|
|
AnzahlPositiv++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual bool ShouldProcessCustomer(Customer customer)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public virtual IList<CustomerVermittlungArbeit> GetVgaList(Customer customer)
|
|
{
|
|
//Alle Aufträge, die ein Startdatum kleiner als der Auswertezeitraum und entweder noch keine Rückgabe oder ein Rückgabe Datum im Auswertezeitraum haben
|
|
var list = customer.CustomerVermittlungArbeiten.Where(v => v.Auftragseingang.HasValue && v.Auftragseingang <= EndDate && (!v.Auftragsruckgabe.HasValue || v.Auftragsruckgabe.Value >= StartDate));
|
|
return list.Where(v => v.VgaType == VgaType).ToList();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |