private void EditActualAmount(Sage.Platform.Controls.ExchangeRateTypeEnum exchangeRateType)
    {
        if (DialogService != null)
        {
            IOpportunity entity = BindingSource.Current as IOpportunity;
            if (GetOpportunityStatusMatch(entity, "ClosedWon"))
            {
                DialogService.SetSpecs(200, 200, 400, 600, "OpportunityClosedWon", "", true);
            }
            else if (GetOpportunityStatusMatch(entity, "ClosedLost"))
            {
                DialogService.SetSpecs(200, 200, 400, 600, "OpportunityClosedLost", "", true);
            }
            else
            {
                DialogService.SetSpecs(200, 200, 200, 300, "UpdateSalesPotential", "", true);
            }

            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                string exchangeRateCode = string.Empty;
                double exchangeRate     = 0.0;
                GetExchageRateData(exchangeRateType, out exchangeRateCode, out exchangeRate);
                DialogService.DialogParameters.Clear();
                DialogService.DialogParameters.Add("ExchangeRateType", exchangeRateType);
                DialogService.DialogParameters.Add("ExchangeRateCode", exchangeRateCode);
                DialogService.DialogParameters.Add("ExchangeRate", exchangeRate);
            }
            DialogService.ShowDialog();
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Handles the Init event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Init(object sender, EventArgs e)
    {
        grdProducts.Columns[6].Visible = BusinessRuleHelper.IsMultiCurrencyEnabled();

        _Context = ApplicationContext.Current.Services.Get <IContextService>();
        _State   = _Context.GetContext("AddProductStateInfo") as AddProductStateInfo;
        if (_State == null)
        {
            _State = new AddProductStateInfo();
        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ISalesOrder salesOrder = BindingSource.Current as ISalesOrder;

        if (salesOrder != null)
        {
            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                UpdateMultiCurrencyExchangeRate(salesOrder, salesOrder.ExchangeRate.GetValueOrDefault(1));
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var quote = BindingSource.Current as IQuote;

        if (quote != null)
        {
            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                UpdateMultiCurrencyExchangeRate(quote, quote.ExchangeRate.GetValueOrDefault(1));
            }
        }
    }
    /// <summary>
    /// Called when [form bound].
    /// </summary>
    protected override void OnFormBound()
    {
        if (ClientBindingMgr != null)
        {
            // register these with the ClientBindingMgr so they can do their thing without causing the dirty data warning message...
            ClientBindingMgr.RegisterBoundControl(lnkEmail);
        }
        var salesOrder = BindingSource.Current as ISalesOrder;

        if (salesOrder != null)
        {
            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                lueCurrencyCode.LookupResultValue =
                    EntityFactory.GetRepository <IExchangeRate>()
                    .FindFirstByProperty("CurrencyCode", salesOrder.CurrencyCode);
            }
            lueCurrencyCode.SeedValue = GetPeriodIdForCurrentDate();
            SetDisplayValues();
            double shipping = salesOrder.Freight ?? 0;
            if (string.IsNullOrEmpty(curBaseShipping.FormattedText))
            {
                curBaseShipping.Text = Convert.ToString(shipping);
            }
            if (string.IsNullOrEmpty(curShipping.FormattedText))
            {
                curShipping.Text = Convert.ToString(shipping);
            }
            if (string.IsNullOrEmpty(curMyShipping.FormattedText))
            {
                curMyShipping.Text = Convert.ToString(shipping);
            }
            var systemInfo = ApplicationContext.Current.Services.Get <ISystemOptionsService>(true);
            if (systemInfo.ChangeSalesOrderRate)
            {
                divExchangeRateLabel.Visible = false;
                divExchangeRateText.Visible  = true;
            }
            else
            {
                divExchangeRateLabel.Visible = true;
                divExchangeRateText.Visible  = false;
                if (!string.IsNullOrEmpty(numExchangeRateValue.Text))
                {
                    lblExchangeRateValue.Text = Math.Round(Convert.ToDecimal(numExchangeRateValue.Text), 4).ToString();
                }
            }
        }
    }
 private void EditSalesPotential(Sage.Platform.Controls.ExchangeRateTypeEnum exchangeRateType)
 {
     if (DialogService != null)
     {
         DialogService.SetSpecs(200, 400, "EditSalesPotential");
         if (BusinessRuleHelper.IsMultiCurrencyEnabled())
         {
             string exchangeRateCode = string.Empty;
             double exchangeRate     = 0.0;
             GetExchageRateData(exchangeRateType, out exchangeRateCode, out exchangeRate);
             DialogService.DialogParameters.Clear();
             DialogService.DialogParameters.Add("ExchangeRateType", exchangeRateType);
             DialogService.DialogParameters.Add("ExchangeRateCode", exchangeRateCode);
             DialogService.DialogParameters.Add("ExchangeRate", exchangeRate);
         }
         DialogService.ShowDialog();
     }
 }
    /// <summary>
    /// Called when [form bound].
    /// </summary>
    protected override void OnFormBound()
    {
        if (BusinessRuleHelper.IsMultiCurrencyEnabled())
        {
            var opportunity = BindingSource.Current as IOpportunity;
            if (opportunity != null)
            {
                var       oppState = opportunity as IChangedState;
                ChangeSet changes  = oppState.GetChangedState();
                if (!changes.HasMemberChange("ExchangeRate"))
                {
                    hfExchangeRate.Value = "-1";
                }
                lueCurrencyCode.SeedValue         = GetPeriodIdForCurrentDate();
                lueCurrencyCode.LookupResultValue =
                    EntityFactory.GetRepository <IExchangeRate>()
                    .FindFirstByProperty("CurrencyCode", opportunity.ExchangeRateCode);
                var pendingChanges = opportunity.SyncStatus ==
                                     Saleslogix.Integration.BOE.Common.Constants.SyncStatus.ChangesPending;
                lblSyncState.Visible      = !string.IsNullOrEmpty(opportunity.ErpExtId) && !pendingChanges;
                lblSyncState.Text         = string.Format(GetLocalResourceObject("lblSyncStateNoPendingChanges").ToString(), opportunity.ModifyDate);
                lblPendingChanges.Visible = !string.IsNullOrEmpty(opportunity.ErpExtId) && pendingChanges && !string.IsNullOrEmpty(opportunity.ErpVariationId);
                lblPendingChanges.Text    = string.Format(GetLocalResourceObject("lblSyncStatePendingChanges").ToString(), opportunity.ModifyDate);
            }
        }
        var systemInfo = ApplicationContext.Current.Services.Get <ISystemOptionsService>(true);

        chkLockRate.Enabled = systemInfo.LockOpportunityRate;
        if (systemInfo.ChangeOpportunityRate)
        {
            divExchangeRateLabel.Visible = false;
            divExchangeRateText.Visible  = true;
        }
        else
        {
            divExchangeRateLabel.Visible = true;
            divExchangeRateText.Visible  = false;
            if (!string.IsNullOrEmpty(numExchangeRateValue.Text))
            {
                lblExchangeRateValue.Text = Math.Round(Convert.ToDecimal(numExchangeRateValue.Text), 4).ToString();
            }
        }
    }
 /// <summary>
 /// Sets the controls to be displayed based on whether multi-currency is enabled.
 /// </summary>
 private void SetControlsDisplay(ISalesOrder salesOrder)
 {
     if (BusinessRuleHelper.IsMultiCurrencyEnabled())
     {
         UpdateMultiCurrencyExchangeRate(salesOrder, salesOrder.ExchangeRate.GetValueOrDefault(1));
         tblDetails.Border        = 1;
         tblDetails.Width         = "100%";
         rowDetailsHeader.Visible = true;
         rowSOSubTotal.Visible    = true;
         rowMyCurSubTotal.Visible = true;
         rowSODiscount.Visible    = true;
         rowMyCurDiscount.Visible = true;
         rowSOShipping.Visible    = true;
         rowMyCurShipping.Visible = true;
         rowSOTax.Visible         = true;
         rowMyCurTax.Visible      = true;
         rowSOTotal.Visible       = true;
         rowMyCurTotal.Visible    = true;
         rowSubTotal.Style.Add(HtmlTextWriterStyle.PaddingRight, "0px");
     }
     if (BusinessRuleHelper.IsBOEEnabled(typeof(ISalesOrder)) && !BusinessRuleHelper.IsLocalCRMPricingEnabled("SalesOrder"))
     {
         rowDiscount.Visible      = false;
         rowShipping.Visible      = false;
         rowTax.Visible           = false;
         tblMultiCurrency.Visible = string.IsNullOrEmpty(salesOrder.ErpExtId);
         var pendingChanges = salesOrder.SyncStatus ==
                              Saleslogix.Integration.BOE.Common.Constants.SyncStatus.ChangesPending ||
                              salesOrder.SyncStatus == Saleslogix.Integration.BOE.Common.Constants.SyncStatus.OutOfSync;
         lblSyncState.Visible      = !string.IsNullOrEmpty(salesOrder.ErpExtId) && !pendingChanges;
         lblSyncState.Text         = string.Format(GetLocalResourceObject("lblSyncStateNoPendingChanges").ToString(), salesOrder.ErpLastModifiedDate);
         lblPendingChanges.Visible = !string.IsNullOrEmpty(salesOrder.ErpExtId) && pendingChanges;
         lblPendingChanges.Text    = salesOrder.SyncStatus == Saleslogix.Integration.BOE.Common.Constants.SyncStatus.OutOfSync
             ? GetLocalResourceObject("lblSyncStateError").ToString()
             : string.Format(GetLocalResourceObject("lblSyncStatePendingChanges").ToString(), salesOrder.ErpLastModifiedDate);
     }
 }
Esempio n. 9
0
    /// <summary>
    /// Sets the currency display values for the grid.
    /// </summary>
    private void SetDisplayValues()
    {
        ISalesOrder salesOrder = (ISalesOrder)BindingSource.Current;

        if (salesOrder != null)
        {
            IAppIdMappingService mappingService = ApplicationContext.Current.Services.Get <IAppIdMappingService>(true);
            bool closed = (ReferenceEquals(salesOrder.Status.ToUpper(), GetLocalResourceObject("SalesOrderStatus_Closed")) ||
                           salesOrder.Status.ToUpper() == "Closed" ||
                           ReferenceEquals(salesOrder.Status.ToUpper(), GetLocalResourceObject("SalesOrderStatus_Transmitted")) ||
                           salesOrder.Status.ToUpper() == "Transmitted to Accounting");
            //if this is a Sales Order that synced from the accounting system or the Sales Order has been submitted then we disable it
            bool isOpen = false;
            if (!String.IsNullOrEmpty(salesOrder.ERPSalesOrder.ERPStatus))
            {
                isOpen =
                    (ReferenceEquals(salesOrder.ERPSalesOrder.ERPStatus, GetLocalResourceObject("ERPStatus_Open")) ||
                     salesOrder.ERPSalesOrder.ERPStatus == "Open" ||
                     ReferenceEquals(salesOrder.ERPSalesOrder.ERPStatus, GetLocalResourceObject("ERPStatus_Rejected")) ||
                     salesOrder.ERPSalesOrder.ERPStatus == "Rejected");
            }
            bool erpSalesOrder = (mappingService.IsIntegrationEnabled() && (salesOrder.GlobalSyncId.HasValue && !isOpen));

            if (mappingService.IsIntegrationEnabled())
            {
                lnkEmail.Visible = erpSalesOrder;
            }

            lnkDiscount.Enabled     = !closed && !erpSalesOrder;
            lnkShipping.Enabled     = !closed && !erpSalesOrder;
            lnkTaxRate.Enabled      = !closed && !erpSalesOrder;
            lueCurrencyCode.Enabled = !closed && !erpSalesOrder;

            double subTotal   = salesOrder.OrderTotal ?? 0;
            double taxRate    = salesOrder.Tax ?? 0;
            double tax        = Sage.SalesLogix.SalesOrder.SalesOrder.GetSalesOrderTaxAmount(salesOrder);
            double discount   = salesOrder.Discount ?? 0;
            double grandTotal = Sage.SalesLogix.SalesOrder.SalesOrder.GetSalesOrderGrandTotal(salesOrder);

            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                UpdateMultiCurrencyExchangeRate(salesOrder, salesOrder.ExchangeRate.GetValueOrDefault(1));
                SetControlsDisplay();
            }
            if (!salesOrder.OrderTotal.HasValue)
            {
                foreach (SalesOrderItem item in salesOrder.SalesOrderItems)
                {
                    if (item.Discount != null)
                    {
                        subTotal += item.Price.Value * (int)item.Quantity.Value * (1 - item.Discount.Value);
                    }
                    else
                    {
                        subTotal += item.Price.Value;
                    }
                }
                if (subTotal > 0 && !salesOrder.OrderTotal.Equals(subTotal))
                {
                    salesOrder.OrderTotal = subTotal;
                }
            }
            double discountAmount = subTotal * discount;

            curBaseSubTotal.Text = Convert.ToString(subTotal);
            curTax.Text          = Convert.ToString(tax);
            curMyTax.Text        = Convert.ToString(tax);
            curBaseTax.Text      = Convert.ToString(tax);
            curDiscount.Text     = Convert.ToString(discountAmount);
            curMyDiscount.Text   = Convert.ToString(discountAmount);
            curBaseDiscount.Text = Convert.ToString(discountAmount);
            lnkDiscount.Text     = discount > 0
                                   ? String.Format("{1} ({0:0.00%})", discount,
                                                   GetLocalResourceObject("lnkDiscount.Caption"))
                                   : GetLocalResourceObject("lnkDiscount.Caption").ToString();
            lnkTaxRate.Text = taxRate > 0
                                  ? String.Format("{1} ({0:0.00%})", taxRate, GetLocalResourceObject("lnkTax.Caption"))
                                  : GetLocalResourceObject("lnkTax.Caption").ToString();
            curTotal.FormattedText   = Convert.ToString(grandTotal);
            curMyTotal.FormattedText = Convert.ToString(grandTotal);
            curBaseTotal.Text        = Convert.ToString(grandTotal);
        }
    }
Esempio n. 10
0
    /// <summary>
    /// Formats the email body.
    /// </summary>
    /// <param name="salesOrder">The sales order.</param>
    /// <returns></returns>
    private string FormatEmailBody(ISalesOrder salesOrder)
    {
        IContextService context     = ApplicationContext.Current.Services.Get <IContextService>(true);
        TimeZone        timeZone    = (TimeZone)context.GetContext("TimeZone");
        bool            isMultiCurr = BusinessRuleHelper.IsMultiCurrencyEnabled();
        string          datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

        string products  = String.Empty;
        string emailBody = String.Format("{0} %0A", GetLocalResourceObject("lblEmailInfo.Caption"));

        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailAccount.Caption"),
                                   CheckForNullValue(salesOrder.Account.AccountName));
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailOpportunity.Caption"),
                                   CheckForNullValue(salesOrder.Opportunity != null
                                                         ? salesOrder.Opportunity.Description
                                                         : String.Empty));
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailDateCreated.Caption"),
                                   timeZone.UTCDateTimeToLocalTime((DateTime)salesOrder.CreateDate).ToString(datePattern));
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailDateRequested.Caption"),
                                   salesOrder.OrderDate.HasValue
                                       ? timeZone.UTCDateTimeToLocalTime((DateTime)salesOrder.OrderDate).ToString(
                                       datePattern)
                                       : String.Empty);
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailDatePromised.Caption"),
                                   salesOrder.DatePromised.HasValue
                                       ? timeZone.UTCDateTimeToLocalTime((DateTime)salesOrder.DatePromised).ToString(
                                       datePattern)
                                       : String.Empty);
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailSalesOrderId.Caption"),
                                   salesOrder.SalesOrderNumber);
        emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailType.Caption"),
                                   CheckForNullValue(salesOrder.OrderType));
        emailBody += String.Format("{0} {1} %0A%0A", GetLocalResourceObject("lblEmailStatus.Caption"),
                                   CheckForNullValue(salesOrder.Status));
        emailBody += String.Format("{0} {1} %0A%0A", GetLocalResourceObject("lblEmailComments.Caption"),
                                   CheckForNullValue(salesOrder.Comments));
        emailBody        += String.Format("{0} %0A", GetLocalResourceObject("lblEmailValue.Caption"));
        curBaseTotal.Text = salesOrder.GrandTotal.ToString();
        emailBody        += String.Format("{0} %0A", String.Format(GetLocalResourceObject("lblEmailBaseGrandTotal.Caption").ToString(),
                                                                   curBaseTotal.FormattedText));
        if (isMultiCurr)
        {
            curTotal.CurrentCode = salesOrder.CurrencyCode;
            curTotal.Text        = salesOrder.GrandTotal.ToString();
            emailBody           += String.Format("{0} %0A", String.Format(GetLocalResourceObject("lblEmailSalesOrderGrandTotal.Caption").ToString(),
                                                                          curTotal.FormattedText));
            emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailCurrencyCode.Caption"),
                                       CheckForNullValue(salesOrder.CurrencyCode));
            emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailExchangeRate.Caption"),
                                       CheckForNullValue(salesOrder.ExchangeRate));
            if (salesOrder.ExchangeRateDate.HasValue)
            {
                emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailExchangeRateDate.Caption"),
                                           timeZone.UTCDateTimeToLocalTime((DateTime)salesOrder.ExchangeRateDate).
                                           ToString(datePattern));
            }
            else
            {
                emailBody += String.Format("{0} {1} %0A", GetLocalResourceObject("lblEmailExchangeRateDate.Caption"),
                                           GetLocalResourceObject("lblNone.Caption"));
            }
        }

        emailBody += String.Format("%0A{0} %0A", GetLocalResourceObject("lblEmailProducts.Caption"));
        foreach (ISalesOrderItem item in salesOrder.SalesOrderItems)
        {
            products += String.Format("{0} ({1}); ", item.Product, item.Quantity);
        }
        emailBody += String.Format("{0} %0A", CheckForNullValue(products));
        emailBody += String.Format("%0A{0} %0A", GetLocalResourceObject("lblEmailBillShipAddress.Caption"));
        emailBody += String.Format("{0} %0A", GetLocalResourceObject("lblEmailBillingAddress.Caption"));
        emailBody += String.Format("{0} {1} %0A",
                                   GetLocalResourceObject("lblEmailBillingAddressName.Caption"),
                                   salesOrder.BillingContact == null ? String.Empty : salesOrder.BillingContact.NameLF);
        emailBody += salesOrder.BillingAddress.FormatFullSalesOrderAddress().Replace("\r\n", "%0A");

        emailBody += String.Format("%0A %0A{0} %0A", GetLocalResourceObject("lblEmailShippingAddress.Caption"));
        emailBody += String.Format("{0} {1} %0A",
                                   GetLocalResourceObject("lblEmailShippingAddressName.Caption"),
                                   salesOrder.ShippingContact == null ? String.Empty : salesOrder.ShippingContact.NameLF);
        emailBody += salesOrder.ShippingAddress.FormatFullSalesOrderAddress().Replace("\r\n", "%0A");
        return(PortalUtil.JavaScriptEncode(emailBody.Replace("+", "%20")));
    }
    private void SetMultiCurrencyDisplay()
    {
        IOpportunity opportunity = BindingSource.Current as IOpportunity;

        if (opportunity != null)
        {
            if (BusinessRuleHelper.IsMultiCurrencyEnabled())
            {
                tblDetails.Border = 1;
                tblDetails.Width  = "100%";
                UpdateMultiCurrencyExchangeRate(opportunity, opportunity.ExchangeRate.GetValueOrDefault(1));
                tblMultiCurrency.Visible       = true;
                rowDetailsHeader.Visible       = true;
                colOppSalesPotential.Visible   = true;
                colMyCurSalesPotential.Visible = true;
                colOppActualWon.Visible        = true;
                colMyCurActualWon.Visible      = true;
                colOppPotentialLost.Visible    = true;
                colMyCurPotentialLost.Visible  = true;
                colOppWeighted.Visible         = true;
                colMyCurWeighted.Visible       = true;
                colActualWon.Style.Add(HtmlTextWriterStyle.PaddingRight, "0px");
                colOpenSalesPotential.Style.Add(HtmlTextWriterStyle.PaddingRight, "0px");
                colPotentialLost.Style.Add(HtmlTextWriterStyle.PaddingRight, "0px");
            }
            if (GetOpportunityStatusMatch(opportunity, "ClosedWon"))
            {
                rowActualWon.Visible          = true;
                rowReasonWon.Visible          = true;
                rowCompetitors.Visible        = true;
                rowOpenSalesPotential.Visible = true;
                rowPotentialLost.Visible      = false;
                rowOpenSummary.Visible        = false;
                rowClosedLost.Visible         = false;
                rowReasonLost.Visible         = false;
                rowWeighted.Visible           = false;
                lblDaysOpen.Text = String.Format(GetLocalResourceObject("lblDaysOpen.Caption").ToString(),
                                                 opportunity.DaysOpen);
                lblCompetitors.Text = String.Format(GetLocalResourceObject("lblCompetitorsReplaced.Caption").ToString(),
                                                    GetOpportunityCompetitors());
            }
            else if (GetOpportunityStatusMatch(opportunity, "ClosedLost"))
            {
                rowPotentialLost.Visible      = true;
                rowClosedLost.Visible         = true;
                rowReasonLost.Visible         = true;
                rowCompetitors.Visible        = true;
                rowOpenSalesPotential.Visible = true;
                rowActualWon.Visible          = false;
                rowOpenSummary.Visible        = false;
                rowClosedWon.Visible          = false;
                rowReasonWon.Visible          = false;
                rowWeighted.Visible           = false;
                lblLostDaysOpen.Text          = String.Format(GetLocalResourceObject("lblDaysOpen.Caption").ToString(),
                                                              opportunity.DaysOpen);
                lblCompetitors.Text = String.Format(GetLocalResourceObject("lblCompetitors.Caption").ToString(),
                                                    GetOpportunityCompetitors());
            }
            else
            {
                rowOpenSalesPotential.Visible = true;
                rowOpenSummary.Visible        = true;
                rowWeighted.Visible           = true;
                rowPotentialLost.Visible      = false;
                rowActualWon.Visible          = false;
                rowClosedWon.Visible          = false;
                rowClosedLost.Visible         = false;
                rowReasonWon.Visible          = false;
                rowReasonLost.Visible         = false;
                rowCompetitors.Visible        = false;
                lblSummary.Text = String.Format(GetLocalResourceObject("lblSummary.Caption").ToString(),
                                                opportunity.DaysOpen);
                lblSummaryActivity.Text =
                    String.Format(GetLocalResourceObject("lblSummaryActivity.Caption").ToString(),
                                  opportunity.DaysSinceLastActivity);
            }
            if (ShowSalesProcessInfo(opportunity))
            {
                rowSalesProcess.Visible = true;
                lblSalesProcess.Text    = String.Format(GetLocalResourceObject("lblSalesProcess.Caption").ToString(),
                                                        opportunity.Stage);
            }
            else
            {
                rowSalesProcess.Visible = false;
            }
        }
    }
    /// <summary>
    /// Formats the email body.
    /// </summary>
    /// <param name="quote">The sales order.</param>
    /// <returns></returns>
    private string FormatEmailBody(IQuote quote)
    {
        var    context     = ApplicationContext.Current.Services.Get <IContextService>(true);
        var    timeZone    = (TimeZone)context.GetContext("TimeZone");
        bool   isMultiCurr = BusinessRuleHelper.IsMultiCurrencyEnabled();
        string datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

        string products  = string.Empty;
        string emailBody = string.Format("{0} \r\n", GetLocalResourceObject("lblEmailInfo.Caption"));

        emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailAccount.Caption"),
                                   CheckForNullValue(quote.Account.AccountName));
        emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailOpportunity.Caption"),
                                   CheckForNullValue(quote.Opportunity != null
                ? quote.Opportunity.Description
                : string.Empty));
        emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailDateCreated.Caption"),
                                   timeZone.UTCDateTimeToLocalTime((DateTime)quote.CreateDate).ToString(datePattern));
        emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailQuoteId.Caption"),
                                   quote.QuoteNumber);
        emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailType.Caption"),
                                   CheckForNullValue(quote.Type));
        emailBody += string.Format("{0} {1} \r\n\r\n", GetLocalResourceObject("lblEmailStatus.Caption"),
                                   CheckForNullValue(quote.Status));
        emailBody += string.Format("{0} {1} \r\n\r\n", GetLocalResourceObject("lblEmailComments.Caption"),
                                   CheckForNullValue(quote.Comments));
        emailBody        += string.Format("{0} \r\n", GetLocalResourceObject("lblEmailValue.Caption"));
        curBaseTotal.Text = quote.GrandTotal.ToString();
        emailBody        += string.Format("{0} \r\n",
                                          string.Format(GetLocalResourceObject("lblEmailGrandTotal.Caption").ToString(),
                                                        curBaseTotal.FormattedText));
        if (isMultiCurr)
        {
            curTotal.CurrentCode = quote.CurrencyCode;
            curTotal.Text        = quote.DocGrandTotal.ToString();
            emailBody           += string.Format("{0} \r\n",
                                                 string.Format(GetLocalResourceObject("lblEmailGrandTotal.Caption").ToString(),
                                                               curTotal.FormattedText));
            emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailCurrencyCode.Caption"),
                                       CheckForNullValue(quote.CurrencyCode));
            emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailExchangeRate.Caption"),
                                       CheckForNullValue(quote.ExchangeRate));
            if (quote.ExchangeRateDate.HasValue)
            {
                emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailExchangeRateDate.Caption"),
                                           timeZone.UTCDateTimeToLocalTime((DateTime)quote.ExchangeRateDate).
                                           ToString(datePattern));
            }
            else
            {
                emailBody += string.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailExchangeRateDate.Caption"),
                                           GetLocalResourceObject("lblNone.Caption"));
            }
        }

        emailBody += string.Format("\r\n{0} \r\n", GetLocalResourceObject("lblEmailProducts.Caption"));
        products   = quote.QuoteItems.Aggregate(products,
                                                (current, item) => current + string.Format("{0} ({1}); ", item.Product, item.Quantity));
        emailBody += string.Format("{0} \r\n", CheckForNullValue(products));
        emailBody += string.Format("\r\n{0} \r\n", GetLocalResourceObject("lblEmailBillShipAddress.Caption"));
        emailBody += string.Format("{0} \r\n", GetLocalResourceObject("lblEmailBillingAddress.Caption"));
        emailBody += string.Format("{0} {1} \r\n",
                                   GetLocalResourceObject("lblEmailAddressName.Caption"),
                                   quote.BillingContact == null ? string.Empty : quote.BillingContact.NameLF);
        emailBody += quote.BillingAddress.FormatFullQuoteAddress().Replace("\r\n", "\r\n");

        emailBody += string.Format("\r\n \r\n{0} \r\n", GetLocalResourceObject("lblEmailShippingAddress.Caption"));
        emailBody += string.Format("{0} {1} \r\n",
                                   GetLocalResourceObject("lblEmailAddressName.Caption"),
                                   quote.ShippingContact == null ? string.Empty : quote.ShippingContact.NameLF);
        emailBody += quote.ShippingAddress.FormatFullQuoteAddress().Replace("\r\n", "\r\n");
        return(PortalUtil.JavaScriptEncode(emailBody.Replace("+", "%20")));
    }
    /// <summary>
    /// Formats the email body.
    /// </summary>
    /// <param name="opportunity">The opportunity.</param>
    /// <returns></returns>
    private string FormatEmailBody(IOpportunity opportunity)
    {
        var    context     = ApplicationContext.Current.Services.Get <IContextService>(true);
        var    timeZone    = (TimeZone)context.GetContext("TimeZone");
        string datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

        string oppProducts = String.Empty;
        bool   oppWon      = GetOpportunityStatusMatch(opportunity, "ClosedWon");
        bool   oppLost     = GetOpportunityStatusMatch(opportunity, "ClosedLost");
        string emailBody   = String.Format("{0} \r\n", GetLocalResourceObject("lblEmailInfo.Caption"));

        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailOppDesc.Caption"),
                                   CheckForNullValue(opportunity.Description));
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("lblEmailOppAccount.Caption"),
                                   CheckForNullValue(opportunity.Account != null
                                                         ? opportunity.Account.AccountName
                                                         : String.Empty));
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("EmailOppAcctMgr.Caption"),
                                   CheckForNullValue(opportunity.AccountManager));
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("EmailOppReseller.Caption"),
                                   CheckForNullValue(opportunity.Reseller));
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("EmailOppEstClose.Caption"),
                                   opportunity.EstimatedClose.HasValue
                                       ? timeZone.UTCDateTimeToLocalTime((DateTime)opportunity.EstimatedClose).ToString
                                       (datePattern)
                                       : String.Empty);
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("EmailOppCloseProb.Caption"),
                                   CheckForNullValue(opportunity.CloseProbability));
        emailBody += String.Format("{0} {1} \r\n\r\n", GetLocalResourceObject("EmailOppComments.Caption"),
                                   CheckForNullValue(opportunity.Notes));
        emailBody += String.Format("{0} \r\n", GetLocalResourceObject("EmailOppValue.Caption"));
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject("lblOpenSalesPotential.Caption"),
                                   curOpenBaseSalesPotential.FormattedText);
        emailBody += String.Format("{0} {1} \r\n", GetLocalResourceObject(
                                       (oppWon || oppLost)
                ? "lblPotentialAmount.Caption"
                : "EmailOppWeighted.Caption"),
                                   (oppWon || oppLost)
                ? curBaseActualWon.FormattedText
                : curBaseWeighted.FormattedText);

        if (BusinessRuleHelper.IsMultiCurrencyEnabled())
        {
            emailBody += String.Format("{0} \r\n\r\n",
                                       String.Format(GetLocalResourceObject("EmailOppExchangeRate.Caption").ToString(),
                                                     opportunity.ExchangeRateCode,
                                                     opportunity.ExchangeRate.ToString(),
                                                     curOpenBaseSalesPotential.FormattedText));
        }

        emailBody += String.Format("\r\n {0} \r\n", GetLocalResourceObject("EmailOppSummary.Caption"));
        if (oppWon || oppLost)
        {
            emailBody += String.Format("{0} \r\n",
                                       String.Format(
                                           GetLocalResourceObject("EmailOppWonLostSummary.Caption").ToString(),
                                           dtpClosedWonSummary.Text,
                                           Convert.ToString(opportunity.DaysOpen)));
            emailBody += oppWon
                             ? String.Format("{0} \r\n",
                                             String.Format(
                                                 GetLocalResourceObject("EmailOppReasonWon.Caption").ToString(),
                                                 CheckForNullValue(opportunity.Reason)))
                             : String.Format("{0} \r\n",
                                             String.Format(
                                                 GetLocalResourceObject("EmailOppReasonLost.Caption").ToString(),
                                                 CheckForNullValue(opportunity.Reason)));
        }
        else
        {
            emailBody += String.Format("{0} \r\n",
                                       String.Format(GetLocalResourceObject("EmailOppStageSummary.Caption").ToString(),
                                                     CheckForNullValue(opportunity.Stage)));
        }
        emailBody += String.Format("{0} \r\n\r\n",
                                   String.Format(GetLocalResourceObject("lblEmailOppType.Caption").ToString(),
                                                 CheckForNullValue(opportunity.Type)));

        emailBody += String.Format("{0} \r\n", GetLocalResourceObject("EmailOppProducts.Caption"));

        oppProducts = Enumerable.Aggregate(opportunity.Products, oppProducts,
                                           (current, oppProduct) =>
                                           current +
                                           String.Format("{0} ({1}); ", oppProduct.Product, oppProduct.Quantity));

        if (!string.IsNullOrEmpty(oppProducts))
        {
            emailBody += String.Format("{0} \r\n\r\n", CheckForNullValue(oppProducts.Substring(0, oppProducts.Length - 2)));
        }

        if (oppWon || oppLost)
        {
            emailBody += String.Format("{0} \r\n{1} \r\n\r\n", GetLocalResourceObject("EmailOppCompetitors.Caption"),
                                       GetOpportunityCompetitors());
        }

        emailBody += String.Format("{0} \r\n", GetLocalResourceObject("EmailOppContacts.Caption"));
        emailBody  = Enumerable.Aggregate(opportunity.Contacts, emailBody,
                                          (current, oppContact) =>
                                          current +
                                          String.Format("{0} \r\n",
                                                        String.Format("{0}, {1}; {2}", oppContact.Contact.Name,
                                                                      oppContact.Contact.Title, oppContact.SalesRole)));
        return(HttpUtility.JavaScriptStringEncode(emailBody));
    }