public ActionResult Index()
        {
            statusService          = new StatusService(context);
            userService            = new UserService(context);
            collectionPointService = new CollectionPointService(context);

            List <Status> list = new List <Status>();

            list.Add(statusService.FindStatusByStatusId(0));
            list.Add(statusService.FindStatusByStatusId(1));
            List <ApplicationUser> allUsersList        = userService.FindAllUsers();
            List <CollectionPoint> collectionPointList = collectionPointService.FindAllCollectionPoints();

            return(View(new DepartmentViewModel
            {
                Statuses = new SelectList(
                    list.Select(x => new { Value = x.StatusId, Text = x.Name }),
                    "Value",
                    "Text"
                    ),
                AllUsers = new SelectList(
                    allUsersList.Select(x => new { value = x.Email, text = x.FirstName + " " + x.LastName }),
                    "Value",
                    "Text"
                    ),
                CollectionPoints = new SelectList(
                    collectionPointList.Select(x => new { value = x.CollectionPointId, text = x.Name }),
                    "Value",
                    "Text"
                    )
            }));
        }
Example #2
0
        public void GetRetrieval_ContainsResult()
        {
            // Arrange
            var statusService = new StatusService(context);

            var expectedId       = "RETCONTROLTEST";
            var expectedQuantity = 999999;

            new RetrievalRepository(context).Save(new Retrieval()
            {
                RetrievalId     = expectedId,
                CreatedDateTime = DateTime.Now,
                Status          = statusService.FindStatusByStatusId(12),
                Disbursements   = new List <Disbursement>()
                {
                    new Disbursement()
                    {
                        DisbursementId      = expectedId,
                        Department          = new DepartmentService(context).FindDepartmentByDepartmentCode("ENGL"),
                        CreatedDateTime     = DateTime.Now,
                        Status              = statusService.FindStatusByStatusId(7),
                        DisbursementDetails = new List <DisbursementDetail>()
                        {
                            new DisbursementDetail()
                            {
                                DisbursementId = expectedId,
                                Item           = new ItemService(context).FindItemByItemCode("E030"),
                                Bin            = "E78",
                                PlanQuantity   = 30,
                                ActualQuantity = expectedQuantity,
                                Status         = statusService.FindStatusByStatusId(17),
                                ItemCode       = "E030",
                            }
                        }
                    }
                }
            });

            var controller = new RetrievalAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            // Act
            IHttpActionResult actionResult = controller.GetRetrieval(new ConfirmRetrievalViewModel()
            {
                RetrievalId = expectedId,
            });

            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <RetrievalDetailByDeptViewModel> >;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.IsTrue(contentResult.Content.Select(x => x.ActualQuantity).Contains(expectedQuantity));
        }
Example #3
0
        // GET: Supplier
        public ActionResult Index()
        {
            statusService = new StatusService(context);

            List <Status> list = new List <Status>();

            list.Add(statusService.FindStatusByStatusId(0));
            list.Add(statusService.FindStatusByStatusId(1));
            return(View(new SupplierViewModel
            {
                Statuses = new SelectList(
                    list.Select(x => new { Value = x.StatusId, Text = x.Name }),
                    "Value",
                    "Text"

                    )
            }));
        }
        // GET: ItemCategory
        public ActionResult Index()
        {
            statusService = new StatusService(context);

            List <Status> list = new List <Status>();

            list.Add(statusService.FindStatusByStatusId(0)); //add disabled option
            list.Add(statusService.FindStatusByStatusId(1)); //add enabled option
            return(View(new ItemCategoryViewModel
            {
                Statuses = new SelectList(
                    list.Select(x => new { Value = x.StatusId, Text = x.Name }),
                    "Value",
                    "Text"

                    )
            }));
        }
        // POST: /Requisition/Draft
        public ActionResult Draft(string rid)
        {
            ApplicationUser user = userRepository.FindById(User.Identity.GetUserId());
            // for testing
            //ApplicationUser user = userRepository.FindById("446a381c-ff6c-4332-ba50-747af26d996e");

            Requisition existingReq = requisitionRepository.FindById(rid);

            // create the requisition
            Requisition r = new Requisition();

            r.RequisitionId      = IdService.GetNewRequisitionId(context);
            r.RequisitionDetails = new List <RequisitionDetail>();
            r.Status             = statusService.FindStatusByStatusId(3); // create a draft
            r.CreatedDateTime    = DateTime.Now;
            r.Department         = user.Department;
            r.CollectionPoint    = user.Department.CollectionPoint;
            r.CreatedBy          = user;

            // create requisition details
            foreach (RequisitionDetail dd in existingReq.RequisitionDetails)
            {
                r.RequisitionDetails.Add(new RequisitionDetail
                {
                    ItemCode = dd.ItemCode,
                    Item     = itemService.FindItemByItemCode(dd.ItemCode),
                    Quantity = dd.Quantity,
                    Status   = statusService.FindStatusByStatusId(4)
                });
            }
            try
            {
                requisitionService.Save(r);
            }
            catch
            {
                TempData["error"] = "error";
                return(RedirectToAction("ManageRequisitions", "Requisition"));
            }

            TempData["draft"] = String.Format("Draft Requisition #{0} created.", r.RequisitionId);
            return(RedirectToAction("ManageRequisitions", "Requisition"));
        }
        //GET:New Item
        public ActionResult Create()
        {
            //get data for Status dropdownlist
            List <Status> list = new List <Status>();

            list.Add(statusService.FindStatusByStatusId(0));
            list.Add(statusService.FindStatusByStatusId(1));
            //get data for Supplier dropdownlist
            List <Supplier> list2    = new List <Supplier>();
            List <Supplier> sAllList = supplierService.FindAllSuppliers();
            //get data for Category dropdownlist
            List <ItemCategory> list3    = new List <ItemCategory>();
            List <ItemCategory> cAllList = categoryService.FindAllItemCategory();

            foreach (ItemCategory i in cAllList)
            {
                list3.Add(i);
            }
            foreach (Supplier i in sAllList)
            {
                list2.Add(i);
            }

            return(View(new EditItemFinalViewModel
            {
                Statuses = new SelectList(
                    list.Select(x => new { Value = x.StatusId, Text = x.Name }),
                    "Value",
                    "Text"
                    ),
                SupplierName = new SelectList(
                    list2.Select(x => new { Value = x.SupplierCode, Text = x.Name }),
                    "Value",
                    "Text"
                    ),
                Categories = new SelectList(
                    list3.Select(x => new { Value = x.ItemCategoryId, Text = x.Name }),
                    "Value",
                    "Text"
                    )
            }));
        }
        public void FindByIdTest()
        {
            // Arrange
            var expected = "Enabled";

            // Act
            var result = statusService.FindStatusByStatusId(1);

            // Assert
            Assert.AreEqual(expected, result.Name);
        }
Example #8
0
        public ActionResult ChangeStatus(DeliveryOrderDetailsViewModel model)
        {
            PurchaseOrder       purchaseOrder       = purchaseOrderService.FindPurchaseOrderById(model.PurchaseOrderNo);
            PurchaseOrderDetail purchaseOrderDetail = purchaseOrderDetailService.FindPurchaseOrderDetailbyIdItem(model.PurchaseOrderNo, model.ItemCode);

            if (purchaseOrder.Status.StatusId == 11)
            {
                purchaseOrderService.DeletePurchaseOrderDetailsFromPurchaseOrder(purchaseOrderDetail);
            }
            else
            {
                purchaseOrderDetail.Status = statusService.FindStatusByStatusId(2);
                purchaseOrderService.SavePurchaseOrderDetail(purchaseOrderDetail);
            }

            int flag = 0;

            foreach (PurchaseOrderDetail pod in purchaseOrder.PurchaseOrderDetails)
            {
                if ((pod.Status.StatusId == 12) || (pod.Status.StatusId == 11))
                {
                    purchaseOrder.Status = statusService.FindStatusByStatusId(12);

                    purchaseOrderService.Save(purchaseOrder);

                    flag = 1;

                    break;
                }
            }

            if (flag != 1)
            {
                purchaseOrder.Status = statusService.FindStatusByStatusId(13);
                purchaseOrderService.Save(purchaseOrder);
            }

            return(new JsonResult {
                Data = new { status = "Saved" }
            });
        }
Example #9
0
        public ActionResult Delete(string purchaseOrderNum, string itemCode)
        {
            decimal totalAmount = 0;

            string[] itemCodeArray = new string[] { itemCode };

            PurchaseOrder purchaseOrder = purchaseOrderService.FindPurchaseOrderById(purchaseOrderNum);

            purchaseOrderService.DeleteItemFromPurchaseOrder(purchaseOrder, itemCodeArray);

            if (purchaseOrder.PurchaseOrderDetails.Count == 0)
            {
                purchaseOrder.Status          = statusService.FindStatusByStatusId(2);
                purchaseOrder.Status.StatusId = 2;
                purchaseOrderService.Save(purchaseOrder);
            }
            else

            {
                foreach (PurchaseOrderDetail pod in purchaseOrder.PurchaseOrderDetails)
                {
                    totalAmount = totalAmount + purchaseOrderService.FindTotalAmountByPurchaseOrderDetail(pod);
                }
            }



            return(new JsonResult {
                Data = new { amount = totalAmount }
            });
        }
        public ActionResult Save(DepartmentViewModel model)
        {
            departmentService      = new DepartmentService(context);
            collectionPointService = new CollectionPointService(context);
            userService            = new UserService(context);
            statusService          = new StatusService(context);

            bool       status = false;
            Department dpt    = new Department();

            if (departmentService.FindDepartmentByDepartmentCode(model.DepartmentCode) == null)
            {
                //new dpt
                dpt.DepartmentCode  = model.DepartmentCode;
                dpt.CreatedDateTime = DateTime.Now;
                dpt.CreatedBy       = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
                dpt.Representative  = userService.FindUserByEmail(model.DepartmentRep);
            }

            else
            {
                //edit dpt
                dpt = departmentService.FindDepartmentByDepartmentCode(model.DepartmentCode);

                //assign user info into update fields
                dpt.UpdatedDateTime = DateTime.Now;
                //dpt.UpdatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
                dpt.UpdatedBy = userService.FindUserByEmail(CurrentUserName);
            }

            dpt.Name = model.DepartmentName;
            dpt.Head = userService.FindUserByEmail(model.EmailHead);

            dpt.CollectionPoint = collectionPointService.FindCollectionPointById(Convert.ToInt32(model.CollectionPointId));
            dpt.ContactName     = model.ContactName;
            dpt.PhoneNumber     = model.PhoneNumber;
            dpt.FaxNumber       = model.FaxNumber;
            dpt.Status          = statusService.FindStatusByStatusId(model.Status);

            //save info to database
            if (departmentService.Save(dpt) != null)
            {
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
Example #11
0
        public ActionResult Save(SupplierViewModel model)
        {
            bool     status = false;
            Supplier s      = new Supplier();

            statusService   = new StatusService(context);
            supplierService = new SupplierService(context);
            userService     = new UserService(context);

            if (supplierService.FindSupplierById(model.SupplierCode) == null)
            {
                //new supplier
                s.SupplierCode = model.SupplierCode;
                //assign user info
                s.CreatedDateTime = DateTime.Now;
                s.CreatedBy       = userService.FindUserByEmail(CurrentUserName);
            }

            else
            {
                //existing supplier
                s = supplierService.FindSupplierById(model.SupplierCode);

                //assign user info into update fields
                s.UpdatedDateTime = DateTime.Now;
                s.UpdatedBy       = userService.FindUserByEmail(CurrentUserName);
            }

            //assign supplier info
            s.Name              = model.Name;
            s.ContactName       = model.ContactName;
            s.PhoneNumber       = model.PhoneNumber;
            s.FaxNumber         = model.FaxNumber;
            s.Address           = model.Address;
            s.GstRegistrationNo = model.GSTNumber;
            s.Status            = statusService.FindStatusByStatusId(model.Status);

            //save info to database
            if (supplierService.Save(s) != null)
            {
                status = true;
            }

            //return RedirectToAction("Index", "Supplier");
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult Save(ItemCategoryViewModel model)
        {
            bool status = false;

            statusService       = new StatusService(context);
            itemcategoryService = new ItemCategoryService(context);
            userService         = new UserService(context);

            ItemCategory s = new ItemCategory();

            if (itemcategoryService.FindItemCategoryByItemCategoryId(model.ItemCategoryId) == null)
            {
                //new item category
                s.ItemCategoryId = IdService.GetNewItemCategoryId(context);
                //assign user info
                s.CreatedDateTime = DateTime.Now;
                s.CreatedBy       = userService.FindUserByEmail(CurrentUserName);
            }

            else
            {
                //existing ItemCategory
                s = itemcategoryService.FindItemCategoryByItemCategoryId(model.ItemCategoryId);

                //assign user info into update fields
                s.UpdatedDateTime = DateTime.Now;
                s.UpdatedBy       = userService.FindUserByEmail(CurrentUserName);
            }

            //assign item category info
            s.Name        = model.Name;
            s.Description = model.Description;
            s.Status      = statusService.FindStatusByStatusId(model.Status);

            //save info to database
            if (itemcategoryService.Save(s) != null)
            {
                status = true;
            }

            //return RedirectToAction("Index", "ItemCategory");
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult SaveStatus(DepartmentViewModel model)
        {
            statusService     = new StatusService(context);
            delegationService = new DelegationService(context);

            bool       status     = false;
            Delegation delegation = delegationService.FindDelegationByDelegationId(model.DelegationId);

            delegation.Status = statusService.FindStatusByStatusId(model.DelegationStatus);
            //delegation.UpdatedBy = user;
            delegation.CreatedBy       = userService.FindUserByEmail(CurrentUserName);
            delegation.UpdatedDateTime = DateTime.Now;

            if (delegationService.DelegateManager(delegation) != null)
            {
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult SaveOptions(DepartmentViewModel model)
        {
            departmentService      = new DepartmentService(context);
            collectionPointService = new CollectionPointService(context);
            userService            = new UserService(context);
            statusService          = new StatusService(context);
            delegationService      = new DelegationService(context);

            int        status     = 0;
            Department dpt        = departmentService.FindDepartmentByUser(userService.FindUserByEmail(CurrentUserName));
            Delegation delegation = new Delegation();

            dpt.UpdatedDateTime = DateTime.Now;
            dpt.UpdatedBy       = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
            dpt.Representative  = userService.FindUserByEmail(model.DepartmentRep);
            dpt.CollectionPoint = collectionPointService.FindCollectionPointById(Convert.ToInt32(model.CollectionPoint));

            if (departmentService.Save(dpt) != null)
            {
                // Send notifications to all Store Clerks
                foreach (var user in new UserService(context).FindUsersByDepartment(departmentService.FindDepartmentByDepartmentCode("STOR")).Where(r => r.Roles.Select(ur => ur.RoleId).Contains("3")))
                {
                    var notification = new NotificationService(context).CreateChangeCollectionPointNotification(dpt, user);
                    new NotificationApiController()
                    {
                        context = context
                    }.SendNotification(notification.NotificationId.ToString());
                    new NotificationApiController()
                    {
                        context = context
                    }.SendEmail(notification.NotificationId.ToString());
                }
                status = 1;
            }

            delegation.Receipient = userService.FindUserByEmail(model.DelegationRecipient);

            if (delegation.Receipient != null && model.StartDate != null && model.EndDate != null)
            {
                delegation.DelegationId    = IdService.GetNewDelegationId(context);
                delegation.StartDate       = DateTime.Parse(model.StartDate, new CultureInfo("fr-FR", false));
                delegation.EndDate         = DateTime.Parse(model.EndDate, new CultureInfo("fr-FR", false));
                delegation.CreatedDateTime = DateTime.Now;
                //delegation.CreatedBy = user;
                delegation.CreatedBy = userService.FindUserByEmail(CurrentUserName);
                delegation.Status    = statusService.FindStatusByStatusId(1);
                delegationService.DelegateManager(delegation);
                status = 2;

                // Role
                //userService.AddDepartmentHeadRole(delegation.Receipient.Email);
            }

            if (delegation.Receipient != null && model.StartDate == null && model.EndDate == null)
            {
                status = 3;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
Example #15
0
        public void ProcessRequisitionsTest_AddQuantity()
        {
            // ARRANGE
            List <Requisition> reqList = new List <Requisition>();

            reqList.Add(context.Requisition.Where(x => x.RequisitionId == "GAB1").ToList().First()); // department is COMM

            Requisition r1 = new Requisition();

            r1.RequisitionId      = "TEST1";
            r1.Department         = context.Department.Where(x => x.DepartmentCode == "COMM").ToList().First();
            r1.RequisitionDetails = new List <RequisitionDetail>();
            r1.EmployeeRemarks    = "From AddDisbursementDetailsFromEachDepartmentTest_AddQuantity";
            r1.CreatedDateTime    = DateTime.Now;
            r1.Status             = statusService.FindStatusByStatusId(6);

            RequisitionDetail rd1 = new RequisitionDetail();

            rd1.Item     = context.Item.Where(x => x.ItemCode == "C001").ToList().First();
            rd1.ItemCode = "C001";
            rd1.Quantity = 20;
            rd1.Status   = statusService.FindStatusByStatusId(6);

            r1.RequisitionDetails.Add(rd1);

            reqList.Add(r1);

            //// ACT
            string retrievalId = requisitionService.ProcessRequisitions(reqList);

            //// ASSERT: RequisitionDetail & Department should result in a single DisbursementDetail with 30 items if C001 has enough inventory

            var query          = context.Disbursement.Where(x => x.Retrieval.RetrievalId == retrievalId);
            var inventoryLevel = new ItemService(context).FindInventoryByItemCode("C001").Quantity;

            if (inventoryLevel >= 30)
            {
                Assert.IsTrue(query.First().DisbursementDetails.Count() == 1); // single DisbursementDetail for 1 Department?
                var dd = query.First().DisbursementDetails.First();
                Assert.IsTrue(dd.ItemCode == "C001");                          // DisbursementDetail's ItemCode is "C001"
                Assert.IsTrue(dd.PlanQuantity == 30);                          // DisbursementDetail's PlanQuantity is 30

                // remove Disbursement which has the generated DisbursementId
                // will remove DisbursementDetails as well
                var d = context.Disbursement.Where(x => x.DisbursementId == dd.DisbursementId);
                context.Disbursement.Remove(d.First());
            }
            else if (inventoryLevel > 0)
            {
                Assert.IsTrue(query.First().DisbursementDetails.Count() == 1); // single DisbursementDetail for 1 Department?
                var dd = query.First().DisbursementDetails.First();
                Assert.IsTrue(dd.ItemCode == "C001");                          // DisbursementDetail's ItemCode is "C001"
                Assert.IsTrue(dd.PlanQuantity > 0);                            // DisbursementDetail's PlanQuantity is 30

                // remove Disbursement which has the generated DisbursementId
                // will remove DisbursementDetails as well
                var d = context.Disbursement.Where(x => x.DisbursementId == dd.DisbursementId);
                context.Disbursement.Remove(d.First());
            }
            else
            {
                Assert.IsTrue(context.Disbursement.Where(x => x.Retrieval.RetrievalId == retrievalId).Count() == 0);
            }

            //// CLEANUP
            // remove the Retrieval with the generated retrievalId
            context.Retrieval.Remove(context.Retrieval.Where(x => x.RetrievalId == retrievalId).First());
            context.SaveChanges();
        }
Example #16
0
        public IHttpActionResult CreateRequisition(UpdateRequisitionJSONViewModel json)
        {
            ApplicationUser user = userRepository.FindById(RequestContext.Principal.Identity.GetUserId());

            // update the collection point
            Department d = departmentRepository.FindById(user.Department.DepartmentCode);

            d.CollectionPoint = collectionPointRepository.FindById(json.CollectionPointId);
            departmentRepository.Save(d);

            if (json.ItemList.Count < 1)
            {
                return(BadRequest("An unexpected error occured."));
            }

            // create the requisition
            Requisition r = new Requisition();

            r.RequisitionId      = IdService.GetNewRequisitionId(context);
            r.RequisitionDetails = new List <RequisitionDetail>();
            r.EmployeeRemarks    = json.Remarks;

            if (json.IsDraft == true)
            {
                r.Status = statusService.FindStatusByStatusId(3);
            }
            else
            {
                r.Status = statusService.FindStatusByStatusId(4);
            }
            r.CreatedDateTime = DateTime.Now;
            r.Department      = user.Department;
            r.CollectionPoint = collectionPointRepository.FindById(json.CollectionPointId);
            r.CreatedBy       = user;

            // create requisition details
            foreach (UpdateRequisitionTableJSONViewModel dd in json.ItemList)
            {
                r.RequisitionDetails.Add(new RequisitionDetail
                {
                    ItemCode = dd.ItemCode,
                    Item     = itemService.FindItemByItemCode(dd.ItemCode),
                    Quantity = dd.Qty,
                    Status   = statusService.FindStatusByStatusId(4)
                });
            }
            try
            {
                requisitionService.Save(r);
            }
            catch
            {
                return(BadRequest("An unexpected error occured."));
            }

            // Create Notification
            Notification n = new NotificationService(context).CreateNotification(r, user.Department.Head);

            new NotificationApiController()
            {
                context = context
            }.SendNotification(n.NotificationId.ToString());
            new NotificationApiController()
            {
                context = context
            }.SendEmail(n.NotificationId.ToString());

            return(Ok(r.RequisitionId));
        }