Search in sources :

Example 81 with Query

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

the class HRPaySelectionCreateFrom method doIt.

//	prepare
/**
     * Perform process.
     * @return Message
     * @throws Exception if not successful
     */
protected String doIt() throws Exception {
    log.info("Pay Selection Id=" + getRecord_ID() + ", Process=" + getPayrollProcessId() + ", Payroll=" + getPayrollId() + ", BP Group=" + getBusinessPartnerGroupId() + ", PaymentRule=" + getPaymentRule() + ", Concept=" + getGlobalPayrollConceptId() + ", Depatment=" + getDepartmentId() + ", Job=" + getPayrollJobId());
    MHRPaySelection paySelection = (MHRPaySelection) getInstance(get_TrxName());
    paySelection.setHR_Process_ID(getPayrollProcessId());
    paySelection.saveEx();
    List<Object> parameters = new ArrayList<Object>();
    if (getRecord_ID() == 0)
        throw new IllegalArgumentException("@HR_PaySelection_ID@ @Notfound@");
    if (paySelection.isProcessed())
        throw new IllegalArgumentException("@HR_PaySelection_ID@ @Processed@");
    parameters.add(getPayrollProcessId());
    parameters.add(true);
    parameters.add(getRecord_ID());
    StringBuilder where = new StringBuilder();
    where.append(MHRMovement.COLUMNNAME_HR_Process_ID).append("=?");
    // Only Concept isPaid
    where.append(" AND HR_Concept_ID IN(SELECT HR_Concept_ID FROM HR_Concept WHERE IsPaid=?)");
    where.append(// Not Exist in PaySelection Process or PaySelection Actual
    " AND HR_Movement_ID NOT IN(SELECT HR_Movement_ID " + " FROM HR_PaySelectionLine " + " WHERE HR_PaySelectionCheck_ID > 0 OR HR_PaySelection_ID=?)");
    if (getBusinessPartnerGroupId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_C_BP_Group_ID).append("=?");
        parameters.add(getBusinessPartnerGroupId());
    }
    if (getEmployeeTypeId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_EmployeeType_ID).append("=?");
        parameters.add(getEmployeeTypeId());
    }
    if (getBusinessPartnerId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_C_BPartner_ID).append("=?");
        parameters.add(getBusinessPartnerId());
    }
    if (getPaymentRule() != null) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_PaymentRule).append("=?");
        parameters.add(getPaymentRule());
    }
    if (getGlobalPayrollConceptId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Concept_ID).append("=?");
        parameters.add(getGlobalPayrollConceptId());
    }
    if (getDepartmentId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Department_ID).append("=?");
        parameters.add(getDepartmentId());
    }
    if (getPayrollJobId() > 0) {
        where.append(" AND ").append(MHRMovement.COLUMNNAME_HR_Job_ID).append("=?");
        parameters.add(getPayrollJobId());
    }
    List<MHRMovement> movements = new Query(getCtx(), MHRMovement.Table_Name, where.toString(), get_TrxName()).setClient_ID().setParameters(parameters).list();
    AtomicInteger lineNo = new AtomicInteger();
    movements.stream().filter(movement -> movement != null).forEach(movement -> {
        I_C_BPartner partner = movement.getC_BPartner();
        Optional<MHREmployee> employeeOption = Optional.ofNullable(MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), movement.get_TrxName()));
        String paymentRule = employeeOption.flatMap(employee -> Optional.ofNullable(employee.getPaymentRule())).orElse(Optional.ofNullable(partner.getPaymentRule()).orElse(MHREmployee.PAYMENTRULE_DirectDeposit));
        lineNo.updateAndGet(count -> count + 10);
        MHRPaySelectionLine paySelectionLine = new MHRPaySelectionLine(getCtx(), 0, get_TrxName());
        paySelectionLine.setHR_PaySelection_ID(getRecord_ID());
        paySelectionLine.setHR_Movement_ID(movement.getHR_Movement_ID());
        paySelectionLine.setPaymentRule(paymentRule);
        paySelectionLine.setAD_Org_ID(paySelection.getAD_Org_ID());
        paySelectionLine.setLine(lineNo.get());
        paySelectionLine.setOpenAmt(movement.getAmount().setScale(2, BigDecimal.ROUND_HALF_DOWN));
        paySelectionLine.setPayAmt(movement.getAmount().setScale(2, BigDecimal.ROUND_HALF_DOWN));
        paySelectionLine.setDescription(partner.getName() + " " + partner.getName2());
        paySelectionLine.setDifferenceAmt(BigDecimal.ZERO.ZERO);
        paySelectionLine.setDiscountAmt(BigDecimal.ZERO);
        paySelectionLine.setIsManual(false);
        paySelectionLine.setIsSOTrx(false);
        paySelectionLine.setIsActive(true);
        paySelectionLine.saveEx();
    });
    return "@HR_PaySelection_ID@  - #" + lineNo.get();
}
Also used : BigDecimal(java.math.BigDecimal) java.util(java.util) Query(org.compiere.model.Query) MHREmployee(org.eevolution.model.MHREmployee) MHRMovement(org.eevolution.model.MHRMovement) MHRPaySelection(org.eevolution.model.MHRPaySelection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRPaySelectionLine(org.eevolution.model.MHRPaySelectionLine) I_C_BPartner(org.compiere.model.I_C_BPartner) MHRPaySelectionLine(org.eevolution.model.MHRPaySelectionLine) Query(org.compiere.model.Query) MHRMovement(org.eevolution.model.MHRMovement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MHRPaySelection(org.eevolution.model.MHRPaySelection) I_C_BPartner(org.compiere.model.I_C_BPartner) MHREmployee(org.eevolution.model.MHREmployee)

Example 82 with Query

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

the class ImportEmployee method getImportEmployeeIds.

/**
     * get employee ids
     * @param isImported
     * @param isProcessed
     * @return
     */
private int[] getImportEmployeeIds(boolean isImported, boolean isProcessed) {
    StringBuilder whereClause = new StringBuilder();
    whereClause.append(I_I_HR_Employee.COLUMNNAME_I_IsImported).append("=? AND ").append(I_I_HR_Employee.COLUMNNAME_Processed).append("=?");
    return new Query(getCtx(), X_I_HR_Employee.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).setParameters(isImported, isProcessed).getIDs();
}
Also used : Query(org.compiere.model.Query)

Example 83 with Query

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

the class RoleAccessUpdate method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("AD_Client_ID=" + p_AD_Client_ID + ", AD_Role_ID=" + p_AD_Role_ID);
    //
    if (p_AD_Role_ID > 0)
        updateRole(new MRole(getCtx(), p_AD_Role_ID, get_TrxName()));
    else {
        List<Object> params = new ArrayList<Object>();
        String whereClause = "1=1";
        if (p_AD_Client_ID > 0) {
            whereClause += " AND AD_Client_ID=? ";
            params.add(p_AD_Client_ID);
        }
        if (// System Role
        p_AD_Role_ID == 0) {
            whereClause += " AND AD_Role_ID=?";
            params.add(p_AD_Role_ID);
        }
        //sql += "ORDER BY AD_Client_ID, Name";
        List<MRole> roles = new Query(getCtx(), MRole.Table_Name, whereClause, get_TrxName()).setOnlyActiveRecords(true).setParameters(params).setOrderBy("AD_Client_ID, Name").list();
        for (MRole role : roles) {
            updateRole(role);
        }
    }
    return "";
}
Also used : Query(org.compiere.model.Query) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList)

Example 84 with Query

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

the class RequisitionPOCreate method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    //	Specific
    if (p_M_Requisition_ID != 0) {
        log.info("M_Requisition_ID=" + p_M_Requisition_ID);
        MRequisition req = new MRequisition(getCtx(), p_M_Requisition_ID, get_TrxName());
        if (!MRequisition.DOCSTATUS_Completed.equals(req.getDocStatus())) {
            throw new AdempiereUserError("@DocStatus@ = " + req.getDocStatus());
        }
        MRequisitionLine[] lines = req.getLines();
        for (int i = 0; i < lines.length; i++) {
            if (lines[i].getC_OrderLine_ID() == 0) {
                process(lines[i]);
            }
        }
        closeOrder();
        return "";
    }
    //	single Requisition
    //	
    log.info("AD_Org_ID=" + p_AD_Org_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID + ", DateDoc=" + p_DateDoc_From + "/" + p_DateDoc_To + ", DateRequired=" + p_DateRequired_From + "/" + p_DateRequired_To + ", PriorityRule=" + p_PriorityRule + ", AD_User_ID=" + p_AD_User_ID + ", M_Product_ID=" + p_M_Product_ID + ", ConsolidateDocument" + p_ConsolidateDocument);
    ArrayList<Object> params = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer("C_OrderLine_ID IS NULL");
    if (p_AD_Org_ID > 0) {
        whereClause.append(" AND AD_Org_ID=?");
        params.add(p_AD_Org_ID);
    }
    if (p_M_Product_ID > 0) {
        whereClause.append(" AND M_Product_ID=?");
        params.add(p_M_Product_ID);
    } else if (p_M_Product_Category_ID > 0) {
        whereClause.append(" AND EXISTS (SELECT 1 FROM M_Product p WHERE M_RequisitionLine.M_Product_ID=p.M_Product_ID").append(" AND p.M_Product_Category_ID=?)");
        params.add(p_M_Product_Category_ID);
    }
    if (p_C_BP_Group_ID > 0) {
        whereClause.append(" AND (").append("M_RequisitionLine.C_BPartner_ID IS NULL").append(" OR EXISTS (SELECT 1 FROM C_BPartner bp WHERE M_RequisitionLine.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)").append(")");
        params.add(p_C_BP_Group_ID);
    }
    //
    //	Requisition Header
    whereClause.append(" AND EXISTS (SELECT 1 FROM M_Requisition r WHERE M_RequisitionLine.M_Requisition_ID=r.M_Requisition_ID").append(" AND r.DocStatus=?");
    params.add(MRequisition.DOCSTATUS_Completed);
    if (p_M_Warehouse_ID > 0) {
        whereClause.append(" AND r.M_Warehouse_ID=?");
        params.add(p_M_Warehouse_ID);
    }
    if (p_DateDoc_From != null) {
        whereClause.append(" AND r.DateDoc >= ?");
        params.add(p_DateDoc_From);
    }
    if (p_DateDoc_To != null) {
        whereClause.append(" AND r.DateDoc <= ?");
        params.add(p_DateDoc_To);
    }
    if (p_DateRequired_From != null) {
        whereClause.append(" AND r.DateRequired >= ?");
        params.add(p_DateRequired_From);
    }
    if (p_DateRequired_To != null) {
        whereClause.append(" AND r.DateRequired <= ?");
        params.add(p_DateRequired_To);
    }
    if (p_PriorityRule != null) {
        whereClause.append(" AND r.PriorityRule >= ?");
        params.add(p_PriorityRule);
    }
    if (p_AD_User_ID > 0) {
        whereClause.append(" AND r.AD_User_ID=?");
        params.add(p_AD_User_ID);
    }
    // End Requisition Header
    whereClause.append(")");
    //
    // ORDER BY clause
    StringBuffer orderClause = new StringBuffer();
    if (!p_ConsolidateDocument) {
        orderClause.append("M_Requisition_ID, ");
    }
    orderClause.append("(SELECT DateRequired FROM M_Requisition r WHERE M_RequisitionLine.M_Requisition_ID=r.M_Requisition_ID),");
    orderClause.append("M_Product_ID, C_Charge_ID, M_AttributeSetInstance_ID");
    POResultSet<MRequisitionLine> rs = new Query(getCtx(), MRequisitionLine.Table_Name, whereClause.toString(), get_TrxName()).setParameters(params).setOrderBy(orderClause.toString()).setClient_ID().scroll();
    try {
        while (rs.hasNext()) {
            process(rs.next());
        }
    } finally {
        DB.close(rs);
        rs = null;
    }
    closeOrder();
    return "";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition)

Example 85 with Query

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

the class MPPWFNodeProduct method forAD_WF_Node_ID.

/**
	 * @return array of node products
	 */
public static Collection<MPPWFNodeProduct> forAD_WF_Node_ID(Properties ctx, int AD_WF_Node_ID) {
    Collection<MPPWFNodeProduct> lines = s_cache.get(AD_WF_Node_ID);
    if (lines != null) {
        return lines;
    }
    final String whereClause = COLUMNNAME_AD_WF_Node_ID + "=?";
    lines = new Query(ctx, Table_Name, whereClause, null).setParameters(new Object[] { AD_WF_Node_ID }).setOnlyActiveRecords(true).setOrderBy(COLUMNNAME_SeqNo).list();
    s_cache.put(AD_WF_Node_ID, lines);
    return lines;
}
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