Пример #1
0
        public static void DeleteAccount(int corpID, long ownerID)
        {
            PublicCorp corp = PublicCorps.GetCorp(corpID);
            if (corp != null)
            {
                corp.OwnerID = ownerID;
                corp.ReloadBankAccountDetails();

                if (corp.BankAccountID > 0)
                {
                    DeleteTransactions(GetAccountTransactions(corp.BankAccountID));

                    EMMADataSet.BankAccountRow account = null;
                    EMMADataSet.BankAccountDataTable table = new EMMADataSet.BankAccountDataTable();

                    bankAccountTableAdapter.FillByID(table, corp.BankAccountID);
                    account = table.FindByAccountID(corp.BankAccountID);

                    if (account != null)
                    {
                        account.Delete();
                        bankAccountTableAdapter.Update(table);
                    }
                }
            }
        }
Пример #2
0
        public static void PayOutstandingInterest(int accountID)
        {
            bool cancel = false;
            EMMADataSet.BankAccountRow accountData = null;
            EMMADataSet.BankAccountDataTable accountTable = new EMMADataSet.BankAccountDataTable();
            CorpPayoutPeriod interestPeriod = CorpPayoutPeriod.Unspecified;
            decimal interestPercentage = 0;
            decimal balance = 0;

            bankAccountTableAdapter.FillByID(accountTable, accountID);
            if (accountTable.Count > 0)
            {
                accountData = accountTable[0];
                PublicCorp corpData = PublicCorps.GetCorp(accountData.PublicCorpID);
                if (corpData == null)
                {
                    cancel = true;
                }
                else
                {
                    interestPeriod = corpData.PayoutPeriod;
                    interestPercentage = corpData.ExpectedPayout;
                }
            }
            else
            {
                cancel = true;
            }

            EMMADataSet.BankTransactionDataTable table = new EMMADataSet.BankTransactionDataTable();

            // First work out when the last interest payment was made.
            // If there isn't one then use the oldest deposit/withdrawl/manual adjustment date.
            // If there's still nothing then we just need to clear the account balance.
            DateTime lastInterestPaymentDate = DateTime.MaxValue;
            bankTransactionTableAdapter.FillByAny(table, accountID,
                (short)BankTransactionType.InterestPayment, true);
            if (table.Count > 0)
            {
                lastInterestPaymentDate = table[0].DateTime;
            }
            else
            {
                bankTransactionTableAdapter.FillByAny(table, accountID,
                    0, false);
                if (table.Count > 0)
                {
                    foreach (EMMADataSet.BankTransactionRow transaction in table)
                    {
                        if (lastInterestPaymentDate.CompareTo(transaction.DateTime) > 0)
                        {
                            lastInterestPaymentDate = transaction.DateTime;
                        }
                    }
                }
                else
                {
                    cancel = true;
                }
            }

            if (cancel)
            {
                // We have no transactions so set account balance to zero.
                if (accountData != null)
                {
                    accountData.Balance = 0;
                    bankAccountTableAdapter.Update(accountData);
                }
            }
            else
            {
                // Now get the time interval between interest payments...
                TimeSpan interestPaymentInterval = new TimeSpan();
                EMMADataSet.PublicCorpPayoutPeriodDataTable periods = CorpPayoutPeriods.GetAll();
                EMMADataSet.PublicCorpPayoutPeriodRow period = periods.FindByID((short)interestPeriod);

                if (interestPeriod != CorpPayoutPeriod.Unspecified && period != null)
                {
                    if (!period.IsDaysNull())
                    {
                        interestPaymentInterval = new TimeSpan(period.Days, 0, 0, 0);
                    }
                }

                if (interestPaymentInterval.TotalDays >= 1)
                {
                    balance = GetAccountBalance(accountID,
                        lastInterestPaymentDate.Add(interestPaymentInterval));

                    // Create any missing interest payments.
                    while (DateTime.UtcNow.CompareTo(
                        lastInterestPaymentDate.Date.Add(interestPaymentInterval)) > 0)
                    {
                        lastInterestPaymentDate = lastInterestPaymentDate.Date.Add(
                            interestPaymentInterval);
                        decimal change = Math.Round(balance * (interestPercentage / 100.0m), 2);

                        if (change >= 0.01m)
                        {
                            StoreBankTransaction(new BankTransaction(lastInterestPaymentDate,
                                accountID, change, BankTransactionType.InterestPayment));
                            balance += change;
                        }

                        // Apply any deposits or withdrawls made between the last payment date and the
                        // next interest interval.
                        if (table.Count > 0)
                        {
                            foreach (EMMADataSet.BankTransactionRow transaction in table)
                            {
                                if (transaction.DateTime.CompareTo(lastInterestPaymentDate) > 0 &&
                                    transaction.DateTime.CompareTo(lastInterestPaymentDate.Add(interestPaymentInterval)) < 0)
                                {
                                    balance += transaction.Change;
                                }
                            }
                        }
                    }

                    // Update the current balance figure on the account.
                    accountData.Balance = balance;
                    bankAccountTableAdapter.Update(accountData);
                }
            }
        }
Пример #3
0
        public static void StoreAccount(PublicCorp data, int reportGroupID, long ownerID)
        {
            EMMADataSet.BankAccountRow account = null;
            EMMADataSet.BankAccountDataTable table = new EMMADataSet.BankAccountDataTable();
            bool newRow = false;

            if (data.BankAccountID != 0)
            {
                bankAccountTableAdapter.FillByID(table, data.BankAccountID);
                account = table.FindByAccountID(data.BankAccountID);
            }

            if (account == null)
            {
                account = table.NewBankAccountRow();
                newRow = true;
            }

            account.PublicCorpID = data.ID;
            account.ReportGroupID = reportGroupID;
            account.Balance = 0;
            account.OwnerID = ownerID;
            if (newRow)
            {
                table.AddBankAccountRow(account);
            }
            bankAccountTableAdapter.Update(table);
        }
Пример #4
0
 public static EMMADataSet.BankAccountDataTable GetBankAccountData(int reportGroupID, long ownerID, int corpID)
 {
     EMMADataSet.BankAccountDataTable table = new EMMADataSet.BankAccountDataTable();
     bankAccountTableAdapter.FillByCorpAndOwner(table, corpID, reportGroupID, ownerID);
     return table;
 }