예제 #1
0
//-------------------------------------------------------------------------------------------
    public void OFXPreview_Click(object sender, EventArgs e)
    {
        ClearError();

        using (WeavverEntityContainer data = new WeavverEntityContainer())
        {
            Accounting_OFXSettings ofxSettings = (from x in data.Accounting_OFXSettings
                                                  where x.AccountId == new Guid(OFXAccounts.SelectedValue)
                                                  select x).FirstOrDefault();

            if (ofxSettings != null)
            {
                Accounting_Accounts acct = (from x in data.Accounting_Accounts
                                            where x.Id == new Guid(OFXAccounts.SelectedValue)
                                            select x).FirstOrDefault();

                List <Accounting_OFXLedgerItem> items = ofxSettings.GetRemoteLedgerItems(DateTime.Parse(OFXStartDate.Text), DateTime.Parse(OFXEndDate.Text));
                Session["Import_Transactions"] = items;
                List <Accounting_LedgerItems> LedgerItemsData = new List <Accounting_LedgerItems>();
                foreach (var item in items)
                {
                    LedgerItemsData.Add(item.LedgerItem);
                }
                var sortedItems = LedgerItemsData.OrderByDescending(x => x.PostAt);
                TransactionsDetected.DataSource = sortedItems;
                TransactionsDetected.DataBind();

                LedgerItems.Visible = true;

                // totals
                var credits = items.Where(x => x.LedgerItem.Amount > 0).Sum(x => x.LedgerItem.Amount);
                var debits  = items.Where(x => x.LedgerItem.Amount < 0).Sum(x => x.LedgerItem.Amount);
                DetectedTotal.Text = items.Count.ToString();
                if (credits.HasValue)
                {
                    TotalCredits.Text = String.Format("{0,10:C}", credits.Value);
                }
                if (debits.HasValue)
                {
                    TotalDebits.Text = String.Format("{0,10:C}", debits.Value);
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ScheduledPayments.ItemDataBound += new DataGridItemEventHandler(ScheduledPayments_ItemDataBound);

        WeavverMaster.FormTitle = "OFX Bill Pay";
        Guid accountId = new Guid(Request["id"]);

        using (WeavverEntityContainer data = new WeavverEntityContainer())
        {
            Accounting_Accounts financialAccount = (from x in data.Accounting_Accounts
                                                    where x.Id == accountId
                                                    select x).FirstOrDefault();
            if (financialAccount.OrganizationId == LoggedInUser.OrganizationId)
            {
                Accounting_OFXSettings ofxBank = financialAccount.GetOFXSettings();

                Logistics_Addresses address = null;

                billPayment.OFXAppId       = "QWIN";
                billPayment.OFXAppVersion  = "1700";
                billPayment.FIUrl          = ofxBank.Url;
                billPayment.FIId           = ofxBank.FinancialInstitutionId.ToString();
                billPayment.FIOrganization = ofxBank.FinancialInstitutionName;
                billPayment.OFXUser        = ofxBank.Username;
                billPayment.OFXPassword    = ofxBank.Password;

                billPayment.Payment.FromBankId    = ofxBank.BankId;
                billPayment.Payment.FromAccountId = financialAccount.AccountNumber;
                LedgerType lType = (LedgerType)Enum.Parse(typeof(LedgerType), financialAccount.LedgerType);
                billPayment.Payment.FromAccountType = Accounting_OFXSettings.ConvertWeavverLedgerTypeToEbankingAccountType(lType);

                billPayment.SynchronizePayments("REFRESH");
                billPayment.SynchronizePayees("REFRESH");     // do these together so we can poll the info in ItemDataBound

                var items = from x in billPayment.SyncPayments
                            orderby x.DateDue descending
                            select x;
                ScheduledPayments.DataSource = items;
                ScheduledPayments.DataBind();
                Payees.DataSource = billPayment.SyncPayees;
                Payees.DataBind();
            }
        }
    }