public PettyCashOpenCloseBalance GetOpeningClosingBalance(DateTime fromDate, DateTime toDate)
        {
            try
            {
                DateTime temporaryDate = toDate.AddDays(1);

                List <PettyCash> query = (from Record in DbContext.PettyCashes.AsNoTracking()
                                          where !Record.IsDeleted
                                          orderby Record.TransactionDate ascending
                                          where (DbFunctions.TruncateTime(Record.TransactionDate) <= DbFunctions.TruncateTime(temporaryDate))
                                          select Record).ToList();

                decimal debitedAmount  = query.Where(a => a.TransactionType.Equals("Credit") && a.TransactionDate.Date < fromDate.Date).Select(x => x.Amount).Sum();
                decimal creditedAmount = query.Where(a => a.TransactionType.Equals("Debit") && a.TransactionDate.Date < fromDate.Date).Select(x => x.Amount).Sum();

                PettyCashOpenCloseBalance openCloseBalance = new PettyCashOpenCloseBalance();
                openCloseBalance.OpeningBalance = creditedAmount - debitedAmount;


                creditedAmount = query.Where(a => a.TransactionType.Equals("Debit") && a.TransactionDate.Date >= fromDate.Date && a.TransactionDate.Date <= toDate.Date).Select(x => x.Amount).Sum();
                debitedAmount  = query.Where(a => a.TransactionType.Equals("Credit") && a.TransactionDate.Date >= fromDate.Date && a.TransactionDate.Date <= toDate.Date).Select(x => x.Amount).Sum();

                openCloseBalance.ClosingBalance = openCloseBalance.OpeningBalance - debitedAmount + creditedAmount;

                return(openCloseBalance);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(null);
            }
        }
Пример #2
0
        public JsonResult GetOpeningClosingBalance(string fromDate, string toDate)
        {
            try
            {
                DateTime frdate = DateTime.Now;
                if (!string.IsNullOrWhiteSpace(fromDate))
                {
                    frdate = DateTime.Parse(fromDate);
                }

                DateTime tdate = DateTime.Now;
                if (!string.IsNullOrWhiteSpace(toDate))
                {
                    tdate = DateTime.Parse(toDate);
                }

                logger.DebugFormat("Getting Opening Closing Balance in Petty Cash with From Date [{0}] and To Ddate [{1}]", frdate.ToShortDateString(), tdate.ToShortDateString());


                PettyCashOpenCloseBalance pettyCashOpenCloseBalance = pettyCashManagement.GetOpeningClosingBalance(frdate, tdate);

                logger.DebugFormat("Successfully Retrieve  Opening Closing Balance From Date [{0}] and To Ddate [{1}] Opening Balance [{2}] Closing Balance [{2}]", frdate.ToShortDateString(), tdate.ToShortDateString(), pettyCashOpenCloseBalance.OpeningBalance, pettyCashOpenCloseBalance.ClosingBalance);

                return(Json(pettyCashOpenCloseBalance));
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(null);
            }
        }