public CollectionsResponse updateCollection()

in service/src/main/java/org/apache/fineract/cn/deposit/service/internal/command/handler/CollectionsCommandHandler.java [91:114]


    public CollectionsResponse updateCollection(@NotNull UpdateCollectionsCommand command) {

        CollectionsEntity collectionsEntity = this.collectionsRepository.findByCollectionReference(command.getCollectionsReference())
                .orElseThrow(() -> ServiceException.notFound("Collection {0} not found", command.getCollectionsReference()));

        collectionsEntity.setAmount(BigDecimal.ZERO);
        collectionsEntity.getIndvCollections().forEach(x->{
                Optional<IndividualPayments> individualPaymentsOptional =  command.getCollectionRequest().getIndividualPayments().stream().filter(a -> x.getAccount().getAccountIdentifier().equals(a.getAccountNumber())).findFirst();
                if(individualPaymentsOptional.isPresent()){
                    IndividualPayments individualPayment = individualPaymentsOptional.get();
                    x.setAttendance(individualPayment.getAttendance());
                    if(individualPayment.getAmount() != null) {
                        x.setAmount(individualPayment.getAmount());
                    }
                    collectionsEntity.setAmount(collectionsEntity.getAmount().add(x.getAmount()));
                }
            }
        );

        //save collections
        collectionsRepository.save(collectionsEntity);

        return CollectionsMapper.map(collectionsEntity);
    }