public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters,
                                                ITranslator translator, out string response)
        {
            response = null;
            var vars             = new Dictionary <string, object>();
            var transactionsList = new List <Dictionary <string, object> >();

            uint   amountPerQuery = 25;
            var    today          = DateTime.Now;
            var    thirtyDays     = today.AddDays(-7);
            string DateStart      = thirtyDays.ToShortDateString();
            string DateEnd        = today.ToShortDateString();
            UUID   UserID         = UUID.Zero;
            int    start          = 0;

            IMoneyModule moneyModule = webInterface.Registry.RequestModuleInterface <IMoneyModule>();
            string       noDetails   = translator.GetTranslatedString("NoTransactionsText");

            // Check if we're looking at the standard page or the submitted one
            if (requestParameters.ContainsKey("Submit"))
            {
                if (requestParameters.ContainsKey("date_start"))
                {
                    DateStart = requestParameters ["date_start"].ToString();
                }
                if (requestParameters.ContainsKey("date_end"))
                {
                    DateEnd = requestParameters ["date_end"].ToString();
                }

                // paginations
                start = httpRequest.Query.ContainsKey("Start")
                    ? int.Parse(httpRequest.Query ["Start"].ToString())
                    : 0;
                int count    = (int)moneyModule.NumberOfTransactions(UserID, UUID.Zero);
                int maxPages = (int)(count / amountPerQuery) - 1;

                if (start == -1)
                {
                    start = (maxPages < 0 ? 0 : maxPages);
                }

                vars.Add("CurrentPage", start);
                vars.Add("NextOne", start + 1 > maxPages ? start : start + 1);
                vars.Add("BackOne", start - 1 < 0 ? 0 : start - 1);
            }
            else
            {
                vars.Add("CurrentPage", 0);
                vars.Add("NextOne", 0);
                vars.Add("BackOne", 0);
            }

            UserAccount user = Authenticator.GetAuthentication(httpRequest);

            // Transaction Logs
            var      timeNow  = DateTime.Now.ToString("HH:mm:ss");
            var      dateFrom = DateTime.Parse(DateStart + " " + timeNow);
            var      dateTo   = DateTime.Parse(DateEnd + " " + timeNow);
            TimeSpan period   = dateTo.Subtract(dateFrom);

            List <AgentTransfer> transactions;

            transactions = moneyModule.GetTransactionHistory(user.PrincipalID, UUID.Zero, dateFrom, dateTo, (uint)start, amountPerQuery);

            // data
            if (transactions.Count > 0)
            {
                noDetails = "";

                foreach (var transaction in transactions)
                {
                    transactionsList.Add(new Dictionary <string, object> {
                        { "Date", Culture.LocaleDate(transaction.TransferDate.ToLocalTime(), "MMM dd, hh:mm:ss tt") },
                        { "ToAgent", transaction.ToAgentName },
                        { "FromAgent", transaction.FromAgentName },
                        { "Description", transaction.Description },
                        { "Amount", transaction.Amount },
                        { "ToBalance", transaction.ToBalance }
                    });
                }
            }

            if (transactionsList.Count == 0)
            {
                transactionsList.Add(new Dictionary <string, object> {
                    { "Date", "" },                   //Culture.LocaleDate(today,"MMM dd, hh:mm:ss")},
                    { "ToAgent", "" },
                    { "FromAgent", "" },
                    { "Description", translator.GetTranslatedString("NoTransactionsText") },
                    { "Amount", "" },
                    { "ToBalance", "" }
                });
            }

            // always required data
            vars.Add("DateStart", DateStart);
            vars.Add("DateEnd", DateEnd);
            vars.Add("Period", period.TotalDays + " " + translator.GetTranslatedString("DaysText"));
            vars.Add("TransactionsList", transactionsList);
            vars.Add("NoTransactionsText", noDetails);

            // labels
            vars.Add("TransactionsText", translator.GetTranslatedString("TransactionsText"));
            vars.Add("DateInfoText", translator.GetTranslatedString("DateInfoText"));
            vars.Add("DateStartText", translator.GetTranslatedString("DateStartText"));
            vars.Add("DateEndText", translator.GetTranslatedString("DateEndText"));

            vars.Add("TransactionDateText", translator.GetTranslatedString("TransactionDateText"));
            vars.Add("TransactionToAgentText", translator.GetTranslatedString("TransactionToAgentText"));
            vars.Add("TransactionFromAgentText", translator.GetTranslatedString("TransactionFromAgentText"));
            vars.Add("TransactionDetailText", translator.GetTranslatedString("TransactionDetailText"));
            vars.Add("TransactionAmountText", translator.GetTranslatedString("TransactionAmountText"));
            vars.Add("TransactionBalanceText", translator.GetTranslatedString("TransactionBalanceText"));

            vars.Add("FirstText", translator.GetTranslatedString("FirstText"));
            vars.Add("BackText", translator.GetTranslatedString("BackText"));
            vars.Add("NextText", translator.GetTranslatedString("NextText"));
            vars.Add("LastText", translator.GetTranslatedString("LastText"));
            vars.Add("CurrentPageText", translator.GetTranslatedString("CurrentPageText"));

            return(vars);
        }
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
                                                ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();
            var transactionsList = new List<Dictionary<string, object>>();

            uint amountPerQuery = 25;
            var today = DateTime.Now;
            var thirtyDays = today.AddDays (-30);
            string DateStart = thirtyDays.ToShortDateString();
            string DateEnd = today.ToShortDateString();
            string UserName = "";
            UUID UserID = UUID.Zero;

            IMoneyModule moneyModule = webInterface.Registry.RequestModuleInterface<IMoneyModule>();
            string noDetails = translator.GetTranslatedString ("NoTransactionsText");

            // Check if we're looking at the standard page or the submitted one
            if (requestParameters.ContainsKey ("Submit"))
            {
                if (requestParameters.ContainsKey ("date_start"))
                    DateStart = requestParameters ["date_start"].ToString ();
                if (requestParameters.ContainsKey ("date_end"))
                    DateEnd = requestParameters ["date_end"].ToString ();
                if (requestParameters.ContainsKey ("user_name"))
                    UserName = requestParameters ["user_name"].ToString ();

                if (UserName != "")
                {
                    // TODO: Work out a better way to catch this
                    UserID = (UUID)Constants.LibraryOwner;         // This user should hopefully never have transactions

                    if (UserName.Split (' ').Length == 2)
                    {
                        IUserAccountService accountService = webInterface.Registry.RequestModuleInterface<IUserAccountService> ();
                        var userAccount = accountService.GetUserAccount (null, UserName);
                        if (userAccount != null)
                            UserID = userAccount.PrincipalID;
                    }
                }

                // paginations
                int start = httpRequest.Query.ContainsKey ("Start")
                    ? int.Parse (httpRequest.Query ["Start"].ToString ())
                    : 0;
                int count = (int) moneyModule.NumberOfTransactions(UserID, UUID.Zero);
                int maxPages = (int)(count / amountPerQuery) - 1;

                if (start == -1)
                    start = (int)(maxPages < 0 ? 0 : maxPages);

                vars.Add ("CurrentPage", start);
                vars.Add ("NextOne", start + 1 > maxPages ? start : start + 1);
                vars.Add ("BackOne", start - 1 < 0 ? 0 : start - 1);


                // Transaction Logs
                var timeNow = DateTime.Now.ToString ("HH:mm:ss");
                var dateFrom = DateTime.Parse (DateStart + " " + timeNow);
                var dateTo = DateTime.Parse (DateEnd + " " + timeNow);

                List<AgentTransfer> transactions;
                if (UserID != UUID.Zero)
                    transactions = moneyModule.GetTransactionHistory (UserID, UUID.Zero, dateFrom, dateTo, (uint)start, amountPerQuery);
                else
                    transactions = moneyModule.GetTransactionHistory (dateFrom, dateTo, (uint)start, amountPerQuery);


                // data
                if (transactions.Count > 0)
                {
                    noDetails = "";

                    foreach (var transaction in transactions)
                    {
                        transactionsList.Add (new Dictionary<string, object> {
                            { "Date", Culture.LocaleDate (transaction.TransferDate.ToLocalTime(), "MMM dd, hh:mm:ss tt") },
                            { "ToAgent", transaction.ToAgentName },
                            { "FromAgent", transaction.FromAgentName },
                            { "Description", transaction.Description },
                            { "Amount",transaction.Amount },
                            { "ToBalance",transaction.ToBalance }

                        });
                    }
                }
            } else
            {
                vars.Add ("CurrentPage", 0 );
                vars.Add ("NextOne", 0);
                vars.Add ("BackOne", 0);
            }

            if (transactionsList.Count == 0)
            {
                transactionsList.Add(new Dictionary<string, object> {
                    {"Date", ""},
                    {"ToAgent", ""},
                    {"FromAgent", ""},
                    {"Description", translator.GetTranslatedString ("NoTransactionsText")},
                    {"Amount",""},
                    {"ToBalance",""}

                });
            }

            // always required data
            vars.Add("DateStart", DateStart );
            vars.Add ("DateEnd", DateEnd );
            vars.Add ("SearchUser", UserName);
            vars.Add("TransactionsList",transactionsList);
            vars.Add ("NoTransactionsText", noDetails);

            // labels
            vars.Add("TransactionsText", translator.GetTranslatedString("TransactionsText"));
            vars.Add("DateInfoText", translator.GetTranslatedString("DateInfoText"));
            vars.Add("DateStartText", translator.GetTranslatedString("DateStartText"));
            vars.Add("DateEndText", translator.GetTranslatedString("DateEndText"));
            vars.Add("SearchUserText", translator.GetTranslatedString("AvatarNameText"));

            vars.Add("TransactionDateText", translator.GetTranslatedString("TransactionDateText"));
            vars.Add("TransactionToAgentText", translator.GetTranslatedString("TransactionToAgentText"));
            vars.Add("TransactionFromAgentText", translator.GetTranslatedString("TransactionFromAgentText"));
            vars.Add("TransactionDetailText", translator.GetTranslatedString("TransactionDetailText"));
            vars.Add("TransactionAmountText", translator.GetTranslatedString("TransactionAmountText"));
            vars.Add("TransactionBalanceText", translator.GetTranslatedString("TransactionBalanceText"));

            vars.Add("FirstText", translator.GetTranslatedString("FirstText"));
            vars.Add("BackText", translator.GetTranslatedString("BackText"));
            vars.Add("NextText", translator.GetTranslatedString("NextText"));
            vars.Add("LastText", translator.GetTranslatedString("LastText"));
            vars.Add("CurrentPageText", translator.GetTranslatedString("CurrentPageText"));
                    
            return vars;
        }
예제 #3
0
        public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters,
                                                ITranslator translator, out string response)
        {
            response = null;
            var vars             = new Dictionary <string, object> ();
            var transactionsList = new List <Dictionary <string, object> > ();

            var    today     = DateTime.Now;
            var    fromDays  = today.AddDays(-7);
            string DateStart = fromDays.ToShortDateString();
            string DateEnd   = today.ToShortDateString();

            IMoneyModule moneyModule = webInterface.Registry.RequestModuleInterface <IMoneyModule> ();
            string       noDetails   = translator.GetTranslatedString("NoTransactionsText");

            // Check if we're looking at the standard page or the submitted one
            if (requestParameters.ContainsKey("Submit"))
            {
                if (requestParameters.ContainsKey("date_start"))
                {
                    DateStart = requestParameters ["date_start"].ToString();
                }
                if (requestParameters.ContainsKey("date_end"))
                {
                    DateEnd = requestParameters ["date_end"].ToString();
                }
            }

            UserAccount user = Authenticator.GetAuthentication(httpRequest);

            if (user == null)
            {
                response = "<h3>Error validating user details</h3>" +
                           "<script language=\"javascript\">" +
                           "setTimeout(function() {window.location.href = \"/?page=user_transactions\";}, 1000);" +
                           "</script>";

                return(null);
            }

            // Transaction Logs
            var      timeNow  = DateTime.Now.ToString("HH:mm:ss");
            var      dateFrom = DateTime.Parse(DateStart + " " + timeNow);
            var      dateTo   = DateTime.Parse(DateEnd + " " + timeNow);
            TimeSpan period   = dateTo.Subtract(dateFrom);

            var transactions = new List <AgentTransfer> ();

            if (user != null && moneyModule != null)
            {
                transactions = moneyModule.GetTransactionHistory(user.PrincipalID, UUID.Zero, dateFrom, dateTo, null, null);
            }

            // data
            if (transactions.Count > 0)
            {
                noDetails = "";

                foreach (var transaction in transactions)
                {
                    transactionsList.Add(new Dictionary <string, object> {
                        { "Date", Culture.LocaleDate(transaction.TransferDate.ToLocalTime(), "MMM dd, hh:mm:ss tt") },
                        { "ToAgent", transaction.ToAgentName },
                        { "FromAgent", transaction.FromAgentName },
                        { "Description", transaction.Description },
                        { "Amount", transaction.Amount },
                        { "ToBalance", transaction.ToBalance }
                    });
                }
            }

            if (transactionsList.Count == 0)
            {
                transactionsList.Add(new Dictionary <string, object> {
                    { "Date", "" },                   //Culture.LocaleDate(today,"MMM dd, hh:mm:ss")},
                    { "ToAgent", "" },
                    { "FromAgent", "" },
                    { "Description", translator.GetTranslatedString("NoTransactionsText") },
                    { "Amount", "" },
                    { "ToBalance", "" }
                });
            }

            // always required data
            vars.Add("DateStart", DateStart);
            vars.Add("DateEnd", DateEnd);
            vars.Add("Period", period.TotalDays + " " + translator.GetTranslatedString("DaysText"));
            vars.Add("TransactionsList", transactionsList);
            vars.Add("NoTransactionsText", noDetails);

            // labels
            vars.Add("UserName", user.Name);
            vars.Add("TransactionsText", translator.GetTranslatedString("TransactionsText"));
            vars.Add("DateInfoText", translator.GetTranslatedString("DateInfoText"));
            vars.Add("DateStartText", translator.GetTranslatedString("DateStartText"));
            vars.Add("DateEndText", translator.GetTranslatedString("DateEndText"));

            vars.Add("TransactionDateText", translator.GetTranslatedString("TransactionDateText"));
            vars.Add("TransactionToAgentText", translator.GetTranslatedString("TransactionToAgentText"));
            vars.Add("TransactionFromAgentText", translator.GetTranslatedString("TransactionFromAgentText"));
            //vars.Add("TransactionTimeText", translator.GetTranslatedString("Time"));
            vars.Add("TransactionDetailText", translator.GetTranslatedString("TransactionDetailText"));
            vars.Add("TransactionAmountText", translator.GetTranslatedString("TransactionAmountText"));
            vars.Add("TransactionBalanceText", translator.GetTranslatedString("TransactionBalanceText"));

            return(vars);
        }