Ejemplo n.º 1
0
        public void Close(BackgroundWorker worker)
        {
            using (var ts = new TransactionScope())
            {
                var context = new ERPContext();

                var accounts = context.Ledger_Accounts
                    .Include("LedgerGeneral")
                    .Include("LedgerAccountBalances")
                    .ToList();

                var revenueAndExpenseAccounts = context.Ledger_Accounts
                    .Include("LedgerGeneral")
                    .Include("LedgerAccountBalances")
                    .Where(e => e.Class.Equals("Expense") || e.Class.Equals("Revenue"))
                    .ToList();

                var index = 1;
                var totalAccounts = accounts.Count + revenueAndExpenseAccounts.Count;
                // Close the Revenue and Expense Accounts to Retained Earnings
                foreach (var account in revenueAndExpenseAccounts)
                {
                    if (account.LedgerGeneral.Debit != 0 || account.LedgerGeneral.Credit != 0)
                        CloseRevenueOrExpenseAccountToRetainedEarnings(account, context);

                    worker.ReportProgress(index++ * (totalAccounts / 100));
                }

                foreach (var account in accounts)
                {
                    if (UtilityMethods.GetCurrentDate().Month == 12)
                    {
                        var newBalance = new LedgerAccountBalance { LedgerAccount = account, PeriodYear = UtilityMethods.GetCurrentDate().Year + 1 };
                        context.Ledger_Account_Balances.Add(newBalance);
                    }

                    if (Period != 12) account.LedgerGeneral.Period++;
                    else
                    {
                        account.LedgerGeneral.PeriodYear++;
                        account.LedgerGeneral.Period = 1;
                    }

                    // Close the balances
                    if (account.Class.Equals("Asset") || account.Class.Equals("Expense"))
                        CloseAssetOrExpenseAccount(account, context);                     
                    else
                        CloseLiabilityOrRevenueAccount(account, context);

                    worker.ReportProgress(index++ * (totalAccounts / 100));
                }

                context.SaveChanges();
                ts.Complete();
            }

            OnPropertyChanged("PeriodYear");
            OnPropertyChanged("Period");
        }
        public void Can_set_monthBalance()
        {
            var ledgerAccountBalance = new LedgerAccountBalance
            {
                LedgerAccountId  = 1,
                BeginningBalance = 0,
                Balance3         = 1000
            };

            ledgerAccountBalance.SetMonthBalance(0, 3000);
            Assert.Equal(3000, ledgerAccountBalance.GetMonthBalance(0));
        }
        public void Can_get_monthBalance()
        {
            var ledgerAccountBalance = new LedgerAccountBalance
            {
                LedgerAccountId  = 1,
                BeginningBalance = 0,
                Balance3         = 1000
            };

            Assert.Equal(0, ledgerAccountBalance.GetMonthBalance(1));
            Assert.Equal(1000, ledgerAccountBalance.GetMonthBalance(3));
        }
        public void Can_create_ledgerAccountBalance()
        {
            var ledgerAccountBalance = new LedgerAccountBalance
            {
                LedgerAccountId  = 1,
                BeginningBalance = 0,
                Balance3         = 1000
            };

            Assert.Equal(1, ledgerAccountBalance.LedgerAccountId);
            Assert.Equal(0, ledgerAccountBalance.BeginningBalance);
            Assert.Equal(1000, ledgerAccountBalance.Balance3);
        }
Ejemplo n.º 5
0
        private LedgerAccountBalance GetPeriodLedgerAccountBalance(int ledgerAccountId, int year, int month,
                                                                   out bool isCreate)
        {
            isCreate = false;
            LedgerAccountBalance accountBalance;

            // If closing month is January, create a new account balance for this year
            if (month == 1)
            {
                isCreate       = true;
                accountBalance = new LedgerAccountBalance {
                    LedgerAccountId = ledgerAccountId, Year = year
                };

                var previousYearAccountBalance =
                    _repository.GetOne <LedgerAccountBalance>(
                        b => b.LedgerAccountId == ledgerAccountId && b.Year == year - 1);

                // Set the beginning balance to previous year's ending balance
                if (previousYearAccountBalance != null)
                {
                    accountBalance.SetMonthBalance(0, previousYearAccountBalance.Balance12);
                }

                return(accountBalance);
            }

            accountBalance =
                _repository.GetOne <LedgerAccountBalance>(b => b.LedgerAccountId == ledgerAccountId && b.Year == year);

            // Create account balance if it does not exist in the database yet
            if (accountBalance == null)
            {
                isCreate       = true;
                accountBalance = new LedgerAccountBalance {
                    LedgerAccountId = ledgerAccountId, Year = year
                };
            }

            return(accountBalance);
        }
Ejemplo n.º 6
0
        private decimal GetPeriodBeginningBalance(LedgerAccountBalance cashBalance)
        {
            switch (_date.Month)
            {
            case 1:
                return(cashBalance.BeginningBalance);

            case 2:
                return(cashBalance.Balance1);

            case 3:
                return(cashBalance.Balance2);

            case 4:
                return(cashBalance.Balance3);

            case 5:
                return(cashBalance.Balance4);

            case 6:
                return(cashBalance.Balance5);

            case 7:
                return(cashBalance.Balance6);

            case 8:
                return(cashBalance.Balance7);

            case 9:
                return(cashBalance.Balance8);

            case 10:
                return(cashBalance.Balance9);

            case 11:
                return(cashBalance.Balance10);

            default:
                return(cashBalance.Balance11);
            }
        }
Ejemplo n.º 7
0
 private decimal GetPeriodBeginningBalance(LedgerAccountBalance cashBalance)
 {
     switch (_date.Month)
     {
         case 1:
             return cashBalance.BeginningBalance;
         case 2:
             return cashBalance.Balance1;
         case 3:
             return cashBalance.Balance2;
         case 4:
             return cashBalance.Balance3;
         case 5:
             return cashBalance.Balance4;
         case 6:
             return cashBalance.Balance5;
         case 7:
             return cashBalance.Balance6;
         case 8:
             return cashBalance.Balance7;
         case 9:
             return cashBalance.Balance8;
         case 10:
             return cashBalance.Balance9;
         case 11:
             return cashBalance.Balance10;
         default:
             return cashBalance.Balance11;
     }
 }
Ejemplo n.º 8
0
        public void Close(BackgroundWorker worker)
        {
            using (var ts = new TransactionScope())
            {
                var context = new ERPContext();

                var accounts = context.Ledger_Accounts
                               .Include("LedgerGeneral")
                               .Include("LedgerAccountBalances")
                               .ToList();

                var revenueAndExpenseAccounts = context.Ledger_Accounts
                                                .Include("LedgerGeneral")
                                                .Include("LedgerAccountBalances")
                                                .Where(e => e.Class.Equals("Expense") || e.Class.Equals("Revenue"))
                                                .ToList();

                var index         = 1;
                var totalAccounts = accounts.Count + revenueAndExpenseAccounts.Count;
                // Close the Revenue and Expense Accounts to Retained Earnings
                foreach (var account in revenueAndExpenseAccounts)
                {
                    if (account.LedgerGeneral.Debit != 0 || account.LedgerGeneral.Credit != 0)
                    {
                        CloseRevenueOrExpenseAccountToRetainedEarnings(account, context);
                    }

                    worker.ReportProgress(index++ *(totalAccounts / 100));
                }

                foreach (var account in accounts)
                {
                    if (UtilityMethods.GetCurrentDate().Month == 12)
                    {
                        var newBalance = new LedgerAccountBalance {
                            LedgerAccount = account, PeriodYear = UtilityMethods.GetCurrentDate().Year + 1
                        };
                        context.Ledger_Account_Balances.Add(newBalance);
                    }

                    if (Period != 12)
                    {
                        account.LedgerGeneral.Period++;
                    }
                    else
                    {
                        account.LedgerGeneral.PeriodYear++;
                        account.LedgerGeneral.Period = 1;
                    }

                    // Close the balances
                    if (account.Class.Equals("Asset") || account.Class.Equals("Expense"))
                    {
                        CloseAssetOrExpenseAccount(account, context);
                    }
                    else
                    {
                        CloseLiabilityOrRevenueAccount(account, context);
                    }

                    worker.ReportProgress(index++ *(totalAccounts / 100));
                }

                context.SaveChanges();
                ts.Complete();
            }

            OnPropertyChanged("PeriodYear");
            OnPropertyChanged("Period");
        }
Ejemplo n.º 9
0
        private void CreateNewAccount(ERPContext context)
        {
            LedgerAccount newAccount;
                
            if (_newEntryGroup.Equals("Bank"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Asset",
                    Notes = "Current Asset",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Operating Expense"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Receivable"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Asset",
                    Notes = "Accounts Receivable",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Payable"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Liability",
                    Notes = "Accounts Payable",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            var newAccountGeneralLedger = new LedgerGeneral
            {
                LedgerAccount = newAccount,
                PeriodYear = context.Ledger_General.First().PeriodYear,
                Period = context.Ledger_General.First().Period
            };

            var newAccountBalances = new LedgerAccountBalance
            {
                LedgerAccount = newAccount,
                PeriodYear = context.Ledger_General.First().PeriodYear
            };

            newAccount.LedgerGeneral = newAccountGeneralLedger;
            newAccount.LedgerAccountBalances.Add(newAccountBalances);
            context.Ledger_Accounts.Add(newAccount);
        }
Ejemplo n.º 10
0
        private void CreateNewAccount(ERPContext context)
        {
            LedgerAccount newAccount;

            if (_newEntryGroup.Equals("Bank"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Asset",
                    Notes = "Current Asset",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Operating Expense"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Receivable"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Asset",
                    Notes = "Accounts Receivable",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Payable"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Liability",
                    Notes = "Accounts Payable",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            var newAccountGeneralLedger = new LedgerGeneral
            {
                LedgerAccount = newAccount,
                PeriodYear    = context.Ledger_General.First().PeriodYear,
                Period        = context.Ledger_General.First().Period
            };

            var newAccountBalances = new LedgerAccountBalance
            {
                LedgerAccount = newAccount,
                PeriodYear    = context.Ledger_General.First().PeriodYear
            };

            newAccount.LedgerGeneral = newAccountGeneralLedger;
            newAccount.LedgerAccountBalances.Add(newAccountBalances);
            context.Ledger_Accounts.Add(newAccount);
        }