}   //  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
Beispiel #2
0
        /// <summary>
        /// Send notice to user
        /// </summary>
        /// <param name="AD_User_ID">Id of user</param>
        /// <param name="NotificationType"> Notification type</param>
        /// <param name="client"> Tenant object</param>
        /// <param name="from"> From user notice</param>
        /// <param name="subject">Subject of notice.</param>
        /// <param name="message">Message to be sent to user</param>
        /// <param name="pdf"> Attachment</param>
        private void SendNoticeNow(int AD_User_ID, String NotificationType,
                                   MClient client, MUser from, String subject, String message, FileInfo pdf)
        {
            MUser to = MUser.Get(GetCtx(), AD_User_ID);

            if (NotificationType == null)
            {
                NotificationType = to.GetNotificationType();
            }
            //	Send Mail
            if (X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                VAdvantage.Model.MMailAttachment1 _mAttachment = new VAdvantage.Model.MMailAttachment1(GetCtx(), 0, null);
                _mAttachment.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                _mAttachment.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                _mAttachment.SetAD_Table_ID(MTable.Get_Table_ID(Table_Name));
                _mAttachment.IsActive();
                _mAttachment.SetMailAddress("");
                _mAttachment.SetAttachmentType("M");
                _mAttachment.SetRecord_ID(_req.GetR_Request_ID());
                _mAttachment.SetTextMsg(message);
                _mAttachment.SetTitle(subject);
                _mAttachment.SetMailAddress(to.GetEMail());

                if (from != null && !string.IsNullOrEmpty(from.GetEMail()))
                {
                    _mAttachment.SetMailAddressFrom(from.GetEMail());
                }
                else
                {
                    _mAttachment.SetMailAddressFrom(client.GetRequestEMail());
                }

                _mAttachment.NewRecord();

                if (client.SendEMail(from, to, subject, message.ToString(), pdf))
                {
                    _success++;
                    if (_emailTo.Length > 0)
                    {
                        _emailTo.Append(", ");
                    }
                    _emailTo.Append(to.GetEMail());
                    _mAttachment.SetIsMailSent(true);
                }
                else
                {
                    log.Warning("Failed: " + to);
                    _failure++;
                    NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                    _mAttachment.SetIsMailSent(false);
                }

                _mAttachment.Save();
            }

            //	Send Note
            if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, AD_User_ID,
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, message.ToString(), Get_TrxName());
                if (note.Save())
                {
                    _notices++;
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("C_DunningRun_ID=" + _C_DunningRun_ID + ",R_MailText_ID=" + _R_MailText_ID
                     + ", EmailPDF=" + _EMailPDF + ",IsOnlyIfBPBalance=" + _IsOnlyIfBPBalance);

            //	Need to have Template
            if (_EMailPDF && _R_MailText_ID == 0)
            {
                throw new Exception("@NotFound@: @R_MailText_ID@");
            }
            String    subject = "";
            MMailText mText   = null;

            if (_EMailPDF)
            {
                mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName());
                if (_EMailPDF && mText.Get_ID() == 0)
                {
                    throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID);
                }
                subject = mText.GetMailHeader();
            }
            //
            MDunningRun run = new MDunningRun(GetCtx(), _C_DunningRun_ID, Get_TrxName());

            if (run.Get_ID() == 0)
            {
                throw new Exception("@NotFound@: @C_DunningRun_ID@ - " + _C_DunningRun_ID);
            }
            //	Print Format on Dunning Level
            MDunningLevel level = new MDunningLevel(GetCtx(), run.GetC_DunningLevel_ID(), Get_TrxName());
            //MPrintFormat format = MPrintFormat.Get(GetCtx(), level.GetDunning_PrintFormat_ID(), false);

            MClient client = MClient.Get(GetCtx());

            int count  = 0;
            int errors = 0;

            MDunningRunEntry[] entries = run.GetEntries(false);
            for (int i = 0; i < entries.Length; i++)
            {
                MDunningRunEntry entry = entries[i];
                if (_IsOnlyIfBPBalance && Env.Signum(entry.GetAmt()) <= 0)
                {
                    continue;
                }
                //	To BPartner
                MBPartner bp = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName());
                if (bp.Get_ID() == 0)
                {
                    AddLog(entry.Get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.GetC_BPartner_ID());
                    errors++;
                    continue;
                }
                //	To User
                MUser to = new MUser(GetCtx(), entry.GetAD_User_ID(), Get_TrxName());
                if (_EMailPDF)
                {
                    if (to.Get_ID() == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.GetName());
                        errors++;
                        continue;
                    }
                    else if (to.GetEMail() == null || to.GetEMail().Length == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @EMail@ - " + to.GetName());
                        errors++;
                        continue;
                    }
                }
                //	BP Language
                //Language language =Language.getLoginLanguage();		//	Base Language
                Language language = Env.GetLoginLanguage(GetCtx());

                String tableName = "C_Dunning_Header_v";
                if (client.IsMultiLingualDocument())
                {
                    tableName += "t";
                    String AD_Language = bp.GetAD_Language();
                    if (AD_Language != null)
                    {
                        //language =language.getLanguage(AD_Language);
                    }
                }
                // format.SetLanguage(language);
                // format.SetTranslationLanguage(language);
                //	query
                Query query = new Query(tableName);
                query.AddRestriction("C_DunningRunEntry_ID", Query.EQUAL,
                                     entry.GetC_DunningRunEntry_ID());

                //	Engine
                //PrintInfo info = new PrintInfo(
                //    bp.GetName(),
                //    X_C_DunningRunEntry.Table_ID,
                //    entry.GetC_DunningRunEntry_ID(),
                //    entry.GetC_BPartner_ID());
                //info.SetDescription(bp.GetName() + ", Amt=" + entry.GetAmt());
                //ReportEngine re = new ReportEngine(GetCtx(), format, query, info);
                bool printed = false;
                if (_EMailPDF)
                {
                    EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), null, null);
                    if (email == null || !email.IsValid())
                    {
                        AddLog(entry.Get_ID(), null, null,
                               "@RequestActionEMailError@ Invalid EMail: " + to);
                        errors++;
                        continue;
                    }
                    mText.SetUser(to);  //	variable context
                    mText.SetBPartner(bp);
                    mText.SetPO(entry);
                    String message = mText.GetMailText(true);
                    if (mText.IsHtml())
                    {
                        email.SetMessageHTML(mText.GetMailHeader(), message);
                    }
                    else
                    {
                        email.SetSubject(mText.GetMailHeader());
                        email.SetMessageText(message);
                    }
                    //
                    //File attachment = re.GetPDF(File.createTempFile("Dunning", ".pdf"));
                    //log.Fine(to + " - " + attachment);
                    //email.AddAttachment(attachment);
                    //
                    String    msg = email.Send();
                    MUserMail um  = new MUserMail(mText, entry.GetAD_User_ID(), email);
                    um.Save();
                    if (msg.Equals(EMail.SENT_OK))
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailOK@");
                        count++;
                        printed = true;
                    }
                    else
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailError@ " + msg);
                        errors++;
                    }
                }
                else
                {
                    //re.print();
                    count++;
                    printed = true;
                }
                if (printed)
                {
                    entry.SetProcessed(true);
                    entry.Save();
                    DunningLevelConsequences(level, entry);
                }
            }   //	for all dunning letters
            if (errors == 0)
            {
                run.SetProcessed(true);
                run.Save();
            }

            if (_EMailPDF)
            {
                return("@Sent@=" + count + " - @Errors@=" + errors);
            }
            return("@Printed@=" + count);
        }
Beispiel #5
0
        }       //	prepare

        /// <summary>
        /// Perrform Process.
        /// </summary>
        /// <returns>Message</returns>
        protected override String DoIt()
        {
            //	Need to have Template
            if (_EMailPDF && _R_MailText_ID == 0)
            {
                throw new Exception("@NotFound@: @R_MailText_ID@");
            }
            log.Info("C_BPartner_ID=" + _C_BPartner_ID
                     + ", C_Invoice_ID=" + _C_Invoice_ID
                     + ", IsSOTrx=" + _IsSOTrx
                     + ", EmailPDF=" + _EMailPDF + ",R_MailText_ID=" + _R_MailText_ID
                     + ", DateInvoiced=" + _dateInvoiced_From + "-" + _dateInvoiced_To
                     + ", DocumentNo=" + _DocumentNo_From + "-" + _DocumentNo_To
                     + ", IncludeDrafts=" + _IncludeDraftInvoices);

            MMailText mText = null;

            if (_R_MailText_ID != 0)
            {
                mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName());
                if (mText.Get_ID() != _R_MailText_ID)
                {
                    throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID);
                }
            }

            //	Too broad selection
            if (_C_BPartner_ID == 0 && _C_Invoice_ID == 0 && _dateInvoiced_From == null && _dateInvoiced_To == null &&
                _DocumentNo_From == null && _DocumentNo_To == null)
            {
                throw new Exception("@RestrictSelection@");
            }

            MClient client = MClient.Get(GetCtx());

            //	Get Info
            StringBuilder sql = new StringBuilder(
                "SELECT i.C_Invoice_ID,bp.AD_Language,c.IsMultiLingualDocument,"                           //	1..3
                //	Prio: 1. BPartner 2. DocType, 3. PrintFormat (Org)	//	see ReportCtl+MInvoice
                + " COALESCE(bp.Invoice_PrintFormat_ID, dt.AD_PrintFormat_ID, pf.Invoice_PrintFormat_ID)," //	4
                + " dt.DocumentCopies+bp.DocumentCopies,"                                                  //	5
                + " bpc.AD_User_ID, i.DocumentNo,"                                                         //	6..7
                + " bp.C_BPartner_ID "                                                                     //	8
                + "FROM C_Invoice i"
                + " INNER JOIN C_BPartner bp ON (i.C_BPartner_ID=bp.C_BPartner_ID)"
                + " LEFT OUTER JOIN AD_User bpc ON (i.AD_User_ID=bpc.AD_User_ID)"
                + " INNER JOIN AD_Client c ON (i.AD_Client_ID=c.AD_Client_ID)"
                + " INNER JOIN AD_PrintForm pf ON (i.AD_Client_ID=pf.AD_Client_ID)"
                + " INNER JOIN C_DocType dt ON (i.C_DocType_ID=dt.C_DocType_ID)")
                                .Append(" WHERE pf.AD_Org_ID IN (0,i.AD_Org_ID) AND "); //	more them 1 PF

            if (_C_Invoice_ID != 0)
            {
                sql.Append("i.C_Invoice_ID=").Append(_C_Invoice_ID);
            }
            else
            {
                if (_IsSOTrx)
                {
                    sql.Append("i.IsSOTrx='Y'");
                }
                else
                {
                    sql.Append("i.IsSOTrx='N'");
                }

                if (!_IncludeDraftInvoices)
                {
                    sql.Append("AND i.DocStatus NOT IN ('DR')");
                }
                if (_C_BPartner_ID != 0)
                {
                    sql.Append(" AND i.C_BPartner_ID=").Append(_C_BPartner_ID);
                }
                //	Date Invoiced
                if (_dateInvoiced_From != null && _dateInvoiced_To != null)
                {
                    sql.Append(" AND TRUNC(i.DateInvoiced,'DD') BETWEEN ")
                    .Append(DataBase.DB.TO_DATE(_dateInvoiced_From, true)).Append(" AND ")
                    .Append(DataBase.DB.TO_DATE(_dateInvoiced_To, true));
                }
                else if (_dateInvoiced_From != null)
                {
                    sql.Append(" AND TRUNC(i.DateInvoiced,'DD') >= ")
                    .Append(DataBase.DB.TO_DATE(_dateInvoiced_From, true));
                }
                else if (_dateInvoiced_To != null)
                {
                    sql.Append(" AND TRUNC(i.DateInvoiced,'DD') <= ")
                    .Append(DataBase.DB.TO_DATE(_dateInvoiced_To, true));
                }
                //	Document No
                else if (_DocumentNo_From != null && _DocumentNo_To != null)
                {
                    sql.Append(" AND i.DocumentNo BETWEEN ")
                    .Append(DataBase.DB.TO_STRING(_DocumentNo_From)).Append(" AND ")
                    .Append(DataBase.DB.TO_STRING(_DocumentNo_To));
                }
                else if (_DocumentNo_From != null)
                {
                    sql.Append(" AND ");
                    if (_DocumentNo_From.IndexOf('%') == -1)
                    {
                        sql.Append("i.DocumentNo >= ")
                        .Append(DataBase.DB.TO_STRING(_DocumentNo_From));
                    }
                    else
                    {
                        sql.Append("i.DocumentNo LIKE ")
                        .Append(DataBase.DB.TO_STRING(_DocumentNo_From));
                    }
                }
            }
            sql.Append(" ORDER BY i.C_Invoice_ID, pf.AD_Org_ID DESC");          //	more than 1 PF record
            log.Finer(sql.ToString());

            MPrintFormat format = null;
            int          old_AD_PrintFormat_ID = -1;
            int          old_C_Invoice_ID      = -1;
            int          C_BPartner_ID         = 0;
            int          count  = 0;
            int          errors = 0;


            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql.ToString(), null, null);

                while (idr.Read())
                {
                    int C_Invoice_ID = Utility.Util.GetValueOfInt(idr[0]);
                    if (C_Invoice_ID == old_C_Invoice_ID)//Multiple pg Records
                    {
                        continue;
                    }
                    old_C_Invoice_ID = C_Invoice_ID;


                    //	Set Language when enabled
                    //Language language = Language.getLoginLanguage();
                    Language language = Env.GetLoginLanguage(GetCtx());
                    //	Base Language
                    //    String AD_Language = rs.getString(2);
                    String AD_Language = Utility.Util.GetValueOfString(idr[1]);
                    //    if (AD_Language != null && "Y".equals(rs.getString(3)))
                    if (AD_Language != null && "Y".Equals(idr[2]))
                    {
                        //language = Language.getLanguage(AD_Language);
                        language = Language.GetLanguage(AD_Language);
                    }


                    //    int AD_PrintFormat_ID = rs.getInt(4);
                    int AD_PrintFormat_ID = Utility.Util.GetValueOfInt(idr[3]);
                    //    int copies = rs.getInt(5);
                    int copies = Utility.Util.GetValueOfInt(idr[4]);
                    if (copies == 0)
                    {
                        copies = 1;
                    }
                    //    int AD_User_ID = rs.getInt(6);
                    int AD_User_ID = Utility.Util.GetValueOfInt(idr[5]);
                    //    MUser to = new MUser (getCtx(), AD_User_ID, get_TrxName());
                    MUser to = new MUser(GetCtx(), AD_User_ID, Get_TrxName());
                    //    String DocumentNo = rs.getString(7);
                    String DocumentNo = Utility.Util.GetValueOfString(idr[6]);
                    //    C_BPartner_ID = rs.getInt(8);
                    C_BPartner_ID = Utility.Util.GetValueOfInt(idr[7]);
                    //    //
                    //    String documentDir = client.getDocumentDir();
                    String documentDir = client.GetDocumentDir();
                    //    if (documentDir == null || documentDir.length() == 0)
                    if (documentDir == null || documentDir.Length == 0)
                    {
                        documentDir = ".";
                    }

                    if (_EMailPDF && (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0))
                    {
                        AddLog(C_Invoice_ID, null, null, DocumentNo + " @RequestActionEMailNoTo@");
                        errors++;
                        continue;
                    }
                    if (AD_PrintFormat_ID == 0)
                    {
                        AddLog(C_Invoice_ID, null, null, DocumentNo + " No Print Format");
                        errors++;
                        continue;
                    }
                    //	Get Format & Data
                    if (AD_PrintFormat_ID != old_AD_PrintFormat_ID)
                    {
                        format = MPrintFormat.Get(GetCtx(), AD_PrintFormat_ID, false);
                        old_AD_PrintFormat_ID = AD_PrintFormat_ID;
                    }

                    format.SetLanguage(language);
                    format.SetTranslationLanguage(language);
                    //    //	query
                    Query query = new Query("C_Invoice_Header_v");
                    query.AddRestriction("C_Invoice_ID", Query.EQUAL, C_Invoice_ID);

                    //	Engine
                    //PrintInfo info = new PrintInfo(
                    //    DocumentNo,
                    //    X_C_Invoice.Table_ID,
                    //    C_Invoice_ID,
                    //    C_BPartner_ID);
                    //info.SetCopies(copies);
                    //ReportEngine re = new ReportEngine(GetCtx(), format, query, info);

                    Boolean printed = false;
                    if (_EMailPDF)
                    {
                        String subject = mText.GetMailHeader() + " - " + DocumentNo;
                        EMail  email   = client.CreateEMail(to.GetEMail(), to.GetName(), subject, null);
                        if (email == null || !email.IsValid())
                        {
                            AddLog(C_Invoice_ID, null, null,
                                   DocumentNo + " @RequestActionEMailError@ Invalid EMail: " + to);
                            errors++;
                            continue;
                        }
                        mText.SetUser(to);                //	Context
                        mText.SetBPartner(C_BPartner_ID); //	Context
                        mText.SetPO(new MInvoice(GetCtx(), C_Invoice_ID, Get_TrxName()));
                        String message = mText.GetMailText(true);
                        if (mText.IsHtml())
                        {
                            email.SetMessageHTML(subject, message);
                        }
                        else
                        {
                            email.SetSubject(subject);
                            email.SetMessageText(message);
                        }
                        //
                        //File invoice = null;
                        FileInfo invoice = null;
                        if (!Ini.IsClient())
                        {
                            //invoice = new File(MInvoice.GetPDFFileName(documentDir, C_Invoice_ID));
                            invoice = new FileInfo(MInvoice.GetPDFFileName(documentDir, C_Invoice_ID));
                        }
                        //File attachment = re.getPDF(invoice);
                        //FileInfo attachment = re.GetPDF(invoice);

                        // log.Fine(to + " - " + attachment);
                        // email.AddAttachment(attachment);

                        //
                        String    msg = email.Send();
                        MUserMail um  = new MUserMail(mText, GetAD_User_ID(), email);
                        um.Save();
                        if (msg.Equals(EMail.SENT_OK))
                        {
                            AddLog(C_Invoice_ID, null, null,
                                   DocumentNo + " @RequestActionEMailOK@ - " + to.GetEMail());
                            count++;
                            printed = true;
                        }
                        else
                        {
                            AddLog(C_Invoice_ID, null, null,
                                   DocumentNo + " @RequestActionEMailError@ " + msg
                                   + " - " + to.GetEMail());
                            errors++;
                        }
                    }
                    else
                    {
                        // re.Print();
                        count++;
                        printed = true;
                    }
                    //	Print Confirm
                    if (printed)
                    {
                        StringBuilder sb = new StringBuilder("UPDATE C_Invoice "
                                                             + "SET DatePrinted=SysDate, IsPrinted='Y' WHERE C_Invoice_ID=")
                                           .Append(C_Invoice_ID);
                        //int no = DataBase.DB.ExecuteUpdateMultiple(sb.ToString(), Get_TrxName());
                        int no = DataBase.DB.ExecuteQuery(sb.ToString(), null, Get_TrxName());
                    }
                } //	for all entries
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql.ToString(), e);
                //throw new Exception (e);
            }
            finally
            {
                idr.Close();
            }
            //
            if (_EMailPDF)
            {
                return("@Sent@=" + count + " - @Errors@=" + errors);
            }
            return("@Printed@=" + count);
        } //	doIt
Beispiel #6
0
        }       //	sendBPGroup

        /// <summary>
        ///	Send Individual Mail
        /// </summary>
        /// <param name="Name">user name</param>
        /// <param name="AD_User_ID">user</param>
        /// <param name="unsubscribe">unsubscribe message</param>
        /// <returns>true if mail has been sent</returns>
        private Boolean SendIndividualMail(String Name, int AD_User_ID, String unsubscribe)
        {
            //	Prevent two email
            int ii = AD_User_ID;

            if (_list.Contains(ii))
            {
                //return null;
                return(false);
            }
            _list.Add(ii);
            //
            MUser to = new MUser(GetCtx(), AD_User_ID, null);

            if (to.IsEMailBounced())                    //	ignore bounces
            {
                //return null;
                return(false);
            }
            _MailText.SetUser(AD_User_ID);              //	parse context
            String message = _MailText.GetMailText(true);

            //	Unsubscribe
            if (unsubscribe != null)
            {
                message += unsubscribe;
            }
            //
            EMail email = _client.CreateEMail(_from, to, _MailText.GetMailHeader(), message);

            if (email == null)
            {
                //return Boolean.FALSE;
                return(false);
            }
            if (_MailText.IsHtml())
            {
                email.SetMessageHTML(_MailText.GetMailHeader(), message);
            }
            else
            {
                email.SetSubject(_MailText.GetMailHeader());
                email.SetMessageText(message);
            }
            if (!email.IsValid() && !email.IsValid(true))
            {
                log.Warning("NOT VALID - " + email);
                to.SetIsActive(false);
                to.AddDescription("Invalid EMail");
                to.Save();
                //return Boolean.FALSE;
                return(false);
            }
            Boolean OK = EMail.SENT_OK.Equals(email.Send());

            new MUserMail(_MailText, AD_User_ID, email).Save();
            if (OK)
            {
                log.Fine(to.GetEMail());
            }
            else
            {
                log.Warning("FAILURE - " + to.GetEMail());
            }
            AddLog(0, null, null, (OK ? "@OK@" : "@ERROR@") + " - " + to.GetEMail());
            return(OK);
        }