206 lines
7.0 KiB
C#
206 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace LandshuterNetzwerk
|
|
{
|
|
public class CustomReportCreator : DefaultReportCreator
|
|
{
|
|
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
|
|
{
|
|
if (queryOid == 100)
|
|
{
|
|
return CreateLeistungsnachweis(queryOid, queryReportId);
|
|
}
|
|
|
|
|
|
return base.CreateQueryReport(queryOid, queryReportId);
|
|
}
|
|
|
|
|
|
private XtraReport CreateLeistungsnachweis(long queryOid, string queryReportId)
|
|
{
|
|
var query = DAOFactory.GenericDAO.LoadByID<Query>(queryOid);
|
|
|
|
if (query == null)
|
|
return new XtraReport();
|
|
|
|
var path = Path.Combine(TempPath, queryReportId + ".xml");
|
|
|
|
var table = Utils.XMLDeserialize<DataTable>(path);
|
|
|
|
var qro = QueryRO.Create(query, table);
|
|
|
|
|
|
if (qro.Rows.Count > 0)
|
|
{
|
|
DateTime monat = DateTime.Parse(qro.Rows[0].Field1.ToString());
|
|
|
|
List<long> customerOids = new List<long>();
|
|
|
|
if (qro.Rows[0].Field2.ToString() != "0")
|
|
{
|
|
var oid = Int64.Parse(qro.Rows[0].Field2.ToString());
|
|
customerOids.Add(oid);
|
|
}
|
|
else
|
|
{
|
|
var allcustomer = DAOFactory.GenericDAO.GetAllActive<Customer>();
|
|
|
|
if (qro.Rows[0].Field3.ToString() != "0")
|
|
{
|
|
var teamoid = Int64.Parse(qro.Rows[0].Field3.ToString());
|
|
|
|
foreach (var customer in allcustomer)
|
|
{
|
|
foreach (var t2c in customer.Team2CustomerList)
|
|
{
|
|
if (t2c.TeamOid == teamoid)
|
|
{
|
|
customerOids.Add(customer.Oid.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
customerOids.AddRange(allcustomer.Select(c => c.Oid.Value));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IBeWoReport<ServiceInvoiceRO> allReports = null;
|
|
|
|
|
|
if (customerOids.Count == 1)
|
|
{
|
|
return CreateEinzelnenLeistungsnachweis(customerOids[0], monat.Month, monat.Year, 0, 0, null, 1, DateTime.DaysInMonth(monat.Year, monat.Month));
|
|
|
|
}
|
|
else
|
|
{
|
|
return CreateAlleLeistungsnachweise(customerOids, monat.Month, monat.Year, 0, 0, null, 1, DateTime.DaysInMonth(monat.Year, monat.Month));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return new XtraReport();
|
|
}
|
|
|
|
private XtraReport CreateAlleLeistungsnachweise(List<long> customerOids, int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
|
|
{
|
|
List<ServicesOverviewRO> lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid).Where(ro => customerOids.Contains(ro.CustomerOid)).ToList();
|
|
|
|
if (lROs.Count > 0)
|
|
{
|
|
var lServiceOverviewAllCustomersReport = new Leistungsnachweis();
|
|
lServiceOverviewAllCustomersReport.SetReportDataSource(lROs[0]);
|
|
(lServiceOverviewAllCustomersReport as XtraReport).CreateDocument();
|
|
var Report = lServiceOverviewAllCustomersReport as XtraReport;
|
|
|
|
for (int i = 1; i < lROs.Count; i++)
|
|
{
|
|
var lNext = new Leistungsnachweis();
|
|
lNext.SetReportDataSource(lROs[i]);
|
|
lNext.CreateDocument();
|
|
Report.Pages.AddRange(lNext.Pages);
|
|
}
|
|
|
|
return lServiceOverviewAllCustomersReport as XtraReport;
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
private XtraReport CreateEinzelnenLeistungsnachweis(long customerOid, int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
|
|
{
|
|
var lServiceOverviewSingleCustomerReport = new Leistungsnachweis();
|
|
lServiceOverviewSingleCustomerReport.SetReportDataSource(ServicesOverviewRO.Create(customerOid, month, year, false, orgaOid, empOid, startDay, endDay, serviceCategoryOid));
|
|
|
|
return lServiceOverviewSingleCustomerReport;
|
|
}
|
|
|
|
|
|
public override XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid,
|
|
long? serviceCategoryOid, int startDay, int endDay)
|
|
{
|
|
|
|
Dictionary<String, List<ServicesOverviewRO>> rosNachTeam = new Dictionary<string, List<ServicesOverviewRO>>();
|
|
|
|
List<ServicesOverviewRO> lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
|
|
|
|
if (lROs.Count > 0)
|
|
{
|
|
foreach (var ro in lROs)
|
|
{
|
|
if (ro.CustomerOid > 0)
|
|
{
|
|
var c = DAOFactory.GenericDAO.LoadByID<Customer>(ro.CustomerOid);
|
|
String teamName = "None";
|
|
|
|
if (c.Team2CustomerList.Count > 0)
|
|
{
|
|
var t = c.Team2CustomerList[0].Team;
|
|
teamName = t.Name;
|
|
}
|
|
|
|
if (!rosNachTeam.ContainsKey(teamName))
|
|
{
|
|
rosNachTeam.Add(teamName, new List<ServicesOverviewRO>());
|
|
}
|
|
rosNachTeam[teamName].Add(ro);
|
|
}
|
|
|
|
}
|
|
|
|
XtraReport mainReport = null;
|
|
|
|
foreach (var team in rosNachTeam.Keys.OrderBy(t => t))
|
|
{
|
|
var ros = rosNachTeam[team];
|
|
|
|
foreach (var ro in ros)
|
|
{
|
|
var nextReport = FindReportImp<ServicesOverviewRO>();
|
|
nextReport.SetReportDataSource(ro);
|
|
(nextReport as XtraReport).CreateDocument();
|
|
|
|
|
|
if (mainReport == null)
|
|
{
|
|
mainReport = nextReport as XtraReport;
|
|
}
|
|
else
|
|
{
|
|
mainReport.Pages.AddRange((nextReport as XtraReport).Pages);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return mainReport;
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
}
|
|
}
|