Search in sources :

Example 41 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class InventoryUtil method createOrder.

public static MOrder createOrder(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int M_PriceList_ID;
    boolean isSOTrx;
    if (MDocType.DOCBASETYPE_SalesOrder.equals(doc.DocBaseType)) {
        M_PriceList_ID = Env.getContextAsInt(ctx, "SO_PriceList_ID");
        isSOTrx = true;
    } else if (MDocType.DOCBASETYPE_PurchaseOrder.equals(doc.DocBaseType)) {
        M_PriceList_ID = Env.getContextAsInt(ctx, "PO_PriceList_ID");
        isSOTrx = false;
    } else {
        throw new IllegalArgumentException("DocBaseType not supported - " + doc);
    }
    //
    int AD_Org_ID = getFirst_Org_ID();
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    //
    MOrder order = new MOrder(ctx, 0, trxName);
    order.setAD_Org_ID(AD_Org_ID);
    order.setIsSOTrx(isSOTrx);
    order.setC_DocTypeTarget_ID();
    order.setDateOrdered(doc.Date);
    order.setDateAcct(doc.Date);
    order.setDatePromised(doc.Date);
    order.setBPartner(getCreatePartner(doc.BPValue));
    order.setM_PriceList_ID(M_PriceList_ID);
    order.setM_Warehouse_ID(locator.getM_Warehouse_ID());
    setGeneratedTag(order);
    order.saveEx();
    // 
    MProduct product = getCreateProduct(doc.ProductValue, null);
    MOrderLine line = new MOrderLine(order);
    line.setProduct(product);
    line.setQty(doc.Qty);
    line.saveEx();
    //
    doc.document = order;
    processDocument(doc, MOrder.DOCACTION_Complete, MOrder.DOCSTATUS_Completed);
    return order;
}
Also used : MOrder(org.compiere.model.MOrder) MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) Properties(java.util.Properties)

Example 42 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class SubCurrentLine method actionPerformed.

// dispose
/**
 * Action Listener
 *
 * @param e event
 */
public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();
    if (action == null || action.length() == 0)
        return;
    log.info("actionPerformed: " + action);
    // Plus
    if (action.equals("Plus")) {
        if (orderLineId > 0) {
            MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
            BigDecimal newQty = line.getQtyOrdered().add(Env.ONE);
            if (line != null && hasStock(line.getProduct(), newQty) && hasCredit(line.getProduct(), newQty)) {
                line.setQty(newQty);
                line.saveEx();
            }
        }
    } else // Minus
    if (action.equals("Minus")) {
        if (orderLineId > 0) {
            MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
            if (line != null) {
                if (line.getQtyOrdered().compareTo(BigDecimal.ONE) > 0) {
                    line.setQty(line.getQtyOrdered().subtract(Env.ONE));
                    line.saveEx();
                }
            }
        }
    } else // Product Attribute
    if (action.equals("PAttribute")) {
        if (orderLineId > 0) {
            MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
            if (line != null) {
                requestProductAttributes(line);
            }
        }
        return;
    } else if (action.equals("Payment")) {
        payOrder();
        return;
    } else if (e.getSource() == f_price && orderLineId > 0) {
        MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
        if (line != null) {
            line.setPrice(new BigDecimal(f_price.getValue().toString()));
            line.saveEx();
        }
    } else if (e.getSource() == f_quantity && orderLineId > 0) {
        MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
        BigDecimal newQty = new BigDecimal(f_quantity.getValue().toString());
        if (line != null && hasStock(line.getProduct(), newQty)) {
            line.setQty(newQty);
            line.saveEx();
        }
    } else // Product
    if (action.equals("Product")) {
        setParameter();
        QueryProduct qt = new QueryProduct(p_posPanel);
        qt.setQueryData(m_M_PriceList_Version_ID, m_M_Warehouse_ID);
        qt.setVisible(true);
        // @emmie - avoid clean BP when no product is selected
        if (orderLineId <= 0)
            return;
    } else // ProductName
    if (e.getSource() == f_productName) {
        try {
            if (findProduct()) {
                p_posPanel.updateInfo();
            }
        } catch (AdempiereException ex) {
            ADialog.error(p_posPanel.getWindowNo(), this, ex.getMessage());
        }
        return;
    } else if ("Previous".equalsIgnoreCase(e.getActionCommand())) {
        int rows = m_table.getRowCount();
        if (rows == 0)
            return;
        int row = m_table.getSelectedRow();
        row--;
        if (row < 0)
            row = 0;
        m_table.getSelectionModel().setSelectionInterval(row, row);
        // https://sourceforge.net/tracker/?func=detail&atid=879332&aid=3121975&group_id=176962
        // @Trifon - BF[3121975]
        m_table.scrollRectToVisible(m_table.getCellRect(row, 1, true));
        return;
    } else if ("Next".equalsIgnoreCase(e.getActionCommand())) {
        int rows = m_table.getRowCount();
        if (rows == 0)
            return;
        int row = m_table.getSelectedRow();
        row++;
        if (row >= rows)
            row = rows - 1;
        m_table.getSelectionModel().setSelectionInterval(row, row);
        // https://sourceforge.net/tracker/?func=detail&atid=879332&aid=3121975&group_id=176962
        // @Trifon - BF[3121975]
        m_table.scrollRectToVisible(m_table.getCellRect(row, 1, true));
        return;
    } else // Delete
    if (action.equals("Cancel")) {
        int rows = m_table.getRowCount();
        if (rows != 0) {
            int row = m_table.getSelectedRow();
            if (row != -1) {
                if (p_posPanel.m_order != null)
                    p_posPanel.m_order.deleteLine(m_table.getSelectedRowKey());
                setQty(null);
                setPrice(null);
                orderLineId = 0;
            }
        }
    }
    p_posPanel.updateInfo();
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 43 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class SubCurrentLine method focusLost.

/**
 * 	Focus Lost
 *	@param e
 */
public void focusLost(FocusEvent e) {
    if (e.isTemporary())
        return;
    log.info("PosSubProduct - focusLost");
    // Product Name
    if (e.getSource() == f_productName) {
        if (!findProduct())
            return;
    } else // Price
    if (e.getSource() == f_price && orderLineId > 0) {
        MOrderLine line = new MOrderLine(p_ctx, orderLineId, null);
        if (line != null) {
            // force commit edited value of f_price
            try {
                f_price.commitEdit();
            } catch (ParseException ex) {
                log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
                return;
            }
            line.setPrice(new BigDecimal(f_price.getValue().toString()));
            line.saveEx();
        }
    }
    p_posPanel.updateInfo();
}
Also used : MOrderLine(org.compiere.model.MOrderLine) ParseException(java.text.ParseException) BigDecimal(java.math.BigDecimal)

Example 44 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class PosOrderModel method createLine.

/**
 * Create new Line
 *
 * @return line or null
 */
public MOrderLine createLine(MProduct product, BigDecimal qtyOrdered, BigDecimal priceActual, int WindowNo) {
    if (!(getDocStatus().equals("DR") || getDocStatus().equals("IP"))) {
        return null;
    }
    String stockMsg = checkStockAvailable(product, qtyOrdered, WindowNo);
    if (stockMsg != null) {
        throw new AdempierePOSException(stockMsg);
    }
    String creditMsg = checkCreditAvailable(product, Env.ONE);
    if (creditMsg != null) {
        throw new AdempierePOSException(creditMsg);
    }
    // add new line or increase qty
    // catch Exceptions at order.getLines()
    int numLines = 0;
    MOrderLine[] lines = null;
    try {
        lines = getLines(null, "Line");
        numLines = lines.length;
        for (int i = 0; i < numLines; i++) {
            if (lines[i].getM_Product_ID() == product.getM_Product_ID()) {
                // increase qty
                BigDecimal current = lines[i].getQtyEntered();
                BigDecimal toadd = qtyOrdered;
                BigDecimal total = current.add(toadd);
                lines[i].setQty(total);
                // sets List/limit
                lines[i].setPrice();
                if (priceActual.compareTo(Env.ZERO) > 0)
                    lines[i].setPrice(priceActual);
                lines[i].save();
                return lines[i];
            }
        }
    } catch (Exception e) {
        log.severe("Order lines cannot be created - " + e.getMessage());
    }
    // create new line
    MOrderLine line = new MOrderLine(this);
    line.setProduct(product);
    line.setQty(qtyOrdered);
    // sets List/limit
    line.setPrice();
    if (priceActual.compareTo(Env.ZERO) > 0)
        line.setPrice(priceActual);
    line.save();
    return line;
}
Also used : MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 45 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class ImprimeTicketEnvio method printDetalle.

// printEncabezado
private void printDetalle(final MOrder orden) throws JposException {
    printer.setRecLetterQuality(false);
    String linea;
    linea = Util.stringRepeat("_", printer.getRecLineChars());
    printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, linea + LF);
    linea = "Código" + Util.stringRepeat(" ", 9) + "Descripción" + Util.stringRepeat(" ", 9) + "Importe";
    printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, linea + LF);
    // printer.setRecLineSpacing(10);
    printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, CENTER + "Cantidad x Precio" + LF);
    // printer.setRecLineSpacing(200);
    linea = Util.stringRepeat("_", printer.getRecLineChars());
    printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, linea + LF);
    for (final MOrderLine det : orden.getLines()) {
        final MProduct prod = det.getProduct();
        final BigDecimal precioLinea = det.getLineNetAmt();
        final BigDecimal precioUnitario = det.getPriceActual();
        linea = Util.justifyString(prod.getValue(), 12, -1) + Util.justifyString(prod.getName(), 20, -1) + Util.formatDecimal(precioLinea, 2, 10);
        printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, linea + LF);
        linea = "     " + det.getQtyInvoiced() + " x " + Util.formatDecimal(precioUnitario, 2, 0) + " c/u";
        printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, linea + LF);
    }
}
Also used : MProduct(org.compiere.model.MProduct) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)87 BigDecimal (java.math.BigDecimal)44 MOrder (org.compiere.model.MOrder)42 MInOutLine (org.compiere.model.MInOutLine)16 MProduct (org.compiere.model.MProduct)15 MBPartner (org.compiere.model.MBPartner)14 MInOut (org.compiere.model.MInOut)11 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)7 MInvoice (org.compiere.model.MInvoice)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 SQLException (java.sql.SQLException)5 MLocator (org.compiere.model.MLocator)5 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MBPartnerLocation (org.compiere.model.MBPartnerLocation)3 MDocType (org.compiere.model.MDocType)3