Exemplo n.º 1
0
 @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);
   }
 }
Exemplo n.º 2
0
  @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  public void paymentToInstallment(Long idPayment) {

    Payment payment = (Payment) paymentService.getById(idPayment);
    if (payment == null) {
      log.warn("No payment found with id :" + idPayment);
      return;
    }
    Installment installment = new Installment();
    installment.setDate(
        payment.getScheduleDate() != null ? payment.getScheduleDate() : payment.getDate());
    installment.setAmount(payment.getAmount());
    installment.setSale(payment.getSale());
    installment.setComment(payment.getComment());
    installment.setRequestDetails(payment.getRequestDetails());
    installment.setRequestBeforeDateSent(payment.isRequestBeforeDateSent());
    installment.setRequestAfterDateSent(payment.isRequestAfterDateSent());

    paymentService.remove(payment, true);
    installmentService.save(installment, true);

    trackingService.addTrackingToUserSession(
        TrackingType.paymentReceivedToInstallment, payment.getSale());
  }