Search in sources :

Example 16 with Query

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

the class CalculateLowLevel method doIt.

//	prepare
protected String doIt() throws Exception {
    AtomicInteger countOk = new AtomicInteger(0);
    int[] productIds = new Query(getCtx(), MProduct.Table_Name, "AD_Client_ID=?", get_TrxName()).setParameters(getAD_Client_ID()).setOrderBy(MProduct.COLUMNNAME_M_Product_ID).getIDs();
    Arrays.stream(productIds).filter(productId -> productId > 0).forEach(productId -> {
        Trx.run(trxName -> {
            int lowLevel = MPPProductBOMLine.getLowLevel(getCtx(), productId, trxName);
            StringBuilder sql = new StringBuilder("UPDATE M_Product SET LowLevel=? WHERE M_Product_ID=?");
            List<Object> parameters = new ArrayList();
            parameters.add(lowLevel);
            parameters.add(productId);
            DB.executeUpdateEx(sql.toString(), parameters.toArray(), trxName);
            countOk.updateAndGet(count -> count + 1);
        });
    });
    return "@Ok@ @Records@ " + countOk + " @Processed@";
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Query(org.compiere.model.Query) DB(org.compiere.util.DB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Trx(org.compiere.util.Trx) MProduct(org.compiere.model.MProduct) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) ArrayList(java.util.ArrayList) Query(org.compiere.model.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList)

Example 17 with Query

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

the class CRPReasoner method getPPOrdersNotCompletedQuery.

public Query getPPOrdersNotCompletedQuery(int S_Resource_ID, String trxName) {
    ArrayList<Object> params = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer();
    // For current AD_Client_ID (security)
    whereClause.append("AD_Client_ID=?");
    params.add(Env.getAD_Client_ID(getCtx()));
    // Skip voided, reversed and closed orders:
    whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_DocStatus).append(" NOT IN (?,?,?)");
    params.add(MPPOrder.DOCSTATUS_Voided);
    params.add(MPPOrder.DOCSTATUS_Reversed);
    params.add(MPPOrder.DOCSTATUS_Closed);
    // For given resource (if any)
    if (S_Resource_ID > 0) {
        whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_S_Resource_ID).append("=?");
        params.add(S_Resource_ID);
    }
    return new Query(getCtx(), MPPOrder.Table_Name, whereClause.toString(), trxName).setParameters(params).setOnlyActiveRecords(true).setOrderBy(MPPOrder.COLUMNNAME_DatePromised);
}
Also used : Query(org.compiere.model.Query) ArrayList(java.util.ArrayList)

Example 18 with Query

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

the class CRPReasoner method getAvailableDate.

/**
	 * @param r resource
	 * @param dateTime
	 * @return next available date
	 */
public Timestamp getAvailableDate(I_S_Resource r, Timestamp dateTime, boolean isScheduleBackward) {
    MResourceType t = MResourceType.get(getCtx(r), r.getS_ResourceType_ID());
    Timestamp date = dateTime;
    ArrayList<Object> params = new ArrayList<Object>();
    String whereClause;
    String orderByClause;
    int direction;
    if (isScheduleBackward) {
        whereClause = MResourceUnAvailable.COLUMNNAME_DateFrom + " <= ?";
        params.add(date);
        orderByClause = MResourceUnAvailable.COLUMNNAME_DateFrom + " DESC";
        direction = 1;
    } else {
        whereClause = MResourceUnAvailable.COLUMNNAME_DateTo + " >= ?";
        params.add(date);
        orderByClause = MResourceUnAvailable.COLUMNNAME_DateTo;
        direction = -1;
    }
    whereClause += " AND " + MResourceUnAvailable.COLUMNNAME_S_Resource_ID + "=? AND AD_Client_ID=?";
    params.add(r.getS_Resource_ID());
    params.add(r.getAD_Client_ID());
    POResultSet<MResourceUnAvailable> rs = new Query(getCtx(r), MResourceUnAvailable.Table_Name, whereClause, null).setOrderBy(orderByClause).setParameters(params).scroll();
    try {
        while (rs.hasNext()) {
            MResourceUnAvailable rua = rs.next();
            if (rua.isUnAvailable(date)) {
                date = TimeUtil.addDays(rua.getDateTo(), 1 * direction);
            }
            date = getAvailableDate(t, dateTime, isScheduleBackward);
        }
    } finally {
        DB.close(rs);
    }
    //
    date = getAvailableDate(t, dateTime, isScheduleBackward);
    return date;
}
Also used : Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MResourceType(org.compiere.model.MResourceType) MResourceUnAvailable(org.compiere.model.MResourceUnAvailable)

Example 19 with Query

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

the class ComponentChange method doIt.

//	prepare
@Override
protected String doIt() throws Exception {
    if (p_Action == null) {
        throw new FillMandatoryException("Action");
    }
    List<Object> params = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer();
    whereClause.append(MPPProductBOMLine.COLUMNNAME_M_Product_ID + "=?");
    params.add(p_M_Product_ID);
    if (p_ValidTo != null) {
        whereClause.append(" AND TRUNC(" + MPPProductBOMLine.COLUMNNAME_ValidTo + ") <= ?");
        params.add(p_ValidTo);
    }
    if (p_ValidFrom != null) {
        whereClause.append(" AND TRUNC(" + MPPProductBOMLine.COLUMNNAME_ValidFrom + ") >= ?");
        params.add(p_ValidFrom);
    }
    List<MPPProductBOMLine> components = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName()).setParameters(params).list();
    for (MPPProductBOMLine bomline : components) {
        if (p_Action.equals(ACTION_Add)) {
            actionAdd(bomline, 0);
        } else if (p_Action.equals(ACTION_Deactivate)) {
            actionDeactivate(bomline);
        } else if (p_Action.equals(ACTION_Expire)) {
            actionExpire(bomline);
        } else if (p_Action.equals(ACTION_Replace)) {
            actionAdd(bomline, bomline.getLine() + 1);
            actionDeactivate(bomline);
        } else if (p_Action.equals(ACTION_ReplaceAndExpire)) {
            actionAdd(bomline, bomline.getLine() + 1);
            actionExpire(bomline);
        } else {
            throw new AdempiereException("Action not supported - " + p_Action);
        }
        addLog(MRefList.getListName(getCtx(), ACTION_AD_Reference_ID, p_Action));
    }
    return "@OK@";
}
Also used : Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine)

Example 20 with Query

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

the class PromotionRule method applyPromotionsByLine.

public static void applyPromotionsByLine(MOrder order, MOrderLine ol) throws Exception {
    MOrderLine bonLine = null;
    String whereClause = "m_product_ID=? and isgiveaway='Y'";
    MOrderLine oldbonLine = new Query(ol.getCtx(), MOrderLine.Table_Name, whereClause, ol.get_TrxName()).setParameters(ol.getM_Product_ID()).first();
    if (oldbonLine != null)
        oldbonLine.deleteEx(false);
    MPromotion pr = new MPromotion(ol.getCtx(), ol.getM_Promotion_ID(), ol.get_TrxName());
    whereClause = "m_promotion_id =? and validfrom<=? and c_bpartner_id =?";
    int promLine = new Query(order.getCtx(), MPromotionLine.Table_Name, whereClause, order.get_TrxName()).setParameters(new Object[] { pr.getM_Promotion_ID(), order.getDateOrdered(), order.getC_BPartner_ID() }).setOrderBy("validfrom desc").firstId();
    if (promLine <= 0) {
        whereClause = "m_promotion_id =? and trunc(validfrom)<=? and c_bpartner_id is null";
        promLine = new Query(order.getCtx(), MPromotionLine.Table_Name, whereClause, order.get_TrxName()).setParameters(new Object[] { pr.getM_Promotion_ID(), order.getDateOrdered() }).setOrderBy("validfrom desc").firstId();
    }
    if (promLine <= 0)
        return;
    whereClause = "m_promotionline_ID=?";
    List<MPromotionDistribution> pds = new Query(order.getCtx(), MPromotionDistribution.Table_Name, whereClause, order.get_TrxName()).setParameters(promLine).setOrderBy("qty desc").list();
    for (MPromotionDistribution dist : pds) {
        if (ol.getQtyOrdered().doubleValue() >= dist.getQty().doubleValue()) {
            bonLine = new MOrderLine(order);
            MOrderLine.copyValues(ol, bonLine);
            bonLine.setPrice(Env.ZERO);
            bonLine.setDiscount(Env.ONEHUNDRED);
            bonLine.setQty(dist.getQtyReward());
            bonLine.setDescription("Bonificaciones");
            bonLine.set_ValueOfColumn("isGiveAway", true);
            bonLine.saveEx();
            break;
        }
    }
}
Also used : Query(org.compiere.model.Query) MOrderLine(org.compiere.model.MOrderLine)

Aggregations

Query (org.compiere.model.Query)212 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)13 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