protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["LedgerType"] == null)
          {
               Visible = false;
               return;
          }

          TextBox dateStart = BasePage.FindControlR<TextBox>("txbDateFrom");
          TextBox dateEnd = BasePage.FindControlR<TextBox>("txbDateThrough");

          Guid accountId = Guid.Empty;
          Guid.TryParse(Request["AccountId"], out accountId);
          if (accountId != Guid.Empty)
          {
               using (WeavverEntityContainer data = new WeavverEntityContainer())
               {
                    string ledgerType = Request["LedgerType"];
                    DateTime? startAt = null;
                    DateTime startAt2;
                    DateTime? endAt = null;
                    DateTime endAt2;

                    if (DateTime.TryParse(dateStart.Text, out startAt2))
                         startAt = startAt2;

                    if (DateTime.TryParse(dateEnd.Text, out endAt2))
                         endAt = endAt2;

                    string x = data.GetName(Guid.Empty);
                    decimal credits = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, false, false, null, null);
                    decimal debits = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, false, true, false, null, null);
                    decimal balance = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, true, false, null, null);
                    FundsIn.Text = String.Format("{0,10:C}", credits);
                    FundsOut.Text = String.Format("{0,10:C}", debits);
                    Balance.Text = String.Format("{0,10:C}", balance);

                    AvailableBalance.Text = String.Format("{0,10:C}", data.Total_ForLedger(BasePage.SelectedOrganization.OrganizationId, accountId, ledgerType, true, true, true, null, null));

                    if (startAt != null || endAt != null)
                    {
                         FilteredTotals.Visible = true;

                         decimal filteredStartingBalance = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, true, true, null, startAt);
                         decimal filteredCredits = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, false, true, startAt, endAt);
                         decimal filteredDebits = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, false, true, true, startAt, endAt);
                         decimal filteredBalance = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, true, true, startAt, endAt);
                         decimal filteredEndingBalance = data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, true, true, null, endAt);

                         VisibleStartingBalance.Text = String.Format("{0,10:C}", filteredStartingBalance);
                         VisibleCredits.Text = String.Format("{0,10:C}", filteredCredits);
                         VisibleDebits.Text = String.Format("{0,10:C}", filteredDebits);
                         VisibleBalance.Text = String.Format("{0,10:C}", filteredBalance);
                         VisibleEndingBalance.Text = String.Format("{0,10:C}", filteredEndingBalance);

                         VisibleAvailableBalance.Text = String.Format("{0,10:C}", data.Total_ForLedger(BasePage.SelectedOrganization.Id, accountId, ledgerType, true, true, true, startAt, endAt));
                    }
              }
         }
    }
    //-------------------------------------------------------------------------------------------
    public void UpdatePage()
    {
        using (WeavverEntityContainer data = new WeavverEntityContainer())
          {
               decimal balance = data.Total_ForLedger(SelectedOrganization.Id, LoggedInUser.OrganizationId, LedgerType.Receivable.ToString(), true, true, false, null, null);

               // data.Total_ForLedger(LoggedInUser.OrganizationId);

               var cards = (from items in data.Accounting_CreditCards
                            where items.OrganizationId == SelectedOrganization.Id
                            select items);

               CreditCards.DataSource = cards;
               CreditCards.DataTextField = "CensoredAccountNumber";
               CreditCards.DataValueField = "Id";
               CreditCards.DataBind();

               if (balance < 0)
               {
                    decimal amount = balance * -1;
                    MinimumPaymentDue.Text = "$" + amount.ToString();
                    Balance.Text = "$" + amount.ToString();
                    PayBalanceAmount.Text = "$" + amount.ToString();
               }
          }
    }