Exemplo n.º 1
0
        }   //  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
Exemplo n.º 2
0
        }       //  processRequests

        private bool SendEmail(MRequest request, String AD_Message)
        {
            //  Alert: Request {0} overdue
            String subject = Msg.GetMsg(m_client.GetAD_Language(), AD_Message,
                                        new String[] { request.GetDocumentNo() });

            return(m_client.SendEMail(request.GetSalesRep_ID(), subject, request.GetSummary(), request.CreatePDF()));
        }   //  sendAlert
Exemplo n.º 3
0
        /// <summary>
        /// Send notice to users.
        /// </summary>
        /// <param name="list"> List of columns changed.</param>
        protected void SendNotices(List <String> list)
        {
            bool          isEmailSent = false;
            StringBuilder finalMsg    = new StringBuilder();

            finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NotificSent"));
            //	Subject
            if (mailText_ID == 0)
            {
                subject = Msg.Translate(GetCtx(), "R_Request_ID")
                          + " " + Msg.GetMsg(GetCtx(), "Updated", true) + ": " + _req.GetDocumentNo() + " (●" + MTable.Get_Table_ID(Table_Name) + "-" + _req.GetR_Request_ID() + "●) " + Msg.GetMsg(GetCtx(), "DoNotChange");
            }
            //	Message

            //		UpdatedBy: Joe
            int   UpdatedBy = GetCtx().GetAD_User_ID();
            MUser from      = MUser.Get(GetCtx(), UpdatedBy);

            FileInfo pdf = CreatePDF();

            log.Finer(message.ToString());

            //	Prepare sending Notice/Mail
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            //	ReSet from if external
            if (from.GetEMailUser() == null || from.GetEMailUserPW() == null)
            {
                from = null;
            }
            _success = 0;
            _failure = 0;
            _notices = 0;

            /** List of users - aviod duplicates	*/
            List <int> userList = new List <int>();
            String     sql      = "SELECT u.AD_User_ID, u.NotificationType, u.EMail, u.Name, MAX(r.AD_Role_ID) "
                                  + "FROM RV_RequestUpdates_Only ru"
                                  + " INNER JOIN AD_User u ON (ru.AD_User_ID=u.AD_User_ID)"
                                  + " LEFT OUTER JOIN AD_User_Roles r ON (u.AD_User_ID=r.AD_User_ID) "
                                  + "WHERE ru.R_Request_ID= " + _req.GetR_Request_ID()
                                  + " GROUP BY u.AD_User_ID, u.NotificationType, u.EMail, u.Name";

            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    int    AD_User_ID       = Utility.Util.GetValueOfInt(idr[0]);
                    String NotificationType = Util.GetValueOfString(idr[1]); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = Util.GetValueOfString(idr[2]);// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = Util.GetValueOfString(idr[3]);//idr.GetString(3);
                    //	Role
                    int AD_Role_ID = Utility.Util.GetValueOfInt(idr[4]);
                    if (idr == null)
                    {
                        AD_Role_ID = -1;
                    }

                    //	Don't send mail to oneself
                    //		if (AD_User_ID == UpdatedBy)
                    //			continue;

                    //	No confidential to externals
                    if (AD_Role_ID == -1 &&
                        (_req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_Internal) ||
                         _req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_PrivateInformation)))
                    {
                        continue;
                    }

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }
                    if ((X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                         X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType)) &&
                        (email == null || email.Length == 0))
                    {
                        if (AD_Role_ID >= 0)
                        {
                            NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                        }
                        else
                        {
                            log.Config("No EMail: " + Name);
                            continue;
                        }
                    }
                    if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) &&
                        AD_Role_ID >= 0)
                    {
                        log.Config("No internal User: "******"\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                idr.Close();
                // Notification For Role
                List <int> _users = SendRoleNotice();
                for (int i = 0; i < _users.Count; i++)
                {
                    MUser  user             = new MUser(GetCtx(), _users[i], null);
                    int    AD_User_ID       = user.GetAD_User_ID();
                    String NotificationType = user.GetNotificationType(); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = user.GetEMail();// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = user.GetName(); //idr.GetString(3);
                                                  //	Role

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }

                    //
                    SendNoticeNow(_users[i], NotificationType,
                                  client, from, subject, message.ToString(), pdf);
                    finalMsg.Append("\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                if (!isEmailSent)
                {
                    finalMsg.Clear();
                    finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NoNotificationSent"));
                }

                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, GetCtx().GetAD_User_ID(),
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, finalMsg.ToString(), Get_TrxName());
                if (note.Save())
                {
                    log.Log(Level.INFO, "ProcessFinished", "");
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }


            //	New Sales Rep (may happen if sent from beforeSave
            if (!userList.Contains(_req.GetSalesRep_ID()))
            {
                SendNoticeNow(_req.GetSalesRep_ID(), null,
                              client, from, subject, message.ToString(), pdf);
            }
        }
Exemplo n.º 4
0
        }   //  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