コード例 #1
0
ファイル: ClosingService.cs プロジェクト: ANR2ME/CashSales
        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);
        }
コード例 #2
0
        public dynamic GetList(string _search, long nd, int rows, int?page, string sidx, string sord, string filters = "")
        {
            // Construct where statement
            string strWhere = GeneralFunction.ConstructWhere(filters);
            string filter   = null;

            GeneralFunction.ConstructWhereInLinq(strWhere, out filter);
            if (filter == "")
            {
                filter = "true";
            }

            // Get Data
            var q = _generalLedgerJournalService.GetQueryable().Include("Account");

            var query = (from model in q
                         select new
            {
                model.Id,
                model.TransactionDate,
                model.Status,
                AccountCode = model.Account.Code,
                Account = model.Account.Name,
                model.Amount,
                model.SourceDocument,
                model.SourceDocumentId
            }).Where(filter).OrderBy(sidx + " " + sord);              //.ToList();

            var list = query.AsEnumerable();

            var pageIndex    = Convert.ToInt32(page) - 1;
            var pageSize     = rows;
            var totalRecords = query.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            // default last page
            if (totalPages > 0)
            {
                if (!page.HasValue)
                {
                    pageIndex = totalPages - 1;
                    page      = totalPages;
                }
            }

            list = list.Skip(pageIndex * pageSize).Take(pageSize);

            return(Json(new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from model in list
                    select new
                {
                    id = model.Id,
                    cell = new object[] {
                        model.Id,
                        model.TransactionDate,
                        model.Status,
                        model.AccountCode,
                        model.Account,
                        model.Amount,
                        model.SourceDocument,
                        model.SourceDocumentId
                    }
                }).ToArray()
            }, JsonRequestBehavior.AllowGet));
        }