Search in sources :

Example 1 with MChangeRequest

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

the class RequestProcessor method processECR.

//	processStatus
/**
	 * 	Create ECR
	 */
private void processECR() {
    //	Get Requests with Request Type-AutoChangeRequest and Group with info
    String sql = "SELECT * FROM R_Request r " + "WHERE M_ChangeRequest_ID IS NULL" + " AND EXISTS (" + "SELECT * FROM R_RequestType rt " + "WHERE rt.R_RequestType_ID=r.R_RequestType_ID" + " AND rt.IsAutoChangeRequest='Y')" + "AND EXISTS (" + "SELECT * FROM R_Group g " + "WHERE g.R_Group_ID=r.R_Group_ID" + " AND (g.M_BOM_ID IS NOT NULL OR g.M_ChangeNotice_ID IS NOT NULL)	)";
    //
    int count = 0;
    int failure = 0;
    //
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MRequest r = new MRequest(getCtx(), rs, null);
            MGroup rg = MGroup.get(getCtx(), r.getR_Group_ID());
            MChangeRequest ecr = new MChangeRequest(r, rg);
            if (r.save()) {
                r.setM_ChangeRequest_ID(ecr.getM_ChangeRequest_ID());
                if (r.save())
                    count++;
                else
                    failure++;
            } else
                failure++;
        }
        rs.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(pstmt);
    }
    m_summary.append("Auto Change Request #").append(count);
    if (failure > 0)
        m_summary.append("(fail=").append(failure).append(")");
    m_summary.append(" - ");
}
Also used : MRequest(org.compiere.model.MRequest) MGroup(org.compiere.model.MGroup) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MChangeRequest(org.compiere.model.MChangeRequest) SQLException(java.sql.SQLException)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 MChangeRequest (org.compiere.model.MChangeRequest)1 MGroup (org.compiere.model.MGroup)1 MRequest (org.compiere.model.MRequest)1