Beispiel #1
0
 public BigDecimal getTotalAmount() {
   BigDecimal total = BigDecimal.ZERO;
   for (InvoiceLine line : getInvoiceLines()) {
     total = total.add(line.getPrice());
   }
   return total;
 }
Beispiel #2
0
  public static Invoice createInvoice(User u, Plan p) {
    Invoice i = new Invoice();
    i.setUser(u);
    i.setInvoiceDate(new Date());
    i.insert();

    InvoiceLine line = new InvoiceLine();
    line.setName(p.getInvoiceLineName());
    line.setDescription(p.getInvoiceLineDescription());
    line.setQuantity(1);
    line.setPrice(p.getMonthlyCost());
    line.setParentInvoice(i);
    line.insert();

    return i;
  }
  /**
   * Descripción de Método
   *
   * @param C_Invoice_ID
   */
  private void loadInvoice(int C_Invoice_ID) {
    log.config("C_Invoice_ID=" + C_Invoice_ID);
    if (C_Invoice_ID > 0) {
      m_invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, null); // save
      // Se carga la EC de la factura.
      if (bPartnerField != null) {
        bPartnerField.setValue(m_invoice.getC_BPartner_ID());
      }
    }
    p_order = null;

    List<InvoiceLine> data = new ArrayList<InvoiceLine>();

    StringBuffer sql = new StringBuffer();
    sql.append("SELECT ") // Entered UOM
        .append("l.C_InvoiceLine_ID, ")
        .append("l.Line, ")
        .append("l.Description, ")
        .append("l.M_Product_ID, ")
        .append("p.Name AS ProductName, ")
        .append("l.C_UOM_ID, ")
        .append("QtyInvoiced, ")
        .append("l.QtyInvoiced-SUM(NVL(mi.Qty,0)) AS RemainingQty, ")
        .append("l.QtyEntered/l.QtyInvoiced AS Multiplier, ")
        .append("COALESCE(l.C_OrderLine_ID,0) AS C_OrderLine_ID ")
        .append("FROM C_UOM uom, C_InvoiceLine l, M_Product p, M_MatchInv mi ")
        .append("WHERE l.C_UOM_ID=uom.C_UOM_ID ")
        .append("AND l.M_Product_ID=p.M_Product_ID ")
        .append("AND l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID(+) ")
        .append("AND l.C_Invoice_ID=? ")
        .append(
            "GROUP BY l.QtyInvoiced, l.QtyEntered/l.QtyInvoiced, l.C_UOM_ID, l.M_Product_ID, p.Name, l.C_InvoiceLine_ID, l.Line, l.C_OrderLine_ID, l.Description ")
        .append("ORDER BY l.Line ");

    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
      pstmt = DB.prepareStatement(sql.toString());
      pstmt.setInt(1, C_Invoice_ID);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        InvoiceLine invoiceLine = new InvoiceLine();

        // Por defecto no está seleccionada para ser procesada
        invoiceLine.selected = false;

        // ID de la línea de factura
        invoiceLine.invoiceLineID = rs.getInt("C_InvoiceLine_ID");

        // Nro de línea
        invoiceLine.lineNo = rs.getInt("Line");

        // Descripción
        invoiceLine.description = rs.getString("Description");

        // Cantidades
        BigDecimal multiplier = rs.getBigDecimal("Multiplier");
        BigDecimal qtyInvoiced = rs.getBigDecimal("QtyInvoiced").multiply(multiplier);
        BigDecimal remainingQty = rs.getBigDecimal("RemainingQty").multiply(multiplier);
        invoiceLine.lineQty = qtyInvoiced;
        invoiceLine.remainingQty = remainingQty;

        // Artículo
        invoiceLine.productID = rs.getInt("M_Product_ID");
        invoiceLine.productName = rs.getString("ProductName");

        // Unidad de Medida
        invoiceLine.uomID = rs.getInt("C_UOM_ID");
        invoiceLine.uomName = getUOMName(invoiceLine.uomID);

        // Línea de pedido (puede ser 0)
        invoiceLine.orderLineID = rs.getInt("C_OrderLine_ID");

        // Agrega la línea a la lista solo si tiene cantidad pendiente
        if (invoiceLine.remainingQty.compareTo(BigDecimal.ZERO) > 0) {
          data.add(invoiceLine);
        }
      }

    } catch (SQLException e) {
      log.log(Level.SEVERE, sql.toString(), e);
    } finally {
      try {
        if (rs != null) rs.close();
        if (pstmt != null) pstmt.close();
      } catch (Exception e) {
      }
    }

    loadTable(data);
  } // loadInvoice
Beispiel #4
0
 public List<InvoiceLine> getInvoiceLines() {
   return InvoiceLine.all().filter("parentInvoice", this).fetch();
 }
Beispiel #5
0
  public void addItem(InvoiceLine item) {
    items.add(item);

    net = net.add(item.getNet());
    gros = gros.add(item.getGros());
  }