Exemple #1
0
        /**
         *  Set AD_User_ID from email
         */
        public void SetAD_User_ID()
        {
            if (GetAD_User_ID() != 0)
            {
                return;
            }
            String email = GetEMail();

            if (email != null && email.Length > 0)
            {
                _user = MUser.Get(GetCtx(), email, Get_TrxName());
                if (_user != null)
                {
                    base.SetAD_User_ID(_user.GetAD_User_ID());
                    if (GetC_BPartner_ID() == 0)
                    {
                        SetC_BPartner_ID(_user.GetC_BPartner_ID());
                    }
                    else if (_user.GetC_BPartner_ID() != GetC_BPartner_ID())
                    {
                        log.Warning("@C_BPartner_ID@ (ID=" + GetC_BPartner_ID()
                                    + ") <> @AD_User_ID@ @C_BPartner_ID@ (ID=" + _user.GetC_BPartner_ID() + ")");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AD_User_ID"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <param name="attachment"></param>
        /// <returns></returns>
        public bool SendEMail(int AD_User_ID, String subject, String message, FileInfo attachment)
        {
            MUser  to      = MUser.Get(GetCtx(), AD_User_ID);
            String toEMail = to.GetEMail();

            if (toEMail == null || toEMail.Length == 0)
            {
                //log.warning("No EMail for recipient: " + to);
                return(false);
            }
            if (to.IsEMailBounced())
            {
                //log.warning("EMail bounced for recipient: " + to);
                return(false);
            }
            EMail email = CreateEMail(null, to, subject, message);

            if (email == null)
            {
                return(false);
            }
            if (attachment != null)
            {
                email.AddAttachment(attachment);
            }
            try
            {
                return(SendEmailNow(null, to, email));
            }
            catch (Exception ex)
            {
                log.Severe(GetName() + " - " + ex.Message);
                return(false);
            }
        }
Exemple #3
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            //	Measure required if nor Summary
            if (!IsSummary() && GetPA_Measure_ID() == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "PA_Measure_ID"));
                return(false);
            }
            if (IsSummary() && GetPA_Measure_ID() != 0)
            {
                SetPA_Measure_ID(0);
            }

            //	User/Role Check
            if ((newRecord || Is_ValueChanged("AD_User_ID") || Is_ValueChanged("AD_Role_ID")) &&
                GetAD_User_ID() != 0)
            {
                MUser   user  = MUser.Get(GetCtx(), GetAD_User_ID());
                MRole[] roles = user.GetRoles(GetAD_Org_ID());
                if (roles.Length == 0)          //	No Role
                {
                    SetAD_Role_ID(0);
                }
                else if (roles.Length == 1)     //	One
                {
                    SetAD_Role_ID(roles[0].GetAD_Role_ID());
                }
                else
                {
                    int AD_Role_ID = GetAD_Role_ID();
                    if (AD_Role_ID != 0)        //	validate
                    {
                        Boolean found = false;
                        for (int i = 0; i < roles.Length; i++)
                        {
                            if (AD_Role_ID == roles[i].GetAD_Role_ID())
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            AD_Role_ID = 0;
                        }
                    }
                    if (AD_Role_ID == 0)                //	Set to first one
                    {
                        SetAD_Role_ID(roles[0].GetAD_Role_ID());
                    }
                }       //	multiple roles
            }

            return(true);
        }
Exemple #4
0
        public static bool GetIsEmployee(Ctx ctx, int AD_USER_ID)
        {
            MUser     user = MUser.Get(ctx, AD_USER_ID);
            MBPartner bp   = MBPartner.Get(ctx, user.GetC_BPartner_ID());

            user = null;
            if (bp == null)
            {
                return(false);
            }
            return(bp.IsEmployee());
        }
        /// <summary>
        ///     Send RfQ, mail subject and body from mail template
        /// </summary>
        /// <returns>true if RfQ is sent per email.</returns>
        public bool SendRfQ()
        {
            try
            {
                MUser     to     = MUser.Get(GetCtx(), GetAD_User_ID());
                MClient   client = MClient.Get(GetCtx());
                MMailText mtext  = new MMailText(GetCtx(), GetRfQ().GetR_MailText_ID(), Get_TrxName());

                if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
                {
                    log.Log(Level.SEVERE, "No User or no EMail - " + to);
                    return(false);
                }

                // Check if mail template is set for RfQ window, if not then get from RfQ Topic window.
                if (mtext.GetR_MailText_ID() == 0)
                {
                    MRfQTopic mRfQTopic = new MRfQTopic(GetCtx(), GetRfQ().GetC_RfQ_Topic_ID(), Get_TrxName());
                    if (mRfQTopic.GetC_RfQ_Topic_ID() > 0)
                    {
                        mtext = new MMailText(GetCtx(), mRfQTopic.GetR_MailText_ID(), Get_TrxName());
                    }
                }

                //Replace the email template constants with tables values.
                StringBuilder message = new StringBuilder();
                mtext.SetPO(GetRfQ(), true);
                message.Append(mtext.GetMailText(true).Equals(string.Empty) ? "** No Email Body" : mtext.GetMailText(true));

                String subject = String.IsNullOrEmpty(mtext.GetMailHeader()) ? "** No Subject" : mtext.GetMailHeader();;

                EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), subject, message.ToString());
                if (email == null)
                {
                    return(false);
                }
                email.AddAttachment(CreatePDF());
                if (EMail.SENT_OK.Equals(email.Send()))
                {
                    //SetDateInvited(new Timestamp(System.currentTimeMillis()));
                    SetDateInvited(DateTime.Now);
                    Save();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Severe(ex.ToString());
                //MessageBox.Show("error--" + ex.ToString());
            }
            return(false);
        }
Exemple #6
0
 /// <summary>
 /// Set Approved
 /// </summary>
 /// <param name="isApproved">approval</param>
 public new void SetIsApproved(Boolean isApproved)
 {
     if (isApproved && !IsApproved())
     {
         int    AD_User_ID = GetCtx().GetAD_User_ID();
         MUser  user       = MUser.Get(GetCtx(), AD_User_ID);
         String info       = user.GetName()
                             + ": "
                             + Msg.Translate(GetCtx(), "IsApproved")
                             + " - " + new DateTime(CommonFunctions.CurrentTimeMillis());
         AddDescription(info);
     }
     base.SetIsApproved(isApproved);
 }
Exemple #7
0
 /// <summary>
 /// Set Approved
 /// </summary>
 /// <param name="isApproved">approval</param>
 public new void SetIsApproved(Boolean isApproved)
 {
     if (isApproved && !IsApproved())
     {
         int    AD_User_ID = GetCtx().GetAD_User_ID();
         MUser  user       = MUser.Get(GetCtx(), AD_User_ID);
         String info       = user.GetName()
                             + ": "
                             + Msg.Translate(GetCtx(), "IsApproved")
                             + " - " + DateTime.Now.ToString();
         AddDescription(info);
     }
     base.SetIsApproved(isApproved);
 }
        }       //	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
Exemple #9
0
 /// <summary>
 ///     Send RfQ
 /// </summary>
 /// <returns>true if RfQ is sent per email.</returns>
 public bool SendRfQ()
 {
     try
     {
         MUser to = MUser.Get(GetCtx(), GetAD_User_ID());
         if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
         {
             log.Log(Level.SEVERE, "No User or no EMail - " + to);
             return(false);
         }
         MClient client = MClient.Get(GetCtx());
         //
         String message = GetDescription();
         if (message == null || message.Length == 0)
         {
             message = GetHelp();
         }
         else if (GetHelp() != null)
         {
             message += "\n" + GetHelp();
         }
         if (message == null)
         {
             message = GetName();
         }
         //
         EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), "RfQ: " + GetName(), message);
         if (email == null)
         {
             return(false);
         }
         email.AddAttachment(CreatePDF());
         if (EMail.SENT_OK.Equals(email.Send()))
         {
             //SetDateInvited(new Timestamp(System.currentTimeMillis()));
             SetDateInvited(DateTime.Now);
             Save();
             return(true);
         }
     }
     catch (Exception ex)
     {
         log.Severe(ex.ToString());
         //MessageBox.Show("error--" + ex.ToString());
     }
     return(false);
 }
Exemple #10
0
 /// <summary>
 /// Set User for parse
 /// </summary>
 /// <param name="AD_User_ID">user</param>
 public void SetUser(int AD_User_ID)
 {
     _user = MUser.Get(GetCtx(), AD_User_ID);
 }
 /**
  *  Get User Name
  *	@return user name
  */
 public String GetUserName()
 {
     return(MUser.Get(GetCtx(), GetAD_User_ID()).GetName());
 }
Exemple #12
0
        /**
         *  Get Name of creator
         *	@return name
         */
        public String GetCreatedByName()
        {
            MUser user = MUser.Get(GetCtx(), GetCreatedBy());

            return(user.GetName());
        }
Exemple #13
0
 /**
  *  Update/save Goals with Projects
  *  @return true if updated
  */
 private Boolean UpdateProjects()
 {
     if (!MEASURETYPE_Project.Equals(GetMeasureType()) ||
         GetC_ProjectType_ID() == 0)
     {
         return(false);
     }
     MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID());
     for (int i = 0; i < goals.Length; i++)
     {
         MGoal goal = goals[i];
         //	Find Role
         MRole role = null;
         if (goal.GetAD_Role_ID() != 0)
         {
             role = MRole.Get(GetCtx(), goal.GetAD_Role_ID());
         }
         else if (goal.GetAD_User_ID() != 0)
         {
             MUser   user  = MUser.Get(GetCtx(), goal.GetAD_User_ID());
             MRole[] roles = user.GetRoles(goal.GetAD_Org_ID());
             if (roles.Length > 0)
             {
                 role = roles[0];
             }
         }
         if (role == null)
         {
             role = MRole.GetDefault(GetCtx(), false);   //	could result in wrong data
         }
         //
         Decimal?     ManualActual = null;
         MProjectType pt           = MProjectType.Get(GetCtx(), GetC_ProjectType_ID());
         String       sql          = pt.GetSqlPI(goal.GetRestrictions(false),
                                                 goal.GetMeasureScope(), GetMeasureDataType(), null, role);
         IDataReader idr = null;
         try             //	SQL statement could be wrong
         {
             idr = DataBase.DB.ExecuteReader(sql, null, null);
             if (idr.Read())
             {
                 ManualActual = Utility.Util.GetValueOfDecimal(idr[0]);
             }
             idr.Close();
         }
         catch (Exception e)
         {
             if (idr != null)
             {
                 idr.Close();
             }
             log.Log(Level.SEVERE, sql, e);
         }
         //	SQL may return no rows or null
         if (ManualActual == null)
         {
             ManualActual = Env.ZERO;
             log.Fine("No Value = " + sql);
         }
         goal.SetMeasureActual(ManualActual);
         goal.Save();
     }
     return(true);
 }