public ActionResult JournalEntry(long? HeaderId)
        {
            LoadAccountHeadList(0);
            LoadJournalBookList(0);
            //LoadAccountBookList(0);
            //var accJournalBookAccHeadId = db.GeneralSettings.FirstOrDefault().PurchaseJournalId;
            //var accBook = db.AccountBooks.Include(x => x.AccountBookTypeId).Where(x => x.AccountBookType.UniqueName.Equals("Journal", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            sdtoViewAccJournalEntry obj = new sdtoViewAccJournalEntry() { Date = DateTime.Now };
            obj.Details.Add(new sdtoViewAccJournalEntryDetails() { });

            if (HeaderId != null && HeaderId.Value > 0)
            {
                var header = db.JournalHeader.Find(HeaderId);
                if (header != null)
                {
                    obj = new sdtoViewAccJournalEntry()
                    {
                        Balance = header.VoucherTotal,
                        Book = new sdtoAccountBook() { AccountBookId = header.BookId },
                        Date = header.TransDate.Value,
                        HeaderId = HeaderId.Value,
                        PreviousVoucherTotal = header.VoucherTotal,
                        Voucher = header.VoucherNo
                    };

                    var headerSubList = db.JournalDetails.Where(x => x.IsDeleted == false && x.JournalId == obj.HeaderId);
                    if (headerSubList != null)
                    {
                        foreach (sdtoJournalDetails dtl in headerSubList)
                        {
                            obj.Details.Add(new sdtoViewAccJournalEntryDetails()
                            {
                                AccountHeadId = dtl.AccountId,
                                DebitAmount = -1 * dtl.DrAmount,
                                CreditAmount = -1 * dtl.CrAmount,
                                Narration = dtl.Narration
                            });
                        }
                    }
                }
            }

            return View(obj);
        }
        public ActionResult JournalEntry(sdtoViewAccJournalEntry objCashReceiptPayment)
        {
            if (objCashReceiptPayment.SourceClick == 0)
                objCashReceiptPayment.Details.Add(new sdtoViewAccJournalEntryDetails());
            else
            {
                if (ModelState.IsValid)
                {
                    var cr = objCashReceiptPayment.Details.Sum(x => x.CreditAmount);
                    var dr = objCashReceiptPayment.Details.Sum(x => x.CreditAmount);

                    if (dr + (-1 * cr) > 0)
                        ModelState.AddModelError("", "The voucher credit total and debit total does not balance.");
                    else
                    {

                        bfTransaction objTransaction = new bfTransaction(db);
                        if (objCashReceiptPayment.HeaderId > 0)
                            objTransaction.CancelJournalAccountHeader(objCashReceiptPayment.HeaderId);

                        objTransaction.AddJournalEntry(objCashReceiptPayment);
                        return RedirectToAction("ListJournalEntry");
                    }
                }
            }
            LoadAccountHeadList(0);
            LoadJournalBookList(objCashReceiptPayment.Book != null ? objCashReceiptPayment.Book.AccountBookId : 0);

            return View(objCashReceiptPayment);
        }
Exemplo n.º 3
0
        public bool AddJournalEntry(sdtoViewAccJournalEntry objJournalEntry)
        {
            sdtoUser user = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            var accBankBook = AppDb.AccountBooks.Where(x => x.AccountBookId == objJournalEntry.Book.AccountBookId).FirstOrDefault();
            if (accBankBook != null)
            {
                sdtoJournalHeader hdrCashReceiptPayment = new sdtoJournalHeader()
                {
                    BookId = accBankBook.AccountBookId,
                    Cancelled = 0,
                    CreatedOn = DateTime.Now,
                    CreatedBy = user.UserID,
                    FinancialYearId = 1,
                    FromModule = 0,
                    IsDeleted = false,
                    TransDate = objJournalEntry.Date,
                    VoucherNo = objJournalEntry.Voucher,
                    VoucherTotal = Convert.ToDecimal((-1 * objJournalEntry.Details.Sum(x => x.CreditAmount)) + objJournalEntry.Details.Sum(x => x.DebitAmount))
                };

                AppDb.JournalHeader.Add(hdrCashReceiptPayment);
                AppDb.SaveChanges();

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

                foreach (sdtoViewAccJournalEntryDetails dtl in objJournalEntry.Details)
                {
                    sdtoJournalDetails bankDepositDtlCr = new sdtoJournalDetails()
                    {
                        JournalId = hdrCashReceiptPayment.Id,
                        AccountId = dtl.AccountHeadId,
                        Narration = dtl.Narration,
                        CrAmount = dtl.CreditAmount,
                        DrAmount = dtl.DebitAmount,
                        CreatedBy = user.UserID,
                        CreatedOn = DateTime.Now,
                        IsDeleted = false
                    };

                    UpdateClosingBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, Convert.ToDecimal(bankDepositDtlCr.CrAmount + bankDepositDtlCr.DrAmount));
                    UpdateDayBookBalance(bankDepositDtlCr.AccountId, CurrentUser.UserSession.FinancialYearId.Value, objJournalEntry.Date, Convert.ToDecimal(bankDepositDtlCr.CrAmount + bankDepositDtlCr.DrAmount), TransactionType.JournalEntry);
                    AppDb.JournalDetails.Add(bankDepositDtlCr);
                }

                AppDb.SaveChanges();

                return true;
            }

            return false;
        }