759 lines
32 KiB
C#
759 lines
32 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Data.Utils;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BeWo.ServiceUtils.History
|
|
{
|
|
public class HistoryCreator
|
|
{
|
|
public static void MakeNewEmployeeHistoryEntry(Employee originalEmployee, EmployeeDC newEmployee, StatementType statementType)
|
|
{
|
|
var employeeHistory = new EmployeeHistory
|
|
{
|
|
ChangeType = statementType,
|
|
|
|
Employee_Aggressiv = newEmployee.Aggressiv,
|
|
//Employee_ApplicationUserOid,
|
|
//Employee_CancellationPeriod,
|
|
Employee_EmployeeColor = newEmployee.EmployeeColor,
|
|
//Employee_EntryDate,
|
|
Employee_HealthInsurance = newEmployee.HealthInsurance,
|
|
//Employee_HourlyRate,
|
|
Employee_Hygienebelehrung = newEmployee.Hygienebelehrung,
|
|
Employee_InsTs = originalEmployee.InsTs,
|
|
Employee_InsuranceNumber = newEmployee.InsuranceNumber,
|
|
Employee_InsUser = originalEmployee.InsUser,
|
|
Employee_IsActive = originalEmployee.IsActive,
|
|
Employee_IsQualified = newEmployee.IsQualified,
|
|
//Employee_leavedays,
|
|
Employee_Notice = originalEmployee.Notice,
|
|
Employee_Notice2 = newEmployee.Notice2,
|
|
Employee_Oid = originalEmployee.Oid,
|
|
Employee_PersonnelNumber = newEmployee.PersonnelNumber,
|
|
//Employee_PersonOid,
|
|
Employee_Pflege = newEmployee.Pflege,
|
|
//Employee_ProbationPeriod,
|
|
Employee_Schutzstufe = newEmployee.Schutzstufe,
|
|
//Employee_Sequence,
|
|
Employee_SystemEntryID = originalEmployee.SystemEntryID,
|
|
Employee_TaxNumber = newEmployee.TaxNumber,
|
|
Employee_TaxClass = newEmployee.TaxClass,
|
|
Employee_ChildCount = newEmployee.ChildCount,
|
|
Employee_Text1 = newEmployee.Text1,
|
|
Employee_Text2 = newEmployee.Text2,
|
|
Employee_Text3 = newEmployee.Text3,
|
|
Employee_Text4 = newEmployee.Text4,
|
|
Employee_Text5 = newEmployee.Text5,
|
|
Employee_Toilettengang = newEmployee.Toilettengang,
|
|
Employee_UdpUser = originalEmployee.UdpUser,
|
|
Employee_Version = originalEmployee.Version,
|
|
//Employee_weeklyfls = employee,
|
|
//Employee_weeklytotalhours,
|
|
};
|
|
|
|
MakeNewPersonHistoryEntry(originalEmployee.Person, newEmployee, statementType);
|
|
|
|
CreateContractHistoryEntries(originalEmployee.Oid.Value, originalEmployee.Contracts, newEmployee.Contracts);
|
|
if (newEmployee.AbsenceTimes != null)
|
|
{
|
|
foreach (var item in newEmployee.AbsenceTimes)
|
|
{
|
|
if (!item.EmployeeOid.HasValue)
|
|
{
|
|
item.EmployeeOid = originalEmployee.Oid.Value;
|
|
}
|
|
}
|
|
}
|
|
CreateAbsenceTimeHistoryEntry(originalEmployee.AbsenceTimes, newEmployee.AbsenceTimes);
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Insert(employeeHistory);
|
|
|
|
}
|
|
|
|
public static void CreateContractHistoryEntries(long employeeOid, IList<Contract> originalContracts, IList<ContractDC> newContracts)
|
|
{
|
|
if (newContracts != null)
|
|
{
|
|
foreach (var nc in newContracts)
|
|
{
|
|
if (!nc.ContractOid.HasValue)
|
|
{
|
|
CreateContractHistoryEntry(employeeOid, nc, StatementType.Insert);
|
|
}
|
|
else
|
|
{
|
|
var oldAt = originalContracts.Where(a => a.Oid == nc.ContractOid).FirstOrDefault();
|
|
|
|
if (oldAt != null)
|
|
{
|
|
CreateContractHistoryEntry(employeeOid, nc, StatementType.Update);
|
|
}
|
|
else
|
|
{
|
|
//Wurde gelöscht?
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var oc in originalContracts)
|
|
{
|
|
//wenn es einen Vertrag gibt, der nicht mehr in der neuen Liste enthalten ist, wurde er gelöscht
|
|
|
|
var nc = newContracts.Where(c => c.ContractOid == oc.Oid).FirstOrDefault();
|
|
|
|
if (nc == null)
|
|
{
|
|
CreateContractHistoryEntry(employeeOid, MapperFactory.ContractDC_Contract.MapToNewDC(oc), StatementType.Delete);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public static void CreateContractHistoryEntry(long employeeOid, ContractDC contract, StatementType statementType)
|
|
{
|
|
|
|
var historyEntry = new ContractHistory()
|
|
{
|
|
ContractOid = contract.ContractOid,
|
|
ContractHistoryCancellationPeriod = contract.CancellationPeriod,
|
|
ContractHistoryContractEndDate = contract.ContractEndDate,
|
|
ContractHistoryContractTypeValueListEntryOid = contract.ContractTypeValueListEntry?.ValueListEntryOid,
|
|
ContractHistoryEmployeeOid = employeeOid,
|
|
ContractHistoryEmploymentTypeOid = contract.EmploymentType?.EmploymentTypeOid,
|
|
ContractHistoryEntryDate = contract.EntryDate,
|
|
ContractHistoryHourlyRate = contract.HourlyRate,
|
|
ContractHistoryHourlyRateCostRateValueOid = contract.HourlyRateCostRateValue?.CostRatePeriodOid,
|
|
ContractHistoryLeaveDays = contract.LeaveDays,
|
|
ContractHistoryMonthlyFLS = contract.MonthlyFLS,
|
|
ContractHistoryMonthlyTotalHours = contract.MonthlyTotalHours,
|
|
ContractHistoryProbationPeriod = contract.ProbationPeriod,
|
|
ContractHistoryProbationPeriod2 = contract.ProbationPeriod2,
|
|
ContractHistoryQualifikationsBedarfValueListEntryOid = contract.QualifikationsBedarfValueListEntry?.ValueListEntryOid,
|
|
ContractHistoryWeeklyDays = contract.WeeklyDays,
|
|
ContractHistoryWeeklyFLS = contract.WeeklyFLS,
|
|
ContractHistoryWeeklyTotalHours = contract.WeeklyTotalHours,
|
|
ContractHistoryGrossSalary = contract.GrossSalary,
|
|
Notice = contract.Notice,
|
|
ChangeType = statementType
|
|
};
|
|
DAOFactory.GenericDAO.Insert(historyEntry);
|
|
|
|
}
|
|
|
|
public static void CreateAbsenceTimeHistoryEntry(IList<AbsenceTime> originalAbsenceTimes, IList<AbsenceTimeDC> newAbsenceTimes)
|
|
{
|
|
if (newAbsenceTimes != null)
|
|
{
|
|
foreach (var na in newAbsenceTimes)
|
|
{
|
|
if (!na.AbsenceTimeOid.HasValue)
|
|
{
|
|
CreateAbsenceTimeHistoryEntry(na, StatementType.Insert);
|
|
}
|
|
else
|
|
{
|
|
var oldAt = originalAbsenceTimes.Where(a => a.Oid == na.AbsenceTimeOid).FirstOrDefault();
|
|
|
|
if (oldAt != null)
|
|
{
|
|
CreateAbsenceTimeHistoryEntry(na, StatementType.Update);
|
|
}
|
|
else
|
|
{
|
|
//Wurde gelöscht?
|
|
}
|
|
}
|
|
}
|
|
}
|
|
foreach (var oat in originalAbsenceTimes)
|
|
{
|
|
//wenn es eine Abwesenheit gibt, der nicht mehr in der neuen Liste enthalten ist, wurde er gelöscht
|
|
|
|
var na = newAbsenceTimes.Where(a => a.AbsenceTimeOid == oat.Oid).FirstOrDefault();
|
|
|
|
if (na == null)
|
|
{
|
|
CreateAbsenceTimeHistoryEntry(MapperFactory.AbsenceTimeDC_AbsenceTime.MapToNewDC(oat), StatementType.Delete);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void CreateAbsenceTimeHistoryEntry(AbsenceTimeDC newAbsenceTime, StatementType statementType)
|
|
{
|
|
|
|
var historyEntry = new AbsenceTimeHistory()
|
|
{
|
|
AbsenceTimeOid = newAbsenceTime.AbsenceTimeOid ?? 0,
|
|
AbsenceReasonOid = newAbsenceTime.Reason?.AbsenceReasonOid ?? 0,
|
|
AbsenceTimeStart = newAbsenceTime.Start,
|
|
AbsenceTimeEnd = newAbsenceTime.End,
|
|
AbsenceTimeKrankheitsMeldung = newAbsenceTime.KrankheitsMeldung,
|
|
AbsenceTimeNotice = newAbsenceTime.Notice,
|
|
AbsenceTimeCustomerOid = newAbsenceTime.CustomerOid,
|
|
AbsenceTimeEmployeeOid = newAbsenceTime.EmployeeOid,
|
|
ChangeType = statementType
|
|
};
|
|
DAOFactory.GenericDAO.Insert(historyEntry);
|
|
|
|
}
|
|
|
|
public static void MakeCustomerHistoryEntry(Customer lOriginal, CustomerDC newCustomer, long? Oid, StatementType statementType, List<Customer2Person> originalCustomer2PersonList, List<Customer2Organisation> originalC2OList, List<Employee2Customer> originale2CList, List<AbsenceTime> originaleAbsenceTimeList)
|
|
{
|
|
var lCustomerHistory = new CustomerHistory
|
|
{
|
|
ChangeType = statementType,
|
|
Childs = lOriginal.Childs,
|
|
CostCenter = lOriginal.CostCenter,
|
|
CustomerInsTs = lOriginal.InsTs,
|
|
CustomerInsUser = lOriginal.InsUser,
|
|
CustomerOid = Oid ?? lOriginal.Oid,
|
|
CustomerUdpUser = lOriginal.UdpUser,
|
|
CustomerVersion = lOriginal.Version ?? 0,
|
|
DebitorNumber = lOriginal.DebitorNumber,
|
|
Diagnosis = lOriginal.Diagnosis,
|
|
Environment = lOriginal.Environment,
|
|
EquityContribution = lOriginal.EquityContribution,
|
|
ICD10Diagnosis = lOriginal.ICD10Diagnosis,
|
|
IsAdvisedOrAttended = lOriginal.IsAdvisedOrAttended,
|
|
Medication = lOriginal.Medication,
|
|
Notice = lOriginal.Notice,
|
|
Person = lOriginal.Person,
|
|
ReferenceNumber = lOriginal.ReferenceNumber,
|
|
TerminationDate = lOriginal.TerminationDate,
|
|
AssistanceBegin = lOriginal.AssistanceBegin
|
|
//Jugendamt = lOriginal.Jugendamt,
|
|
//Ansprechpartner = lOriginal.Ansprechpartner
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(lCustomerHistory);
|
|
|
|
MakeHistoryEntry(lOriginal.Customer2PersonList, originalCustomer2PersonList, lOriginal.Oid, statementType);
|
|
MakeHistoryEntry(lOriginal.Customer2OrganisationList, originalC2OList, lOriginal.Oid, statementType);
|
|
MakeHistoryEntry(lOriginal.Employee2CustomerList, originale2CList, lOriginal.Oid, statementType);
|
|
MakeHistoryEntry(lOriginal.AbsenceTimes, originaleAbsenceTimeList, lOriginal.Oid, statementType);
|
|
|
|
var person = lOriginal.Person;
|
|
MakeNewPersonHistoryEntry(person, newCustomer, statementType);
|
|
|
|
//if (newCustomer.AbsenceTimes != null)
|
|
//{
|
|
// foreach (var item in newCustomer.AbsenceTimes)
|
|
// {
|
|
// if (!item.CustomerOid.HasValue)
|
|
// {
|
|
// item.CustomerOid = lOriginal.Oid.Value;
|
|
// }
|
|
// }
|
|
//}
|
|
//CreateAbsenceTimeHistoryEntry(lOriginal.AbsenceTimes, newCustomer.AbsenceTimes);
|
|
}
|
|
|
|
public static void MakeNewPersonHistoryEntry(Person originalPerson, PersonDC newPerson, StatementType statementType)
|
|
{
|
|
var personHistoryEntry = new PersonHistory
|
|
{
|
|
ChangeType = statementType,
|
|
Person_Oid = originalPerson.Oid,
|
|
|
|
Person_Abbreviation = newPerson.Abbreviation,
|
|
Person_AufenthaltsStatus = newPerson.AufenthaltsStatus?.TypeDescription ?? "",
|
|
Person_DateOfBirth = newPerson.DateOfBirth,
|
|
Person_FamilyStatus = newPerson.FamilyStatus,
|
|
Person_FirstName = newPerson.FirstName,
|
|
Person_Function = newPerson.Function?.TypeDescription ?? "",
|
|
Person_InsTs = originalPerson.InsTs,
|
|
Person_InsUser = originalPerson.InsUser,
|
|
Person_IsActive = originalPerson.IsActive,
|
|
Person_IsMigrant = newPerson.IsMigrant,
|
|
Person_LastName = newPerson.LastName,
|
|
Person_Nationalitaet = newPerson.Nationalitaet?.TypeDescription ?? "",
|
|
Person_Notice = newPerson.PersonNotice,
|
|
|
|
Person_Profession = newPerson.Profession,
|
|
Person_Sex = newPerson.Sex,
|
|
Person_SystemEntryID = originalPerson.SystemEntryID,
|
|
|
|
Person_Tid = originalPerson.Tid,
|
|
Person_Title = newPerson.Title?.TypeDescription ?? "",
|
|
Person_Type = newPerson.Type,
|
|
Person_Version = originalPerson.Version
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(personHistoryEntry);
|
|
|
|
|
|
MakeNewAddressHistoryEntry(originalPerson.Address, newPerson, statementType);
|
|
MakeNewContactHistoryEntry(originalPerson.Oid.Value, originalPerson.Contacts, newPerson.ContactInformations, statementType);
|
|
|
|
}
|
|
|
|
private static void MakeNewContactHistoryEntry(long personOid, IList<Contact> originalContacts, IList<ContactDC> newContacts, StatementType statementType)
|
|
{
|
|
foreach (var nc in newContacts)
|
|
{
|
|
|
|
if (!nc.ContactOID.HasValue)
|
|
{
|
|
var ec = originalContacts.Where(c => c.Type == nc.ContactType && c.Value.EqualsNullCheck(nc.ContactValue)).FirstOrDefault();
|
|
long oid = 0;
|
|
if (ec != null && ec.Oid.HasValue)
|
|
{
|
|
oid = ec.Oid.Value;
|
|
|
|
}
|
|
CreateContactHistoryEntry(personOid, oid, nc.ContactValue, StatementType.Insert);
|
|
}
|
|
else
|
|
{
|
|
var oldC = originalContacts.Where(c => c.Oid == nc.ContactOID).FirstOrDefault();
|
|
if (oldC != null && !oldC.Value.EqualsNullCheck(nc.ContactValue))
|
|
{
|
|
CreateContactHistoryEntry(personOid, nc.ContactOID.Value, nc.ContactValue, StatementType.Update);
|
|
}
|
|
else if (oldC == null)
|
|
{
|
|
//Wurde gelöscht?
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var oc in originalContacts)
|
|
{
|
|
//wenn es eine Abwesenheit gibt, der nicht mehr in der neuen Liste enthalten ist, wurde er gelöscht
|
|
|
|
var nc = newContacts.Where(c => c.ContactOID == oc.Oid).FirstOrDefault();
|
|
|
|
if (nc == null)
|
|
{
|
|
CreateContactHistoryEntry(personOid, oc.Oid, oc.Value, StatementType.Delete);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void CreateContactHistoryEntry(long personOid, long? contactOid, String contactAddress, StatementType statementType)
|
|
{
|
|
var contactHistoryEntry = new ContactHistory
|
|
{
|
|
ChangeType = statementType,
|
|
Contact_Value = contactAddress,
|
|
Contact_Oid = contactOid,
|
|
Contact_PersonOid = personOid
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(contactHistoryEntry);
|
|
}
|
|
|
|
private static void MakeNewAddressHistoryEntry(Address originalAddress, PersonDC newPerson, StatementType statementType)
|
|
{
|
|
if (originalAddress != null || !String.IsNullOrEmpty(newPerson.AddressLine1) || !String.IsNullOrEmpty(newPerson.PostalCode) || !String.IsNullOrEmpty(newPerson.Street) || !String.IsNullOrEmpty(newPerson.Town))
|
|
{
|
|
long oid = 0;
|
|
if (originalAddress != null && originalAddress.Oid.HasValue)
|
|
{
|
|
oid = originalAddress.Oid.Value;
|
|
}
|
|
var addressHistoryEntry = new AddressHistory
|
|
{
|
|
ChangeType = statementType,
|
|
|
|
Address_AddressLine1 = newPerson.AddressLine1,
|
|
Address_InsTs = originalAddress?.InsTs,
|
|
Address_InsUser = originalAddress?.InsUser,
|
|
Address_Oid = oid,
|
|
Address_PostalCode = newPerson.PostalCode,
|
|
Address_Street = newPerson.Street,
|
|
Address_SystemEntryID = originalAddress?.SystemEntryID,
|
|
Address_Town = newPerson.Town
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(addressHistoryEntry);
|
|
}
|
|
}
|
|
|
|
public static void MakeSupportConceptHistoryEntry(SupportConcept lOriginal, long? Oid, StatementType statementType)
|
|
{
|
|
var supportConceptHistoryEntry = new SupportConceptHistory()
|
|
{
|
|
ChangeType = statementType,
|
|
SupportConcept_ApprovalDate = lOriginal.ApprovalDate,
|
|
SupportConcept_Conference = lOriginal.Conference,
|
|
SupportConcept_ConferenceDate = lOriginal.ConferenceDate,
|
|
SupportConcept_ConferenceVenue = lOriginal.ConferenceVenue,
|
|
SupportConcept_ConsultingNeeded = lOriginal.ConsultingNeeded,
|
|
//SupportConcept_CostBearer2SupportConceptList = lOriginal.CostBearer2SupportConceptList,
|
|
SupportConcept_CustomerOid = lOriginal.Customer.Oid,
|
|
SupportConcept_EmployeeOid = lOriginal.Originator.Oid,
|
|
SupportConcept_RenewalSendDate = lOriginal.RenewalSendDate,
|
|
SupportConcept_RequisitionSendDate = lOriginal.RequisitionSendDate,
|
|
SupportConcept_SupportConceptSendDate = lOriginal.RequisitionSendDate,
|
|
SupportConceptOid = lOriginal.Oid,
|
|
Notice = lOriginal.Notice
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(supportConceptHistoryEntry);
|
|
|
|
List<CostBearer2SupportConceptHistory> cb2schToInsert = new List<CostBearer2SupportConceptHistory>();
|
|
List<SupportConceptApprovalPeriodHistory> scApprovalPeriodHistoriesToInsert = new List<SupportConceptApprovalPeriodHistory>();
|
|
foreach (var originalC2S in lOriginal.CostBearer2SupportConceptList)
|
|
{
|
|
var C2SHistory = new CostBearer2SupportConceptHistory()
|
|
{
|
|
//CostBearer2SupportConcept_AccountingTransactions = originalC2S.AccountingTransactions,
|
|
CostBearer2SupportConcept_ApprovedEndDate = originalC2S.ApprovedEndDate,
|
|
CostBearer2SupportConcept_ApprovedStartDate = originalC2S.ApprovedStartDate,
|
|
CostBearer2SupportConcept_AuswahlBezeichnung = originalC2S.AuswahlBezeichnung,
|
|
CostBearer2SupportConcept_KontoHilfeplan = originalC2S.KontoHilfeplan,
|
|
CostBearer2SupportConcept_KostenstelleHilfeplan = originalC2S.KostenstelleHilfeplan,
|
|
CostBearer2SupportConcept_CostBearerContactPersonOid = originalC2S.CostBearerContactPerson?.Oid,
|
|
CostBearer2SupportConcept_CostBearerOid = originalC2S.CostBearer?.Oid,
|
|
CostBearer2SupportConcept_CustomerReferenceNumber = originalC2S.CustomerReferenceNumber,
|
|
CostBearer2SupportConcept_MonthlyPayment = originalC2S.MonthlyPayment,
|
|
CostBearer2SupportConcept_RequestedEndDate = originalC2S.RequestedEndDate,
|
|
CostBearer2SupportConcept_RequestedStartDate = originalC2S.RequestedStartDate,
|
|
//CostBearer2SupportConcept_ServiceRecords = originalC2S.ServiceRecords,
|
|
CostBearer2SupportConcept_Status = originalC2S.Status,
|
|
//CostBearer2SupportConcept_SupportConceptApprovalPeriodList = originalC2S.ApprovalPeriodList
|
|
CostBearer2SupportConcept_SupportConceptHistoryOid = lOriginal.Oid.Value,
|
|
ChangeType = statementType,
|
|
Notice = originalC2S.Notice
|
|
};
|
|
DAOFactory.GenericDAO.Insert(C2SHistory);
|
|
|
|
foreach (var item in originalC2S.ApprovalPeriodList)
|
|
{
|
|
var scApprovalPeriodHistory = new SupportConceptApprovalPeriodHistory()
|
|
{
|
|
ChangeType = statementType,
|
|
SupportConceptApprovalPeriod_ApprovedBEInterval = item.ApprovedBEInterval,
|
|
SupportConceptApprovalPeriod_ApprovedBEPerInterval = item.ApprovedBEPerInterval,
|
|
SupportConceptApprovalPeriod_ApprovedBETotal = item.ApprovedBETotal,
|
|
SupportConceptApprovalPeriod_ApprovedFixedAmount = item.ApprovedFixedAmount,
|
|
SupportConceptApprovalPeriod_ApprovedFixedAmountInterval = item.ApprovedFixedAmountInterval,
|
|
SupportConceptApprovalPeriod_Bewilligungsart = item.Bewilligungsart,
|
|
SupportConceptApprovalPeriod_BudgetOid = item.Budget?.Oid.Value,
|
|
SupportConceptApprovalPeriod_ContactCountInterval = item.ContactCountInterval,
|
|
SupportConceptApprovalPeriod_ContactCountPerInterval = item.ContactCountPerInterval,
|
|
SupportConceptApprovalPeriod_CostBearer2SupportConceptHistoryOid = originalC2S.Oid.Value,
|
|
SupportConceptApprovalPeriod_EndDate = item.EndDate,
|
|
SupportConceptApprovalPeriod_IsApprovedBEShifting = item.IsApprovedBEShifting,
|
|
SupportConceptApprovalPeriod_IsApprovedFixedAmountShifting = item.IsApprovedFixedAmountShifting,
|
|
SupportConceptApprovalPeriod_MonthlyPayment = item.MonthlyPayment,
|
|
SupportConceptApprovalPeriod_StartDate = item.StartDate,
|
|
SupportConceptApprovalPeriod_SupportConceptApprovalPeriod2Employee = item.SupportConceptApprovalPeriod2Employee,
|
|
SupportConceptApprovalPeriod_SupportConceptHistoryOid = supportConceptHistoryEntry.Oid.Value,
|
|
Notice = item.Notice
|
|
};
|
|
DAOFactory.GenericDAO.Insert(scApprovalPeriodHistory);
|
|
}
|
|
}
|
|
//MakeHistoryEntry(lOriginal.Customer2PersonList, originalCustomer2PersonList, lOriginal.Oid, statementType);
|
|
//MakeHistoryEntry(lOriginal.Customer2OrganisationList, originalC2OList, lOriginal.Oid, statementType);
|
|
//MakeHistoryEntry(lOriginal.Employee2CustomerList, originale2CList, lOriginal.Oid, statementType);
|
|
}
|
|
|
|
// ToDo: Unterschriftenbemerkung hier einbauen
|
|
public static void MakeServiceRecordHistoryEntry(List<ServiceRecord> lOriginals, IEnumerable<long> serviceRecordOidList, StatementType statementType)
|
|
{
|
|
var serviceRecordHistoryEntries = new List<ServiceRecordHistory>();
|
|
|
|
if (statementType.Equals(StatementType.Insert) && serviceRecordOidList != null)
|
|
{
|
|
var iterator = 0;
|
|
foreach (var history in lOriginals.Select(serviceRecordOriginal => new ServiceRecordHistory
|
|
{
|
|
TimeStamp = DateTime.Now,
|
|
ChangeType = statementType,
|
|
CostBearer2SupportConcept = serviceRecordOriginal.CostBearer2SupportConcept,
|
|
CostBearer2SupportConceptOid = serviceRecordOriginal.CostBearer2SupportConceptOid,
|
|
Customer = serviceRecordOriginal.Customer,
|
|
CustomerOid = serviceRecordOriginal.CustomerOid,
|
|
Employee = serviceRecordOriginal.Employee,
|
|
EmployeeOid = serviceRecordOriginal.EmployeeOid,
|
|
End = serviceRecordOriginal.End,
|
|
Group = serviceRecordOriginal.Group,
|
|
GroupEmployeeCount = serviceRecordOriginal.GroupEmployeeCount,
|
|
GroupOid = serviceRecordOriginal.GroupOid,
|
|
GroupPersonCount = serviceRecordOriginal.GroupPersonCount,
|
|
GroupRoundedDuration = serviceRecordOriginal.GroupRoundedDuration,
|
|
IP = serviceRecordOriginal.IP,
|
|
IsActive = serviceRecordOriginal.IsActive,
|
|
Notice = serviceRecordOriginal.Notice,
|
|
ServiceRecordOid = serviceRecordOidList.ElementAt(iterator),
|
|
RoundedDuration = serviceRecordOriginal.RoundedDuration,
|
|
ServiceDescription = serviceRecordOriginal.ServiceDescription,
|
|
ServiceRecordType = serviceRecordOriginal.ServiceRecordType,
|
|
ServiceRecordInsTs = serviceRecordOriginal.InsTs,
|
|
ServiceRecordVersion = serviceRecordOriginal.Version ?? 0,
|
|
ServiceRecordInsUser = serviceRecordOriginal.InsUser,
|
|
ServiceRecordUdpUser = serviceRecordOriginal.UdpUser,
|
|
Start = serviceRecordOriginal.Start,
|
|
SupportConcept = serviceRecordOriginal.SupportConcept,
|
|
SystemEntryID = serviceRecordOriginal.SystemEntryID,
|
|
DistanceInMeter = serviceRecordOriginal.DistanceInMeter,
|
|
IsCreatedInMobileClient = serviceRecordOriginal.IsCreatedInMobileClient
|
|
}))
|
|
{
|
|
iterator++;
|
|
serviceRecordHistoryEntries.Add(history);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var original in lOriginals)
|
|
{
|
|
SignatureStateInfoFromServiceRecordHistoryEntry previousRecordHistorySignatureInfo = null;
|
|
|
|
if (original.Oid.HasValue)
|
|
{
|
|
previousRecordHistorySignatureInfo = DAOFactory.SearchDAO.FindMostRecentSignatureStatusInfoByServiceRecordOid(original.Oid.Value);
|
|
}
|
|
|
|
serviceRecordHistoryEntries.AddIfNotIn(new ServiceRecordHistory
|
|
{
|
|
TimeStamp = DateTime.Now,
|
|
ChangeType = statementType,
|
|
CostBearer2SupportConcept = original.CostBearer2SupportConcept,
|
|
CostBearer2SupportConceptOid = original.CostBearer2SupportConceptOid,
|
|
Customer = original.Customer,
|
|
CustomerOid = original.CustomerOid,
|
|
Employee = original.Employee,
|
|
EmployeeOid = original.EmployeeOid,
|
|
End = original.End,
|
|
Group = original.Group,
|
|
GroupEmployeeCount = original.GroupEmployeeCount,
|
|
GroupOid = original.GroupOid,
|
|
GroupPersonCount = original.GroupPersonCount,
|
|
GroupRoundedDuration = original.GroupRoundedDuration,
|
|
IP = original.IP,
|
|
IsActive = original.IsActive,
|
|
Notice = original.Notice,
|
|
ServiceRecordOid = original.Oid,
|
|
RoundedDuration = original.RoundedDuration,
|
|
ServiceDescription = original.ServiceDescription,
|
|
ServiceRecordType = original.ServiceRecordType,
|
|
ServiceRecordInsTs = original.InsTs,
|
|
ServiceRecordVersion = original.Version ?? 0,
|
|
ServiceRecordInsUser = original.InsUser,
|
|
ServiceRecordUdpUser = original.UdpUser,
|
|
Start = original.Start,
|
|
SupportConcept = original.SupportConcept,
|
|
SystemEntryID = original.SystemEntryID,
|
|
DistanceInMeter = original.DistanceInMeter,
|
|
IsCreatedInMobileClient = original.IsCreatedInMobileClient,
|
|
ServiceRecordSignatureStateType = previousRecordHistorySignatureInfo?.ServiceRecordSignatureStateType ?? SignatureStateType.None,
|
|
CustomerConfirmationReceiptSignatureStateType = previousRecordHistorySignatureInfo?.CustomerConfirmationReceiptSignatureStateType ?? SignatureStateType.None,
|
|
EmployeeConfirmationReceiptSignatureStateType = previousRecordHistorySignatureInfo?.EmployeeConfirmationReceiptSignatureStateType ?? SignatureStateType.None,
|
|
CustomerConfirmationReceiptSignatureOid = previousRecordHistorySignatureInfo?.CustomerConfirmationReceiptSignatureOid,
|
|
EmployeeConfirmationReceiptSignatureOid = previousRecordHistorySignatureInfo?.EmployeeConfirmationReceiptSignatureOid
|
|
});
|
|
}
|
|
}
|
|
|
|
DAOFactory.GenericDAO.Insert(serviceRecordHistoryEntries);
|
|
}
|
|
|
|
public static void MakeServiceRecordHistoryEntryWithSignatureStates(List<ServiceRecord2SignatureStates> serviceRecords2SignatureStates, StatementType statementType)
|
|
{
|
|
var serviceRecordHistoryEntries = new List<ServiceRecordHistory>();
|
|
|
|
foreach (var serviceRecord2SignatureState in serviceRecords2SignatureStates)
|
|
{
|
|
var serviceRecord = serviceRecord2SignatureState.ServiceRecord;
|
|
var singleSignatureState = serviceRecord2SignatureState.SingleSignatureStateType;
|
|
var customerMonthlySignatureState = serviceRecord2SignatureState.CustomerMonthlySignatureStateType;
|
|
var employeeMonthlySignatureState = serviceRecord2SignatureState.EmployeeMonthlySignatreStateType;
|
|
|
|
SignatureStateInfoFromServiceRecordHistoryEntry previousRecordHistorySignatureInfo = null;
|
|
|
|
if (serviceRecord.Oid.HasValue)
|
|
{
|
|
//previousRecordHistoryEntry = DAOFactory.SearchDAO.FindMostRecentServiceRecordHistoryEntryByServiceRecordOid(serviceRecord.Oid.Value);
|
|
previousRecordHistorySignatureInfo = DAOFactory.SearchDAO.FindMostRecentSignatureStatusInfoByServiceRecordOid(serviceRecord.Oid.Value);
|
|
}
|
|
|
|
serviceRecordHistoryEntries.AddIfNotIn(new ServiceRecordHistory
|
|
{
|
|
TimeStamp = DateTime.Now,
|
|
ChangeType = statementType,
|
|
CostBearer2SupportConcept = serviceRecord.CostBearer2SupportConcept,
|
|
CostBearer2SupportConceptOid = serviceRecord.CostBearer2SupportConceptOid,
|
|
Customer = serviceRecord.Customer,
|
|
CustomerOid = serviceRecord.CustomerOid,
|
|
Employee = serviceRecord.Employee,
|
|
EmployeeOid = serviceRecord.EmployeeOid,
|
|
End = serviceRecord.End,
|
|
Group = serviceRecord.Group,
|
|
GroupEmployeeCount = serviceRecord.GroupEmployeeCount,
|
|
GroupOid = serviceRecord.GroupOid,
|
|
GroupPersonCount = serviceRecord.GroupPersonCount,
|
|
GroupRoundedDuration = serviceRecord.GroupRoundedDuration,
|
|
IP = serviceRecord.IP,
|
|
IsActive = serviceRecord.IsActive,
|
|
Notice = serviceRecord.Notice,
|
|
ServiceRecordOid = serviceRecord.Oid,
|
|
RoundedDuration = serviceRecord.RoundedDuration,
|
|
ServiceDescription = serviceRecord.ServiceDescription,
|
|
ServiceRecordType = serviceRecord.ServiceRecordType,
|
|
ServiceRecordInsTs = serviceRecord.InsTs,
|
|
ServiceRecordVersion = serviceRecord.Version ?? 0,
|
|
ServiceRecordInsUser = serviceRecord.InsUser,
|
|
ServiceRecordUdpUser = serviceRecord.UdpUser,
|
|
Start = serviceRecord.Start,
|
|
SupportConcept = serviceRecord.SupportConcept,
|
|
SystemEntryID = serviceRecord.SystemEntryID,
|
|
DistanceInMeter = serviceRecord.DistanceInMeter,
|
|
IsCreatedInMobileClient = serviceRecord.IsCreatedInMobileClient,
|
|
ServiceRecordSignatureStateType = singleSignatureState ?? previousRecordHistorySignatureInfo?.ServiceRecordSignatureStateType ?? SignatureStateType.None,
|
|
CustomerConfirmationReceiptSignatureStateType = customerMonthlySignatureState ?? previousRecordHistorySignatureInfo?.CustomerConfirmationReceiptSignatureStateType ?? SignatureStateType.None,
|
|
EmployeeConfirmationReceiptSignatureStateType = employeeMonthlySignatureState ?? previousRecordHistorySignatureInfo?.EmployeeConfirmationReceiptSignatureStateType ?? SignatureStateType.None,
|
|
CustomerConfirmationReceiptSignatureOid = previousRecordHistorySignatureInfo?.CustomerConfirmationReceiptSignatureOid,
|
|
EmployeeConfirmationReceiptSignatureOid = previousRecordHistorySignatureInfo?.EmployeeConfirmationReceiptSignatureOid
|
|
});
|
|
}
|
|
|
|
DAOFactory.GenericDAO.Insert(serviceRecordHistoryEntries);
|
|
}
|
|
|
|
public static Bargeldtransaktionshistory CreateTransactionHistoryObject(Bargeldtransaktion transaction, StatementType changeType, SignatureStateType signatureState)
|
|
{
|
|
return new Bargeldtransaktionshistory
|
|
{
|
|
Betrag = transaction.Betrag,
|
|
BargeldtransaktionOid = transaction.Oid,
|
|
BargeldtransaktionInsTs = transaction.InsTs,
|
|
BargeldtransaktionInsUser = transaction.InsUser,
|
|
BargeldtransaktionUdpUser = transaction.UdpUser,
|
|
BargeldtransaktionVersion = transaction.Version,
|
|
ChangeType = changeType,
|
|
Belegnummer = transaction.Belegnummer,
|
|
Notice = transaction.Notice,
|
|
IsActive = ActivationTypeId.Active,
|
|
SignatureOid = transaction.SignatureOid,
|
|
SignatureState = signatureState,
|
|
Zahlungstyp = transaction.Zahlungstyp,
|
|
Zahlungsdatum = transaction.Zahlungsdatum
|
|
};
|
|
}
|
|
|
|
public static void MakeHistoryEntry<T>(IList<T> lNewList, List<T> lOriginalList, long? customerOid, StatementType sType) where T : BeWoEntityBase
|
|
{
|
|
if (sType.Equals(StatementType.Delete) || sType.Equals(StatementType.Insert) || sType.Equals(StatementType.Archived) || sType.Equals(StatementType.Reactivate))
|
|
{
|
|
foreach (T newObject in lNewList)
|
|
MakeActualHistoryEntry(newObject, sType, customerOid);
|
|
|
|
return;
|
|
}
|
|
|
|
List<long?> OidOfOriginalsList = lOriginalList.Select(element => element.Oid.Value).Select(oid => (long?)oid).ToList();
|
|
List<long?> OidOfNewsList = lNewList.Select(element => element.Oid.Value).Select(oid => (long?)oid).ToList();
|
|
|
|
if (lOriginalList.Count <= 0 && lNewList.Count <= 0)
|
|
return;
|
|
|
|
foreach (T newObject in lNewList)
|
|
{
|
|
if (!OidOfOriginalsList.Contains(newObject.Oid))
|
|
MakeActualHistoryEntry(newObject, StatementType.Insert, customerOid);
|
|
else
|
|
{
|
|
T TObject = lOriginalList.Find(t => t.Oid.Equals(newObject.Oid));
|
|
if (TObject.Version != newObject.Version)
|
|
MakeActualHistoryEntry(newObject, StatementType.Update, customerOid);
|
|
}
|
|
}
|
|
|
|
foreach (T oldObject in lOriginalList.Where(oldObject => !OidOfNewsList.Contains(oldObject.Oid)))
|
|
MakeActualHistoryEntry(oldObject, StatementType.Delete, customerOid);
|
|
}
|
|
|
|
public static void MakeActualHistoryEntry<T>(T entityObj, StatementType sType, long? customerOid)
|
|
{
|
|
Customer customer = null;
|
|
if (customerOid != null)
|
|
customer = DAOFactory.GenericDAO.LoadByID<Customer>(customerOid.Value);
|
|
|
|
if (entityObj is Customer2Person)
|
|
{
|
|
var customer2Person = entityObj as Customer2Person;
|
|
var historyEntry = new Customer2PersonHistory
|
|
{
|
|
ChangeType = sType,
|
|
Customer2PersonInsTs = customer2Person.InsTs,
|
|
Customer2PersonInsUser = customer2Person.InsUser,
|
|
Customer2PersonOid = customer2Person.Oid,
|
|
Customer2PersonUdpUser = customer2Person.UdpUser,
|
|
Customer2PersonVersion = customer2Person.Version.Value,
|
|
Notice = customer2Person.Notice,
|
|
Person = customer2Person.Person,
|
|
CustomerOid = customer.Oid
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(historyEntry);
|
|
}
|
|
else if (entityObj is Customer2Organisation)
|
|
{
|
|
var customer2Organisation = entityObj as Customer2Organisation;
|
|
var historyEntry = new Customer2OrganisationHistory
|
|
{
|
|
ChangeType = sType,
|
|
Organisation = customer2Organisation.Organisation,
|
|
Notice = customer2Organisation.Notice,
|
|
Customer2OrganisationInsTs = customer2Organisation.InsTs,
|
|
Customer2OrganisationOid = customer2Organisation.Oid,
|
|
Customer2OrganisationInsUser = customer2Organisation.InsUser,
|
|
Customer2OrganisationUdpUser = customer2Organisation.UdpUser,
|
|
Customer2OrganisationVersion = customer2Organisation.Version.Value,
|
|
Info1 = customer2Organisation.Info1,
|
|
Info2 = customer2Organisation.Info2,
|
|
Info3 = customer2Organisation.Info3,
|
|
Info4 = customer2Organisation.Info4,
|
|
Info5 = customer2Organisation.Info5,
|
|
CustomerOid = customer.Oid
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(historyEntry);
|
|
}
|
|
else if (entityObj is Employee2Customer)
|
|
{
|
|
var employee2Customer = entityObj as Employee2Customer;
|
|
var historyEntry = new Employee2CustomerHistory
|
|
{
|
|
ChangeType = sType,
|
|
Customer = customer,
|
|
CustomerOid = customer.Oid,
|
|
Employee = employee2Customer.Employee,
|
|
EmployeeOid = employee2Customer.EmployeeOid,
|
|
Employee2CustomerInsTs = employee2Customer.InsTs,
|
|
Employee2CustomerInsUser = employee2Customer.InsUser,
|
|
Employee2CustomerOid = employee2Customer.Oid.Value,
|
|
Employee2CustomerUdpUser = employee2Customer.UdpUser,
|
|
Employee2CustomerVersion = employee2Customer.Version.Value,
|
|
Notice = employee2Customer.Notice
|
|
};
|
|
|
|
DAOFactory.GenericDAO.Insert(historyEntry);
|
|
}
|
|
else if (entityObj is AbsenceTime)
|
|
{
|
|
var at = entityObj as AbsenceTime;
|
|
var atDc = MapperFactory.AbsenceTimeDC_AbsenceTime.MapToNewDC(at);
|
|
atDc.CustomerOid = customerOid;
|
|
CreateAbsenceTimeHistoryEntry(atDc, sType);
|
|
}
|
|
}
|
|
}
|
|
}
|