예제 #1
0
        // Revenue - Expense - TaxExpense - Divident = NetEarnings
        public ActionResult ReportIncomeStatement(int period, int yearPeriod)
        {
            var     company = _companyService.GetQueryable().FirstOrDefault();
            Closing closing = _closingService.GetObjectByPeriodAndYear(period, yearPeriod);

            if (closing == null)
            {
                return(Content(Constant.ErrorPage.ClosingNotFound));
            }

            ValidComb Revenue = _validCombService.FindOrCreateObjectByAccountAndClosing(_accountService.GetObjectByLegacyCode(Constant.AccountLegacyCode.Revenue).Id, closing.Id);
            ValidComb COGS    = _validCombService.FindOrCreateObjectByAccountAndClosing(_accountService.GetObjectByLegacyCode(Constant.AccountLegacyCode.COGS).Id, closing.Id);
            // TODO
            decimal OperationalExpensesAmount = 0, InterestEarningAmount = 0, DepreciationAmount = 0, AmortizationAmount = 0, TaxAmount = 0, DividentAmount = 0;

            ModelIncomeStatement model = new ModelIncomeStatement()
            {
                CompanyName         = company.Name,
                BeginningDate       = closing.BeginningPeriod.Date,
                EndDate             = closing.EndDatePeriod.Date,
                Revenue             = Revenue.Amount,
                COGS                = COGS.Amount,
                OperationalExpenses = OperationalExpensesAmount,
                InterestEarning     = InterestEarningAmount,
                Depreciation        = DepreciationAmount,
                Amortization        = AmortizationAmount,
                Tax      = TaxAmount,
                Divident = DividentAmount
            };

            List <ModelIncomeStatement> list = new List <ModelIncomeStatement>();

            list.Add(model);

            var rd = new ReportDocument();

            //Loading Report
            rd.Load(Server.MapPath("~/") + "Reports/Finance/IncomeStatement.rpt");

            // Setting report data source
            rd.SetDataSource(list);

            var stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            return(File(stream, "application/pdf"));
        }
예제 #2
0
        public bool DeleteObject(int Id, IAccountService _accountService, IValidCombService _validCombService)
        {
            IList <Account> allAccounts = _accountService.GetAll();

            foreach (var account in allAccounts)
            {
                ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(account.Id, Id);
                _validCombService.DeleteObject(validComb.Id);
            }
            return(_repository.DeleteObject(Id));
        }
예제 #3
0
        public Closing CloseObject(Closing closing, IAccountService _accountService,
                                   IGeneralLedgerJournalService _generalLedgerJournalService, IValidCombService _validCombService)
        {
            if (_validator.ValidCloseObject(closing, this))
            {
                // Count ValidComb for each leaf account
                IList <Account> leafAccounts = _accountService.GetLeafObjects();
                foreach (var leaf in leafAccounts)
                {
                    DateTime EndDate = closing.EndDatePeriod.AddDays(1);
                    IList <GeneralLedgerJournal> ledgers = _generalLedgerJournalService.GetQueryable()
                                                           .Where(x => x.AccountId == leaf.Id &&
                                                                  x.TransactionDate >= closing.BeginningPeriod &&
                                                                  x.TransactionDate < EndDate)
                                                           .ToList();
                    decimal totalAmountInLedgers = 0;
                    foreach (var ledger in ledgers)
                    {
                        Account account = _accountService.GetObjectById(ledger.AccountId);
                        if ((ledger.Status == Constant.GeneralLedgerStatus.Debit &&
                             (account.Group == Constant.AccountGroup.Asset ||
                              account.Group == Constant.AccountGroup.Expense)) ||
                            (ledger.Status == Constant.GeneralLedgerStatus.Credit &&
                             (account.Group == Constant.AccountGroup.Liability ||
                              account.Group == Constant.AccountGroup.Equity ||
                              account.Group == Constant.AccountGroup.Revenue)))
                        {
                            totalAmountInLedgers += ledger.Amount;
                        }
                        else
                        {
                            totalAmountInLedgers -= ledger.Amount;
                        }
                    }

                    ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(leaf.Id, closing.Id);
                    validComb.Amount = totalAmountInLedgers;
                    _validCombService.UpdateObject(validComb, _accountService, this);
                }

                var groupNodeAccounts = _accountService.GetQueryable().Where(x => !x.IsLeaf).OrderByDescending(x => x.Level);
                foreach (var groupNode in groupNodeAccounts)
                {
                    FillValidComb(groupNode, closing, _accountService, _validCombService);
                }

                _repository.CloseObject(closing);
            }
            return(closing);
        }
예제 #4
0
 public Closing OpenObject(Closing closing, IAccountService _accountService, IValidCombService _validCombService)
 {
     if (_validator.ValidOpenObject(closing))
     {
         IList <Account> allAccounts = _accountService.GetAll();
         foreach (var account in allAccounts)
         {
             ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(account.Id, closing.Id);
             validComb.Amount = 0;
             _validCombService.UpdateObject(validComb, _accountService, this);
         }
     }
     return(_repository.OpenObject(closing));
 }
예제 #5
0
        private void FillValidComb(Account nodeAccount, Closing closing, IAccountService _accountService, IValidCombService _validCombService)
        {
            ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(nodeAccount.Id, closing.Id);

            _validCombService.CalculateTotalAmount(validComb, _accountService, this);
        }