Files
BeWoPlaner/ReportImp/CaritasKleve/Service/CustomAccountingService.cs
Lyndon Jetten f99d674f8c FaC:
NullPointerException bei Zusagen/Absagen von Serienterminen gefixt.
Terminanzeige im HomeView hat "In Zeiterfassung übertragen"-Icons
Terminanzeige Termine werden wie folgt dargestellt: [Datum]: [Betreff]

MoK:
Auswahl des Ladeintervalls der Zeiterfassungseinträge ist standardmäßig auf "Letzte 7 Tage" und die Änderung wird nur in der Session gespeichert.
Termine in die Zeiterfassung übertragen
2023-03-03 21:54:36 +01:00

195 lines
9.0 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
namespace CaritasKleve.Service
{
public class CustomAccountingService : AccountingService
{
//public override List<InvoiceBaseDC> GetInvoiceBases(DateTime? startDate, DateTime? endDate)
//{
// if (startDate.HasValue && startDate.Value.Year == 2011)
// {
// ConvertResourceBookingsToResourceAppointments();
// }
// return base.GetInvoiceBases(startDate, endDate);
//}
private void ConvertResourceBookingsToResourceAppointments()
{
//const string selectQuery = "SELECT Oid, ResourceBookingSequenceOid FROM resourcebooking WHERE startdatetime >= '1921-01-01' AND IsActive = 1 AND IsDeleted = 0";
const string selectQuery = "SELECT Oid, ResourceBookingSequenceOid FROM resourcebooking IsActive = 1 AND IsDeleted = 0";
var dataSet = DAOFactory.AdoDAO.ExecuteQuery(selectQuery);
var dataReader = dataSet.CreateDataReader();
var rbs2rb = new Dictionary<long, List<long>>();
var newSchedulerAppointments = new List<SchedulerAppointmentDC>();
var sequence2booking = new Dictionary<ResourceBookingSequence, List<ResourceBooking>>();
var allResourceBookings = DAOFactory.GenericDAO.GetAllActive<ResourceBooking>();
var changedBookings = new List<ResourceBooking>();
while (dataReader.Read())
{
rbs2rb.AddOrUpdateValueInDictionary((long)dataReader.GetValue(0), new List<long> { (long)dataReader.GetValue(1) });
}
if (allResourceBookings.Count == 0) return;
allResourceBookings = allResourceBookings.OrderBy(o => o.Oid).ToList();
foreach (var b in allResourceBookings)
{
if (rbs2rb.ContainsKey(b.Oid.Value))
{
if (!sequence2booking.ContainsKey(b.Sequence))
{
sequence2booking.Add(b.Sequence, new List<ResourceBooking> { b });
}
else
{
sequence2booking[b.Sequence].Add(b);
}
}
}
foreach (var kvp in sequence2booking)
{
var sequence = kvp.Key;
var frequencyType = sequence.FrequencyType;
foreach (var booking in kvp.Value)
{
var originator = DAOFactory.SearchDAO.FindEmployeeByFullname(booking.InsUser) ?? booking.Employee;
if (booking.Sequence.FrequencyType.Equals(ResourceBookingFrequencyType.MonthlyOnLastDay))
{
//var singleBookings = ConvertType6ResourceAppointment(booking);
//newSchedulerAppointments.AddRange(singleBookings);
continue;
}
var employeeList = new List<Employee2SchedulerAppointmentDC>();
if (booking.Employee != null)
employeeList.Add(new Employee2SchedulerAppointmentDC
{
Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(booking.Employee),
ParticipationAnswer = ParticipationAnswer.Zusage,
IsPC_CheckedTs = null,
IsPChanged = false
});
var resourceList = new List<ResourceDC> { MapperFactory.ResourceDC_Resource.MapToNewDC(booking.Sequence.Resource) };
var newSchedulerAppointment = new SchedulerAppointmentDC
{
ActivationType = ActivationTypeId.Active,
AllDay = booking.Start.Equals(booking.End),
CustomerList = new List<CompactCustomerDC>(),
Description = booking.Notice,
EmployeeList = employeeList,
EndDate = booking.End,
StartDate = booking.Start,
IsPrivate = false,
ResourceList = resourceList,
Subject = booking.Notice,
Originator = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(originator),
Type = 0,
FormerBookingSequenceOid = booking.Sequence.Oid,
ServiceRecordList = new List<ServiceRecordDC>(),
SupportConceptList = new List<CompactSupportConceptDC>()
};
if (kvp.Value.Count > 1 && booking.SequencePosition > 0)
{
newSchedulerAppointment.Type = booking.IsDeleted ? 4 : 3;
}
else if (frequencyType != ResourceBookingFrequencyType.Once)
{
newSchedulerAppointment.Type = 1;
}
if (!booking.Sequence.FrequencyType.Equals(ResourceBookingFrequencyType.Once))
{
//newSchedulerAppointment.RecurrenceInfo = CreateRecurrenceInfo(booking).ToXml();
}
if (newSchedulerAppointments.FirstOrDefault(f => f.FormerBookingSequenceOid.Equals(sequence.Oid)) != null)
{
var x = newSchedulerAppointments.First(f => f.FormerBookingSequenceOid.Equals(sequence.Oid) && f.RecurrenceInfo != null).RecurrenceInfo;
using (var reader = XmlReader.Create(new StringReader(x)))
{
reader.ReadToFollowing("RecurrenceInfo");
reader.MoveToAttribute("Id");
var id = reader.Value;
var doc = XDocument.Load(new StringReader(newSchedulerAppointment.RecurrenceInfo));
var xElement = doc.Element("RecurrenceInfo");
if (xElement != null)
{
xElement.RemoveAttributes();
xElement.Add(new XAttribute("Id", id));
xElement.Add(new XAttribute("Index", booking.SequencePosition));
}
newSchedulerAppointment.RecurrenceInfo = doc.ToString();
}
}
changedBookings.Add(booking);
newSchedulerAppointments.Add(newSchedulerAppointment);
}
}
foreach (var resourcebooking in changedBookings)
{
//resourcebooking.IsActive = ActivationTypeId.Deleted;
//resourcebooking.Sequence.IsActive = ActivationTypeId.Deleted;
}
//DAOFactory.GenericDAO.Update(changedBookings);
InsertSchedulerAppointments(newSchedulerAppointments);
}
public void InsertSchedulerAppointments(IList<SchedulerAppointmentDC> pSchedulerAppointments)
{
foreach (var item in pSchedulerAppointments)
{
item.EmployeeList?.ForEach(each =>
{
each.Employee2SchedulerAppointmentOid = null;
each.Employee2SchedulerAppointmentVersion = null;
each.SchedulerAppointmentOid = null;
each.IsPChanged = false;
each.IsPC_CheckedTs = null;
});
var lRelations = MapperFactory.Employee2SchedulerAppointmentDC_Employee2SchedulerAppointment.MapToNewEntities(item.EmployeeList);
DAOFactory.GenericDAO.Insert(lRelations);
var neu = MapperFactory.Employee2SchedulerAppointmentDC_Employee2SchedulerAppointment.MapToNewDCs(lRelations);
item.EmployeeList = neu;
}
var lAppointments = MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewEntities(pSchedulerAppointments);
DAOFactory.GenericDAO.Insert(lAppointments);
}
}
}