Search in sources :

Example 6 with MRequestType

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

the class RequestInvoice method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("R_RequestType_ID=" + p_R_RequestType_ID + ", R_Group_ID=" + p_R_Group_ID + ", R_Category_ID=" + p_R_Category_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + ", p_M_Product_ID=" + p_M_Product_ID);
    MRequestType type = MRequestType.get(getCtx(), p_R_RequestType_ID);
    if (type.get_ID() == 0)
        throw new AdempiereSystemError("@R_RequestType_ID@ @NotFound@ " + p_R_RequestType_ID);
    if (!type.isInvoiced())
        throw new AdempiereSystemError("@R_RequestType_ID@ <> @IsInvoiced@");
    String sql = "SELECT * FROM R_Request r" + " INNER JOIN R_Status s ON (r.R_Status_ID=s.R_Status_ID) " + "WHERE s.IsClosed='Y'" + " AND r.R_RequestType_ID=?";
    //		"WHERE ru.R_Request_ID=r.R_Request_ID AND NVL(C_InvoiceLine_ID,0)=0";
    if (p_R_Group_ID != 0)
        sql += " AND r.R_Group_ID=?";
    if (p_R_Category_ID != 0)
        sql += " AND r.R_Category_ID=?";
    if (p_C_BPartner_ID != 0)
        sql += " AND r.C_BPartner_ID=?";
    sql += " AND r.IsInvoiced='Y' " + "ORDER BY C_BPartner_ID";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        int index = 1;
        pstmt.setInt(index++, p_R_RequestType_ID);
        if (p_R_Group_ID != 0)
            pstmt.setInt(index++, p_R_Group_ID);
        if (p_R_Category_ID != 0)
            pstmt.setInt(index++, p_R_Category_ID);
        if (p_C_BPartner_ID != 0)
            pstmt.setInt(index++, p_C_BPartner_ID);
        ResultSet rs = pstmt.executeQuery();
        int oldC_BPartner_ID = 0;
        while (rs.next()) {
            MRequest request = new MRequest(getCtx(), rs, get_TrxName());
            if (!request.isInvoiced())
                continue;
            if (oldC_BPartner_ID != request.getC_BPartner_ID())
                invoiceDone();
            if (m_invoice == null) {
                invoiceNew(request);
                oldC_BPartner_ID = request.getC_BPartner_ID();
            }
            invoiceLine(request);
        }
        invoiceDone();
        //
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    //	R_Category_ID
    return null;
}
Also used : MRequest(org.compiere.model.MRequest) AdempiereSystemError(org.compiere.util.AdempiereSystemError) ResultSet(java.sql.ResultSet) MRequestType(org.compiere.model.MRequestType) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MRequestType (org.compiere.model.MRequestType)6 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 MAchievement (org.compiere.model.MAchievement)2 MGoal (org.compiere.model.MGoal)2 MMeasureCalc (org.compiere.model.MMeasureCalc)2 MProjectType (org.compiere.model.MProjectType)2 MQuery (org.compiere.model.MQuery)2 ArrayList (java.util.ArrayList)1 MRequest (org.compiere.model.MRequest)1 AdempiereSystemError (org.compiere.util.AdempiereSystemError)1