Search in sources :

Example 1 with MRequest

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

the class WebInfo method getRequest.

//	getRequests
/**
	 * 	Get Request.
	 * 	Needs to have ID set first; Check that it is owned / created by requestor
	 *	@return invoice of BP with ID
	 */
public MRequest getRequest() {
    m_infoMessage = null;
    MRequest retValue = null;
    String sql = "SELECT * FROM R_Request " + "WHERE R_Request_ID=?" + " AND (C_BPartner_ID=?" + " OR SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=?))";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_id);
        pstmt.setInt(2, getC_BPartner_ID());
        pstmt.setInt(3, getC_BPartner_ID());
        rs = pstmt.executeQuery();
        if (rs.next())
            retValue = new MRequest(m_ctx, rs, null);
    } catch (Exception e) {
        log.log(Level.SEVERE, "R_Request_ID=" + m_id, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("R_Request_ID=" + m_id + " - " + retValue);
    return retValue;
}
Also used : MRequest(org.compiere.model.MRequest) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with MRequest

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

the class RequestServlet method doPost.

//	streamAttachment
/**************************************************************************
	 *  Process the HTTP Post request
	 *
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String contentType = request.getContentType();
    log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr() + " - " + contentType);
    //  Get Session attributes
    HttpSession session = request.getSession(true);
    session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
    //
    Properties ctx = JSPEnv.getCtx(request);
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    if (wu == null) {
        log.warning("No web user");
        if (!response.isCommitted())
            //	entry
            response.sendRedirect("loginServlet?ForwardTo=request.jsp");
        return;
    }
    if (contentType != null && contentType.indexOf("multipart/form-data") != -1) {
        uploadFile(request, response);
        return;
    }
    //	Addl Info
    String requestURL = request.getRequestURL().toString();
    String requestRef = request.getHeader("referer");
    String source = WebUtil.getParameter(request, P_SOURCE);
    String info = WebUtil.getParameter(request, P_INFO);
    String forwardTo = WebUtil.getParameter(request, P_FORWARDTO);
    log.fine("Referer=" + requestRef + ", Source=" + source + ", ForwardTo=" + forwardTo);
    if (requestURL == null)
        requestURL = "";
    if (//  if URL and Referrer are the same, get source
    requestURL.equals(requestRef)) {
        requestRef = source;
        source = null;
    }
    int AD_Client_ID = Env.getContextAsInt(ctx, "AD_Client_ID");
    int R_RequestType_ID = WebUtil.getParameterAsInt(request, P_REQUESTTYPE_ID);
    int C_Order_ID = WebUtil.getParameterAsInt(request, P_REF_ORDER_ID);
    int R_Request_ID = WebUtil.getParameterAsInt(request, P_REQUEST_ID);
    int SalesRep_ID = WebUtil.getParameterAsInt(request, P_SALESREP_ID);
    if (SalesRep_ID != 0 && !MUser.isSalesRep(SalesRep_ID)) {
        log.warning("Invalid (set to 0) SalesRep_ID=" + SalesRep_ID);
        SalesRep_ID = 0;
    }
    //	The text
    String Summary = WebUtil.getParameter(request, P_SUMMARY);
    if (Summary == null || Summary.length() == 0) {
        WebUtil.createErrorPage(request, response, this, "No Data Received");
        return;
    }
    boolean IsConfidential = WebUtil.getParameterAsBoolean(request, P_CONFIDENTIAL);
    boolean IsClose = WebUtil.getParameterAsBoolean(request, P_CLOSE);
    boolean IsEscalate = WebUtil.getParameterAsBoolean(request, P_ESCALATE);
    MRequest req = null;
    //	New SelfService Request
    if (R_Request_ID == 0) {
        req = new MRequest(ctx, SalesRep_ID, R_RequestType_ID, Summary, true, null);
        req.setC_BPartner_ID(wu.getC_BPartner_ID());
        req.setAD_User_ID(wu.getAD_User_ID());
        if (C_Order_ID > 0)
            req.setC_Order_ID(C_Order_ID);
        if (IsConfidential)
            req.setConfidentialType(MRequest.CONFIDENTIALTYPE_PartnerConfidential);
        //
        StringBuffer sb = new StringBuffer();
        sb.append("From:").append(request.getRemoteHost()).append("-").append(request.getRemoteAddr());
        sb.append(", Request:").append(requestURL).append("-").append(requestRef);
        if (source != null)
            sb.append("-").append(source);
        sb.append("-").append(info);
        sb.append(", User=").append(request.getHeader("accept-language")).append("-").append(request.getHeader("user-agent"));
        req.setLastResult(sb.toString());
        //
        if (!req.save()) {
            log.log(Level.SEVERE, "New Request NOT saved");
            WebUtil.createErrorPage(request, response, this, "Request Save Error. Shorten Text!");
            return;
        }
    } else //	existing Request
    {
        req = new MRequest(ctx, R_Request_ID, null);
        if (req.get_ID() == 0) {
            log.log(Level.SEVERE, "Request NOT found - R_Request_ID=" + R_Request_ID);
            WebUtil.createErrorPage(request, response, this, "Request Not found.");
            return;
        }
        //	Update Info
        if (C_Order_ID != 0 && req.getC_Order_ID() == 0)
            req.setC_Order_ID(C_Order_ID);
        if (!req.webUpdate(Summary)) {
            WebUtil.createErrorPage(request, response, this, "Request Cannot be updated.");
            return;
        }
        //	Flags
        if (IsConfidential)
            req.setConfidentialTypeEntry(MRequest.CONFIDENTIALTYPEENTRY_PartnerConfidential);
        if (IsClose)
            req.doClose();
        else if (IsEscalate) {
            boolean isUser = req.getC_BPartner_ID() == wu.getC_BPartner_ID();
            if (//	allow only user or sales rep to escalate
            isUser || wu.isSalesRep())
                req.doEscalate(isUser);
        }
        if (!req.save()) {
            log.log(Level.SEVERE, "Request Action Error");
            WebUtil.createErrorPage(request, response, this, "Request Process Error.");
            return;
        }
    }
    //	Requests
    //	Send EMail to Customer
    StringBuffer message = new StringBuffer(req.getSummary());
    String result = req.getResult();
    if (result != null && result.length() > 0)
        message.append("\n----------\n").append(req.getResult());
    JSPEnv.sendEMail(request, wu, MMailMsg.MAILMSGTYPE_Request, new Object[] { req.getDocumentNo(), wu.getName(), message, "\n---------- " + req.getMailTag() });
    //  --  Fini
    String webStoreURL = "http://" + request.getServerName() + request.getContextPath() + "/";
    if (forwardTo == null || forwardTo.length() == 0)
        forwardTo = requestRef;
    if (forwardTo != null && (forwardTo.indexOf("request.jsp") != -1 || forwardTo.indexOf("requestDetails.jsp") != -1))
        //	list of requests
        forwardTo = "requests.jsp";
    if (forwardTo == null || forwardTo.length() == 0)
        forwardTo = webStoreURL;
    if (forwardTo.indexOf("Servlet") != -1)
        forwardTo = webStoreURL;
    WebUtil.createForwardPage(response, "Web Request Received - Thanks", forwardTo, 10);
}
Also used : MRequest(org.compiere.model.MRequest) HttpSession(javax.servlet.http.HttpSession) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties)

Example 3 with MRequest

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

the class Request method changeRequest.

/**
	 * Updates a Request.
	 * 
	 * @param request
	 * @param ctx
	 * @return
	 */
public static String changeRequest(HttpServletRequest request, Properties ctx) {
    String l_szTrxName = null;
    String l_szReturn = null;
    boolean l_bSuccess = true;
    BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt");
    int l_nReqID = getParameterAsInt(request, "R_Request_ID");
    int l_nOrgID = getParameterAsInt(request, "AD_Org_ID");
    //int l_nSalesRepID 	= getParameterAsInt(request, "SalesRep_ID");
    int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID");
    int l_nRGroupID = getParameterAsInt(request, "R_Group_ID");
    int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID");
    int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID");
    int l_nRStatusID = getParameterAsInt(request, "R_Status_ID");
    int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID");
    int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID");
    int l_nUserID = getParameterAsInt(request, "AD_User_ID");
    int l_nProjectID = getParameterAsInt(request, "C_Project_ID");
    int l_nAssetID = getParameterAsInt(request, "A_Asset_ID");
    int l_nOrderID = getParameterAsInt(request, "C_Order_ID");
    int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID");
    int l_nProductID = getParameterAsInt(request, "M_Product_ID");
    int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID");
    int l_nInOutID = getParameterAsInt(request, "M_InOut_ID");
    int l_nRMAID = getParameterAsInt(request, "M_RMA_ID");
    int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID");
    int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID");
    int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID");
    int l_nActivityID = getParameterAsInt(request, "C_Activity_ID");
    int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID");
    BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent");
    BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced");
    BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan");
    Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction");
    Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan");
    Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan");
    Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate");
    Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate");
    MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName);
    // values for values no fieldgroup
    newRequest.setAD_Org_ID(l_nOrgID);
    newRequest.setDueType(getParameterAsString(request, "DueType"));
    newRequest.setR_RequestType_ID(l_nRReqTypeID);
    newRequest.setR_Group_ID(l_nRGroupID);
    newRequest.setR_Category_ID(l_nRCategoryID);
    newRequest.setR_RequestRelated_ID(l_nRReqRelID);
    newRequest.setR_Status_ID(l_nRStatusID);
    newRequest.setR_Resolution_ID(l_nRResolID);
    newRequest.setPriority(getParameterAsString(request, "Priority"));
    newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser"));
    newRequest.setSummary(getParameterAsString(request, "Summary"));
    newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType"));
    newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced"));
    // values for fieldgroup Action
    newRequest.setDateNextAction(l_tsDateNextAction);
    newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry"));
    newRequest.setR_StandardResponse_ID(l_nResponseID);
    newRequest.setR_MailText_ID(l_nMailTextID);
    newRequest.setResult(getParameterAsString(request, "Result"));
    newRequest.setC_Activity_ID(l_nActivityID);
    newRequest.setQtyPlan(l_QtyPlan);
    newRequest.setQtySpent(l_QtySpent);
    newRequest.setM_ProductSpent_ID(l_nProdSpentID);
    newRequest.setQtyInvoiced(l_QtyInvoiced);
    newRequest.setDateStartPlan(l_tsDateStartPlan);
    newRequest.setDateCompletePlan(l_tsDateCompletePlan);
    newRequest.setStartDate(l_tsStartDate);
    newRequest.setCloseDate(l_tsCloseDate);
    // values for fieldgroup Reference
    newRequest.setC_BPartner_ID(l_nBPartnerID);
    newRequest.setAD_User_ID(l_nUserID);
    newRequest.setC_Project_ID(l_nProjectID);
    newRequest.setA_Asset_ID(l_nAssetID);
    newRequest.setC_Order_ID(l_nOrderID);
    newRequest.setC_Invoice_ID(l_nInvoiceID);
    newRequest.setM_Product_ID(l_nProductID);
    newRequest.setC_Payment_ID(l_nPaymentID);
    newRequest.setM_InOut_ID(l_nInOutID);
    newRequest.setM_RMA_ID(l_nRMAID);
    newRequest.setRequestAmt(l_bdAmt);
    newRequest.setC_Campaign_ID(l_nCampaignID);
    l_bSuccess &= newRequest.save();
    if (l_bSuccess) {
        try {
            DB.commit(true, l_szTrxName);
            l_szReturn = "" + newRequest.get_ID();
        } catch (Exception e) {
            l_szReturn = e.getMessage();
        }
    }
    return l_szReturn;
}
Also used : MRequest(org.compiere.model.MRequest) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) ParseException(java.text.ParseException)

Example 4 with MRequest

use of org.compiere.model.MRequest 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)

Example 5 with MRequest

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

the class RequestProcessor method processStatus.

//  escalate
/**************************************************************************
	 * 	Process Request Status
	 */
private void processStatus() {
    int count = 0;
    //	Requests with status with after timeout
    String sql = "SELECT * FROM R_Request r WHERE EXISTS (" + "SELECT * FROM R_Status s " + "WHERE r.R_Status_ID=s.R_Status_ID" + " AND s.TimeoutDays > 0 AND s.Next_Status_ID > 0" + " AND r.DateLastAction+s.TimeoutDays < SysDate" + ") " + "ORDER BY R_Status_ID";
    PreparedStatement pstmt = null;
    MStatus status = null;
    MStatus next = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MRequest r = new MRequest(getCtx(), rs, null);
            //	Get/Check Status
            if (status == null || status.getR_Status_ID() != r.getR_Status_ID())
                status = MStatus.get(getCtx(), r.getR_Status_ID());
            if (status.getTimeoutDays() <= 0 || status.getNext_Status_ID() == 0)
                continue;
            //	Next Status
            if (next == null || next.getR_Status_ID() != status.getNext_Status_ID())
                next = MStatus.get(getCtx(), status.getNext_Status_ID());
            //
            String result = Msg.getMsg(getCtx(), "RequestStatusTimeout") + ": " + status.getName() + " -> " + next.getName();
            r.setResult(result);
            r.setR_Status_ID(status.getNext_Status_ID());
            if (r.save())
                count++;
        }
        rs.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(pstmt);
    }
    m_summary.append("Status Timeout #").append(count).append(" - ");
}
Also used : MRequest(org.compiere.model.MRequest) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MStatus(org.compiere.model.MStatus) SQLException(java.sql.SQLException)

Aggregations

MRequest (org.compiere.model.MRequest)15 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)4 Properties (java.util.Properties)4 MAttachment (org.compiere.model.MAttachment)3 BigDecimal (java.math.BigDecimal)2 Timestamp (java.sql.Timestamp)2 ParseException (java.text.ParseException)2 Address (javax.mail.Address)2 HttpSession (javax.servlet.http.HttpSession)2 WebUser (org.compiere.util.WebUser)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Multipart (javax.mail.Multipart)1 Part (javax.mail.Part)1 MChangeRequest (org.compiere.model.MChangeRequest)1 MGroup (org.compiere.model.MGroup)1