public ActionResult Authorise(string sessionId)
        {
            Employee          user        = EmployeeService.GetUserBySessionId(sessionId);
            List <AdjVoucher> adjVouchers = new List <AdjVoucher>();

            if (user.EmpRole == "STORE_SUPERVISOR")
            {
                adjVouchers = AdjVoucherService.GetAdjByStatus(2);
            }
            else if (user.EmpRole == "STORE_MANAGER")
            {
                adjVouchers = AdjVoucherService.GetAdjByStatus(3);
            }
            else
            {
                ViewData["sessionId"] = sessionId;
                return(View("NotAuthorised", "Home"));
            }

            long adjId = 0;

            foreach (AdjVoucher adj in adjVouchers)
            {
                if (adj.AdjId != adjId)
                {
                    adjId = adj.AdjId;
                    AdjVoucherService.AuthoriseBy(adjId, user.EmpId);
                }
            }

            TempData["errorMsg"]  = "<script>alert('Adjustment vouchers have been authorised successfully.');</script>";
            ViewData["userName"]  = user.EmpName;
            ViewData["sessionId"] = sessionId;
            return(View("~/Views/StoreLandingPage/Home.cshtml"));
        }
        public ActionResult PutReason(string sessionId)
        {
            List <AdjVoucher> adjVouchers = new List <AdjVoucher>();

            //status = 0 means need to be submit for reason.
            adjVouchers = AdjVoucherService.GetAdjByStatus(0);
            if (adjVouchers.Count == 0)
            {
                return(RedirectToAction("AllAdjVouchers", new { sessionId }));
            }
            else
            {
                foreach (AdjVoucher adj in adjVouchers)
                {
                    adj.Reason = null;
                    adj.Item   = CatalogueService.GetCatalogueById(adj.ItemId);
                    adj.Item.ItemSuppliersDetails = PurchaseOrderService.GetItemSuppliersDetails(adj.ItemId);
                }
                ViewData["adjVouchers"] = adjVouchers;
                ViewData["sessionId"]   = sessionId;
                return(View());
            }
        }
        //public ActionResult AuthoriseByS(List<AdjVoucher> adjVouchers, string sessionId)
        //{
        //    Employee user = EmployeeService.GetUserBySessionId(sessionId);
        //    double totalAmount = 0;
        //    foreach (AdjVoucher adj in adjVouchers)
        //    {
        //        PriceList priceList = PriceListService.GetPriceListByItemId(adj.ItemId);
        //        double price = 0;
        //        if (priceList != null)
        //        {
        //            price = priceList.Supplier1UnitPrice;
        //        }

        //        double amount = price * adj.AdjQty;
        //        totalAmount = totalAmount + amount;
        //        AdjVoucherService.UpdateReason(adj);
        //    }

        //    if (totalAmount > -250)
        //    {
        //        //status = 1, auto approved by supervisor
        //        AdjVoucherService.UpdateStatus(adjVouchers[0].AdjId, 1);
        //        AdjVoucherService.AuthoriseBy(adjVouchers[0].AdjId, user.EmpId);
        //        TempData["errorMsg"] = "<script>alert('Total discrepancy is less than $250, authorised already.');</script>";
        //    }
        //    else
        //    {
        //        //status = 2, pending approve for manager
        //        AdjVoucherService.UpdateStatus(adjVouchers[0].AdjId, 2);
        //        TempData["errorMsg"] = "<script>alert('Total discrepancy is more than $250, pending for Store Manager to authorise.');</script>";

        //    }
        //    ViewData["userName"] = user.EmpName;
        //    ViewData["sessionId"] = sessionId;
        //    return View("~/Views/StoreLandingPage/Home.cshtml");
        //}


        public ActionResult PendingApprove(string sessionId)
        {
            Employee          user        = EmployeeService.GetUserBySessionId(sessionId);
            List <AdjVoucher> adjVouchers = new List <AdjVoucher>();
            string            authoriseBy = null;

            if (user.EmpRole == "STORE_SUPERVISOR")
            {
                adjVouchers = AdjVoucherService.GetAdjByStatus(2);

                foreach (var adj in adjVouchers)
                {
                    //to get item details for view
                    adj.Item = CatalogueService.GetCatalogueById(adj.ItemId);
                    adj.Item.ItemSuppliersDetails = PurchaseOrderService.GetItemSuppliersDetails(adj.ItemId);
                }
                if (adjVouchers.Count == 0)
                {
                    return(RedirectToAction("AllAdjVouchers", new { sessionId }));
                }
                authoriseBy = "Supervisor";
            }
            else if (user.EmpRole == "STORE_MANAGER")
            {
                adjVouchers = AdjVoucherService.GetAdjByStatus(3);

                foreach (var adj in adjVouchers)
                {
                    //to get item details for view
                    adj.Item = CatalogueService.GetCatalogueById(adj.ItemId);
                    adj.Item.ItemSuppliersDetails = PurchaseOrderService.GetItemSuppliersDetails(adj.ItemId);
                }

                if (adjVouchers.Count == 0)
                {
                    return(RedirectToAction("AllAdjVouchers", new { sessionId }));
                }
                authoriseBy = "Manager";
            }

            //To group by vouchers
            Dictionary <long, List <AdjVoucher> > byVouchers = new Dictionary <long, List <AdjVoucher> >();

            foreach (var adj in adjVouchers)
            {
                if (byVouchers.ContainsKey(adj.AdjId))
                {
                    byVouchers[adj.AdjId].Add(adj);
                }
                else
                {
                    List <AdjVoucher> adjs = new List <AdjVoucher>();
                    adjs.Add(adj);
                    byVouchers[adj.AdjId] = adjs;
                }
            }

            ViewData["authoriseBy"] = authoriseBy;
            ViewData["adjVouchers"] = adjVouchers;
            ViewData["byVouchers"]  = byVouchers;
            ViewData["sessionId"]   = sessionId;
            return(View());
        }