Beispiel #1
0
        /// <summary>
        /// Get Account Summary Grouped By Currency .. Used to fill summary table at page top
        /// </summary>
        /// <param name="parentAccId"></param>
        /// <param name="isCreditAccount"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <returns>AccountSummary object</returns>
        public static AccountSummary GetAccountSummaryGrouped(string parentAccId, bool isCreditAccount = false,
                                                              DateTime?fromDate = null, DateTime?toDate = null, int bId = 0)
        {
            AccountSummary accountSummary = new AccountSummary();

            var accSummaryList = GetAccSummaryByParentAccId(parentAccId, isCreditAccount, fromDate, toDate);

            AccountingEntities db = new AccountingEntities();

            accountSummary.AccountNameEn = db.AccountingCharts.Where(x => x.AccountId == parentAccId).FirstOrDefault().AccountNameEn;

            //Cash in Bank .. get for specific bank ID
            if (parentAccId == "193" && bId != 0)
            {
                var accIdsForBank = db.BankAccounts.Where(x => x.BankId == bId).Select(x => x.AccountId).ToList();

                accSummaryList = accSummaryList.Where(x => accIdsForBank.Contains(x.AccountId)).ToList();
            }


            if (accSummaryList.Count > 0)
            {
                var grouped = accSummaryList.GroupBy(x => x.CurrencySign)
                              .Select(x => new
                {
                    Currency  = x.Key,
                    DebitSum  = x.Sum(y => y.DebitAmout),
                    CreditSum = x.Sum(y => y.CreditAmount)
                }).ToList();

                List <AccountSummaryTotal> sumByCurrency = new List <AccountSummaryTotal>();
                AccountSummaryTotal        accountSummaryTotal;
                decimal diffAmount;
                foreach (var item in grouped)
                {
                    accountSummaryTotal = new AccountSummaryTotal();
                    accountSummaryTotal.CurrencySign = item.Currency;
                    diffAmount = item.DebitSum - item.CreditSum;
                    if (diffAmount > 0)
                    {
                        accountSummaryTotal.DebitAmout = diffAmount;
                    }
                    else
                    {
                        accountSummaryTotal.CreditAmount = diffAmount * -1;
                    }

                    sumByCurrency.Add(accountSummaryTotal);
                }

                accountSummary.TotalByCurrency = sumByCurrency;
            }

            return(accountSummary);
        }
Beispiel #2
0
        /// <summary>
        /// Get Account Summary contains totals grouped by currency for specific account number
        /// Used to fill summary table at page top
        /// </summary>
        /// <param name="accId"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <returns></returns>
        public static AccountSummary GetAccSummaryByAccId(string accId, string fromDate = null, string toDate = null)
        {
            ReportsAccountingEntities db         = new ReportsAccountingEntities();
            AccountSummary            accSummary = new AccountSummary();
            var spResult = db.GetAccountDetailsByAccId(accId, fromDate == "" ? null : fromDate, toDate == "" ? null : toDate).ToList();

            if (spResult.Count > 0)
            {
                accSummary.AccountNameEn = spResult.FirstOrDefault().AccountNameEn;
                accSummary.AccountNameAr = spResult.FirstOrDefault().AccountNameAr;
                accSummary.DiffAmount    = accSummary.DebitAmout - accSummary.CreditAmount;

                var grouped = spResult.GroupBy(x => x.CurrencySign)
                              .Select(x => new
                {
                    Currency  = x.Key,
                    DebitSum  = x.Sum(y => y.DebitAmount),
                    CreditSum = x.Sum(y => y.CreditAmount)
                }).ToList();

                List <AccountSummaryTotal> sumByCurrency = new List <AccountSummaryTotal>();
                AccountSummaryTotal        accountSummaryTotal;
                decimal diffAmount;
                foreach (var item in grouped)
                {
                    accountSummaryTotal = new AccountSummaryTotal();
                    accountSummaryTotal.CurrencySign = item.Currency;
                    diffAmount = item.DebitSum - item.CreditSum;
                    if (diffAmount > 0)
                    {
                        accountSummaryTotal.DebitAmout = diffAmount;
                    }
                    else
                    {
                        accountSummaryTotal.CreditAmount = diffAmount * -1;
                    }

                    sumByCurrency.Add(accountSummaryTotal);
                }

                accSummary.TotalByCurrency = sumByCurrency;
            }

            return(accSummary);
        }