public ActionResult BankDeposit(sdtoViewAccDepositWithdrawal objDepositWithdrawal)
        {
            if (objDepositWithdrawal.SourceClick == 0)
                objDepositWithdrawal.Details.Add(new sdtoViewAccDepositWithdrawalDetails());
            else
            {
                if (ModelState.IsValid)
                {
                    bfTransaction objTransaction = new bfTransaction(db);
                    objTransaction.AddBankDeposit(objDepositWithdrawal);

                    if (objDepositWithdrawal.HeaderId > 0)
                        objTransaction.CancelBankAccountHeader(objDepositWithdrawal.HeaderId);

                    return RedirectToAction("ListBankDepositWithdrawal");
                }
            }

            var bankBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Bank", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            LoadAccountHeadList(0);
            LoadAccountBookList(objDepositWithdrawal.Book != null ? objDepositWithdrawal.Book.AccountBookId : 0, bankBookType.AccountBookTypeId);

            return View(objDepositWithdrawal);
        }
        public ActionResult BankDeposit(long? HeaderId)
        {
            var bankBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Bank", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            LoadAccountHeadList(0);
            LoadAccountBookList(0, bankBookType.AccountBookTypeId);
            sdtoViewAccDepositWithdrawal obj = new sdtoViewAccDepositWithdrawal() { Date = DateTime.Now };
            obj.Details.Add(new sdtoViewAccDepositWithdrawalDetails() { InstrumentDate = DateTime.Now });

            if (HeaderId != null && HeaderId.Value > 0)
            {
                var header = db.BankDepositHeader.Find(HeaderId);
                if (header != null)
                {
                    var accountBook = db.AccountBooks.Find(header.BookId);
                    var openingBalance = db.OpeningBalance.Where(x => x.AccountHeadId == accountBook.AccountHeadId).FirstOrDefault();

                    obj = new sdtoViewAccDepositWithdrawal()
                    {
                        VoucherTotal = header.VoucherTotal,
                        Book = new sdtoAccountBook() { AccountBookId = header.BookId },
                        Date = header.TransDate,
                        HeaderId = HeaderId.Value,
                        PreviousVoucherTotal = header.VoucherTotal,
                        Voucher = header.VoucherNo,
                        Balance = openingBalance == null ? 0 : openingBalance.ClosingBalance
                    };

                    var headerSubList = db.BankDepositDetails.Where(x => x.IsDeleted == false && x.BankDepositId == obj.HeaderId);
                    if (headerSubList != null)
                    {
                        foreach (sdtoBankDepositDetails dtl in headerSubList)
                        {
                            obj.Details.Add(new sdtoViewAccDepositWithdrawalDetails()
                            {
                                AccountHeadId = dtl.AccountId,
                                Amount = -1 * dtl.Amount,
                                Narration = dtl.Narration
                            });
                        }
                    }
                }
            }

            return View(obj);
        }
 public ActionResult DepositWithdrawalSave(sdtoViewAccDepositWithdrawal DepositWithdrawal)
 {
     LoadAccountHeadList(0);
     LoadAccountBookList(DepositWithdrawal != null && DepositWithdrawal.Book != null ? DepositWithdrawal.Book.AccountBookId : 0, 0);
     return View(DepositWithdrawal);
 }
        public ActionResult DepositWithdrawalNewRow(sdtoViewAccDepositWithdrawal objDepositWithdrawal)
        {
            objDepositWithdrawal.Details.Add(new sdtoViewAccDepositWithdrawalDetails());
            //if (TempData["PrevItems"] == null)
            //{
            //    TempData["PrevItems"] = objDepositWithdrawal.Details;
            //}
            //else
            //{
            //    List<sdtoViewAccDepositWithdrawalDetails> tempList = TempData["PrevItems"] as List<sdtoViewAccDepositWithdrawalDetails>;
            //    foreach (sdtoViewAccDepositWithdrawalDetails dtl in tempList)
            //    {
            //        objDepositWithdrawal.Details.Add(dtl);
            //    }
            //    objDepositWithdrawal.Details.Add(new sdtoViewAccDepositWithdrawalDetails());
            //    TempData["PrevItems"] = objDepositWithdrawal.Details;
            //}
            LoadAccountHeadList(0);
            LoadAccountBookList(objDepositWithdrawal.Book != null ? objDepositWithdrawal.Book.AccountBookId : 0, 0);

            return View(objDepositWithdrawal);
        }
Exemplo n.º 5
0
        public bool AddBankDeposit(sdtoViewAccDepositWithdrawal objDepositWithdrawal)
        {
            var accBankBook = AppDb.AccountBooks.Where(x => x.AccountBookId == objDepositWithdrawal.Book.AccountBookId).FirstOrDefault();
            if (accBankBook != null)
            {
                sdtoBankDepositHeader hdrBankDeposit = new sdtoBankDepositHeader()
                {
                    BookId = objDepositWithdrawal.Book.AccountBookId,
                    Cancelled = 0,
                    CreatedOn = DateTime.Now,
                    CreatedBy = CurrentUser.UserID,
                    TransDate = objDepositWithdrawal.Date,
                    FinYear = 1,
                    FromModule = 0,
                    IsDeleted = false,
                    VoucherNo = objDepositWithdrawal.Voucher,
                    VoucherTotal = objDepositWithdrawal.VoucherTotal
                };

                AppDb.BankDepositHeader.Add(hdrBankDeposit);
                AppDb.SaveChanges();

                hdrBankDeposit.VoucherNo = accBankBook.ReceiptVoucherPrefix + hdrBankDeposit.Id + accBankBook.ReceiptVoucherSuffix;
                AppDb.Entry(hdrBankDeposit).State = EntityState.Modified;
                AppDb.SaveChanges();

                foreach (sdtoViewAccDepositWithdrawalDetails dtl in objDepositWithdrawal.Details)
                {
                    sdtoBankDepositDetails bankDepositDtlCr = new sdtoBankDepositDetails()
                    {
                        BankDepositId = hdrBankDeposit.Id,
                        AccountId = dtl.AccountHeadId,
                        Narration = dtl.Narration,
                        Amount = -1 * dtl.Amount,
                        CreatedBy = CurrentUser.UserID,
                        CreatedOn = DateTime.Now,
                        Display = 1,
                        IsDeleted = false,
                        Instrument = dtl.InstrumentType,
                        InstrumentNo = dtl.InstrumentNo
                    };

                    if (dtl.InstrumentDate != DateTime.MinValue)
                        bankDepositDtlCr.InstrumentDate = dtl.InstrumentDate;

                    UpdateClosingBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, Convert.ToDecimal(bankDepositDtlCr.Amount));
                    UpdateDayBookBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, objDepositWithdrawal.Date, Convert.ToDecimal(bankDepositDtlCr.Amount), TransactionType.BankDeposit);
                    AppDb.BankDepositDetails.Add(bankDepositDtlCr);
                }
                AppDb.SaveChanges();

                sdtoBankDepositDetails bankDepositDtlDb = new sdtoBankDepositDetails()
                {
                    BankDepositId = hdrBankDeposit.Id,
                    AccountId = accBankBook.AccountHeadId.Value,
                    Narration = "Bank deposit/withdrawal",
                    Amount = objDepositWithdrawal.Details.Sum(x => x.Amount),
                    CreatedBy = CurrentUser.UserID,
                    CreatedOn = DateTime.Now,
                    Display = 0,
                    IsDeleted = false,
                    Instrument = objDepositWithdrawal.Details.FirstOrDefault().InstrumentType,
                    InstrumentNo = objDepositWithdrawal.Details.FirstOrDefault().InstrumentNo,
                    InstrumentDate = objDepositWithdrawal.Details.FirstOrDefault().InstrumentDate
                };

                UpdateClosingBalance(bankDepositDtlDb.AccountId, CurrentUser.UserSession.FinancialYearId.Value, Convert.ToDecimal(bankDepositDtlDb.Amount));
                AppDb.BankDepositDetails.Add(bankDepositDtlDb);
                AppDb.SaveChanges();

                return true;
            }
            else
                return false;
        }