Beispiel #1
0
  public void update(Integer entityId, NewInvoiceDTO addition) {
    // add the lines to the invoice first
    createLines(addition);
    // update the inoice record considering the new lines
    invoice.setTotal(calculateTotal()); // new total
    // adjust the balance
    addition.calculateTotal();
    BigDecimal balance = invoice.getBalance();
    balance = balance.add(addition.getTotal());
    invoice.setBalance(balance);

    if (invoice.getBalance().compareTo(BigDecimal.ZERO) == 0) {
      invoice.setToProcess(Integer.valueOf(0));
    }

    if (addition.getMetaFields() != null && !addition.getMetaFields().isEmpty()) {
      invoice.updateMetaFieldsWithValidation(entityId, addition);
    }
  }
  private InvoiceDTO generateDBInvoice(
      Integer userId, NewInvoiceDTO newInvoice, BillingProcessDTO process, Integer origin)
      throws SessionInternalError {
    // The invoice row is created first
    // all that fits in the DTO goes there
    newInvoice.calculateTotal();

    newInvoice.setBalance(newInvoice.getTotal());

    newInvoice.setInProcessPayment(new Integer(1));
    InvoiceBL invoiceBL = new InvoiceBL();

    try {
      invoiceBL.create(userId, newInvoice, process);
      invoiceBL.createLines(newInvoice);
    } catch (Exception e) {
      LOG.fatal("CreateException creating invoice record", e);
      throw new SessionInternalError("Couldn't create the invoice record");
    }

    createOrderProcess(newInvoice, invoiceBL.getEntity(), process, origin);

    return invoiceBL.getEntity();
  }