@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void installmentToPayment(Installment installment) throws IabakoPackageForbiddenException { Installment installmentFromDB = (Installment) installmentService.getById(installment.getId()); if (installmentFromDB == null) { log.warn("No installment found with id :" + installment.getId()); return; } Payment payment = new Payment(); payment.setDate(GenericTools.getDateFromString(installment.getDateString())); payment.setScheduleDate(GenericTools.getDateFromString(installment.getScheduleDateString())); payment.setAmount(installment.getAmount()); payment.setSale(installment.getSale()); payment.setComment(installment.getComment()); payment.setPaymentMethod(installment.getPaymentMethod()); payment.setRequestDetails(installment.getRequestDetails()); payment.setRequestBeforeDateSent(installment.isRequestBeforeDateSent()); payment.setRequestAfterDateSent(installment.isRequestAfterDateSent()); installmentService.remove(installmentFromDB, true); paymentService.save(payment, true); trackingService.addTrackingToUserSession( TrackingType.installmentToPaymentReceived, installment.getSale()); }
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void deleteInstallmentsByAmount(Sale sale, Double amount) { List<Installment> installments = getInstallments(sale); Double balance = amount; List<Installment> toDelete = new ArrayList<Installment>(); Installment toMerge = null; for (Installment i : installments) { balance = ServerTools.round(balance - i.getAmount()); if (balance >= 0) { toDelete.add(i); } else { toMerge = i; toMerge.setAmount(balance * -1); break; } } for (Installment i : toDelete) { installmentService.remove(i, true); } if (toMerge != null) { installmentService.save(toMerge, true); } }