} // invoiceDone /// <summary> /// New Invoice /// </summary> /// <param name="request">request</param> private void InvoiceNew(MRequest request) { _m_invoice = new MInvoice(GetCtx(), 0, Get_TrxName()); _m_invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_ARINVOICE); MBPartner partner = new MBPartner(GetCtx(), request.GetC_BPartner_ID(), Get_TrxName()); _m_invoice.SetBPartner(partner); _m_invoice.SetM_PriceList_ID(partner.GetM_PriceList_ID()); int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { _m_invoice.SetVA009_PaymentMethod_ID(partner.GetVA009_PaymentMethod_ID()); } _m_invoice.Save(); request.SetC_Invoice_ID(_m_invoice.GetC_Invoice_ID()); request.Save(); if (string.IsNullOrEmpty(_msg)) { _msg = "Invoice-[ID:" + _m_invoice.Get_ID() + "] created"; } else { _msg += ",Invoice-[ID: " + _m_invoice.Get_ID() + "] created"; } //_m_linecount = 0; } // invoiceNew
} // sendAlert private bool Escalate(MRequest request) { // Get Supervisor MUser supervisor = request.GetSalesRep(); // self int supervisor_ID = request.GetSalesRep().GetSupervisor_ID(); if ((supervisor_ID == 0) && (m_model.GetSupervisor_ID() != 0)) { supervisor_ID = m_model.GetSupervisor_ID(); } if ((supervisor_ID != 0) && (supervisor_ID != request.GetAD_User_ID())) { supervisor = MUser.Get(GetCtx(), supervisor_ID); } // Escalated: Request {0} to {1} String subject = Msg.GetMsg(m_client.GetAD_Language(), "RequestEscalate", new String[] { request.GetDocumentNo(), supervisor.GetName() }); String to = request.GetSalesRep().GetEMail(); if ((to == null) || (to.Length == 0)) { log.Warning("SalesRep has no EMail - " + request.GetSalesRep()); } else { m_client.SendEMail(request.GetSalesRep_ID(), subject, request.GetSummary(), request.CreatePDF()); } // Not the same - send mail to supervisor if (request.GetSalesRep_ID() != supervisor.GetAD_User_ID()) { to = supervisor.GetEMail(); if ((to == null) || (to.Length == 0)) { log.Warning("Supervisor has no EMail - " + supervisor); } else { m_client.SendEMail(supervisor.GetAD_User_ID(), subject, request.GetSummary(), request.CreatePDF()); } } // ---------------- request.SetDueType(); request.SetIsEscalated(true); request.SetResult(subject); return(request.Save()); } // escalate
} // isSubscribed /** * After Save * @param newRecord new * @param success success * @return success */ protected override Boolean AfterSave(Boolean newRecord, Boolean success) { if (success && newRecord && IsSubscribed()) { MInterestArea ia = MInterestArea.Get(GetCtx(), GetR_InterestArea_ID()); if (ia.GetR_Source_ID() != 0) { String summary = "Subscribe: " + ia.GetName(); // MSource source = MSource.Get(GetCtx(), ia.GetR_Source_ID()); MUser user = null; if (Get_TrxName() == null) { user = MUser.Get(GetCtx(), GetAD_User_ID()); } else { user = new MUser(GetCtx(), GetAD_User_ID(), Get_TrxName()); } // Create Request if (MSource.SOURCECREATETYPE_Both.Equals(source.GetSourceCreateType()) || MSource.SOURCECREATETYPE_Request.Equals(source.GetSourceCreateType())) { MRequest request = new MRequest(GetCtx(), 0, Get_TrxName()); request.SetClientOrg(this); request.SetSummary(summary); request.SetAD_User_ID(GetAD_User_ID()); request.SetC_BPartner_ID(user.GetC_BPartner_ID()); request.SetR_Source_ID(source.GetR_Source_ID()); request.Save(); } // Create Lead if (MSource.SOURCECREATETYPE_Both.Equals(source.GetSourceCreateType()) || MSource.SOURCECREATETYPE_Lead.Equals(source.GetSourceCreateType())) { MLead lead = new MLead(GetCtx(), 0, Get_TrxName()); lead.SetClientOrg(this); lead.SetDescription(summary); lead.SetAD_User_ID(GetAD_User_ID()); lead.SetR_InterestArea_ID(GetR_InterestArea_ID()); lead.SetC_BPartner_ID(user.GetC_BPartner_ID()); lead.SetR_Source_ID(source.GetR_Source_ID()); lead.Save(); } } } return(success); } // afterSave
} // prepare /// <summary> /// Process It /// </summary> /// <returns>message</returns> protected override String DoIt() { MRequest request = new MRequest(GetCtx(), _R_Request_ID, Get_TrxName()); log.Info(request.ToString()); if (request.Get_ID() == 0) { throw new Exception("@NoRequsetFound@ " + _R_Request_ID); } request.SetR_Status_ID(); // set default status request.SetProcessed(false); if (request.Save() && !request.IsProcessed()) { return("@Created Successfully@"); } return("@Error@"); } // doUt
/** * Create Project from Lead * @return error message */ public String CreateProject(int C_ProjectType_ID) { if (GetC_Project_ID() != 0) { return("@AlreadyExists@: @C_Project_ID@ (ID=" + GetC_Project_ID() + ")"); } if (GetC_BPartner_ID() == 0) { String retValue = CreateBP(); if (retValue != null) { return(retValue); } } _project = new MProject(GetCtx(), 0, Get_TrxName()); _project.SetAD_Org_ID(GetAD_Org_ID()); _project.SetProjectLineLevel(MProject.PROJECTLINELEVEL_Project); _project.SetName(GetName()); _project.SetDescription(GetDescription()); _project.SetNote(GetHelp()); // _project.SetC_BPartner_ID(GetC_BPartner_ID()); _project.SetC_BPartner_Location_ID(GetC_BPartner_Location_ID()); _project.SetAD_User_ID(GetAD_User_ID()); _project.SetC_BPartnerSR_ID(GetC_BPartnerSR_ID()); _project.SetC_Campaign_ID(GetC_Campaign_ID()); _project.SetC_ProjectType_ID(C_ProjectType_ID); _project.SetSalesRep_ID(GetSalesRep_ID()); _project.SetC_SalesRegion_ID(GetC_SalesRegion_ID()); if (!_project.Save()) { return("@SaveError@"); } // if (GetRequest() != null) { _request.SetC_Project_ID(_project.GetC_Project_ID()); _request.Save(); } // SetC_Project_ID(_project.GetC_Project_ID()); return(null); }
/** * Create Request from Lead * @param R_RequestType_ID request type * @return error message */ private String CreateRequest(int R_RequestType_ID) { if (GetR_Request_ID() != 0) { return("@AlreadyExists@: @R_Request_ID@ (ID=" + GetR_Request_ID() + ")"); } if (GetC_BPartner_ID() == 0) { String retValue = CreateBP(); if (retValue != null) { return(retValue); } } _request = new MRequest(GetCtx(), 0, Get_TrxName()); _request.SetAD_Org_ID(GetAD_Org_ID()); String summary = GetName(); if (summary == null) { summary = GetHelp(); } if (summary == null) { summary = GetSummary(); } if (summary == null) { summary = GetDescription(); } _request.SetSummary(summary); // _request.SetR_RequestType_ID(R_RequestType_ID); if (IsR_Status_IDValid(GetR_Status_ID())) { _request.SetR_Status_ID(GetR_Status_ID()); } else { _request.SetR_Status_ID(); } // _request.SetC_Lead_ID(GetC_Lead_ID()); // _request.SetC_BPartner_ID(GetC_BPartner_ID()); _request.SetAD_User_ID(GetAD_User_ID()); _request.SetC_Project_ID(GetC_Project_ID()); _request.SetC_Campaign_ID(GetC_Campaign_ID()); _request.SetR_Source_ID(GetR_Source_ID()); _request.SetC_BPartnerSR_ID(GetC_BPartnerSR_ID()); _request.SetC_SalesRegion_ID(GetC_SalesRegion_ID()); _request.SetSalesRep_ID(GetSalesRep_ID()); if (!_request.Save()) { return("@SaveError@"); } // SetR_Request_ID(_request.GetR_Request_ID()); return(null); }
private void ProcessRequests() { /** * Due Requests (Scheduled -> Due) */ String sql = "SELECT * FROM R_Request " + "WHERE DueType='" + X_R_Request.DUETYPE_Scheduled + "' AND Processed='N'" + " AND DateNextAction > SysDate" + " AND AD_Client_ID=" + m_model.GetAD_Client_ID(); if (m_model.GetR_RequestType_ID() != 0) { sql += " AND R_RequestType_ID=" + m_model.GetR_RequestType_ID(); } int count = 0; int countEMails = 0; try { DataSet ds = DB.ExecuteDataset(sql); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(GetCtx(), dr, null); request.SetDueType(); if (request.IsDue()) { if (request.GetRequestType().IsEMailWhenDue()) { if (SendEmail(request, "RequestDue")) { request.SetDateLastAlert(); countEMails++; } } request.Save(); count++; } } } catch (Exception e) { log.Log(Level.SEVERE, sql, e); } m_summary.Append("New Due #").Append(count); if (countEMails > 0) { m_summary.Append(" (").Append(countEMails).Append(" EMail)"); } m_summary.Append(" - "); /** * Overdue Requests. * Due Requests - are they overdue? (Send EMail) */ sql = "SELECT * FROM R_Request r " + "WHERE r.DueType='" + X_R_Request.DUETYPE_Due + "' AND r.Processed='N'" + " AND AD_Client_ID=" + m_model.GetAD_Client_ID() + " AND EXISTS (SELECT * FROM R_RequestType rt " + "WHERE r.R_RequestType_ID=rt.R_RequestType_ID" + " AND addDays(r.DateNextAction,rt.DueDateTolerance) > SysDate)"; // + " AND addDays(COALESCE(r.DateNextAction,Updated),rt.DueDateTolerance)>SysDate)"; if (m_model.GetR_RequestType_ID() != 0) { sql += " AND r.R_RequestType_ID=" + m_model.GetR_RequestType_ID(); } count = 0; countEMails = 0; try { DataSet ds = DB.ExecuteDataset(sql); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(GetCtx(), dr, null); request.SetDueType(); if (request.IsOverdue()) { if (request.GetRequestType().IsEMailWhenOverdue() && !TimeUtil.IsSameDay(request.GetDateLastAlert(), null)) { if (SendEmail(request, "RequestDue")) { request.SetDateLastAlert(); countEMails++; } } request.Save(); count++; } } } catch (Exception e) { log.Log(Level.SEVERE, sql, e); } m_summary.Append("New Overdue #").Append(count); if (countEMails > 0) { m_summary.Append(" (").Append(countEMails).Append(" EMail)"); } m_summary.Append(" - "); /** * Send (over)due alerts */ if (m_model.GetOverdueAlertDays() > 0) { sql = "SELECT * FROM R_Request " + "WHERE Processed='N'" + " AND AD_Client_ID=" + m_model.GetAD_Client_ID() //jz + " AND (DateNextAction+" + m_model.getOverdueAlertDays() + ") > SysDate" + " AND addDays(DateNextAction," + m_model.GetOverdueAlertDays() + ") > SysDate " + " AND (DateLastAlert IS NULL"; if (m_model.GetRemindDays() > 0) { //jz sql += " OR (DateLastAlert+" + m_model.getRemindDays() sql += " OR addDays(DateLastAlert," + m_model.GetRemindDays() + ") > SysDate "; } sql += ")"; if (m_model.GetR_RequestType_ID() != 0) { sql += " AND R_RequestType_ID=" + m_model.GetR_RequestType_ID(); } count = 0; countEMails = 0; try { DataSet ds = DB.ExecuteDataset(sql); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(GetCtx(), dr, null); request.SetDueType(); if (request.GetRequestType().IsEMailWhenOverdue() && ((request.GetDateLastAlert() == null) || !TimeUtil.IsSameDay(request.GetDateLastAlert(), null))) { if (SendEmail(request, "RequestAlert")) { request.SetDateLastAlert(); countEMails++; } } request.Save(); count++; } } catch (SqlException e) { log.Log(Level.SEVERE, sql, e); } m_summary.Append("Alerts #").Append(count); if (countEMails > 0) { m_summary.Append(" (").Append(countEMails).Append(" EMail)"); } m_summary.Append(" - "); } // Overdue /** * Escalate if Date Next Action + Overdue Assign Days > SysDate */ if (m_model.GetOverdueAssignDays() > 0) { sql = "SELECT * FROM R_Request " + "WHERE Processed='N'" + " AND AD_Client_ID=" + m_model.GetAD_Client_ID() + " AND IsEscalated='N'" + " AND addDays(DateNextAction," + m_model.GetOverdueAssignDays() + ") > SysDate"; if (m_model.GetR_RequestType_ID() != 0) { sql += " AND R_RequestType_ID=" + m_model.GetR_RequestType_ID(); } count = 0; countEMails = 0; try { DataSet ds = DB.ExecuteDataset(sql); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(GetCtx(), dr, null); if (Escalate(request)) { count++; } } } catch (SqlException e) { log.Log(Level.SEVERE, sql, e); } m_summary.Append("Escalated #").Append(count).Append(" - "); } // Esacalate /** * Send Inactivity alerts */ if (m_model.GetInactivityAlertDays() > 0) { sql = "SELECT * FROM R_Request r " + "WHERE r.Processed='N'" + " AND r.AD_Client_ID=" + m_model.GetAD_Client_ID() // Nothing happening for x days + " AND addDays(r.Updated," + m_model.GetInactivityAlertDays() + ") < SysDate " + " AND (r.DateLastAlert IS NULL"; if (m_model.GetRemindDays() > 0) { sql += " OR addDays(r.DateLastAlert," + m_model.GetRemindDays() + ") < SysDate "; } sql += ")"; // Next Date & Updated over due date tolerance sql += " AND EXISTS (SELECT * FROM R_RequestType rt " + "WHERE r.R_RequestType_ID=rt.R_RequestType_ID" + " AND addDays(COALESCE(r.DateNextAction,Updated),rt.DueDateTolerance) > SysDate)"; if (m_model.GetR_RequestType_ID() != 0) { sql += " AND r.R_RequestType_ID=" + m_model.GetR_RequestType_ID(); } count = 0; countEMails = 0; try { DataSet ds = DB.ExecuteDataset(sql); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(GetCtx(), dr, null); request.SetDueType(); // only once per day if (!TimeUtil.IsSameDay(request.GetDateLastAlert(), null)) { if (SendEmail(request, "RequestInactive")) { request.SetDateLastAlert(); countEMails++; } request.Save(); count++; } } } catch (SqlException e) { log.Log(Level.SEVERE, sql, e); } m_summary.Append("Inactivity #").Append(count); if (countEMails > 0) { m_summary.Append(" (").Append(countEMails).Append(" EMail)"); } m_summary.Append(" - "); } // Inactivity } // processRequests
} // processEMail private void FindSalesRep() { int changed = 0; int notFound = 0; Ctx ctx = new Ctx(); // String sql = "SELECT * FROM R_Request " + "WHERE AD_Client_ID=@AD_Client_ID" + " AND SalesRep_ID=0 AND Processed='N'"; if (m_model.GetR_RequestType_ID() != 0) { sql += " AND R_RequestType_ID=@R_RequestType_ID"; } try { SqlParameter[] param = null; if (m_model.GetR_RequestType_ID() != 0) { param = new SqlParameter[2]; } else { param = new SqlParameter[1]; } param[0] = new SqlParameter("@AD_Client_ID", m_model.GetAD_Client_ID()); if (m_model.GetR_RequestType_ID() != 0) { param[1] = new SqlParameter("@AD_Client_ID", m_model.GetR_RequestType_ID()); } DataSet ds = DB.ExecuteDataset(sql, param); foreach (DataRow dr in ds.Tables[0].Rows) { MRequest request = new MRequest(ctx, dr, null); if (request.GetSalesRep_ID() != 0) { continue; } int SalesRep_ID = FindSalesRep(request); if (SalesRep_ID != 0) { request.SetSalesRep_ID(SalesRep_ID); request.Save(); changed++; } else { notFound++; } } } catch (SqlException ex) { log.Log(Level.SEVERE, sql, ex); } // if ((changed == 0) && (notFound == 0)) { m_summary.Append("No unallocated Requests"); } else { m_summary.Append("Allocated SalesRep=").Append(changed); } if (notFound > 0) { m_summary.Append(",Not=").Append(notFound); } m_summary.Append(" - "); } // findSalesRep