public int DeleteConfirmDetail(int id)
        {
            Session["err"] = "Error, Can't Delete, Please check Dependency Data";
            Session["msg"] = "";
            int postdatedchequeid = 0;
            PostDatedChequeDetail postdatedchequedetail = db.PostDatedChequeDetails.Find(id);

            try
            {
                postdatedchequeid = postdatedchequedetail.PostDatedChequeID;
                db.PostDatedChequeDetails.Remove(postdatedchequedetail);
                db.SaveChanges();
                decimal totalamtfinal = 0;
                try
                {
                    totalamtfinal = db.PostDatedChequeDetails.Where(u => u.PostDatedChequeID == postdatedchequeid).Sum(u => (decimal)u.Amount);
                    PostDatedCheque postdatedcheque = db.PostDatedCheques.Find(postdatedchequeid);
                    postdatedcheque.TotalAmount     = decimal.Round(Convert.ToDecimal(totalamtfinal.ToString("#.##")), 2, MidpointRounding.AwayFromZero);
                    db.Entry(postdatedcheque).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch { }
                Session["err"] = "";
                Session["msg"] = "Deleted Successfully";
            }
            catch { }
            return(postdatedchequeid);
        }
        public ActionResult Edit(int id)
        {
            var postdatedcheque       = db.PostDatedCheques.Where(b => b.PostDatedChequeID == id).ToList();
            var postdatedchequedetail = db.PostDatedChequeDetails.Where(b => b.PostDatedChequeID == id).ToList();

            if (postdatedchequedetail.Count == 0)
            {
                PostDatedChequeDetail postdatedchequedetail1 = new PostDatedChequeDetail();
                postdatedchequedetail1.PostDatedChequeID = id;
                postdatedchequedetail1.ReceivedFromID    = 1;
                postdatedchequedetail1.AccountHeadID     = 1;
                postdatedchequedetail1.Amount            = 0.00M;
                postdatedchequedetail1.Remarks           = "";
                db.PostDatedChequeDetails.Add(postdatedchequedetail1);
                db.SaveChanges();
                postdatedchequedetail = db.PostDatedChequeDetails.Where(b => b.PostDatedChequeID == id).ToList();
            }
            PostDatedChequePostDatedChequeDetailPostDatedChequeDetailAllocationModel multiModel = new PostDatedChequePostDatedChequeDetailPostDatedChequeDetailAllocationModel();

            multiModel.PostDatedCheques       = postdatedcheque;
            multiModel.PostDatedChequeDetails = postdatedchequedetail;

            ViewBag.AccountHeads = db.AccountHeads.OrderBy(a => a.Name);
            ViewBag.VoucherTypes = db.VoucherTypes;
            ViewBag.Banks        = db.Banks;

            ViewBag.Message = Session["msg"];
            ViewBag.Error   = Session["err"];
            Session["err"]  = "";
            Session["msg"]  = "";
            return(View(multiModel));
        }
        public ActionResult Create()
        {
            PostDatedCheque postdatedcheque = new PostDatedCheque();

            postdatedcheque.VoucherNo       = "PDCR-";
            postdatedcheque.TransactionDate = DateTime.Now;
            postdatedcheque.VoucherTypeID   = 1;
            postdatedcheque.BankID          = 1;
            postdatedcheque.PayersBank      = "";
            postdatedcheque.ChequeNo        = "";
            postdatedcheque.ChequeDate      = DateTime.Now;
            postdatedcheque.TotalAmount     = 0.00M;
            postdatedcheque.Remarks         = "";
            postdatedcheque.Flag            = false;
            db.PostDatedCheques.Add(postdatedcheque);
            db.SaveChanges();
            postdatedcheque.VoucherNo       = "PDCR-" + postdatedcheque.PostDatedChequeID.ToString("D" + 6);
            db.Entry(postdatedcheque).State = EntityState.Modified;
            db.SaveChanges();

            PostDatedChequeDetail postdatedchequedetail = new PostDatedChequeDetail();

            postdatedchequedetail.PostDatedChequeID = postdatedcheque.PostDatedChequeID;
            postdatedchequedetail.ReceivedFromID    = 1;
            postdatedchequedetail.AccountHeadID     = 1;
            postdatedchequedetail.Amount            = 0.00M;
            postdatedchequedetail.Remarks           = "";
            db.PostDatedChequeDetails.Add(postdatedchequedetail);
            db.SaveChanges();

            return(RedirectToAction("Edit", new { id = postdatedcheque.PostDatedChequeID }));
        }
        public ActionResult EditPostDatedChequeDetail(List <tempPostDatedChequeDetail> postDatedChequeDetailList, List <tempPostDatedCheque> postDatedChequeList)
        {
            int postdatedchequeid = SavePostDatedCheque(postDatedChequeDetailList, postDatedChequeList);
            PostDatedChequeDetail postdatedchequedetail = new PostDatedChequeDetail();

            postdatedchequedetail.PostDatedChequeID = postdatedchequeid;
            postdatedchequedetail.ReceivedFromID    = 1;
            postdatedchequedetail.AccountHeadID     = 1;
            postdatedchequedetail.Amount            = 0.00M;
            postdatedchequedetail.Remarks           = "";
            db.PostDatedChequeDetails.Add(postdatedchequedetail);
            db.SaveChanges();
            return(RedirectToAction("Edit", "PostDatedCheque", new { id = postdatedchequeid }));
        }
        public int SavePostDatedCheque(List <tempPostDatedChequeDetail> postDatedChequeDetailList, List <tempPostDatedCheque> postDatedChequeList)
        {
            Session["err"] = "Error, Please Check Input Fields";
            Session["msg"] = "";
            int postdatedchequeid = 0;

            foreach (tempPostDatedChequeDetail t in postDatedChequeDetailList.ToList())
            {
                postdatedchequeid = t.postdatedchequeid;
                if (Convert.ToDecimal(t.amount) > 0)
                {
                    try
                    {
                        PostDatedChequeDetail postdatedchequedetail = db.PostDatedChequeDetails.Find(t.postdatedchequedetailid);
                        if (postdatedchequedetail == null)
                        {
                            PostDatedChequeDetail postdatedchequedetail1 = new PostDatedChequeDetail();
                            postdatedchequedetail1.PostDatedChequeID = t.postdatedchequeid;
                            postdatedchequedetail1.ReceivedFromID    = t.receivedfromid;
                            postdatedchequedetail1.AccountHeadID     = t.accountheadid;
                            postdatedchequedetail1.Amount            = decimal.Round(Convert.ToDecimal(t.amount.Replace(",", "")), 2, MidpointRounding.AwayFromZero);
                            postdatedchequedetail1.Remarks           = "";
                            db.PostDatedChequeDetails.Add(postdatedchequedetail1);
                            db.SaveChanges();
                        }
                        else
                        {
                            postdatedchequedetail.PostDatedChequeID = t.postdatedchequeid;
                            postdatedchequedetail.ReceivedFromID    = t.receivedfromid;
                            postdatedchequedetail.AccountHeadID     = t.accountheadid;
                            postdatedchequedetail.Amount            = decimal.Round(Convert.ToDecimal(t.amount.Replace(",", "")), 2, MidpointRounding.AwayFromZero);
                            postdatedchequedetail.Remarks           = t.remarks;
                            db.Entry(postdatedchequedetail).State   = EntityState.Modified;
                            db.SaveChanges();
                        }

                        postdatedchequeid = t.postdatedchequeid;
                    }
                    catch { }
                }
            }

            decimal totalamtfinal = 0;

            try
            {
                totalamtfinal = db.PostDatedChequeDetails.Where(u => u.PostDatedChequeID == postdatedchequeid).Sum(u => (decimal)u.Amount);
            }
            catch { }
            try
            {
                foreach (tempPostDatedCheque bv in postDatedChequeList.ToList())
                {
                    PostDatedCheque postdatedchequefinal = db.PostDatedCheques.Find(postdatedchequeid);
                    if (bv.vouchertypeid == 1)
                    {
                        postdatedchequefinal.VoucherNo = "PDCR-" + postdatedchequeid.ToString("D" + 6);
                    }
                    else
                    {
                        postdatedchequefinal.VoucherNo = "PDCP-" + postdatedchequeid.ToString("D" + 6);
                    }
                    postdatedchequefinal.TransactionDate = bv.transactiondate;
                    postdatedchequefinal.VoucherTypeID   = bv.vouchertypeid;
                    postdatedchequefinal.BankID          = bv.bankid;
                    postdatedchequefinal.PayersBank      = bv.payersbank;
                    postdatedchequefinal.ChequeNo        = bv.chequeno;
                    postdatedchequefinal.ChequeDate      = bv.chequedate;
                    postdatedchequefinal.TotalAmount     = decimal.Round(Convert.ToDecimal(totalamtfinal.ToString("#.##")), 2, MidpointRounding.AwayFromZero);
                    postdatedchequefinal.Remarks         = bv.remarks;
                    db.Entry(postdatedchequefinal).State = EntityState.Modified;
                    db.SaveChanges();
                }
                Session["msg"] = "Created Successfully";
                Session["err"] = "";
            }
            catch
            {
            }

            return(postdatedchequeid);
        }