Beispiel #1
0
        public ReturnValue PastDue()
        {
            ReturnValue _result = new ReturnValue();

            #region get TProgram_Email

            TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();
            _result = _tProgram_Email.getEmailTemplate("10DaysPastDue");
            if (_result.Success == false)
            {
                Common.Log("getProgram_InfoList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getProgram_InfoList---OK");
            }


            _tProgram_Email = _result.Object as TProgram_EmailTF;

            #endregion


            #region get Invoices

            TInvoice _ttInvoice = new TInvoice();
            _result = _ttInvoice.getPastDueInvoiceList();
            if (_result.Success == false)
            {
                Common.Log("getPastDueInvoiceList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getPastDueInvoiceList---OK");
            }


            #endregion

            EntityList _list = _result.ObjectList;

            int    _successfulRecord = 0;
            int    _failedRecord     = 0;
            string _errorNotes       = "";

            #region sent email

            foreach (TInvoice _item in _list)
            {
                string _content = System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml);

                TProgram_Email _email = _tProgram_Email.Clone() as TProgram_Email;



                DateTime dt1    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateTime dt3    = new DateTime(_item.DueDate.Year, _item.DueDate.Month, _item.DueDate.Day);
                int      _aging = dt1.Subtract(dt3).Days;

                _content = _content.Replace("[customeraccount]", _item.CustomerAccount)
                           .Replace("[OrderDate]", _item.OrderDate.ToString("MM/dd/yyyy"))
                           .Replace("[aging]", _aging.ToString())
                           .Replace("[invoiceNo]", _item.InvoiceId.ToString())
                           .Replace("[duedate]", _item.DueDate.ToString("MM/dd/yyyy"));

                _email.ToAddress  = _item.Email;
                _email.FullHtml   = _content;
                _email.CCAddress  = _email.CCAddress + ";" + _item.InvoiceEmail;
                _email.BccAddress = _email.BccAddress + ";" + _item.SalesRepEmail;


                #region attached pdf

                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(_item.InvoiceId);
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                string pdffilename = "Invoice/TFInvoice_" + _item.InvoiceId.ToString() + ".pdf";

                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";



                #endregion



                _result = SentEmail(_email, EmailFormat.Html, _item.InvoiceId, fileAttachment);

                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                _item.PastDueEmailOn = System.DateTime.Now;
                _result = _item.Update();
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                _successfulRecord++;
                Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---OK");
            }

            #endregion


            if (_failedRecord != 0)
            {
                Common.SentAlterEmail(_failedRecord, _errorNotes);
            }


            return(_result);
        }
Beispiel #2
0
        public ReturnValue SentInvoiceEmail(int invoiceId)
        {
            ReturnValue _result = new ReturnValue();

            string MailContent = "";

            string _emailTo = "";

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            Model.TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();

            try
            {
                #region generate Email Content

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerByInvoiceId(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;


                _result = _tProgram_Email.getEmailTemplate("ShipInvoices");
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tProgram_Email = _result.Object as Model.TProgram_EmailTF;

                string _mailHtmlContent = System.Web.HttpUtility.HtmlDecode(System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml));


                MailContent = _mailHtmlContent.Replace("[CustomerName]", _tCustomer.FirstName);

                EmailMessage _mail = new EmailMessage();

                _mail.HtmlPart    = new HtmlAttachment(MailContent);
                _mail.FromAddress = new EmailAddress(_tProgram_Email.RespondTo);
                _mail.Subject     = _tProgram_Email.Subject;



                #endregion

                #region setup EmailMessage

                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _emailTo = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tCustomer.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            if (string.IsNullOrEmpty(_item) == false)
                            {
                                _mail.AddToAddress(new EmailAddress(_item));
                            }
                        }
                    }

                    _emailTo = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(_tProgram_Email.BccAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(_tProgram_Email.CCAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(_tCustomer.InvoiceEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.InvoiceEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                #endregion

                #region attached pdf

                string pdffilename = "";


                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }

                pdffilename = "Invoice/TFInvoice_" + invoiceId.ToString() + ".pdf";



                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";

                _mail.AddMixedAttachment(fileAttachment);

                #endregion

                DotNetOpenMail.SmtpAuth.SmtpAuthToken token = new DotNetOpenMail.SmtpAuth.SmtpAuthToken(
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"],
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"]);


                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"]);
                server.SmtpAuthToken = token;

                if (_mail.Send(server) == false)
                {
                    _result.Success = false;
                }
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            #region Log App_Log_Mail
            App_Log_Mail _app_Log_Mail = new App_Log_Mail();
            // _app_Log_Mail.ProgramId = this.Owner.DefaultProgram.ProgramId;
            _app_Log_Mail.IsTest      = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString());
            _app_Log_Mail.CreatedOn   = System.DateTime.Now;
            _app_Log_Mail.AddressFrom = _tProgram_Email.RespondTo;
            _app_Log_Mail.AddressTo   = _emailTo;
            _app_Log_Mail.AddressBcc  = _tProgram_Email.BccAddress;
            _app_Log_Mail.Subject     = _tProgram_Email.Subject;
            _app_Log_Mail.Content     = MailContent;

            _app_Log_Mail.OId     = invoiceId.ToString();
            _app_Log_Mail.Success = _result.Success;
            _app_Log_Mail.Notes   = _result.ErrMessage;
            _app_Log_Mail.Type    = "ShippingInvoice";
            _app_Log_Mail.Save();

            #endregion


            return(_result);
        }
Beispiel #3
0
        public ReturnValue Run(string ownerCode, string action, string oid)
        {
            ReturnValue _result = new ReturnValue();

            #region get Owner List

            Controler Controler = new Controler();
            _result = Controler.getControler();
            if (_result.Success == false)
            {
                Common.ProcessError(_result, true);

                return(_result);
            }

            #endregion

            foreach (Owner owner in Controler.Owners)
            {
                if (ownerCode == "999" || ownerCode == owner.OwnerCode.ToString())
                {
                    #region check and set onwer setting

                    bool enableRun = false;
                    if (owner.Actions.ContainsKey(action.ToUpper()) == true)
                    {
                        enableRun = Convert.ToBoolean(owner.Actions[action.ToUpper()].ToString());
                    }

                    if (enableRun == false)
                    {
                        continue;
                    }

                    Common.OwnerCode  = owner.OwnerCode;
                    WComm.ConInfo.Url = owner.RegSubKey;
                    VCBusiness.BaseOrder Order = Common.CreateObject(owner, "Order") as VCBusiness.BaseOrder;
                    Order.Owner = owner;
                    VCBusiness.BaseProduct Product = Common.CreateObject(owner, "Product") as VCBusiness.BaseProduct;
                    Product.Owner      = owner;
                    Common.ProcessType = action;

                    #endregion

                    #region Run function

                    if (action.ToUpper() == "OrderDownload".ToUpper())
                    {
                        Common.Log("Start OrderDownload");
                        _result = Order.Download();
                    }

                    if (action.ToUpper() == "UpdateShipment".ToUpper())
                    {
                        Common.Log("Start Update Shipment");
                        _result = Order.UpdateShipment();
                    }

                    if (action.ToUpper() == "ProductDownload".ToUpper())
                    {
                        Common.Log("Start Product Download");
                        _result = Product.ProductDownload();
                    }

                    if (action.ToUpper() == "UpdateInventoryStatus".ToUpper())
                    {
                        Common.Log("Start UpdateInventoryStatus");
                        _result = Product.UpdateInventoryStatus();
                    }

                    if (action.ToUpper() == "ShipConfirmEmail".ToUpper())
                    {
                        #region ShipConfirmEmail

                        Common.Log("Start ShipConfirmEmail");

                        VCBusiness.Model.TProgram_Email _tProgram_Email = Common.CreateObject(owner, "TProgram_Email") as VCBusiness.Model.TProgram_Email;
                        _result = _tProgram_Email.getEmailTemplate("SHIP_CONFIRMATION");
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        _tProgram_Email = _result.Object as TProgram_Email;


                        VCBusiness.EmailFactory EmailFactory = Common.CreateObject(owner, "EmailFactory") as VCBusiness.EmailFactory;
                        _result = EmailFactory.GetMailContent(int.Parse(oid), 1, _tProgram_Email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }
                        EmailMessage email = _result.ObjectValue as EmailMessage;

                        _result = EmailFactory.SentEmail(int.Parse(oid), 1, email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        #endregion
                    }



                    if (action.ToUpper() == "ImportDMOrderDetail".ToUpper())
                    {
                        _result = Order.ImportDMOrderDetail(int.Parse(oid));
                    }

                    if (action.ToUpper() == "GenerateInvoicePDF".ToUpper())
                    {
                        VCBusiness.TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                        _result = TecnifibreInvoicePDF.PrintInvoice(int.Parse(oid));
                    }

                    if (action.ToUpper() == "InvoiceEmail".ToUpper())
                    {
                        VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();
                        _result = EmailFactory.ReSentInvoiceEmail();
                    }

                    #region Tecnifibre

                    Tecnifibre Tecnifibre = new Tecnifibre();

                    if (action.ToUpper() == "TFDueInvoices".ToUpper())
                    {
                        Common.Log("Start TFDueInvoices");
                        _result = Tecnifibre.DueInvoices();
                    }

                    if (action.ToUpper() == "TFPastDue".ToUpper())
                    {
                        Common.Log("Start TFPastDue");
                        _result = Tecnifibre.PastDue();
                    }

                    if (action.ToUpper() == "TFCancelOrder".ToUpper())
                    {
                        Common.Log("Start TFCancelOrder");
                        _result = Tecnifibre.CancelHDOrder();
                    }

                    if (action.ToUpper() == "TFWishList".ToUpper())
                    {
                        Common.Log("Start TFWishList");
                        _result = Tecnifibre.WishList();
                    }


                    #endregion


                    #endregion

                    if (_result.Success == false)
                    {
                        Common.ProcessError(_result, false);
                    }

                    Common.Log("Finish");
                }
            }

            return(_result);
        }