public JsonResult AddLinetoRecive(int HeaderId, double Amount, int rid, string HeaderText)
        {
            bool status = false;
            int  rdd    = 0;

            if (ModelState.IsValid)
            {
                //Order order = new Order { OrderNo = O.OrderNo, OrderDate = O.OrderDate, Description = O.Description };

                //
                // i.TotalAmount =
                RecieveDetail Recievedetail = new RecieveDetail();
                Recievedetail.rid      = rid;
                Recievedetail.HeaderId = HeaderId;
                Recievedetail.Amount   = Amount;
                db.RecieveDetail.Add(Recievedetail);
                db.SaveChanges();
                rdd = Recievedetail.rdid;

                status = true;
            }
            else
            {
                status = false;
            }
            return(new JsonResult {
                Data = new { status = status, rdd = rdd, amount = Amount }
            });
        }
        public async Task <ActionResult> DeleteLine(int id)
        {
            RecieveDetail Receivedetail = await db.RecieveDetail.FindAsync(id);

            db.RecieveDetail.Remove(Receivedetail);
            await db.SaveChangesAsync();

            return(RedirectToAction("Edit/" + Receivedetail.rid));
        }
        public ActionResult  Mass(FormCollection frm)
        {
            string obillid = frm["BillID"];
            string odate   = frm["edate"];

            string[] obill = obillid.Split(',');
            foreach (var obi in obill)
            {
                int bi     = Convert.ToInt32(obi);
                var billid = db.BillRegisters.Find(bi);
                if (billid != null)

                {
                    billid.paid = "Y";
                    db.SaveChanges();

                    RecieveMaster rc = new RecieveMaster();
                    rc.memberId = billid.memberId;
                    rc.rDate    = Convert.ToDateTime(odate);
                    rc.billId   = billid.BillID.ToString();
                    //rc.total = billid.total;
                    // rc.Remarks = "Mass Received";
                    rc.CMonth = billid.BillDate.Month.ToString("MMMM");
                    db.RecieveMasters.Add(rc);
                    db.SaveChanges();
                    int rid        = rc.rid;
                    var billdetail = db.Billdetail.Where(a => a.BillID == bi);
                    foreach (var bild in billdetail)
                    {
                        RecieveDetail rd = new RecieveDetail();
                        rd.rid      = rid;
                        rd.HeaderId = bild.HeaderId;
                        rd.Amount   = bild.Amount;
                        db.RecieveDetail.Add(rd);
                    }
                    db.SaveChanges();
                }
            }
            // Response.Write(billid);
            //return View();
            return(RedirectToAction("Index", "MassCollection"));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            RecieveDetail recievedetail = await db.RecieveDetail.FindAsync(id);

            if (recievedetail != null)
            {
                db.RecieveDetail.Remove(recievedetail);
            }
            RecieveMaster recieveMaster = await db.RecieveMasters.FindAsync(id);

            string billid = recieveMaster.billId.ToString();

            if (billid != "0")
            {
                if (!String.IsNullOrEmpty(billid))

                {
                    string[] obill = billid.Split(',');
                    foreach (var obi in obill)
                    {
                        int bi    = Convert.ToInt32(obi);
                        var bllid = db.BillRegisters.Find(bi);
                        if (bllid != null)

                        {
                            bllid.paid = "N";
                            db.SaveChanges();
                        }
                    }
                }
            }

            db.RecieveMasters.Remove(recieveMaster);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public JsonResult SaveOrder(RecieveVm O)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                //Order order = new Order { OrderNo = O.OrderNo, OrderDate = O.OrderDate, Description = O.Description };
                string billiid = "";
                string cmonth  = "";
                int    t       = 0;
                //foreach (var k in O.billid)
                //{
                //    if (t == 0)
                //    {
                //        billiid = k.ToString();
                //        t = 1;
                //    }
                //    else
                //        billiid += "," + k.ToString();

                //}
                // t = 0;
                foreach (var k in O.CMonth)
                {
                    if (t == 0)
                    {
                        cmonth = k.ToString();
                        t      = 1;
                    }
                    else
                    {
                        cmonth += "," + k.ToString();
                    }
                }


                RecieveMaster recievMaster = new RecieveMaster {
                    rDate = O.recivedate, Remarks = O.remarks, memberId = O.memberid, billId = billiid, CMonth = cmonth
                };
                db.RecieveMasters.Add(recievMaster);
                db.SaveChanges();
                foreach (var i in O.ReciveDetail)
                {
                    //
                    // i.TotalAmount =
                    RecieveDetail recievedetail = new RecieveDetail();
                    recievedetail.rid      = recievMaster.rid;
                    recievedetail.HeaderId = i.headerid;
                    recievedetail.Amount   = i.amount;
                    db.RecieveDetail.Add(recievedetail);
                    db.SaveChanges();
                    Session["rid"] = recievMaster.rid;
                }
                //foreach(var j in O.billid)
                //{
                //    int bi = int.Parse(j);
                //    var billid = db.BillRegisters.Find(bi);
                //    if (billid!=null)

                //    {
                //        billid.paid = "Y";
                //        db.SaveChanges();

                //    }



                //}


                status = true;
            }
            else
            {
                status = false;
            }
            var    TotalBill    = db.BillRegisters.Where(a => a.memberId == O.memberid).ToList();
            var    TotalRecive  = db.RecieveMasters.Where(a => a.memberId == O.memberid).ToList();
            double TotalBalance = TotalBill.Sum(i => i.total) - TotalRecive.Sum(i => i.total);

            return(new JsonResult {
                Data = new { status = status, balance = TotalBalance }
            });
        }