Search in sources :

Example 56 with Query

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

the class AcctViewer method actionButton.

//  actionTable
/**
	 *  Action Button
	 *
	 *  @param button pressed button
	 *  @return ID
	 */
private int actionButton(CButton button) {
    String keyColumn = button.getActionCommand();
    log.info(keyColumn);
    String whereClause = "(IsSummary='N' OR IsSummary IS NULL)";
    String lookupColumn = keyColumn;
    int record_id = m_data.getButtonRecordID(keyColumn);
    if (keyColumn.equals("Account_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User1_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList1);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User2_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList2);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User3_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList3);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User4_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList4);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("M_Product_ID")) {
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement1_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X1' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement2_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X2' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    } else if (selDocument.isSelected())
        whereClause = "";
    if (//  Record_ID
    button == selRecord)
        record_id = m_data.Record_ID;
    else
        record_id = m_data.getButtonRecordID(keyColumn);
    String tableName = lookupColumn.substring(0, lookupColumn.length() - 3);
    Info info = Info.create(this, true, m_data.WindowNo, tableName, lookupColumn, record_id, "", false, true, whereClause);
    if (!info.loadedOK()) {
        info.dispose();
        info = null;
        button.setText("");
        m_data.whereInfo.put(keyColumn, "");
        m_data.buttonRecordID.put(keyColumn, null);
        return 0;
    }
    info.setVisible(true);
    boolean isCancelled = info.isCancelled();
    boolean isOK = info.isOk();
    Integer key = 0;
    if (// Delete the saved info
    isCancelled && !isOK) {
        key = 0;
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  no query
            m_data.whereInfo.put(keyColumn, "");
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        button.setText("");
    } else if (!isCancelled && isOK) {
        //  Save for query
        //  C_Project_ID=100 or ""
        String selectSQL = info.getSelectedSQL();
        key = (Integer) info.getSelectedKey();
        log.config(keyColumn + " - " + key);
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  Add to query
            m_data.whereInfo.put(keyColumn, keyColumn + "=" + key.intValue());
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        //  Display Selection and resize
        button.setText(m_data.getButtonText(tableName, lookupColumn, selectSQL));
        pack();
    } else if (// xor: window closed or error - no change
    !(isCancelled ^ isOK)) {
        // m_data not changed
        if (//  Record_ID
        button == selRecord)
            key = m_data.Record_ID = key.intValue();
        else
            key = m_data.getButtonRecordID(keyColumn);
    }
    info = null;
    return key.intValue();
}
Also used : Query(org.compiere.model.Query) Info(org.compiere.apps.search.Info) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 57 with Query

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

the class ScanBar method getDocumentLines.

private List<PO> getDocumentLines() {
    StringBuilder whereClause = new StringBuilder();
    whereClause.append(getTable().getKeyColumns()[0]).append("=? ");
    return new Query(Env.getCtx(), tableLine.getTableName(), whereClause.toString(), null).setClient_ID().setParameters(getRecord_ID()).list();
}
Also used : Query(org.compiere.model.Query)

Example 58 with Query

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

the class ScanBar method createLine.

public void createLine() {
    int lineNo = DB.getSQLValueEx(null, "SELECT Line FROM " + tableLine.getTableName() + " WHERE " + table.getTableName() + "_ID=?", getRecord_ID());
    if (lineNo <= 0)
        lineNo = 10;
    for (Vector<Object> line : getData().values()) {
        String value = (String) line.get(0);
        String lotNo = (String) line.get(2);
        String serNo = (String) line.get(3);
        Boolean isASI = (lotNo != null && lotNo.length() > 0) || (serNo != null && serNo.length() > 0) ? true : false;
        BigDecimal qty = (BigDecimal) line.get(4);
        int id = (Integer) line.get(5);
        Integer referenceId = (Integer) line.get(6);
        PO poLine = null;
        MAttributeSetInstance asi = null;
        MProduct product = new Query(Env.getCtx(), I_M_Product.Table_Name, "Value = ? ", null).setClient_ID().setParameters(value).firstOnly();
        String desc = null;
        poLine = tableLine.getPO(id, null);
        if (product.getM_AttributeSet_ID() > 0 && isASI) {
            if (poLine != null && poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID) > 0)
                asi = new MAttributeSetInstance(Env.getCtx(), poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID), null);
            else
                asi = getAttributeSetInstance(product, lotNo, serNo, getM_Locater_ID(), null);
        }
        poLine.set_ValueOfColumn(table.getKeyColumns()[0], getRecord_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_M_Product_ID, product.get_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_C_UOM_ID, product.getC_UOM_ID());
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_Line, lineNo);
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_IsActive, true);
        int locatorColumnId = poLine.get_ColumnIndex(I_M_InOutLine.COLUMNNAME_M_Locator_ID);
        if (locatorColumnId > 0 && getM_Locater_ID() > 0)
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_M_Locator_ID, getM_Locater_ID());
        if (asi == null && isASI) {
            if (asi == null && isASI) {
                asi = new MAttributeSetInstance(Env.getCtx(), 0, product.getM_AttributeSet_ID(), null);
                if (lotNo != null) {
                    asi.setLot(lotNo);
                    desc = lotNo;
                }
                if (serNo != null) {
                    asi.setSerNo(serNo);
                    if (desc != null)
                        desc = desc + " - " + serNo;
                    else
                        desc = serNo;
                }
                asi.setDescription(desc);
                asi.saveEx();
            }
        }
        if (poLine instanceof MInventoryLine) {
            MStorage storage = MStorage.get(Env.getCtx(), getM_Locater_ID(), product.getM_Product_ID(), asi == null ? 0 : asi.getM_AttributeSetInstance_ID(), null);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyCount, qty);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyBook, storage == null ? Env.ZERO : storage.getQtyOnHand());
        } else if (poLine instanceof MInOutLine) {
            MInOutLine ioLine = (MInOutLine) poLine;
            ioLine.setQty(qty);
            ioLine.setC_OrderLine_ID(referenceId);
        } else if (poLine instanceof MMovementLine) {
            MMovementLine movementLine = (MMovementLine) poLine;
            movementLine.setM_LocatorTo_ID(getM_LocaterTo_ID());
            movementLine.setMovementQty(qty);
        } else
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_MovementQty, qty);
        poLine.set_ValueOfColumn(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID, asi == null ? 0 : asi.get_ID());
        if (poLine.is_Changed())
            poLine.saveEx();
        lineNo = lineNo + 10;
    }
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MInventoryLine(org.compiere.model.MInventoryLine) MInOutLine(org.compiere.model.MInOutLine) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MMovementLine(org.compiere.model.MMovementLine) PO(org.compiere.model.PO)

Example 59 with Query

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

the class ValuationEffectiveDate method setup.

/**
	 * Setup the collections
	 */
private void setup() {
    if (getAccountingSchemaId() > 0)
        acctSchemas.add(MAcctSchema.get(getCtx(), getAccountingSchemaId(), get_TrxName()));
    else
        acctSchemas = Arrays.asList(MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()));
    if (getCostTypeId() > 0)
        costTypes.add(new MCostType(getCtx(), getCostTypeId(), get_TrxName()));
    else
        costTypes = MCostType.get(getCtx(), get_TrxName());
    if (getCostElementId() > 0)
        costElements.add(MCostElement.get(getCtx(), getCostElementId()));
    else
        costElements = MCostElement.getCostElement(getCtx(), get_TrxName());
    if (getWarehouseId() > 0)
        warehouses.add(MWarehouse.get(getCtx(), getWarehouseId(), get_TrxName()));
    else {
        warehouses = new Query(getCtx(), MWarehouse.Table_Name, "", get_TrxName()).setClient_ID().list();
    }
    if (getProductId() == 0)
        products = new Query(getCtx(), I_M_Product.Table_Name, "", get_TrxName()).setClient_ID().getIDs();
    else
        products = new int[] { getProductId() };
    setWhere();
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_InventoryValue ").append("(AD_PInstance_ID,DateValue,AD_Client_ID,AD_Org_ID,C_AcctSchema_ID,M_CostElement_ID,M_CostType_ID,M_Warehouse_ID,").append("M_Product_ID,M_Product_Category_ID,M_AttributeSetInstance_ID,Group1,Group2,QtyOnHand,CostAmt,CostAmtLL) ").append("SELECT ").append(getAD_PInstance_ID()).append(",").append("tc.DateAcct").append(",").append("p.AD_Client_ID,p.AD_Org_ID, tc.C_AcctSchema_ID ,tc.M_CostElement_ID,tc.M_CostType_ID, tc.M_Warehouse_ID,p.M_Product_ID,").append("p.M_Product_Category_ID,tc.M_AttributeSetInstance_ID,p.Group1,p.Group2,  tc.qty + tc.cumulatedqty AS QtyOnHand,").append(" CASE WHEN tc.Qty < 0 OR (tc.qty = 0 AND tc.cumulatedqty < 0) THEN ((tc.costAmt + tc.costadjustment) * -1) + tc.CumulatedAmt ELSE ((tc.costAmt + tc.costadjustment) * 1) + tc.CumulatedAmt END  AS CostAmt,").append(" CASE WHEN tc.Qty < 0 OR (tc.qty = 0 AND tc.cumulatedqty < 0) THEN ((tc.costAmtLL + tc.costadjustmentLL) * -1)  + tc.CumulatedAmtLL ELSE ((tc.costAmtLL + tc.costadjustmentLL) * 1) + tc.CumulatedAmtLL END AS CostAmtLL").append(" FROM M_Product p ").append(" INNER JOIN M_CostDetail tc ON (p.M_Product_ID=tc.M_Product_ID) ");
    insert.append(whereClause1).append(whereClause2);
    pstmt = DB.prepareStatement(insert.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, get_TrxName());
}
Also used : Query(org.compiere.model.Query) MCostType(org.compiere.model.MCostType)

Example 60 with Query

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

the class ScanBar method getProductByValueC.

public MProduct getProductByValueC(String barCode) {
    StringBuilder whereClause = new StringBuilder();
    whereClause.append("UPPER(").append(I_M_Product.COLUMNNAME_Value).append(")=?");
    return new Query(Env.getCtx(), I_M_Product.Table_Name, whereClause.toString(), null).setClient_ID().setParameters(barCode.toUpperCase()).first();
}
Also used : Query(org.compiere.model.Query)

Aggregations

Query (org.compiere.model.Query)210 ArrayList (java.util.ArrayList)49 BigDecimal (java.math.BigDecimal)25 Properties (java.util.Properties)22 MProduct (org.compiere.model.MProduct)20 AdempiereException (org.adempiere.exceptions.AdempiereException)12 MTable (org.compiere.model.MTable)12 MOrderLine (org.compiere.model.MOrderLine)8 MWarehouse (org.compiere.model.MWarehouse)8 PO (org.compiere.model.PO)8 MBPartner (org.compiere.model.MBPartner)6 MQuery (org.compiere.model.MQuery)6 MPPProductBOM (org.eevolution.model.MPPProductBOM)6 MColumn (org.compiere.model.MColumn)5 MLocation (org.compiere.model.MLocation)5 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)5 SQLException (java.sql.SQLException)4 Timestamp (java.sql.Timestamp)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 MClient (org.compiere.model.MClient)4