Esempio n. 1
0
        // GET: Order
        public ActionResult Show(int?page, string OrderCode = "", string DateFrom = "", string DateTo = "", string StaffCode = "", string ProcessId = "process", string StatusId = "", string SalePlace = "", string C1Code = "")
        {
            int permit = Utitl.CheckRoleShowInfo(db, User.Identity.Name);

            int pageSize   = 30;
            int pageNumber = (page ?? 1);

            var current = DateTime.Now;

            DateTime dFrom;

            DateTime dTo;

            if (String.IsNullOrEmpty(DateFrom) || String.IsNullOrEmpty(DateTo))
            {
                dTo   = current;
                dFrom = current.AddMonths(-1);
            }
            else
            {
                dFrom = DateTime.ParseExact(DateFrom, "d/M/yyyy", null);
                dTo   = DateTime.ParseExact(DateTo, "d/MM/yyyy", null);
            }

            ViewBag.DateFrom  = dFrom.ToString("dd/MM/yyyy");
            ViewBag.DateTo    = dTo.ToString("dd/MM/yyyy");
            ViewBag.StaffCode = StaffCode;
            ViewBag.ProcessId = ProcessId;
            ViewBag.StatusId  = StatusId;
            ViewBag.SalePlace = SalePlace;
            ViewBag.C1Code    = C1Code;

            List <get_list_orders_Result> data = new List <get_list_orders_Result>();

            if (!String.IsNullOrEmpty(OrderCode))
            {
                data = db.get_list_orders_by_code("%" + OrderCode + "%").ToList();
            }
            else
            {
                data = db.get_list_orders(dFrom.ToString("yyyy-MM-dd"), dTo.ToString("yyyy-MM-dd"), "%" + ProcessId + "%", "%" + StatusId + "%", "%" + StaffCode + "%", "%" + C1Code + "%").ToList();
            }

            data = data.Where(p => p.SalePlace.Contains(SalePlace)).ToList();

            if (permit == 2)
            {
                // get list cn
                var branchPermit = db.UserBranchPermisses.Where(p => p.UserName == User.Identity.Name).Select(p => p.BranchCode).ToList();
                data = data.Where(p => branchPermit.Contains(p.BrachCode)).ToList();
            }

            return(View(data.OrderByDescending(p => p.CreateDate).ToPagedList(pageNumber, pageSize)));
        }