public ActionResult CashReceipt(long? HeaderId) { var cashBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Cash", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); LoadAccountHeadList(0); LoadAccountBookList(0, cashBookType.AccountBookTypeId); sdtoViewAccCashReceiptPayment obj = new sdtoViewAccCashReceiptPayment() { Date = DateTime.Now }; obj.Details.Add(new sdtoViewAccCashReceiptPaymentDetails() { }); if (HeaderId != null && HeaderId.Value > 0) { var header = db.ReceiptHeader.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 sdtoViewAccCashReceiptPayment() { 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.ReceiptDetails.Where(x => x.IsDeleted == false && x.ReceiptsId == obj.HeaderId); if (headerSubList != null) { foreach (sdtoReceiptDetails dtl in headerSubList) { if (dtl.Display == 1) obj.Details.Add(new sdtoViewAccCashReceiptPaymentDetails() { AccountHeadId = dtl.AccountId, Amount = -1 * dtl.Amount, Narration = dtl.Narration }); } } } } return View(obj); }
public ActionResult CashReceipt(sdtoViewAccCashReceiptPayment objCashReceiptPayment) { if (objCashReceiptPayment.SourceClick == 0) objCashReceiptPayment.Details.Add(new sdtoViewAccCashReceiptPaymentDetails()); else { if (ModelState.IsValid) { bfTransaction objTransaction = new bfTransaction(db); if (objCashReceiptPayment.HeaderId > 0) objTransaction.CancelCashAccountHeader(objCashReceiptPayment.HeaderId); objTransaction.AddCashReceipt(objCashReceiptPayment); return RedirectToAction("ListCashReceiptPayment"); } } var cashBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Cash", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); LoadAccountHeadList(0); LoadAccountBookList(objCashReceiptPayment.Book != null ? objCashReceiptPayment.Book.AccountBookId : 0, cashBookType.AccountBookTypeId); return View(objCashReceiptPayment); }
public bool AddCashReceipt(sdtoViewAccCashReceiptPayment objCashReceiptPayment) { var accBankBook = AppDb.AccountBooks.Where(x => x.AccountBookId == objCashReceiptPayment.Book.AccountBookId).FirstOrDefault(); if (accBankBook != null) { sdtoReceiptHeader hdrBankDeposit = new sdtoReceiptHeader() { BookId = accBankBook.AccountBookId, Cancelled = 0, CreatedOn = DateTime.Now, CreatedBy = CurrentUser.UserID, TransDate = objCashReceiptPayment.Date, FinancialYearId = CurrentUser.UserSession.FinancialYearId.Value, FromModule = 0, IsDeleted = false, //VoucherNo = objCashReceiptPayment.Voucher, VoucherTotal = objCashReceiptPayment.Details.Sum(x => x.Amount), Transaction = TransactionType.CashReceipt, TransType = ReceiptType.Receipt }; AppDb.ReceiptHeader.Add(hdrBankDeposit); AppDb.SaveChanges(); hdrBankDeposit.VoucherNo = accBankBook.ReceiptVoucherPrefix + hdrBankDeposit.Id + accBankBook.ReceiptVoucherSuffix; AppDb.Entry(hdrBankDeposit).State = EntityState.Modified; AppDb.SaveChanges(); foreach (sdtoViewAccCashReceiptPaymentDetails dtl in objCashReceiptPayment.Details) { sdtoReceiptDetails bankDepositDtlCr = new sdtoReceiptDetails() { ReceiptsId = hdrBankDeposit.Id, AccountId = dtl.AccountHeadId, Narration = dtl.Narration, Amount = -1 * dtl.Amount, CreatedBy = CurrentUser.UserID, CreatedOn = DateTime.Now, Display = 1, IsDeleted = false, }; UpdateClosingBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, bankDepositDtlCr.Amount); UpdateDayBookBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, objCashReceiptPayment.Date, bankDepositDtlCr.Amount, TransactionType.CashReceipt); AppDb.ReceiptDetails.Add(bankDepositDtlCr); } sdtoReceiptDetails bankDepositDtlDb = new sdtoReceiptDetails() { ReceiptsId = hdrBankDeposit.Id, AccountId = accBankBook.AccountHeadId.Value, Narration = "Cash Receipt - " + hdrBankDeposit.VoucherNo, Amount = objCashReceiptPayment.Details.Sum(x => x.Amount), CreatedBy = CurrentUser.UserID, CreatedOn = DateTime.Now, Display = 0, IsDeleted = false }; UpdateClosingBalance(bankDepositDtlDb.AccountId, CurrentUser.UserSession.FinancialYearId.Value, bankDepositDtlDb.Amount); UpdateDayBookBalance(bankDepositDtlDb.AccountId, CurrentUser.UserSession.FinancialYearId.Value, objCashReceiptPayment.Date, bankDepositDtlDb.Amount, TransactionType.CashReceipt); AppDb.ReceiptDetails.Add(bankDepositDtlDb); AppDb.SaveChanges(); } return true; }