Beispiel #1
0
        public ActionResult OrderHistory()
        {
            string    token = GetToken();
            UserModel um    = GetUser();
            List <RequisitionModel> reqms = new List <RequisitionModel>();

            try
            {
                reqms = APIRequisition.GetRequisitionByDepid(um.Deptid, token, out string error);

                if (reqms == null)
                {
                    reqms = new List <RequisitionModel>();
                }
                else
                {
                    reqms = reqms.Where(p => p.Status == ConRequisition.Status.COMPLETED).OrderByDescending(x => x.Reqdate).ToList();
                }


                if (error != "")
                {
                    return(RedirectToAction("Index", "Error", new { error }));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }

            return(View(reqms));
        }
Beispiel #2
0
        public ActionResult Index()
        {
            string    error = "";
            string    token = GetToken();
            UserModel um    = GetUser();
            List <RequisitionModel> reqs = new List <RequisitionModel>();

            try
            {
                reqs = APIRequisition.GetRequisitionByDepid(um.Deptid, token, out error);

                if (reqs != null)
                {
                    // for dashboard counts

                    ViewBag.ReqCount      = reqs.Where(x => x.Status == ConRequisition.Status.PENDING).Count();
                    ViewBag.InProReqCount = reqs.Where(x => x.Status > ConRequisition.Status.PENDING && x.Status < ConRequisition.Status.OUTSTANDINGREQUISITION).Count();
                    ViewBag.OldReqCount   = reqs.Where(x => x.Status == ConRequisition.Status.COMPLETED || x.Status == ConRequisition.Status.OUTSTANDINGREQUISITION).Count();
                }
                else
                {
                    ViewBag.ReqCount      = 0;
                    ViewBag.InProReqCount = 0;
                    ViewBag.OldReqCount   = 0;
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            return(View());
        }
Beispiel #3
0
        public ActionResult ApproveRequisition(ApproveRequisitionViewModel viewmodel)
        {
            string            token = GetToken();
            UserModel         um    = GetUser();
            RequisitionModel  reqm  = new RequisitionModel();
            NotificationModel nom   = new NotificationModel();


            try
            {
                reqm            = APIRequisition.GetRequisitionByReqid(viewmodel.ReqID, token, out string error);
                reqm.Status     = ConRequisition.Status.APPROVED;
                reqm.Approvedby = um.Userid;
                if (!viewmodel.Approve)
                {
                    reqm.Status  = ConRequisition.Status.REJECTED;
                    nom.Deptid   = reqm.Depid;
                    nom.Role     = ConUser.Role.EMPLOYEE;
                    nom.Title    = "Requisition Rejected";
                    nom.NotiType = ConNotification.NotiType.RejectedRequistion;
                    nom.ResID    = reqm.Reqid;
                    nom.Remark   = "The new requisition has been rejected by the HOD with remark : " + viewmodel.Remark;
                    nom          = APINotification.CreateNoti(token, nom, out error);

                    nom.Deptid   = reqm.Depid;
                    nom.Role     = ConUser.Role.DEPARTMENTREP;
                    nom.Title    = "Requisition Rejected";
                    nom.NotiType = ConNotification.NotiType.RejectedRequistion;
                    nom.ResID    = reqm.Reqid;
                    nom.Remark   = "The new requisition has been rejected by the HOD with remark : " + viewmodel.Remark;
                    nom          = APINotification.CreateNoti(token, nom, out error);
                }

                reqm = APIRequisition.UpdateRequisition(reqm, token, out error);


                Session["noti"]     = true;
                Session["notitype"] = "success";

                if (viewmodel.Approve)
                {
                    Session["notititle"]   = "Requisition Approval";
                    Session["notimessage"] = "Requisiton is now approved!";
                    return(RedirectToAction("TrackRequisition", new { id = reqm.Reqid }));
                }
                Session["notititle"]   = "Requisition Rejection";
                Session["notimessage"] = "Requisiton is rejected!";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
        }
Beispiel #4
0
        public ActionResult RequisitionDetail(int id)
        {
            string           token = GetToken();
            UserModel        um    = GetUser();
            RequisitionModel reqm  = new RequisitionModel();

            try
            {
                reqm = APIRequisition.GetRequisitionByReqid(id, token, out string error);
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            return(View(reqm));
        }
Beispiel #5
0
        public ActionResult ApproveRequisition(int id)
        {
            string           token = GetToken();
            UserModel        um    = GetUser();
            RequisitionModel reqm  = new RequisitionModel();

            ViewBag.RequisitionModel = reqm;
            ApproveRequisitionViewModel viewmodel = new ApproveRequisitionViewModel();

            try
            {
                reqm = APIRequisition.GetRequisitionByReqid(id, token, out string error);

                if (reqm.Status == ConRequisition.Status.APPROVED)
                {
                    Session["noti"]        = true;
                    Session["notitype"]    = "error";
                    Session["notititle"]   = "Already Approved Requisiton!";
                    Session["notimessage"] = "This requisition has already been approved!";
                    return(RedirectToAction("Index", "Home"));
                }
                else if (reqm.Status == ConRequisition.Status.REJECTED)
                {
                    Session["noti"]        = true;
                    Session["notitype"]    = "error";
                    Session["notititle"]   = "Already Approved Requisiton!";
                    Session["notimessage"] = "This requisition has already been approved!";
                    return(RedirectToAction("Index", "Home"));
                }

                ViewBag.RequisitionModel = reqm;
                viewmodel.ReqID          = reqm.Reqid;
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            return(View(viewmodel));
        }
Beispiel #6
0
        public ActionResult Index()
        {
            string    error = "";
            string    token = GetToken();
            UserModel um    = GetUser();

            List <RequisitionModel> reqs             = new List <RequisitionModel>();
            UserModel CurrentRep                     = new UserModel();
            DepartmentCollectionPointModel CurrentCP = new DepartmentCollectionPointModel();
            DelegationModel CurrentTemp              = new DelegationModel();
            UserModel       CurrentTempUser          = new UserModel();

            try
            {
                reqs                   = APIRequisition.GetRequisitionByStatus(ConRequisition.Status.PENDING, token, out error);
                ViewBag.ReqCount       = 0;
                ViewBag.ReqCount       = reqs.Where(x => x.Depid == um.Deptid).Count();
                ViewBag.DelegationType = "Temporary HOD";

                CurrentRep      = APIUser.GetUserByRoleAndDeptID(ConUser.Role.DEPARTMENTREP, um.Deptid, token, out error).FirstOrDefault();
                ViewBag.RepName = CurrentRep.Fullname;
                if (ViewBag.RepName == null)
                {
                    ViewBag.RepName = "None";
                }


                CurrentCP = APICollectionPoint.GetActiveDepartmentCollectionPointByDeptID(token, um.Deptid, out error);
                ViewBag.CollectionPoint = CurrentCP.CpName;
                if (ViewBag.CollectionPoint == null)
                {
                    ViewBag.CollectionPoint = "None";
                }

                CurrentTemp = APIDelegation.GetPreviousDelegationByDepid(token, um.Deptid, out error);
                if (CurrentTemp.Delid != 0)
                {
                    CurrentTempUser  = APIUser.GetUserByUserID(CurrentTemp.Userid, token, out error);
                    ViewBag.TempHOD  = CurrentTempUser.Fullname;
                    ViewBag.TempDate = CurrentTemp.Startdate.Value.ToShortDateString() + " - " + CurrentTemp.Enddate.Value.ToShortDateString();
                    if (CurrentTemp.Startdate <= DateTime.Today && DateTime.Today <= CurrentTemp.Enddate)
                    {
                        ViewBag.DelegationType = "Current Temporary HOD";
                    }
                    else
                    {
                        ViewBag.DelegationType = "Upcoming Temporary HOD";
                    }
                }
                if (CurrentTemp.Delid == 0 || ViewBag.TempHOD == null)
                {
                    ViewBag.DelegationType = "Temporary HOD";
                    ViewBag.TempHOD        = "None";
                    ViewBag.TempDate       = "-";
                }
                return(View());
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
        }
Beispiel #7
0
        public ActionResult TrackRequisition(int id)
        {
            string           token = GetToken();
            UserModel        um    = GetUser();
            string           error = "";
            RequisitionModel reqm  = new RequisitionModel();

            ViewBag.Pending   = "btn-danger";
            ViewBag.Preparing = "btn-danger";
            ViewBag.Ready     = "btn-danger";
            ViewBag.Collected = "btn-danger";
            ViewBag.Track     = "";

            try
            {
                reqm = APIRequisition.GetRequisitionByReqid(id, token, out error);
                if (reqm.Depid != um.Deptid)
                {
                    error = "You don't have authority to view this requisition";
                }
                switch (reqm.Status)
                {
                case ConRequisition.Status.APPROVED:
                    ViewBag.Pending   = "btn-warning";
                    ViewBag.Preparing = "btn-danger";
                    ViewBag.Ready     = "btn-danger";
                    ViewBag.Collected = "btn-danger";
                    ViewBag.Track     = "Request Pending";
                    break;

                case ConRequisition.Status.REQUESTPENDING:
                    ViewBag.Pending   = "btn-warning";
                    ViewBag.Preparing = "btn-danger";
                    ViewBag.Ready     = "btn-danger";
                    ViewBag.Collected = "btn-danger";
                    ViewBag.Track     = "Request Pending";
                    break;

                case ConRequisition.Status.PREPARING:
                    ViewBag.Pending   = "btn-success";
                    ViewBag.Preparing = "btn-warning";
                    ViewBag.Ready     = "btn-danger";
                    ViewBag.Collected = "btn-danger";
                    ViewBag.Track     = "Preparing Items";

                    break;

                case ConRequisition.Status.DELIVERED:
                    ViewBag.Pending   = "btn-success";
                    ViewBag.Preparing = "btn-success";
                    ViewBag.Ready     = "btn-warning";
                    ViewBag.Collected = "btn-danger";
                    ViewBag.Track     = "Ready to Collect";

                    break;

                case ConRequisition.Status.OUTSTANDINGREQUISITION:
                    ViewBag.Pending   = "btn-success";
                    ViewBag.Preparing = "btn-success";
                    ViewBag.Ready     = "btn-success";
                    ViewBag.Collected = "btn-warning";
                    ViewBag.Track     = "Completed";

                    break;

                case ConRequisition.Status.COMPLETED:
                    ViewBag.Pending   = "btn-success";
                    ViewBag.Preparing = "btn-success";
                    ViewBag.Ready     = "btn-success";
                    ViewBag.Collected = "btn-success";
                    ViewBag.Track     = "Completed";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            if (error != "")
            {
                return(RedirectToAction("Index", "Error", new { error }));
            }
            return(View(reqm));
        }
Beispiel #8
0
        public ActionResult RaiseRequisition(RequisitionViewModel reqvm)
        {
            if (reqvm.Requisitiondetails.Count < 1)
            {
                Session["noti"]        = true;
                Session["notitype"]    = "error";
                Session["notititle"]   = "Raise Requisition Error";
                Session["notimessage"] = "You cannot raise requisition without any items!";
                return(RedirectToAction("RaiseRequisition"));
            }

            bool duplicateExists = reqvm.Requisitiondetails.GroupBy(n => n.Itemid).Any(g => g.Count() > 1);

            if (duplicateExists)
            {
                Session["noti"]        = true;
                Session["notitype"]    = "error";
                Session["notititle"]   = "Raise Requisition Error";
                Session["notimessage"] = "You cannot raise requisition with duplicate items!";
                return(RedirectToAction("RaiseRequisition"));
            }

            string    token = GetToken();
            UserModel um    = GetUser();
            DepartmentCollectionPointModel dcpm = new DepartmentCollectionPointModel();
            List <ItemModel> ItemsList          = new List <ItemModel>();
            RequisitionModel reqm = new RequisitionModel();
            List <RequisitionDetailsModel> reqdms = new List <RequisitionDetailsModel>();

            try
            {
                reqm.Reqdate  = DateTime.Now;
                reqm.Raisedby = um.Userid;
                if (um.Role == ConUser.Role.TEMPHOD)
                {
                    reqm.Approvedby = um.Userid;
                }
                reqm.Depid  = um.Deptid;
                dcpm        = APICollectionPoint.GetActiveDepartmentCollectionPointByDeptID(token, um.Deptid, out string error);
                reqm.Cpid   = dcpm.CpID;
                reqm.Cpname = dcpm.CpName;
                reqm.Status = ConRequisition.Status.PENDING;
                reqm        = APIRequisition.CreateRequisition(reqm, token, out error);

                foreach (var reqd in reqvm.Requisitiondetails)
                {
                    RequisitionDetailsModel reqdm = new RequisitionDetailsModel
                    {
                        Reqid  = reqm.Reqid,
                        Itemid = reqd.Itemid,
                        Qty    = reqd.Qty
                    };
                    reqdms = APIRequisition.CreateRequisitionDetails(reqdm, token, out error);
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            return(RedirectToAction("TrackRequisition", "Employee", new { id = reqm.Reqid }));
        }