/// <summary>
        /// SEND REPORT IN DAY
        /// </summary>
        /// <param name="TargetName"></param>
        internal void SendReportDay(string TargetName, Business.TimeEvent timeEvent)
        {
            return;

            string total = string.Empty;
            Business.Market.LogContentSendMail = string.Empty;

            #region GET END OF DAY
            DateTime timeCurrent = DateTime.Now;
            DateTime timeEndDay = new DateTime();
            DateTime timeStartDay = new DateTime();
            bool IsReportWeekends = false;
            string pathStatements = string.Empty;
            string serverName = string.Empty;

            #region GET MARKET CONFIG
            if (Business.Market.MarketConfig != null)
            {
                int count = Business.Market.MarketConfig.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.MarketConfig[i].Code == "C02")
                    {
                        serverName = Business.Market.MarketConfig[i].StringValue;
                    }

                    if (Business.Market.MarketConfig[i].Code == "C26")
                    {
                        if (Business.Market.MarketConfig[i].BoolValue == 1)
                            IsReportWeekends = true;
                    }

                    if (Business.Market.MarketConfig[i].Code == "C35")
                    {
                        pathStatements = Business.Market.MarketConfig[i].StringValue;
                    }
                }
            }
            #endregion   
         
            if (string.IsNullOrEmpty(pathStatements))
                pathStatements = Environment.CurrentDirectory + DateTime.Now.Ticks + "_" + serverName;

            if (DateTime.Now.Hour < 10)
                timeCurrent = timeCurrent.AddDays(-1);

            timeStartDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day , 00, 00, 00);
            timeEndDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day, 23, 59, 59);            
            #endregion

            #region CHECK Generate statements at weekends
            if (timeStartDay.DayOfWeek == DayOfWeek.Saturday || timeStartDay.DayOfWeek == DayOfWeek.Sunday)
            {
                if (!IsReportWeekends)
                    return;
            }
            #endregion
                        
            //CLEAR LIST END OF DAY AGENT
            Business.Market.ListEODAgent.Clear();

            #region SEND MAIL TO INVESTOR
            if (Business.Market.InvestorList != null && Business.Market.InvestorList.Count > 0)
            {   
                int count = Business.Market.InvestorList.Count;
                for (int i = 0; i < count; i++)
                {
                    List<Business.OpenTrade> listOpenTrade = new List<OpenTrade>();
                    List<Business.OpenTrade> listPendingOrder = new List<OpenTrade>();
                    List<Business.OpenTrade> listCommandHistory = new List<OpenTrade>();

                    #region GET ONLINE COMMAND OF INVESTOR
                    if (Business.Market.InvestorList[i].CommandList != null)
                    {
                        int countCommand = Business.Market.InvestorList[i].CommandList.Count;
                        for (int j = 0; j < countCommand; j++)
                        {
                            bool isPending = TradingServer.Model.TradingCalculate.Instance.CheckIsPendingPosition(Business.Market.InvestorList[i].CommandList[j].Type.ID);
                            if (!isPending)
                            {
                                double tempProfit = Math.Round(Business.Market.InvestorList[i].CommandList[j].Profit, 2);
                                Business.Market.InvestorList[i].CommandList[j].Profit = tempProfit;
                                listOpenTrade.Add(Business.Market.InvestorList[i].CommandList[j]);
                            }
                            else
                            {
                                double tempProfit = Math.Round(Business.Market.InvestorList[i].CommandList[j].Profit, 2);
                                Business.Market.InvestorList[i].CommandList[j].Profit = tempProfit;
                                listPendingOrder.Add(Business.Market.InvestorList[i].CommandList[j]);
                            }
                        }
                    }
                    #endregion

                    #region GET COMMAND HISTORY OF INVESTOR
                    listCommandHistory = TradingServer.Facade.FacadeGetCommandHistoryWithTime(Business.Market.InvestorList[i].InvestorID, timeStartDay, timeEndDay);
                    #endregion

                    #region DATA > 0
                    if (listOpenTrade != null && listOpenTrade.Count > 0 ||
                      listPendingOrder != null && listPendingOrder.Count > 0 ||
                      listCommandHistory != null && listCommandHistory.Count > 0)
                    {
                        Model.MailConfig newMailConfig = new Model.MailConfig();
                        newMailConfig = this.GetMailConfig(Business.Market.InvestorList[i]);

                        double tempBalance = Business.Market.InvestorList[i].PreviousLedgerBalance;

                        StringBuilder content = new StringBuilder();
                        Business.ReportItem contentOpenPosition = new ReportItem();
                        Business.ReportItem contentClosePosition = new ReportItem();
                        StringBuilder contentPendingPosition = new StringBuilder();

                        Business.StatementTemplate newTemplate = new StatementTemplate();

                        content = newTemplate.GetStatementReport(listOpenTrade, listCommandHistory, listPendingOrder, Business.Market.InvestorList[i], timeEndDay);
                        content.Replace("[ReportDay]", timeEndDay.ToShortDateString());

                        string tempContent = content.ToString();

                        #region CHECK SCALPER INVESTOR
                        bool isScalper = this.CheckScalperInvestor(listCommandHistory);
                        #endregion

                        if (Business.Market.InvestorList[i].SendReport)
                        {
                            #region GET MAIL CONFIG AND SEND REPORT
                            if (newMailConfig != null)
                            {
                                if (newMailConfig.isEnable)
                                {
                                    if (!string.IsNullOrEmpty(newMailConfig.SmtpHost) && !string.IsNullOrEmpty(newMailConfig.MessageFrom) &&
                                        !string.IsNullOrEmpty(newMailConfig.PasswordCredential))
                                    {
                                        if (!string.IsNullOrEmpty(Business.Market.InvestorList[i].Email))
                                        {
                                            content = content.Replace("[ScalperName]", "");
                                            content = content.Replace("[Scalper]", "");

                                            if (timeStartDay.DayOfWeek == DayOfWeek.Sunday || timeStartDay.DayOfWeek == DayOfWeek.Saturday)
                                            {
                                                if (IsReportWeekends)
                                                {
                                                    Model.TradingCalculate.Instance.SendMailAsync(Business.Market.InvestorList[i].Email, "Daily Confirmation", content.ToString(), newMailConfig);
                                                }
                                            }
                                            else
                                            {
                                                Model.TradingCalculate.Instance.SendMailAsync(Business.Market.InvestorList[i].Email, "Daily Confirmation", content.ToString(), newMailConfig);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }

                        if (!string.IsNullOrEmpty(pathStatements) && pathStatements != "NaN")
                        {   
                            //STREAM FILE SAVE CONTENT SEND MAIL REPORT
                            TradingServer.Model.TradingCalculate.Instance.StreamFile(tempContent.ToString(), Business.Market.InvestorList[i].Code, timeStartDay, 0, pathStatements, isScalper);
                        }

                        if (!string.IsNullOrEmpty(content.ToString()))
                        {
                            Business.Statement newStatement = new Statement();
                            newStatement.InvestorCode = Business.Market.InvestorList[i].Code;
                            newStatement.StatementType = 1;
                            newStatement.TimeStatement = timeStartDay;
                            newStatement.Email = Business.Market.InvestorList[i].Email;
                            newStatement.Content = tempContent.ToString();

                            Business.Market.ListStatement.Add(newStatement);
                        }
                    }
                    #endregion

                    #region UPDATE PREVIOUS LEDGER BALANCE
                    TradingServer.Facade.FacadeUpdatePreviousLedgerBalance(Business.Market.InvestorList[i].InvestorID, Business.Market.InvestorList[i].PreviousLedgerBalance);
                    #endregion  
             
                    #region PROCESS LAST ACCOUNT
                    Business.SumLastAccount newSumLastAccount = new SumLastAccount();
                    newSumLastAccount.InvestorAccount = Business.Market.InvestorList[i];
                    newSumLastAccount.ListHistory = listCommandHistory;

                    if (newSumLastAccount.ListOpenTrade == null)
                        newSumLastAccount.ListOpenTrade = new List<OpenTrade>();
                     
                    if (listOpenTrade != null)
                    {
                        int countOpenTrade = listOpenTrade.Count;
                        for (int j = 0; j < countOpenTrade; j++)
                        {
                            Business.OpenTrade newOpenTrade = new OpenTrade();
                            newOpenTrade.AgentCommission = listOpenTrade[j].AgentCommission;
                            newOpenTrade.ClientCode = listOpenTrade[j].ClientCode;
                            newOpenTrade.ClosePrice = listOpenTrade[j].ClosePrice;
                            newOpenTrade.CloseTime = listOpenTrade[j].CloseTime;
                            newOpenTrade.CommandCode = listOpenTrade[j].CommandCode;
                            newOpenTrade.Comment = listOpenTrade[j].Comment;
                            newOpenTrade.Commission = listOpenTrade[j].Commission;
                            newOpenTrade.ExpTime = listOpenTrade[j].ExpTime;
                            newOpenTrade.FreezeMargin = listOpenTrade[j].FreezeMargin;
                            newOpenTrade.ID = listOpenTrade[j].ID;
                            newOpenTrade.IGroupSecurity = listOpenTrade[j].IGroupSecurity;
                            newOpenTrade.Investor = listOpenTrade[j].Investor;
                            newOpenTrade.IsClose = listOpenTrade[j].IsClose;
                            newOpenTrade.IsHedged = listOpenTrade[j].IsHedged;
                            newOpenTrade.Margin = listOpenTrade[j].Margin;
                            newOpenTrade.MaxDev = listOpenTrade[j].MaxDev;
                            newOpenTrade.NumberUpdate = listOpenTrade[j].NumberUpdate;
                            newOpenTrade.OpenPrice = listOpenTrade[j].OpenPrice;
                            newOpenTrade.OpenTime = listOpenTrade[j].OpenTime;

                            double tempProfit = listOpenTrade[j].Profit;
                            newOpenTrade.Profit = tempProfit;

                            newOpenTrade.Size = listOpenTrade[j].Size;
                            newOpenTrade.SpreaDifferenceInOpenTrade = listOpenTrade[j].SpreaDifferenceInOpenTrade;
                            newOpenTrade.StopLoss = listOpenTrade[j].StopLoss;
                            newOpenTrade.Swap = listOpenTrade[j].Swap;
                            newOpenTrade.Symbol = listOpenTrade[j].Symbol;
                            newOpenTrade.TakeProfit = listOpenTrade[j].TakeProfit;
                            newOpenTrade.Taxes = listOpenTrade[j].Taxes;
                            newOpenTrade.TotalSwap = listOpenTrade[j].TotalSwap;
                            newOpenTrade.Type = listOpenTrade[j].Type;

                            newSumLastAccount.ListOpenTrade.Add(newOpenTrade);
                        }
                    }
                    
                    newSumLastAccount.TimeEndDay = timeEndDay;

                    Business.Market.ListLastAccount.Add(newSumLastAccount);
                    #endregion
                }
            }
            #endregion

            #region SAVE FILE TO HARD DRIVE
            if (!string.IsNullOrEmpty(pathStatements) && pathStatements != "NaN")
            {
                TradingServer.Model.TradingCalculate.Instance.StreamFile(Business.Market.LogContentSendMail, "", timeStartDay, 1, pathStatements);
                string folder = timeStartDay.Year.ToString() + timeStartDay.Month.ToString() + timeStartDay.Day.ToString();
                TradingServer.Model.TradingCalculate.Instance.ZipFolder(pathStatements + @"\" + folder, folder + ".zip", pathStatements + @"\" + folder + ".zip");
            }
            #endregion
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listClosePosition"></param>
        /// <returns></returns>
        public Business.ReportItem RendClosePosition(List<Business.OpenTrade> listClosePosition)
        {
            Business.ReportItem reportData = new ReportItem();

            StringBuilder result = new StringBuilder();
            double commission = 0;
            double swap = 0;
            double totalProfit = 0;
            double realizedPL = 0;
            double deposit = 0;
            double withdrawal = 0;
            double creditIn = 0;
            double creditOut = 0;

            if (listClosePosition != null && listClosePosition.Count > 0)
            {
                int count = listClosePosition.Count;
                for (int i = 0; i < count; i++)
                {
                    if (listClosePosition[i].Type.ID == 21)
                        continue;

                    result.Append("<tr>");
                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" + "#" + listClosePosition[i].CommandCode + "</td>");
                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        listClosePosition[i].OpenTime.ToString("MM/dd/yyyy HH:mm:ss") + "</td>");

                    if (listClosePosition[i].Type.ID == 13 || listClosePosition[i].Type.ID == 14 || listClosePosition[i].Type.ID == 15 || listClosePosition[i].Type.ID == 16)
                    {
                        if (listClosePosition[i].Type.ID == 13)
                            deposit += listClosePosition[i].Profit;

                        if (listClosePosition[i].Type.ID == 14)
                            withdrawal += listClosePosition[i].Profit;

                        if (listClosePosition[i].Type.ID == 15)
                            creditIn += listClosePosition[i].Profit;

                        if (listClosePosition[i].Type.ID == 16)
                            creditOut += listClosePosition[i].Profit;

                        #region REND TEMPLATE DEPOSIT
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Facade.FacadeConvertTypeIDToName(listClosePosition[i].Type.ID) + "</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'></td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>0.00</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>0.00</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:right;background-color:#EEEEEE;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].Profit, 2).ToString(), 2) + "</td>");
                        result.Append("</tr>");
                        #endregion
                    }
                    else
                    {
                        #region REND CLOSE POSITION
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" + listClosePosition[i].Symbol.Name + "</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listClosePosition[i].Size.ToString(), 2) + "</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Facade.FacadeConvertTypeIDToName(listClosePosition[i].Type.ID) + "</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].OpenPrice, listClosePosition[i].Symbol.Digit).ToString(),
                            listClosePosition[i].Symbol.Digit) + "</td>");

                        if (listClosePosition[i].TakeProfit > 0)
                            result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                                TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].TakeProfit, listClosePosition[i].Symbol.Digit).ToString(),
                                listClosePosition[i].Symbol.Digit) + "</td>");
                        else
                            result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");

                        if (listClosePosition[i].StopLoss > 0)
                            result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                                TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].StopLoss, listClosePosition[i].Symbol.Digit).ToString(),
                                listClosePosition[i].Symbol.Digit) + "</td>");
                        else
                            result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");

                        //ADD NEW COLUMN PIP
                        double spread = listClosePosition[i].ClosePrice - listClosePosition[i].OpenPrice;

                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(spread, listClosePosition[i].Symbol.Digit).ToString(), listClosePosition[i].Symbol.Digit) + "</td>");

                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].ClosePrice, listClosePosition[i].Symbol.Digit).ToString(),
                            listClosePosition[i].Symbol.Digit) + "</td>");
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            listClosePosition[i].CloseTime.ToString("MM/dd/yyyy HH:mm:ss") + "</td>");

                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].Swap, 2).ToString(), 2) + "</td>");

                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].Commission, 2).ToString(), 2) + "</td>");

                        result.Append("<td style='border-bottom:1px solid Gray;text-align:right;background-color:#EEEEEE;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listClosePosition[i].Profit, 2).ToString(), 2) + "</td>");
                        result.Append("</tr>");

                        commission += listClosePosition[i].Commission;
                        swap += listClosePosition[i].Swap;
                        totalProfit += listClosePosition[i].Profit;
                        #endregion
                    }
                }

                realizedPL = Math.Round(totalProfit + commission + swap, 2);
                //realizedPL = Math.Round(totalProfit + commission, 2);

                result.Append("<tr style='text-align:center;background-color:#EEEEEE;font-family:Arial;'>");
                result.Append("<td colspan='11'>&nbsp;</td>");
                result.Append("<td>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(swap, 2).ToString(), 2) + "</td>");
                result.Append("<td>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(commission, 2).ToString(), 2) + "</td>");
                result.Append("<td align='right'>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(totalProfit, 2).ToString(), 2) + "</td>");
                result.Append("</tr>");
                result.Append("<tr>");
                result.Append("<td colspan='14'>");
                result.Append("<table cellspacing='0' cellpadding='3' align='right' style='width:30%;background-color:#DBDBDB'>");
                result.Append("<tr>");
                result.Append("<td><strong>Realized P&amp;L:</strong></td>");
                result.Append("<td align='right'><strong>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(realizedPL.ToString(), 2) + "</strong></td>");
                result.Append("</tr>");
                result.Append("</table>");
                result.Append("</td>");
                result.Append("</tr>");
            }
            else
            {
                result.Append("<tr><td style='border-bottom:1px solid black;text-align:center;font-family:Arial;' colspan='14'>-No transactions-</td></tr>");
            }

            reportData.Comission = commission;
            reportData.Content = result;
            reportData.Profit = totalProfit;
            reportData.Swap = swap;
            reportData.TotalProfit = realizedPL;
            reportData.Deposit = deposit;
            reportData.Withdrawls = withdrawal;
            reportData.CreditIn = creditIn;
            reportData.CreditOut = creditOut;

            return reportData;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listOpenPosition"></param>
        /// <returns></returns>
        public Business.ReportItem RendOpenPosition(List<Business.OpenTrade> listOpenPosition)
        {
            Business.ReportItem reportData = new ReportItem();
            StringBuilder result = new StringBuilder();
            double commission = 0;
            double swap = 0;
            double profitLoss = 0;
            double unrealize = 0;

            if (listOpenPosition != null && listOpenPosition.Count > 0)
            {
                int count = listOpenPosition.Count;
                for (int i = 0; i < count; i++)
                {
                    result.Append("<tr>");
                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" + "#" + listOpenPosition[i].CommandCode + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        listOpenPosition[i].OpenTime.ToString("MM/dd/yyyy HH:mm:ss") + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" + listOpenPosition[i].Symbol.Name + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                         TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].Size.ToString(), 2) + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Facade.FacadeConvertTypeIDToName(listOpenPosition[i].Type.ID) + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].OpenPrice.ToString(), listOpenPosition[i].Symbol.Digit) + "</td>");

                    if (listOpenPosition[i].TakeProfit > 0)
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].TakeProfit.ToString(), listOpenPosition[i].Symbol.Digit) + "</td>");
                    else
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");

                    if (listOpenPosition[i].StopLoss > 0)
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                            TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].StopLoss.ToString(), listOpenPosition[i].Symbol.Digit) + "</td>");
                    else
                        result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>-</td>");

                    double closePrice = listOpenPosition[i].ClosePrice;
                    double spread = closePrice - listOpenPosition[i].OpenPrice;
                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(spread, listOpenPosition[i].Symbol.Digit).ToString(), listOpenPosition[i].Symbol.Digit) + "</td>");

                    //ADD NEW TWO COLUMN(CLOSE PRICE AND CLOSE TIME)
                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].ClosePrice.ToString(), listOpenPosition[i].Symbol.Digit) +
                        "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].Swap.ToString(), 2) + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:center;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(listOpenPosition[i].Commission.ToString(), 2) + "</td>");

                    result.Append("<td style='border-bottom:1px solid Gray;text-align:right;background-color:#EEEEEE;font-family:Arial;'>" +
                        TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(listOpenPosition[i].Profit,2).ToString(), 2) + "</td>");
                    result.Append("</tr>");

                    commission += listOpenPosition[i].Commission;
                    swap += listOpenPosition[i].Swap;
                    profitLoss += listOpenPosition[i].Profit;
                }

                unrealize = Math.Round(profitLoss + swap + commission, 2);
                //unrealize = Math.Round(profitLoss + commission, 2);

                result.Append("<tr style='text-align:center;background-color:#EEEEEE;font-family:Arial;'>");
                result.Append("<td colspan='11'>&nbsp;</td>");
                result.Append("<td>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(swap, 2).ToString(), 2) + "</td>");
                result.Append("<td>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(commission, 2).ToString(), 2) + "</td>");
                result.Append("<td align='right'>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(profitLoss, 2).ToString(), 2) + "</td>");
                result.Append("</tr>");
                result.Append("<tr>");
                result.Append("<td colspan='14'>");
                result.Append("<table cellspacing='0' cellpadding='3' align='right' style='width:30%;background-color:#DBDBDB'>");
                result.Append("<tr>");
                result.Append("<td><strong>Unrealized P&amp;L:</strong></td>");
                result.Append("<td align='right'><strong>" + TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(unrealize, 2).ToString(), 2) + "</strong></td>");
                result.Append("</tr>");
                result.Append("</table>");
                result.Append("</td>");
                result.Append("</tr>");
            }
            else
            {
                result.Append("<tr><td style='border-bottom:1px solid black;text-align:center;font-family:Arial;' colspan='14'>-No transactions-</td></tr>");
            }

            result.Append("</table>");
            result.Append("</td>");
            result.Append("</tr>");

            reportData.Comission = commission;
            reportData.Content = result;
            reportData.Profit = profitLoss;
            reportData.Swap = swap;
            reportData.TotalProfit = unrealize;

            return reportData;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listOpenPosition"></param>
        /// <param name="listClosePosition"></param>
        /// <param name="listPendingPosition"></param>
        /// <returns></returns>
        public StringBuilder GetStatementReport(List<Business.OpenTrade> listOpenPosition, List<Business.OpenTrade> listClosePosition, List<Business.OpenTrade> listPendingPosition, Business.Investor account, DateTime timeEndDay)
        {
            StringBuilder result = new StringBuilder();

            try
            {
                Business.ReportItem openPosition = new ReportItem();
                Business.ReportItem closePosition = new ReportItem();
                StringBuilder pendingPosition = new StringBuilder();

                result = this.GetStatementTemplate();
                openPosition = this.RendOpenPosition(listOpenPosition);
                closePosition = this.RendClosePosition(listClosePosition);
                pendingPosition = this.RendPendingPosition(listPendingPosition);

                result.Replace("<tr><td>[#ClosePosition]</td></tr>", closePosition.Content.ToString());
                result.Replace("<tr><td>[#OpenPosition]</td></tr>", openPosition.Content.ToString());
                result.Replace("<tr><td>[#LimitStopOrder]</td></tr>", pendingPosition.ToString());

                result.Replace("[LoginCode]", account.Code);
                result.Replace("[LoginName]", account.NickName);
                result.Replace("[Currency]", "USD");

                string serverName = string.Empty;
                string serverType = string.Empty;
                if (Business.Market.MarketConfig != null)
                {
                    int countMarketConfig = Business.Market.MarketConfig.Count;
                    for (int j = 0; j < countMarketConfig; j++)
                    {
                        if (Business.Market.MarketConfig[j].Code == "C01")
                        {
                            serverName = Business.Market.MarketConfig[j].StringValue;
                        }

                        if (Business.Market.MarketConfig[j].Code == "C02")
                        {
                            serverType = Business.Market.MarketConfig[j].StringValue;
                        }
                    }
                }

                result.Replace("[HeaderStatement]", "Daily Statement - " + serverName);
                result.Replace("[CompanyName]", serverName + " " + serverType);

                //company name get in admin(Because Need test)
                //result.Replace("[CompanyName]", Business.Market.CompanyName);

                double equity = 0;
                double balance = 0;

                //double previousLedgerBalance = TradingServer.Facade.FacadeGetPreviousLedgerBalance(account.InvestorID);
                double previousLedgerBalance = 0;

                #region NEW CODE(22/05/2012) GET PREVIOUSLEDGERBALANCE = LAST BALANCE IN COMMAND HISTORY WITH TYPE = 21
                TradingServer.Business.OpenTrade LastBalance = null;
                if (timeEndDay.DayOfWeek == DayOfWeek.Monday)
                {
                    DateTime tempTimeStart = timeEndDay.AddDays(-3);
                    DateTime timeStartLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 00, 00, 00);
                    DateTime timeEndLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 23, 59, 59);

                    LastBalance = TradingServer.Facade.FacadeGetLastBalanceByInvestor(account.InvestorID, timeStartLastBalance, 21, timeEndLastBalance);
                }
                else
                {
                    if (timeEndDay.DayOfWeek == DayOfWeek.Sunday)
                    {
                        DateTime tempTimeStart = timeEndDay.AddDays(-2);
                        DateTime timeStartLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 00, 00, 00);
                        DateTime timeEndLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 23, 59, 59);

                        LastBalance = TradingServer.Facade.FacadeGetLastBalanceByInvestor(account.InvestorID, timeStartLastBalance, 21, timeEndLastBalance);
                    }
                    else
                    {
                        DateTime tempTimeStart = timeEndDay.AddDays(-1);
                        DateTime timeStartLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 00, 00, 00);
                        DateTime timeEndLastBalance = new DateTime(tempTimeStart.Year, tempTimeStart.Month, tempTimeStart.Day, 23, 59, 59);

                        LastBalance = TradingServer.Facade.FacadeGetLastBalanceByInvestor(account.InvestorID, timeStartLastBalance, 21, timeEndLastBalance);
                    }
                }

                if (LastBalance != null)
                    previousLedgerBalance = LastBalance.Profit;
                #endregion

                balance = Math.Round(previousLedgerBalance + closePosition.TotalProfit +
                    closePosition.Deposit - closePosition.Withdrawls, 2);

                equity = Math.Round(balance + openPosition.TotalProfit + account.Credit, 2);

                result.Replace("[PreviousLedger]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(previousLedgerBalance.ToString(), 2));
                result.Replace("[Withdrawal]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(closePosition.Withdrawls.ToString(), 2));
                result.Replace("[Deposit]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(closePosition.Deposit.ToString(), 2));
                result.Replace("[Equity]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(equity.ToString(), 2));
                result.Replace("[Unrealized]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(openPosition.TotalProfit, 2).ToString(), 2));
                result.Replace("[Realized]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(closePosition.TotalProfit.ToString(), 2));
                result.Replace("[Margin]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit((account.Margin + account.FreezeMargin).ToString(), 2));
                result.Replace("[CreditIn]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(closePosition.CreditIn, 2).ToString(), 2));
                result.Replace("[CreditOut]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(closePosition.CreditOut, 2).ToString(), 2));
                //result.Replace("[Swap]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(openPosition.Swap, 2).ToString(), 2));
                result.Replace("[Credit]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(account.Credit, 2).ToString(), 2));

                double freeMargin = equity - (account.Margin + account.FreezeMargin);

                result.Replace("[FreeMargin]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(freeMargin, 2).ToString(), 2));

                double tempTotalMargin = (account.Margin + account.FreezeMargin);

                double marginLevel = 0;

                if (tempTotalMargin > 0)
                    marginLevel = (equity * 100) / tempTotalMargin;

                if (marginLevel != 0)
                    result.Replace("[MarginLevel]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Math.Round(marginLevel, 2).ToString(), 2));
                else
                    result.Replace("[MarginLevel]", "-");

                result.Replace("[Balance]", TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(balance.ToString(), 2));

                account.PreviousLedgerBalance = balance;
            }
            catch (Exception ex)
            {

            }

            return result;
        }