in service/src/main/java/org/apache/fineract/cn/payroll/service/internal/command/handler/PayrollDistributionAggregate.java [70:104]
public String process(final DistributePayrollCommand distributePayrollCommand) {
final PayrollCollectionSheet payrollCollectionSheet = distributePayrollCommand.payrollCollectionSheet();
final PayrollCollectionEntity payrollCollectionEntity = new PayrollCollectionEntity();
payrollCollectionEntity.setIdentifier(RandomStringUtils.randomAlphanumeric(32));
payrollCollectionEntity.setSourceAccountNumber(payrollCollectionSheet.getSourceAccountNumber());
payrollCollectionEntity.setCreatedBy(UserContextHolder.checkedGetUser());
payrollCollectionEntity.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
final PayrollCollectionEntity savedPayrollCollectionEntity = this.payrollCollectionRepository.save(payrollCollectionEntity);
payrollCollectionSheet.getPayrollPayments().forEach(payrollPayment ->
this.payrollConfigurationService
.findPayrollConfiguration(payrollPayment.getCustomerIdentifier())
.ifPresent(payrollConfiguration -> {
final PayrollPaymentEntity payrollPaymentEntity = new PayrollPaymentEntity();
payrollPaymentEntity.setPayrollCollection(savedPayrollCollectionEntity);
payrollPaymentEntity.setCustomerIdentifier(payrollPayment.getCustomerIdentifier());
payrollPaymentEntity.setEmployer(payrollPayment.getEmployer());
payrollPaymentEntity.setSalary(payrollPayment.getSalary());
final Optional<String> optionalErrorMessage =
this.accountingAdaptor.postPayrollPayment(savedPayrollCollectionEntity, payrollPayment, payrollConfiguration);
if (optionalErrorMessage.isPresent()) {
payrollPaymentEntity.setMessage(optionalErrorMessage.get());
payrollPaymentEntity.setProcessed(Boolean.FALSE);
} else {
payrollPaymentEntity.setProcessed(Boolean.TRUE);
}
this.payrollPaymentRepository.save(payrollPaymentEntity);
})
);
return payrollCollectionSheet.getSourceAccountNumber();
}