예제 #1
0
        public ActionResult History()
        {
            string token = GetToken();
            List <AdjustmentModel> adjlist = new List <AdjustmentModel>();
            SupplierItemModel      supp    = new SupplierItemModel();

            try
            {
                adjlist = APIAdjustment.GetAdjustmentByStatus(token, ConAdjustment.Active.APPROVED, out string error);
                if (adjlist != null)
                {
                    foreach (AdjustmentModel ad in adjlist)
                    {
                        foreach (AdjustmentDetailModel add in ad.Adjds)
                        {
                            supp           = APISupplier.GetOneSupplierItemByItemId(add.Itemid, token, out error);
                            add.Price      = supp.Price * Math.Abs(add.Adjustedqty);
                            ad.TotalPrice += add.Price;
                        }
                    }
                }
                TempData["history"] = adjlist;
            }
            catch (Exception ex)
            {
                RedirectToAction("Index", "Error", new { error = ex.Message });
            }


            return(View(adjlist));
        }
        public ActionResult Approve()
        {
            string token = GetToken();
            List <AdjustmentModel>       adjlist   = new List <AdjustmentModel>();
            List <AdjustmentDetailModel> adjdetail = new List <AdjustmentDetailModel>();
            SupplierItemModel            supp      = new SupplierItemModel();

            try
            {
                //get pending status adjustments
                adjlist = APIAdjustment.GetAdjustmentByStatus(token, ConAdjustment.Active.PENDING, out string error);
                if (adjlist != null)
                {
                    foreach (AdjustmentModel ad in adjlist)
                    {
                        //to divide according to raised to user role
                        ad.RaiseToRole = (APIUser.GetUserByUserID((int)ad.Raisedto, token, out error)).Role;
                        foreach (AdjustmentDetailModel adj in ad.Adjds)
                        {
                            try
                            {
                                //to show each item adjusted price and total pirce of adjustment form
                                supp           = APISupplier.GetOneSupplierItemByItemId(adj.Itemid, token, out error);
                                adj.Price      = supp.Price * Math.Abs(adj.Adjustedqty);
                                ad.TotalPrice += adj.Price;
                            }
                            catch (Exception)
                            {
                                if (supp == null)
                                {
                                    ad.TotalPrice += 0;
                                }
                            }
                        }
                    }
                    //separate adjustment pending list by reported to roles (supervisor/manager)
                    ViewBag.manager = adjlist.Where(x => x.RaiseToRole == ConUser.Role.MANAGER).ToList();
                    adjlist         = adjlist.Where(x => x.RaiseToRole == ConUser.Role.SUPERVISOR).ToList();
                }
                else
                {
                    adjlist         = new List <AdjustmentModel>();
                    ViewBag.manager = adjlist;
                }
            }
            catch (Exception ex)
            {
                RedirectToAction("Index", "Error", new { error = ex.Message });
            }
            return(View(adjlist));
        }