示例#1
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();


            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getCustomerInfo
            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            if (_tOrder.SourceId == 19)
            {
                _result.Code = 19;
                return(_result);
            }


            TCustomer _tCustomer = new TCustomer();
            _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tCustomer = _result.Object as TCustomer;



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(_tOrder.OrderId, releaseID);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _list = _result.ObjectList;

            if (_list.Count == 0)
            {
                return(_result);
            }

            _tOrder_Line_Item = _list[0] as TOrder_Line_Item;

            TShipMethod _tShipMethod = new TShipMethod();
            _result = _tShipMethod.getShipMethodById(_tOrder_Line_Item.ShipMethodId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipMethod = _result.Object as TShipMethod;


            TAddress _tBillAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.CustomerAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tBillAddress = _result.Object as TAddress;



            TAddress _tShipAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipAddress = _result.Object as TAddress;


            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getPaymentArrangementList(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _paymentList = _result.ObjectList;


            double _paymentApplied     = 0;
            double _estimatedAmountDue = 0;

            foreach (TPaymentArrangement _item in _paymentList)
            {
                if (_item.PayMethodId == 4)
                {
                    _estimatedAmountDue += _item.Amount;
                }
                else
                {
                    _paymentApplied += _item.Amount;
                }
            }



            #endregion


            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                #region filter the email content
                MailContent = MailContent.Replace("[CustomerName]", _tCustomer.FirstName == null ? "" : _tCustomer.FirstName.ToString());
                MailContent = MailContent.Replace("[OrderDate]", _tOrder.OrderDate.ToString("MM/dd/yyyy"));

                string siteURL = "http://admin.tecnifibreusa.com/";
                MailContent = MailContent.Replace("[WebSite]", siteURL);
                MailContent = MailContent.Replace("[OrderNumber]", _tOrder.AltOrderNum);
                MailContent = MailContent.Replace("[PONumber]", _tOrder.PONumber);
                MailContent = MailContent.Replace("[CustomerAcct]", _tCustomer.AltCustNum);
                MailContent = MailContent.Replace("[ShipMethod]", _tShipMethod.Description);

                MailContent = MailContent.Replace("[BillingAddress]", _tBillAddress.Company + "<br> " + _tBillAddress.Address1 + " " + _tBillAddress.Address2 + "<br>" + _tBillAddress.City + ", " + _tBillAddress.StateCode + " " + _tBillAddress.PostalCode);
                MailContent = MailContent.Replace("[ShippingAddress]", _tShipAddress.Company + "<br> " + _tShipAddress.Address1 + " " + _tShipAddress.Address2 + "<br>" + _tShipAddress.City + ", " + _tShipAddress.StateCode + " " + _tShipAddress.PostalCode);

                MailContent = MailContent.Replace("[SubTotal]", (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Tax]", "(" + Utilities.Round(_tOrder.TaxRate * 100, 2).ToString() + "%)" + (_tOrder.TotalTax - _tOrder.CompTax).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Shipping]", (_tOrder.TotalShipping - _tOrder.CompShipingCost).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Discount]", (_tOrder.TotalDiscountAmount + _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[OrderTotal]", _tOrder.TotalOrderAmount.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[PaymentApplied]", _paymentApplied.ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[EstimatedAmountDue]", _estimatedAmountDue.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[BFirstName]", _tBillAddress.FirstName);
                MailContent = MailContent.Replace("[BLastName]", _tBillAddress.LastName);
                MailContent = MailContent.Replace("[SFirstName]", _tShipAddress.FirstName);
                MailContent = MailContent.Replace("[SLastName]", _tShipAddress.LastName);


                StringBuilder OrderItemHTML = new StringBuilder();

                foreach (TOrder_Line_Item _item in _list)
                {
                    OrderItemHTML.Append("<tr>");
                    OrderItemHTML.Append("  <td>" + _item.LineNum + "</td>");
                    OrderItemHTML.Append("<td>" + _item.PartNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.ProductName + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Quantity + "</td>");
                    if (_item.ShippedDate != null)
                    {
                        OrderItemHTML.Append("<td>" + _item.ShippedDate.Value.ToString("MM/dd/yyyy") + "</td>");
                    }
                    else
                    {
                        OrderItemHTML.Append("<td></td>");
                    }
                    OrderItemHTML.Append("<td>" + _item.TrackingNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Price.ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.DiscountAmount + _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + ((_item.ActualPrice - _item.ComAmount) / _item.Quantity).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.ActualPrice - _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("</tr>");
                }
                #endregion


                MailContent = MailContent.Replace("[Items]", OrderItemHTML.ToString());


                _mail.HtmlPart = new HtmlAttachment(MailContent);


                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        _mail.AddToAddress(new EmailAddress(_tCustomer.Email));
                    }

                    _result.Table = _tCustomer.Email;
                }


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


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

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


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            return(_result);
        }
示例#2
0
        protected override ReturnValue customerEventPostShipmentUpdate(TOrder order, EntityList orderline, Transaction tran)
        {
            ReturnValue _result = new ReturnValue();

            #region Invoice

            #region get order

            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            #endregion

            #region search invoice

            TInvoice _tInvoice = new TInvoice();
            _result = _tInvoice.getInvoice(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tInvoice = _result.Object as TInvoice;

            #endregion

            if (_tInvoice.InvoiceId == 0)
            {
                #region Create new invoice

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;

                TPaymentTerms _tPaymentTerms = new TPaymentTerms();
                _result = _tPaymentTerms.getPaymentTermsById(_tCustomer.PaymentTermsId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tPaymentTerms = _result.Object as TPaymentTerms;

                TUser _tUser = new TUser();
                _result = _tUser.getUserById(_tCustomer.SalesRepId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tUser = _result.Object as TUser;

                _tInvoice.InvoiceDate = System.DateTime.Now;
                _tInvoice.ShippedDate = order.ShippedDate.Value;
                _tInvoice.CreatedOn   = System.DateTime.Now;
                _tInvoice.OrderId     = order.OrderId;
                //_tInvoice.SessionId = _sessionId;
                _tInvoice.PONum         = _tOrder.PONumber;
                _tInvoice.CustomerId    = _tOrder.PWPCustomerId;
                _tInvoice.AltInvoiceNum = order.OrderId.ToString();

                _tInvoice.SalesRep = _tCustomer.SalesRepId;
                _tInvoice.Terms    = _tCustomer.PaymentTermsId;

                _tInvoice.TermsName    = _tPaymentTerms.Description;
                _tInvoice.SalesRepName = _tUser.SaleRepInitials;

                _tInvoice.DueDate       = System.DateTime.Now.AddDays(_tPaymentTerms.NetDueInDays);
                _tInvoice.PaymentStatus = "PEND";

                _result = _tInvoice.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                //_tInvoice.AltInvoiceNum = _orderId.ToString();
                _tInvoice.InvoiceId = _result.IdentityId;
                _tInvoice.QBRef     = _tInvoice.InvoiceId.ToString();
                _result             = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }


                //_invoiceList.Add(_tInvoice);

                #endregion
            }

            #region invoice line

            foreach (TOrder_Line_Item item in orderline)
            {
                _result = item.getOrderLineByOrderPartNumber(order.OrderId, item.PartNumber, item.Quantity, tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                TOrder_Line_Item _tOrder_Line_Item = _result.Object as TOrder_Line_Item;

                if (_tOrder_Line_Item.ShippedDate == null || _tOrder_Line_Item.Quantity == 0 || item.Quantity == 0)
                {
                    continue;
                }

                TInvoice_Line_Item _tInvoice_Line_Item = new TInvoice_Line_Item();
                _tInvoice_Line_Item.InvoiceId        = _tInvoice.InvoiceId;
                _tInvoice_Line_Item.LineNum          = _tOrder_Line_Item.LineNum;
                _tInvoice_Line_Item.ProgramProductId = _tOrder_Line_Item.ProgramProductId;
                _tInvoice_Line_Item.ProductName      = _tOrder_Line_Item.ProductName;
                _tInvoice_Line_Item.PartNumber       = _tOrder_Line_Item.PartNumber;
                _tInvoice_Line_Item.Quantity         = item.Quantity;
                _tInvoice_Line_Item.ShippedDate      = _tOrder_Line_Item.ShippedDate.Value;
                _tInvoice_Line_Item.TrackingNumber   = _tOrder_Line_Item.TrackingNumber;
                _tInvoice_Line_Item.ReleaseNumber    = _tOrder_Line_Item.ReleaseNumber.Value;

                _tInvoice_Line_Item.OrderLineItemId = _tOrder_Line_Item.OrderLineItemId;
                _tInvoice_Line_Item.Amount          = (_tOrder_Line_Item.ActualPrice - _tOrder_Line_Item.ComAmount) * (item.Quantity / _tOrder_Line_Item.Quantity);
                _tInvoice_Line_Item.Price           = _tInvoice_Line_Item.Amount / item.Quantity;
                _result = _tInvoice_Line_Item.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region update paid amount & invocie status

            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getTFOrderPaymentArrangementList(order.OrderId);
            if (_result.Success == false)
            {
                return(_result);
            }
            EntityList _payList = _result.ObjectList;


            double _paiedAmount = 0.00;

            bool _noPT = true;

            foreach (TPaymentArrangement _pItem in _payList)
            {
                if (_pItem.PayMethodId != 4)
                {
                    _paiedAmount += _pItem.Amount;
                }
                else
                {
                    _noPT = false;
                }
            }


            TInvoice_Line_Item _Invoice_Line_Item = new TInvoice_Line_Item();
            _result = _Invoice_Line_Item.getTotalInvoiceLineItemByInvoiceId(_tInvoice.InvoiceId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _Invoice_Line_Item = _result.Object as TInvoice_Line_Item;

            if ((_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount) != 0)
            {
                Double _productAmountRate = _Invoice_Line_Item.Amount / (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount);

                _tInvoice.Subtotal      = WComm.Utilities.Round(_Invoice_Line_Item.Amount, 2);
                _tInvoice.Shipping      = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalShipping - _tOrder.CompShipingCost), 2);
                _tInvoice.Tax           = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalTax - _tOrder.CompTax), 2);
                _tInvoice.InvoiceAmount = WComm.Utilities.Round(_tInvoice.Subtotal + _tInvoice.Shipping + _tInvoice.Tax, 2);
                _tInvoice.PaiedAmount   = WComm.Utilities.Round(_paiedAmount * _productAmountRate, 2);
                _tInvoice.BalanceDue    = WComm.Utilities.Round(_tInvoice.InvoiceAmount - _tInvoice.PaiedAmount, 2);
                if (_noPT == true)
                {
                    _tInvoice.PaymentStatus = "PAID";
                    _tInvoice.BalanceDue    = 0;
                    _tInvoice.PaiedAmount   = _tInvoice.InvoiceAmount;
                }
                _result = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region sent invoice email

            VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();

            _result = EmailFactory.SentInvoiceEmail(_tInvoice.InvoiceId);
            if (_result.Success == false)
            {
                return(_result);
            }


            _tInvoice.EmailSentOn = System.DateTime.Now;
            _result = _tInvoice.Update(tran);
            if (_result.Success == false)
            {
                return(_result);
            }

            #endregion


            #endregion

            return(_result);
        }