public JsonResult getBillByDate(string bdate)
        {
            //var bdate2=Convert.ToDateTime(bdate);
            using (LundryDbContext db = new LundryDbContext())
            {
                String format = "dd/MM/yyyy";
                // var dd = DateTime.Today.ToString("dd/MM/yyyy");
                DateTime dte = DateTime.ParseExact(bdate, format, System.Globalization.CultureInfo.InvariantCulture);

                bool pb = db.Bills.Where(x => x.Date.Equals(dte)).Any();

                if (!pb == false)
                {
                    var getBdetails = (from b in db.Bills
                                       where b.Date == dte
                                       join c in db.Customers on b.CustId equals c.CustId
                                       join p in db.paidbills on b.BillNo equals p.BillNo
                                       group new { b, c, p } by new { b.BillNo } into bg
                                       select new BillViewData
                    {
                        TransId = bg.FirstOrDefault().b.TransId,
                        CustId = bg.FirstOrDefault().c.CustId,
                        CustName = bg.FirstOrDefault().c.CustName,
                        Date = bg.FirstOrDefault().b.Date,
                        Qyt = bg.FirstOrDefault().b.Qyt,
                        Cost = bg.Sum(x => x.b.Cost),
                        BillNo = bg.FirstOrDefault().b.BillNo,
                        IsPaid = bg.FirstOrDefault().p.IsPaid
                    });
                    return(Json(getBdetails, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { message = "Sorry No Data Found!" }, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
 //TODO: Check to see of there is a bill has the same bill no-----------------------------------
 public bool IsBillExist(int billno)
 {
     using (LundryDbContext db = new LundryDbContext())
     {
         return(db.paidbills.Where(x => x.BillNo.Equals(billno)).Any()); // the Any() checks at least for one match and it return true if it found one, or false if it not
     }
 }
        public JsonResult getBill(int BNO)
        {
            using (LundryDbContext db = new LundryDbContext())
            {
                bool pb = db.paidbills.Where(x => x.BillNo.Equals(BNO)).Any();

                if (!pb == false)
                {
                    var getBdetails = (from b in db.Bills
                                       where b.BillNo == BNO
                                       join c in db.Customers on b.CustId equals c.CustId
                                       join p in db.paidbills on b.BillNo equals p.BillNo
                                       group new { b, c, p } by new { b.BillNo } into bg
                                       select new BillViewData
                    {
                        TransId = bg.FirstOrDefault().b.TransId,
                        CustId = bg.FirstOrDefault().c.CustId,
                        CustName = bg.FirstOrDefault().c.CustName,
                        Date = bg.FirstOrDefault().b.Date,
                        Qyt = bg.FirstOrDefault().b.Qyt,
                        Cost = bg.Sum(x => x.b.Cost),
                        BillNo = bg.FirstOrDefault().b.BillNo,
                        IsPaid = bg.FirstOrDefault().p.IsPaid
                    }).ToList();
                    return(Json(getBdetails, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { message = "Sorry No Data Found!" }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult getItemCosts(int id)
        {
            LundryDbContext db         = new LundryDbContext();
            var             getItmCost = db.Items.Where(x => x.ItemId == id).FirstOrDefault();

            return(new JsonResult {
                Data = getItmCost, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #5
0
        //TODO: Add new Bill----------------------------------------------------------------
        public void AddNewBill(AddNewBill bdv)
        {
            //hear we are going to get the max no form YearMaxBillNo., why we do that because that no will be used to form the finall bill no.
            int maxNo = 0;

            using (LundryDbContext db = new LundryDbContext())
            {
                if (checkDates()) //if the current date is less than the end date which is the last day in the year e.g (31/12/2016)
                {
                    //TODO: if result is true...get max from the current year;
                    var getCYear = DateTime.Now.Year.ToString();
                    maxNo = getMaxBillNo(getCYear); //get the max bill no depending on the year from table yearmaxbillnoes
                    AddBill(maxNo);                 //calling the method AddBill to add the new bill to the database

                    //update the YearMaxBillNoes by adding the new max bill no to the year

                    int getCount = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).Count();

                    if (getCount > 0) // check to see if we are not at the begining of the year
                    {
                        YearMaxBillNo yrbl = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).FirstOrDefault();
                        yrbl.maxbillno = (maxNo + 1);
                        db.SaveChanges();
                    }
                    else
                    {
                        YearMaxBillNo yrbl = new YearMaxBillNo();
                        yrbl.year      = getCYear;
                        yrbl.maxbillno = 1;
                        db.yearmaxbillno.Add(yrbl);
                        db.SaveChanges();
                    }
                }
                else
                {
                    //TODO: if result is true...get max from the current year;
                    var getCYear = DateTime.Now.Year.ToString();
                    maxNo = getMaxBillNo(getCYear); //get the max bill no depending on the year from table yearmaxbillnoes
                    AddBill(maxNo);                 //calling the method AddBill to add the new bill to the database

                    //update the YearMaxBillNoes by adding the new max bill no to the year
                    YearMaxBillNo yrbl = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).FirstOrDefault();
                    if (string.IsNullOrEmpty(yrbl.year))
                    {
                        yrbl.maxbillno = maxNo + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        yrbl.year      = getCYear;
                        yrbl.maxbillno = 1;
                        db.SaveChanges();
                    }
                }
            }
        }
 //TODO: Add New MainCategory
 public void AddNewMainCat(AddNewMainCategory itMaCa)
 {
     using (LundryDbContext db = new LundryDbContext())
     {
         ItemMainCategory mainCat = new ItemMainCategory();
         mainCat.catName = itMaCa.catName;
         db.ItemMainCategories.Add(mainCat);
         db.SaveChanges();
     }
 }
Example #7
0
        public ActionResult OnDemand()
        {
            List <ItemMainCategory> all = new List <ItemMainCategory>();

            using (LundryDbContext db = new LundryDbContext())
            {
                all = db.ItemMainCategories.OrderBy(a => a.Id).ToList();
            }
            return(View(all));
        }
Example #8
0
        //Gere
        public ActionResult Report(string id)
        {
            LocalReport lr   = new LocalReport();
            string      path = Path.Combine(Server.MapPath("~/Report"), "Report1.rdlc");

            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }
            else
            {
                return(View("Index"));
            }
            List <Bill> cm = new List <Bill>();

            using (LundryDbContext dc = new LundryDbContext())
            {
                cm = dc.Bills.ToList();
            }
            ReportDataSource rd = new ReportDataSource("DataSet1", cm);

            lr.DataSources.Add(rd);
            string reportType = id;
            string mimeType;
            string encoding;
            string fileNameExtension;



            string deviceInfo =

                "<DeviceInfo>" +
                "  <OutputFormat>" + id + "</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>11in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>1in</MarginLeft>" +
                "  <MarginRight>1in</MarginRight>" +
                "  <MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";

            Warning[] warnings;
            string[]  streams;
            byte[]    renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            return(File(renderedBytes, mimeType));
        }
Example #9
0
        //TODO: Disable all the Discount.This may used in case we choosed discount fro All Branche, and we need to make all other discound in active
        public void DisableAll()
        {
            using (var db = new LundryDbContext())
            {
                db.Discs
                .Where(x => x.status == true)
                .ToList()
                .ForEach(a => a.status = false);

                db.SaveChanges();
            }
            //var disall = db.Discs.Where(x => x.status == true).ToList().ForEach(x=>x.status= false);
        }
 //TODO: Check to see if the Main Category is added before
 public bool isMainCateogryExists(string catname)
 {
     using (LundryDbContext db = new LundryDbContext())
     {
         bool getCat = db.ItemMainCategories.Where(x => x.catName.Equals(catname)).Any();
         if (getCat == true)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #11
0
        public JsonResult GetSubMenu2(string pid)
        {
            LundryDbContext db = new LundryDbContext();
            // this action for Get Sub Menus from database and return as json data
            //System.Threading.Thread.Sleep(1000);
            //List<Item> subMenus = new List<Item>();
            int pID = 0;

            int.TryParse(pid, out pID);
            var getItem = db.Items.Where(x => x.SId == pID).ToList();

            //subMenus = db.Items.Where(a => a.Equals(pID)).OrderBy(a => a.ItemName).ToList();


            return(new JsonResult {
                Data = getItem, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #12
0
        public void AddBill(int maxBillNo)
        {
            using (LundryDbContext db = new LundryDbContext())
            {
                var getCYear = DateTime.Now.Year.ToString();//get current year
                getCYear = getCYear.Substring(2);
                Bill     bl  = new Bill();
                paidbill pbl = new paidbill();
                //here am searching inside the temp table to get all the items qyt and price, which were perviouslly added before saving the whole bill details
                var orr = (from s in db.tempBills
                           select s).ToList();

                foreach (var itm in orr)
                {
                    bl.ItemId = itm.ItemId;
                    bl.CustId = itm.CustId;
                    bl.Qyt    = itm.Qyt;
                    bl.Cost   = itm.Cost;
                    String   format      = "dd/MM/yyyy";
                    var      currentDate = DateTime.Today.ToString("dd/MM/yyyy");
                    DateTime dt          = DateTime.ParseExact(currentDate.ToString(), format, System.Globalization.CultureInfo.InvariantCulture);
                    //  DateTime dte = DateTime.ParseExact(dd, format, CultureInfo.InvariantCulture);
                    bl.Date        = dt;
                    bl.BillNo      = maxBillNo + 1;
                    bl.printedBill = "(0" + SessionPersister.BranchID + ")" + (getCYear + (maxBillNo + 1)).ToString().PadLeft(5, '0'); // this is the bill no which will be printed

                    db.Bills.Add(bl);
                    db.SaveChanges();
                }
                //Here we are going to remove all the items from the tempBills table
                foreach (var itm in orr)
                {
                    db.tempBills.Remove(itm);
                }
                // now we are going to add the new entered bill inot the paidbill tables, and makred it unpaid
                pbl.BillNo      = maxBillNo + 1;
                pbl.printedBill = "(0" + SessionPersister.BranchID + ")" + (getCYear + (maxBillNo + 1)).ToString().PadLeft(5, '0'); // this is the bill no which will be printed
                pbl.IsPaid      = false;

                db.paidbills.Add(pbl);
                db.SaveChanges();
                SessionPersister.printBillNo = "(0" + SessionPersister.BranchID + ")" + (getCYear + (maxBillNo + 1)).ToString().PadLeft(5, '0');
            }
        }
Example #13
0
        //Get the Maximum bill Nol---------------------------------------------------------------------------
        public int getMaxBillNo(string yr)
        {
            int maxBNo = 0;

            using (LundryDbContext db = new LundryDbContext())
            {
                // get the maximum no for yearmaxbillno
                //This is add 0 if the result of sum is null, because if there is no previous bill added before, then the result of the sum is null to prevent that we add 0
                int getCount = db.yearmaxbillno.Where(x => x.year.Equals(yr)).Select(x => new { maxbillno = x.maxbillno }).Count();
                if (getCount > 0)
                {
                    maxBNo = db.yearmaxbillno.Where(x => x.year.Equals(yr)).Select(x => new { maxbillno = x.maxbillno }).FirstOrDefault().maxbillno;
                }
                else
                {
                    maxBNo = 0;
                }
                return(maxBNo);
            }
        }