Ejemplo n.º 1
0
        // Calculates and sets the total price
        // for a purchase order given a
        // poWithItems object
        public void poTotalSet(poWithItems x)
        {
            var    allItems = x.itemList;
            double ans      = 0;

            foreach (var line in allItems)
            {
                double lineTotal = line.Quantity * (double)line.Inventory.NetPrice;
                ans += lineTotal;
            }
            x.p.totalPrice = ans;
            return;
        }
Ejemplo n.º 2
0
        // Returns a string status OPEN or CLOSED
        // depending on the state of a PO(id)
        public string getStatus(int id)
        {
            poWithItems x = getOrderWithItems(id, db);

            if (!(x.itemList.Any()))
            {
                return("OPEN");
            }
            if (x.itemList.First().Received == 0)
            {
                return("OPEN");
            }
            return("CLOSED");
        }
Ejemplo n.º 3
0
        // CANCEL A PURCHASE ORDER (bring it to a state of never having existed)
        public ActionResult Cancel(int?id)
        {
            poWithItems entireOrder = getOrderWithItems((int)id, db);

            foreach (var item in entireOrder.itemList)
            {
                db.PurchaseOrderItems.Remove(item);
            }
            db.PurchaseOrders.Remove(entireOrder.p);
            db.SaveChanges();

            //PurchaseOrder purchaseOrder = db.PurchaseOrders.Find(id);
            //db.PurchaseOrders.Remove(purchaseOrder);
            //db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        // Get a poWithItems object based on a given purchase order ID and db instance
        public poWithItems getOrderWithItems(int givenID, MusciToolkitDBEntities dbInstance)
        {
            var ansPO   = db.PurchaseOrders.SingleOrDefault(x => x.PurchaseOrderID == givenID);
            var ansList = db.PurchaseOrderItems.Where(x => x.PurchaseOrderID == givenID);

            // Declare total line price for each PurchaseOrderItem in the list.. Shoutout to Luke!!
            foreach (var each in ansList)
            {
                double currLineCost = (double)each.Quantity * (double)each.Inventory.NetPrice;
                each.totalPrice = currLineCost;
            }
            db.SaveChanges();
            var ans = new poWithItems(ansPO, ansList);

            poTotalSet(ans);
            return(ans);
        }
Ejemplo n.º 5
0
        // CANCEL A PURCHASE ORDER (bring it to a state of never having existed)
        public ActionResult Cancel(int?id)
        {
            // Must be Manager or Admin to cancel a purchase order
            if (!(Session["UserRole"].Equals("Manager") || Session["UserRole"].Equals("Admin")))
            {
                return(RedirectToAction("LowPermission"));
            }
            poWithItems entireOrder = getOrderWithItems((int)id, db);

            foreach (var item in entireOrder.itemList)
            {
                db.PurchaseOrderItems.Remove(item);
            }
            db.PurchaseOrders.Remove(entireOrder.p);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        /*
         * public ActionResult Search()
         * {
         *  List<poWithItems> allPOsComplete = new List<poWithItems>();
         *  /*
         * Below is the code to show all PurcahseOrders upon entering the search page.
         *  List<PurchaseOrder> allPOs = db.PurchaseOrders.ToList();
         *  foreach (var item in allPOs)
         *  {
         *      int currID = item.PurchaseOrderID;
         *      poWithItems currItem = getOrderWithItems(currID, db);
         *      allPOsComplete.Add(currItem);
         *  }
         *  //pass the StudentList list object to the view.
         *
         *  return View(allPOsComplete);
         * }*/


        public ActionResult Search(string option, string search)
        {
            Session["searchdebug"] = search;
            List <poWithItems>   poListComplete = new List <poWithItems>();
            List <PurchaseOrder> poList         = db.PurchaseOrders.ToList();

            foreach (var item in poList)
            {
                int         currID   = item.PurchaseOrderID;
                poWithItems currItem = getOrderWithItems(currID, db);
                poListComplete.Add(currItem);
            }
            //if a user choose the radio button option as Subject
            if (option == "ID")
            {
                try
                {
                    //Index action method will return a view with a student records based on what a user specify the value in textbox
                    return(View(poListComplete.Where(x => x.p.PurchaseOrderID == Int32.Parse(search) || search == null).ToList()));
                }
                catch
                {
                    return(View(new List <poWithItems>()));
                }
            }
            else if (option == "Date")
            {
                return(View(poListComplete.Where(x => x.p.dateStr.Equals(search) || search == null).ToList()));
            }
            else if (option == "Status")
            {
                return(View(poListComplete.Where(x => getStatus(x.p.PurchaseOrderID).Equals(search) || search == null).ToList()));
            }
            else
            {
                // Return empty list / no search results
                //return View(new List<poWithItems>());
                return(View(new List <poWithItems>()));
            }
        }
Ejemplo n.º 7
0
        // RECEIVE PURCHASE ORDER
        public ActionResult Receive(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            poWithItems entireOrder = getOrderWithItems((int)id, db);

            if (entireOrder == null)
            {
                return(HttpNotFound());
            }

            foreach (var line in entireOrder.itemList)
            {
                line.Inventory.Quantity += line.Quantity;
                // Set receieved to 'true'
                line.Received = 1;
            }
            db.SaveChanges();
            return(RedirectToAction("Details", new { id = entireOrder.p.PurchaseOrderID }));
        }
Ejemplo n.º 8
0
        // Returns total price of a purchase order
        // given a purchase order ID
        public double getTotalPrice(int id)
        {
            poWithItems x = getOrderWithItems(id, db);

            return(x.p.totalPrice);
        }