Search in sources :

Example 61 with Query

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

the class CPOS method getCreditNotes.

//	getCreditCards
/**
	 * 	Get Credit Notes
	 * 
	 */
public ValueNamePair[] getCreditNotes() {
    try {
        String whereClause = "C_BPartner_ID = ? " + "AND IsPaid ='N' " + "AND EXISTS(SELECT 1 " + "				FROM C_DocType dt " + "				WHERE dt.C_DocType_ID = C_Invoice.C_DocType_ID " + "				AND dt.DocBaseType ='ARC'" + ")";
        List<MInvoice> invoiceList = new Query(Env.getCtx(), MInvoice.Table_Name, whereClause, null).setParameters(currentOrder.getC_BPartner_ID()).list();
        //
        //	to eliminate duplicates
        HashMap<String, ValueNamePair> map = new HashMap<String, ValueNamePair>();
        ValueNamePair valueNamePair;
        for (MInvoice invoice : invoiceList) {
            Integer id = invoice.getC_Invoice_ID();
            valueNamePair = new ValueNamePair(id.toString(), invoice.getDocumentNo() + " " + invoice.getOpenAmt().toString());
            map.put(invoice.getDocumentNo(), valueNamePair);
        }
        //	for all payment processors
        //
        ValueNamePair[] retValue = new ValueNamePair[map.size()];
        map.values().toArray(retValue);
        return retValue;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : Query(org.compiere.model.Query) HashMap(java.util.HashMap) MInvoice(org.compiere.model.MInvoice) ValueNamePair(org.compiere.util.ValueNamePair) AdempierePOSException(org.adempiere.pos.AdempierePOSException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 62 with Query

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

the class RollupWorkflow method getProductIds.

/**
     * get products
     * @return
     */
private int[] getProductIds() {
    List<Object> params = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer("AD_Client_ID=?");
    params.add(getAD_Client_ID());
    whereClause.append(" AND (").append(MProduct.COLUMNNAME_ProductType).append("=?");
    params.add(MProduct.PRODUCTTYPE_Item);
    whereClause.append(" OR ").append(MProduct.COLUMNNAME_ProductType).append("=?");
    params.add(MProduct.PRODUCTTYPE_Resource);
    whereClause.append(") AND ").append(MProduct.COLUMNNAME_IsBOM).append("=?");
    params.add(true);
    if (getProductId() > 0) {
        whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_ID).append("=?");
        params.add(getProductId());
    }
    if (getProductCategoryId() > 0) {
        whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_Category_ID).append("=?");
        params.add(getProductCategoryId());
    }
    if (getProductClassId() > 0) {
        whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_Class_ID).append("=?");
        params.add(getProductClassId());
    }
    if (getProductGroupId() > 0) {
        whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_Group_ID).append("=?");
        params.add(getProductGroupId());
    }
    if (getProductClassificationId() > 0) {
        whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_Classification_ID).append("=?");
        params.add(getProductClassificationId());
    }
    return new Query(getCtx(), MProduct.Table_Name, whereClause.toString(), get_TrxName()).setOrderBy(MProduct.COLUMNNAME_LowLevel).setParameters(params).getIDs();
}
Also used : Query(org.compiere.model.Query) ArrayList(java.util.ArrayList)

Example 63 with Query

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

the class SimulatedPickList method loadBOM.

/**
	 * Action: Fill Tree with all nodes
	 */
private void loadBOM() throws Exception {
    int count = 0;
    if (p_M_Product_ID == 0)
        raiseError("Error: ", "Product ID not found");
    MProduct product = new MProduct(getCtx(), p_M_Product_ID, get_TrxName());
    X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
    tboml.setAD_Org_ID(product.getAD_Org_ID());
    tboml.setPP_Product_BOM_ID(0);
    tboml.setPP_Product_BOMLine_ID(0);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setM_Product_ID(p_M_Product_ID);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setDateTrx(p_DateTrx);
    tboml.setImplosion(false);
    tboml.setLevelNo(0);
    tboml.setLevels("0");
    tboml.setQtyBOM(Env.ONE);
    tboml.setQtyRequired(p_QtyRequiered);
    tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
    tboml.setSeqNo(0);
    tboml.setAD_PInstance_ID(AD_PInstance_ID);
    tboml.saveEx();
    final String whereClause = MPPProductBOM.COLUMNNAME_M_Product_ID + "=?";
    List<MPPProductBOM> boms = new Query(getCtx(), X_PP_Product_BOM.Table_Name, whereClause, get_TrxName()).setClient_ID().setOnlyActiveRecords(true).setParameters(p_M_Product_ID).list();
    for (MPPProductBOM bom : boms) {
        if (bom.isValidFromTo(p_DateTrx)) {
            parentExplotion(bom.get_ID(), p_QtyRequiered);
            ++count;
        }
    }
    if (count == 0)
        raiseError("Error: ", "Product is not a BOM");
}
Also used : MProduct(org.compiere.model.MProduct) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) MPPProductBOM(org.eevolution.model.MPPProductBOM) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Example 64 with Query

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

the class SimulatedPickList method component.

/**
	 * Find if this product as component
	 * 
	 * @param M_Product_ID
	 *            ID Component
	 */
public void component(int M_Product_ID, BigDecimal qtyRequiered) throws Exception {
    if (LevelNo == p_LevelNo)
        return;
    String value = DB.getSQLValueString(get_TrxName(), "SELECT Value FROM M_Product WHERE M_Product_ID=?", M_Product_ID);
    final StringBuilder whereClause = new StringBuilder(MPPProductBOM.COLUMNNAME_Value).append("=? AND ").append(MPPProductBOM.COLUMNNAME_M_Product_ID).append("=?");
    List<MPPProductBOM> boms = new Query(getCtx(), MPPProductBOM.Table_Name, whereClause.toString(), get_TrxName()).setClient_ID().setOnlyActiveRecords(true).setParameters(value, M_Product_ID).list();
    boolean level = false;
    for (MPPProductBOM bom : boms) {
        if (bom.isValidFromTo(p_DateTrx)) {
            if (!level)
                LevelNo += 1;
            level = true;
            parentExplotion(bom.get_ID(), qtyRequiered);
            LevelNo -= 1;
        }
    }
}
Also used : MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Example 65 with Query

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

the class SimulatedPickList method parentExplotion.

/**
	 * Generate an Explosion for this BOM
	 * 
	 * @param PP_Product_BOMLine_ID
	 *            ID BOM Line
	 */
public void parentExplotion(int PP_Product_BOM_ID, BigDecimal qtyRequiered) throws Exception {
    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(PP_Product_BOM_ID);
    final StringBuilder whereClause = new StringBuilder(MPPProductBOMLine.COLUMNNAME_PP_Product_BOM_ID).append("=?");
    if (p_BackflushGroup != null) {
        whereClause.append(" AND ").append(MPPProductBOMLine.COLUMNNAME_BackflushGroup).append("LIKE ?");
        parameters.add(p_BackflushGroup);
    }
    List<MPPProductBOMLine> bomLines = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName()).setClient_ID().setOnlyActiveRecords(true).setParameters(parameters).setOrderBy(MPPProductBOMLine.COLUMNNAME_Line).list();
    for (MPPProductBOMLine line : bomLines) {
        if (line.isValidFromTo(p_DateTrx)) {
            SeqNo += 1;
            MProduct product = new MProduct(getCtx(), line.getM_Product_ID(), get_TrxName());
            X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
            tboml.setAD_Org_ID(product.getAD_Org_ID());
            tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
            tboml.setPP_Product_BOMLine_ID(line.get_ID());
            tboml.setM_Product_ID(line.getM_Product_ID());
            tboml.setLevelNo(LevelNo);
            tboml.setDateTrx(p_DateTrx);
            tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
            tboml.setSeqNo(SeqNo);
            tboml.setAD_PInstance_ID(AD_PInstance_ID);
            tboml.setSel_Product_ID(p_M_Product_ID);
            tboml.setQtyBOM(line.getQty(true));
            tboml.setQtyRequired(qtyRequiered.multiply(line.getQty(true)));
            tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
            tboml.setImplosion(false);
            tboml.saveEx();
            component(line.getM_Product_ID(), tboml.getQtyBOM());
        }
    }
}
Also used : MProduct(org.compiere.model.MProduct) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

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