예제 #1
0
        }       //	prepare

        /// <summary>
        /// Perrform process.
        /// </summary>
        /// <returns>Message to be translated</returns>
        protected override String DoIt()
        {
            log.Info("");
            long start = CommonFunctions.CurrentTimeMillis();// System.currentTimeMillis();

            //	Test
            if (_client.GetSmtpHost() == null || _client.GetSmtpHost().Length == 0)
            {
                throw new Exception("No Client SMTP Info");
            }
            if (_client.GetRequestEMail() == null)
            {
                throw new Exception("No Client Request User");
            }

            //	Asset selected
            if (_A_Asset_ID != 0)
            {
                String msg = DeliverIt(_A_Asset_ID);
                AddLog(_A_Asset_ID, null, null, msg);
                return(msg);
            }
            //
            StringBuilder sql = new StringBuilder("SELECT A_Asset_ID, GuaranteeDate "
                                                  + "FROM A_Asset a"
                                                  + " INNER JOIN M_Product p ON (a.M_Product_ID=p.M_Product_ID) "
                                                  + "WHERE ");

            if (_A_Asset_Group_ID != 0 && _A_Asset_Group_ID != -1)
            {
                sql.Append("a.A_Asset_Group_ID=").Append(_A_Asset_Group_ID).Append(" AND ");
            }
            if (_M_Product_ID != 0)
            {
                sql.Append("p.M_Product_ID=").Append(_M_Product_ID).Append(" AND ");
            }
            if (_C_BPartner_ID != 0)
            {
                sql.Append("a.C_BPartner_ID=").Append(_C_BPartner_ID).Append(" AND ");
            }
            String s = sql.ToString();

            if (s.EndsWith(" WHERE "))
            {
                throw new Exception("@RestrictSelection@");
            }
            //	No mail to expired
            if (_NoGuarantee_MailText_ID == 0)
            {
                sql.Append("TRUNC(GuaranteeDate,'DD') >= ").Append(DB.TO_DATE(_GuaranteeDate, true));
                s = sql.ToString();
            }
            //	Clean up
            if (s.EndsWith(" AND "))
            {
                s = sql.ToString().Substring(0, sql.Length - 5);
            }
            //
            int         count     = 0;
            int         errors    = 0;
            int         reminders = 0;
            IDataReader idr       = null;

            try
            {
                idr = DB.ExecuteReader(s);
                while (idr.Read())
                {
                    int      A_Asset_ID    = Util.GetValueOfInt(idr[0]);      // rs.getInt(1);
                    DateTime?GuaranteeDate = Util.GetValueOfDateTime(idr[1]); // rs.getTimestamp(2);

                    //	Guarantee Expired
                    //if (GuaranteeDate.Value != null && GuaranteeDate.before(m_GuaranteeDate))
                    if (GuaranteeDate.Value != null && GuaranteeDate.Value < _GuaranteeDate)
                    {
                        if (_NoGuarantee_MailText_ID != 0)
                        {
                            SendNoGuaranteeMail(A_Asset_ID, _NoGuarantee_MailText_ID, Get_Trx());
                            reminders++;
                        }
                    }
                    else //	Guarantee valid
                    {
                        String msg = DeliverIt(A_Asset_ID);
                        AddLog(A_Asset_ID, null, null, msg);
                        if (msg.StartsWith("** "))
                        {
                            errors++;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, s, e);
            }

            log.Info("Count=" + count + ", Errors=" + errors + ", Reminder=" + reminders
                     + " - " + (CommonFunctions.CurrentTimeMillis() - start) + "ms");
            return("@Sent@=" + count + " - @Errors@=" + errors);
        }       //	doIt