"Stopped (error): Cannot create a record in Employee Benefits (Go2PayEmplBenefit). Insert not supported with the values specified for 'Effective' and 'Expiration'. New record overlaps with multiple existing records."
private void updateEmployeeBenefits(HRServiceRequest _serviceRequest, List _benefits, EmplId _emplId)
{
EmplBenefit emplBenefit, emplBenefitNew;
EmplGroupBenefit emplGroupBenefit;
HRMPayrollLine payrolling;
TransDate transDate, validFrom, validTo, startDate, endDate;
ListEnumerator enumerator = _benefits.getEnumerator();
transDate = systemDateGet();
while(enumerator.moveNext())
{
str currentBenefitType = enumerator.current();
select validtimestate(transDate) payrollLine
where payrollLine.EmplId == _emplId;
if(!payrollLine.HrmPayrollCategoryId)
{
return;
}
startDate = payrollLine.ValidFrom;
endDate = payrollLine.ValidTo;
while select validtimestate(startDate, endDate) emplGroupBenefit
where emplGroupBenefit.BenefitType == currentBenefitType
&& emplGroupBenefit.HRMPayrollCategoryId == payrollLine.HrmPayrollCategoryId
{
if(emplGroupBenefit)
{
validFrom = emplGroupBenefit.ValidFrom;
validTo = emplGroupBenefit.ValidTo;
select forupdate validtimestate(validTo) emplBenefit
where emplBenefit.EmplId == _emplId
&& emplBenefit.BenefitType == emplGroupBenefit.BenefitType;
if(emplBenefit)
{
ttsbegin;
emplBenefit.EntitledBenefitsAmount = emplGroupBenefit.Amount;
emplBenefit.BenefitsTaken = emplGroupBenefit.Amount;
emplBenefit.Monetize = _serviceRequest.Monetize ? NoYes::Yes : NoYes::No;
emplBenefit.ValidFrom = _serviceRequest.RequiredDate;
emplBenefit.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
emplBenefit.update();
ttscommit;
continue;
}
select validtimestate(validFrom, validTo) emplBenefit
order by validFrom
where emplBenefit.EmplId == _emplId
&& emplBenefit.BenefitType == emplGroupBenefit.BenefitType;
emplBenefitNew.clear();
emplBenefitNew.BenefitType = emplGroupBenefit.BenefitType;
emplBenefitNew.EntitledBenefitsAmount = emplGroupBenefit.Amount;
emplBenefitNew.BenefitsTaken = emplGroupBenefit.Amount;
emplBenefitNew.Monetize = _serviceRequest.Monetize ? NoYes::Yes : NoYes::No;
if (emplBenefit.RecId)
{
// Handle overlapping records
emplBenefitNew.ValidFrom = _serviceRequest.RequiredDate;
emplBenefitNew.ValidTo = emplGroupBenefit.ValidTo - 1;
}
else
{
emplBenefitNew.ValidFrom = _serviceRequest.RequiredDate;
emplBenefitNew.ValidTo = emplGroupBenefit.ValidTo;
}
emplBenefitNew.validTimeStateUpdateMode(ValidTimeStateUpdate::CreateNewTimePeriod);
emplBenefitNew.insert();
}
}
}
}