Help with code: record already exists

Can not create a record in Earnings statements (PayrollEarningStatement). Earnings statement number (The record already exists)

payrollEarningStatement = payrollEarningStatement::findByDocumentNumber(_PayRoll.DocumentNumber(),true);
if(!payrollEarningStatement.RecId)
{
payrollEarningStatement.DocumentNumber = _PayRoll.DocumentNumber();
payrollEarningStatement.SourceDocumentHeader = _PayRoll.SourceDocumentHeader();
payrollEarningStatement.Note = _PayRoll.Note();
payrollEarningStatement.Worker = _PayRoll.Worker();
payrollEarningStatement.PayPeriod = _PayRoll.PayPeriod();
payrollEarningStatement.Worker = hcmWorker.RecId;
payrollEarningStatement.SourceDocumentHeader = SourceDocumentHeader.RecId;
payrollEarningStatement.PayPeriod = payrollPayPeriod.RecId;

payrollEarningStatement.insert();

The error says that you can’t insert a record with such values, because there already is another record with the same values in a unique index. The database doesn’t allow you to put duplicates to unique indexes.
Use different values.