use of org.compiere.model.MNote in project adempiere by adempiere.
the class MPPMRP method getDocType.
public static int getDocType(Properties ctx, String docBaseType, int AD_Org_ID, int Planner_ID, String trxName) {
MDocType[] docs = MDocType.getOfDocBaseType(ctx, docBaseType);
if (docs == null || docs.length == 0) {
String reference = Msg.getMsg(ctx, "SequenceDocNotFound");
String textMsg = "Not found default document type for docbasetype " + docBaseType;
MNote note = new MNote(ctx, MMessage.getAD_Message_ID(ctx, "SequenceDocNotFound"), Planner_ID, MPPMRP.Table_ID, 0, reference, textMsg, trxName);
note.setAD_Org_ID(AD_Org_ID);
note.saveEx();
throw new AdempiereException(textMsg);
} else {
for (MDocType doc : docs) {
if (doc.getAD_Org_ID() == AD_Org_ID) {
return doc.getC_DocType_ID();
}
}
//log.info("Doc Type for "+docBaseType+": "+ docs[0].getC_DocType_ID());
return docs[0].getC_DocType_ID();
}
}
use of org.compiere.model.MNote in project adempiere by adempiere.
the class WebInfo method getNote.
// getNotes
/**
* Get Notification.
* Needs to have ID set first
* @return notification of User with ID
*/
public MNote getNote() {
m_infoMessage = null;
MNote retValue = null;
String sql = "SELECT * FROM AD_Note WHERE AD_User_ID=? AND AD_Note_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getAD_User_ID());
pstmt.setInt(2, m_id);
rs = pstmt.executeQuery();
if (rs.next())
retValue = new MNote(m_ctx, rs, null);
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Note_ID=" + m_id, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("AD_Note_ID=" + m_id + " - " + retValue);
return retValue;
}
use of org.compiere.model.MNote in project adempiere by adempiere.
the class WebInfo method getNotes.
// getCommissionRuns
/**
* Get Notices
* @return notices
*/
public ArrayList<MNote> getNotes() {
ArrayList<MNote> list = new ArrayList<MNote>();
String sql = "SELECT * FROM AD_Note " + "WHERE AD_User_ID=?" + " AND (Processed='N' OR Processed IS NULL) " + "ORDER BY Created DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getAD_User_ID());
rs = pstmt.executeQuery();
while (rs.next()) list.add(new MNote(m_ctx, rs, null));
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("#" + list.size());
return list;
}
use of org.compiere.model.MNote in project adempiere by adempiere.
the class NoteServlet 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 {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
String url = "/notes.jsp";
// 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=notes.jsp");
return;
}
WebEnv.dump(request);
int AD_Note_ID = WebUtil.getParameterAsInt(request, P_Note_ID);
String processed = WebUtil.getParameter(request, "Processed");
boolean prc = processed != null && processed.length() > 0;
if (prc) {
MNote note = new MNote(ctx, AD_Note_ID, null);
if (note.get_ID() == AD_Note_ID) {
note.setProcessed(true);
note.saveEx();
log.fine("doPost - " + note);
}
}
// Redisplay
log.info("Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
use of org.compiere.model.MNote in project adempiere by adempiere.
the class MWFActivity method setUserChoice.
// setVariable
/**
* Set User Choice
* @param AD_User_ID user
* @param value new Value
* @param displayType display type
* @param textMsg optional Message
* @return true if set
* @throws Exception if error
*/
public boolean setUserChoice(int AD_User_ID, String value, int displayType, String textMsg) throws Exception {
// Check if user approves own document when a role is reponsible
/*
* 2007-06-08, matthiasO.
* The following sequence makes sure that only users in roles which
* have the 'Approve own document flag' set can set the user choice
* of 'Y' (approve) or 'N' (reject).
* IMHO this is against the meaning of 'Approve own document': Why
* should a user who is faced with the task of approving documents
* generally be required to have the ability to approve his OWN
* documents? If the document to approve really IS his own document
* this will be respected when trying to find an approval user in
* the call to getApprovalUser(...) below.
*/
/*
if (getNode().isUserApproval() && getPO() instanceof DocAction)
{
DocAction doc = (DocAction)m_po;
MUser user = new MUser (getCtx(), AD_User_ID, null);
MRole[] roles = user.getRoles(m_po.getAD_Org_ID());
boolean canApproveOwnDoc = false;
for (int r = 0; r < roles.length; r++)
{
if (roles[r].isCanApproveOwnDoc())
{
canApproveOwnDoc = true;
break;
} // found a role which allows to approve own document
}
if (!canApproveOwnDoc)
{
String info = user.getName() + " cannot approve own document " + doc;
addTextMsg(info);
log.fine(info);
return false; // ignore
}
}*/
setWFState(StateEngine.STATE_Running);
setAD_User_ID(AD_User_ID);
Trx trx = (get_TrxName() != null) ? Trx.get(get_TrxName(), false) : null;
boolean ok = setVariable(value, displayType, textMsg, trx);
if (!ok)
return false;
String newState = StateEngine.STATE_Completed;
// Approval
if (getNode().isUserApproval() && getPO(trx) instanceof DocAction) {
DocAction doc = (DocAction) m_po;
try {
// Not approved
if (!"Y".equals(value)) {
newState = StateEngine.STATE_Aborted;
if (!(doc.processIt(DocAction.ACTION_Reject)))
setTextMsg("Cannot Reject - Document Status: " + doc.getDocStatus());
} else {
if (isInvoker()) {
int startAD_User_ID = Env.getAD_User_ID(getCtx());
if (startAD_User_ID == 0)
startAD_User_ID = doc.getDoc_User_ID();
int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), // own doc
startAD_User_ID == doc.getDoc_User_ID());
// No Approver
if (nextAD_User_ID <= 0) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - No Approver");
doc.processIt(DocAction.ACTION_Reject);
} else if (startAD_User_ID != nextAD_User_ID) {
forwardTo(nextAD_User_ID, "Next Approver");
newState = StateEngine.STATE_Suspended;
} else // Approve
{
if (!(doc.processIt(DocAction.ACTION_Approve))) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - Document Status: " + doc.getDocStatus());
}
}
} else // No Invoker - Approve
if (!(doc.processIt(DocAction.ACTION_Approve))) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - Document Status: " + doc.getDocStatus());
}
}
doc.saveEx();
} catch (Exception e) {
newState = StateEngine.STATE_Terminated;
setTextMsg("User Choice: " + e.toString());
addTextMsg(e);
log.log(Level.WARNING, "", e);
}
// Send Approval Notification
if (newState.equals(StateEngine.STATE_Aborted)) {
MUser to = new MUser(getCtx(), doc.getDoc_User_ID(), null);
// send email
if (to.isNotificationEMail()) {
MClient client = MClient.get(getCtx(), doc.getAD_Client_ID());
client.sendEMail(doc.getDoc_User_ID(), Msg.getMsg(getCtx(), "NotApproved") + ": " + doc.getDocumentNo(), (doc.getSummary() != null ? doc.getSummary() + "\n" : "") + (doc.getProcessMsg() != null ? doc.getProcessMsg() + "\n" : "") + (getTextMsg() != null ? getTextMsg() : ""), null);
}
// Send Note
if (to.isNotificationNote()) {
MNote note = new MNote(getCtx(), "NotApproved", doc.getDoc_User_ID(), null);
note.setTextMsg((doc.getSummary() != null ? doc.getSummary() + "\n" : "") + (doc.getProcessMsg() != null ? doc.getProcessMsg() + "\n" : "") + (getTextMsg() != null ? getTextMsg() : ""));
// 2007-06-08, matthiasO.
// Add record information to the note, so that the user receiving the
// note can jump to the doc easily
note.setRecord(m_po.get_Table_ID(), m_po.get_ID());
note.saveEx();
}
}
}
setWFState(newState);
return ok;
}
Aggregations