Exemplo n.º 1
0
        public IActionResult ViewRF(int id)
        {
            RequisitionViewModel vmRequisition = new RequisitionViewModel();
            //emp = JsonConvert.DeserializeObject<Employee>(HttpContext.Session.GetString("employee")) as Employee;

            Employee        emp = eservice.GetEmployeeById(6); //hard-coded id for test
            RequisitionForm rf  = rpService.FindRequisitionFormById(id);
            List <RequisitionFormsProduct> rfpList = rpService.FindRequisitionFormProductListById(id);

            vmRequisition.employee        = emp;
            vmRequisition.requisitionForm = rf;
            vmRequisition.rfpList         = rfpList;

            if (emp.EmployeeType.EmployeeTypeName.Equals("Store Manager") || emp.EmployeeType.EmployeeTypeName.Equals("Department Head"))
            {
                if (!rf.RFStatus.Equals(Enums.RFStatus.Submitted))
                {
                    return(Ok(vmRequisition));
                }
                else
                {
                    for (int i = 0; i < rfpList.Count; i++)
                    {
                        rfpList[i].ProductApproved = rfpList[i].ProductRequested;
                    }
                    return(Ok(vmRequisition));
                }
            }
            else
            {
                return(Ok(vmRequisition));
            }
        }
Exemplo n.º 2
0
        public bool SaveRFFromCSV(List <CSVRequisitionForm> rfList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    foreach (CSVRequisitionForm rf in rfList)
                    {
                        RequisitionForm rfSave = new RequisitionForm();
                        rfSave.RFCode         = rf.RFCode;
                        rfSave.Employee       = empService.GetEmployee(rf.Username);
                        rfSave.RFDate         = DateTime.Parse(rf.RFDate);
                        rfSave.RFStatus       = (RFStatus)Enum.Parse(typeof(RFStatus), rf.RFStatus);
                        rfSave.RFComments     = rf.RFComments;
                        rfSave.RFApprovalDate = DateTime.Parse(rf.RFApprovalDate);
                        rfSave.RFApprovalBy   = empService.GetEmployee(rf.RFApprovalUsername);
                        rfSave.RFHeadReply    = rf.RFHeadReply;
                        db.RequisitionForms.Add(rfSave);
                    }

                    db.SaveChanges();
                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Exemplo n.º 3
0
        public List <Product> GetListOfProductsFromRFIdList(List <int> rfIdList)
        {
            List <Product>                 pList  = new List <Product>();
            List <RequisitionForm>         rfList = new List <RequisitionForm>();
            List <RequisitionFormsProduct> rfpConsolidatedList = new List <RequisitionFormsProduct>();

            foreach (int rfId in rfIdList)
            {
                RequisitionForm rf = db.RequisitionForms.Find(rfId);
                rfList.Add(rf);
            }
            foreach (RequisitionForm rf in rfList)
            {
                List <RequisitionFormsProduct> rfpList = db.RequisitionFormsProducts
                                                         .Where(x => x.RequisitionForm == rf)
                                                         .ToList();
                foreach (RequisitionFormsProduct rfp in rfpList)
                {
                    rfp.ProductBalanceForSR = rfp.ProductApproved - rfp.ProductCollectedTotal;
                    rfpConsolidatedList.Add(rfp);
                }
            }

            IEnumerable <Product> pListEnumerable = rfpConsolidatedList.Select(x => x.Product).Distinct();

            foreach (Product p in pListEnumerable)
            {
                pList.Add(db.Products.Find(p.Id));
            }

            return(pList);
        }
        public IActionResult Cancel(int id)
        {
            rpservice.ChangeRFStatusToCancelledById(id);
            RequisitionForm rf = rpservice.FindRequisitionFormById(id);

            return(Ok(rf));
        }
Exemplo n.º 5
0
        public List <RequisitionFormsProduct> GetListOfProductsRequested(List <int> rfIdList)
        {
            List <RequisitionForm> rfList = new List <RequisitionForm>();

            List <RequisitionFormsProduct> rfpConsolidatedList = new List <RequisitionFormsProduct>();

            foreach (int rfId in rfIdList)
            {
                RequisitionForm rf = db.RequisitionForms.Find(rfId);
                rfList.Add(rf);
            }
            foreach (RequisitionForm rf in rfList)
            {
                List <RequisitionFormsProduct> rfpList = db.RequisitionFormsProducts
                                                         .Where(x => x.RequisitionForm == rf)
                                                         .ToList();
                foreach (RequisitionFormsProduct rfp in rfpList)
                {
                    rfp.ProductBalanceForSR = rfp.ProductApproved - rfp.ProductCollectedTotal;
                    rfpConsolidatedList.Add(rfp);
                }
            }

            return(rfpConsolidatedList);
        }
        public IActionResult GetRequisitionById(int reqId)
        {
            System.Diagnostics.Debug.WriteLine("This is inside get req by Id : " + reqId);
            RequisitionForm rqform = rpservice.FindRequisitionFormById(reqId);

            return(Ok(rqform));
        }
Exemplo n.º 7
0
        public RequisitionForm FindRequisitionFormById(int id)
        {
            RequisitionForm rf = db.RequisitionForms
                                 .Where(x => x.Id == id)
                                 .FirstOrDefault();

            return(rf);
        }
Exemplo n.º 8
0
        public void ChangeRFStatusToCancelledById(int id)
        {
            RequisitionForm rf = db.RequisitionForms
                                 .Where(x => x.Id == id)
                                 .FirstOrDefault();

            rf.RFStatus = Enums.RFStatus.Cancelled;
            db.SaveChanges();
        }
Exemplo n.º 9
0
        public List <RequisitionForm> FindRFListByRF(List <int> rfIntList)
        {
            List <RequisitionForm> _rfList = new List <RequisitionForm>();

            foreach (int rfId in rfIntList)
            {
                RequisitionForm _rf = db.RequisitionForms.Find(rfId);
                _rfList.Add(_rf);
            }
            return(_rfList);
        }
        public IActionResult ViewApprovalRF(int id)
        {
            RequisitionViewModel rVModel = new RequisitionViewModel();
            //emp = JsonConvert.DeserializeObject<Employee>(HttpContext.Session.GetString("employee")) as Employee;
            RequisitionForm rf = rpservice.FindRequisitionFormById(id);
            List <RequisitionFormsProduct> rfpList = rpservice.FindRequisitionFormProductListById(id);

            //rVModel.employee = emp;
            rVModel.requisitionForm = rf;
            rVModel.rfpList         = rfpList;
            return(Ok(rVModel));
        }
        public IActionResult ViewRF(int reqId, String Username)
        {
            RequisitionViewModel vmRequisition = new RequisitionViewModel();

            //emp = eservice.GetEmployeeById(6);  //hard-coded id for test
            Employee        emp = eservice.GetEmployee(Username);
            RequisitionForm rf  = rpservice.FindRequisitionFormById(reqId);
            List <RequisitionFormsProduct> rfpList = rpservice.FindRequisitionFormProductListById(reqId);

            vmRequisition.employee        = emp;
            vmRequisition.requisitionForm = rf;
            vmRequisition.rfpList         = rfpList;
            return(Ok(vmRequisition));
        }
Exemplo n.º 12
0
        public ContentResult Update(FormCollection form)
        {
            JObject json = new JObject();
            json["error"] = false;
            json["message"] = "";

            if (form.GetValue("id") != null && form.GetValue("v") != null)
            {
                if (this.CheckLogin(AccountType.DepartmentHead) || this.CheckLogin(AccountType.Employee) && 
                    ((Employee)this.GetAccount().Profile).Department.Type == DepartmentType.HumanResources)
                {
                    try
                    {
                        RequisitionForm RequisitionForm =
                            new RequisitionForm(Int32.Parse(form.GetValue("id").AttemptedValue));
                        RequisitionForm.Status = (RequisitionStatus)Int32.Parse(form.GetValue("v").AttemptedValue);
                        RequisitionForm.Update(false);

                        if (RequisitionForm.Status == RequisitionStatus.Requisitioned)
                        {
                            Notification notif = new Notification();
                            notif.Message = "Your requisition request # " + RequisitionForm.RequisitionID
                                                                          + " has been filled";
                            notif.TimeStamp = DateTime.Now;
                            notif.Status = NotificationStatus.Unread;
                            notif.Account = new Account().FindByProfile(((Employee) RequisitionForm.RequestedBy).Profile.ProfileID);
                            notif.Create();
                        }
                    }
                    catch (Exception e)
                    {
                        json["error"] = true;
                        json["message"] = "Invalid data sent.";
                    }
                }
                else
                {
                    json["error"] = true;
                    json["message"] = "Oops! Looks like you're not an HR!";
                }
            }
            else
            {
                json["error"] = true;
                json["message"] = "Form is incomplete";
            }

            return Content(json.ToString(), "application/json");
        }
Exemplo n.º 13
0
        public List <StationeryRetrievalProduct> CreateSRPListFromRFIdList(List <int> rfIdList)
        {
            List <RequisitionForm>            rfList = new List <RequisitionForm>();
            List <RequisitionFormsProduct>    rfpConsolidatedList = new List <RequisitionFormsProduct>();
            List <StationeryRetrievalProduct> _srpList            = new List <StationeryRetrievalProduct>();

            foreach (int rfId in rfIdList)
            {
                RequisitionForm rf = db.RequisitionForms.Find(rfId);
                rfList.Add(rf);
            }
            foreach (RequisitionForm rf in rfList)
            {
                List <RequisitionFormsProduct> rfpList = db.RequisitionFormsProducts
                                                         .Where(x => x.RequisitionForm == rf)
                                                         .ToList();
                foreach (RequisitionFormsProduct rfp in rfpList)
                {
                    rfp.ProductBalanceForSR = rfp.ProductApproved - rfp.ProductCollectedTotal;
                    rfpConsolidatedList.Add(rfp);
                }
            }

            IEnumerable <Product> pListEnumerable = rfpConsolidatedList.Select(x => x.Product).Distinct();

            foreach (Product p in pListEnumerable)
            {
                StationeryRetrievalProduct srp = new StationeryRetrievalProduct()
                {
                    Product              = p,
                    ProductCount         = 0,
                    ProductApprovedCount = 0
                };
                _srpList.Add(srp);
            }

            foreach (StationeryRetrievalProduct srp in _srpList)
            {
                foreach (RequisitionFormsProduct rfpConsolidated in rfpConsolidatedList)
                {
                    if (srp.Product.Id == rfpConsolidated.Product.Id)
                    {
                        srp.ProductCount         = rfpConsolidated.ProductBalanceForSR + srp.ProductCount;
                        srp.ProductApprovedCount = rfpConsolidated.ProductApproved + srp.ProductApprovedCount;
                    }
                }
            }
            return(_srpList);
        }
        public RequisitionController()
        {
            requisition     = new Requisition();
            requisitionForm = new RequisitionForm();

            departmentRepository      = new DepartmentRepository();
            periodRepository          = new PeriodRepository();
            priorityRepository        = new PriorityRepository();
            productRepository         = new ProductRepository();
            requisitionRepository     = new RequisitionRepository();
            requisitionLineRepository = new RequisitionLineRepository();
            requisitionRuleRepository = new RequisitionRuleRepository();
            statusRepository          = new StatusRepository();
            supplierRepository        = new SupplierRepository();
        }
Exemplo n.º 15
0
        public bool ChangeRFStatusToRejectedById(RequisitionForm rf, Employee deptHead, string comment)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    //Find Employee
                    Employee _emp = db.Employees.Find(deptHead.Id);

                    //Check for comment if reject
                    if (comment == null || comment == "")
                    {
                        throw new Exception("There is no reply");
                    }

                    //Find the RF
                    RequisitionForm _rf = db.RequisitionForms.Find(rf.Id);

                    _rf.RFStatus       = RFStatus.Rejected;
                    _rf.RFHeadReply    = comment;
                    _rf.RFApprovalDate = DateTime.Now;
                    _rf.RFApprovalBy   = _emp;
                    db.RequisitionForms.Update(_rf);

                    db.SaveChanges();
                    transcat.Commit();

                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress("IMS System", "*****@*****.**"));
                    message.To.Add(new MailboxAddress(_rf.Employee.Firstname + " " + _rf.Employee.Lastname, _rf.Employee.Email));
                    message.Subject = "[ " + _rf.RFCode + " ] Status: Rejected";
                    message.Body    = new TextPart("plain")
                    {
                        Text = "[ " + _rf.RFCode + " ]: Approved" +
                               "\n Department Head Comments: " + _rf.RFHeadReply
                    };
                    EmailUtil eUtil = new EmailUtil();
                    eUtil.SendEmail(message);

                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
        public IActionResult ViewRF([FromRoute] int id)
        {
            RequisitionViewModel rVModel = new RequisitionViewModel();

            emp = JsonConvert.DeserializeObject <Employee>(HttpContext.Session.GetString("employee")) as Employee;

            RequisitionForm rf = rpService.FindRequisitionFormById(id);
            List <RequisitionFormsProduct> rfpList = rpService.FindRequisitionFormProductListById(id);
            List <DisbursementFormRequisitionFormProduct> dfrfpList = dfService.FindDFRFPListByRFId(id);
            List <DisbursementFormRequisitionForm>        dfrfList  = dfService.FindDFRFListByRFId(id);

            rVModel.employee        = emp;
            rVModel.requisitionForm = rf;
            rVModel.rfpList         = rfpList;
            rVModel.dfrfpList       = dfrfpList;
            rVModel.dfrfList        = dfrfList;

            return(View("RequisitionFormView", rVModel));
        }
Exemplo n.º 17
0
        public ActionResult view_single_request(string form_id, string notify, string sid)
        {
            employee_utility       eu   = new employee_utility();
            Employee               user = (Employee)Session["user"];
            List <RequisitionForm> notify_form_list;
            int count;

            if (notify == "seen")
            {
                using (ModelDBContext db = new ModelDBContext())
                {
                    RequisitionForm old_rec_to_update = db.RequisitionForms.Where(e => e.FormNumber == form_id).FirstOrDefault();
                    if (old_rec_to_update != null)
                    {
                        old_rec_to_update.Notification = "seen_by_emp";
                    }
                    db.SaveChanges();
                }
            }
            using (ModelDBContext db = new ModelDBContext())
            {
                notify_form_list = db.RequisitionForms.Where(f => f.EmployeeId == user.Id && (f.Notification == "approved_by_hod" || f.Notification == "rejected_by_hod")).ToList();
                count            = db.RequisitionForms.Where(f => f.EmployeeId == user.Id && (f.Notification == "approved_by_hod" || f.Notification == "rejected_by_hod")).Count();
            }

            Session["count"]            = count;
            Session["notify_form_list"] = notify_form_list;

            ViewData["form_cart"]        = eu.get_RequisitionFormDetails(form_id);
            ViewData["form_number"]      = form_id;
            ViewData["emp"]              = eu.get_employee(user);
            ViewData["emp_dept"]         = eu.get_department(user);
            ViewData["catalog_list"]     = eu.get_catalog_items();
            ViewData["single_form_view"] = true;
            ViewData["req_form"]         = eu.get_single_form_details(form_id);
            ViewData["sid"]              = sid;

            return(View("newrequest"));
        }
Exemplo n.º 18
0
        public ActionResult Requisition(FormCollection form)
        {
            JObject json = new JObject();
            json["error"] = false;
            json["message"] = true;

            string[] keys = new string[]
                            {
                                "month", "day", "year", "description", "position", "reason", "skills", "qualification",
                                "experience", "supervision", "description"
                            };

            if (this.HasValues(form, keys))
            {
                if (this.CheckLogin(AccountType.DepartmentHead))
                {
                    try
                    {
                        string sched = (Int32.Parse(form.GetValue("month").AttemptedValue) + 1).ToString("00") + "/"
                                        + (Int32.Parse(form.GetValue("day").AttemptedValue) + 1)
                                           .ToString("00") + "/"+ form.GetValue("year").AttemptedValue;

                        RequisitionForm rf = new RequisitionForm();
                        rf.Date = DateTime.Now;
                        rf.Department = ((Employee)this.GetAccount().Profile).Department;
                        rf.RequestedBy = ((Employee)this.GetAccount().Profile);

                        rf.Description = form.GetValue("description").AttemptedValue;
                        rf.Position = form.GetValue("position").AttemptedValue;
                        rf.ReasonforVacancy = form.GetValue("reason").AttemptedValue;
                        rf.SkillsRequired = form.GetValue("skills").AttemptedValue;
                        rf.Qualification = form.GetValue("qualification").AttemptedValue;
                        rf.ExperienceRequired = form.GetValue("experience").AttemptedValue;
                        rf.UnderSupervision = new Employee(Int32.Parse(form.GetValue("supervision").AttemptedValue));
                        rf.ExpectedJoiningDate = DateTime.ParseExact(sched, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        rf.Description = form.GetValue("description").AttemptedValue;
                        rf.Status = RequisitionStatus.Pending;

                        rf.Create();
                    

                        Notification notifS = new Notification();
                        notifS.Account = new Account().FindByProfile(rf.UnderSupervision.Profile.ProfileID);
                        notifS.Message = "Info: You have been assigned to supervise an incoming manpower requisition.";
                        notifS.TimeStamp = DateTime.Now;
                        notifS.Status = NotificationStatus.Unread;

                        notifS.Create();
                        DBHandler db = new DBHandler();
                        using (DataTable dt = db.Execute<DataTable>(
                            CRUD.READ,
                            "SELECT E.Profile FROM Employee E INNER JOIN Department D ON E.Department = D.DepartmentID WHERE D.Type = "
                            + ((int)DepartmentType.HumanResources)))
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                Notification notifHR = new Notification();
                                notifHR.Account = new Account().FindByProfile(Int32.Parse(row["Profile"].ToString()));
                                notifHR.TimeStamp = DateTime.Now;
                                notifHR.Status = NotificationStatus.Unread;
                                notifHR.Message = "A new requisition form was issued by the "
                                                  + (rf.UnderSupervision.Department.Type) + " department for the position: <b>" + rf.Position + "</b>";

                                notifHR.Create();
                            }
                        }

                        json["message"] = "Successfully completed request, please wait for further notification...";
                    }
                    catch (Exception e)
                    {
                        json["error"] = true;
                        json["message"] = e.Message;
                    }
                }
                else
                {
                    json["error"] = true;
                    json["message"] = "You are not authorized to continue...";
                }
            }

            return Content(json.ToString(), "application/json");
        }
Exemplo n.º 19
0
        public TrendAnalysisChartViewModel getTrend()
        {
            //TODO: write algorithm to retrieve the historical inventory trend from DB and return in the form of TrendAnalysisChartViewMOdel
            List <int> data1 = new List <int>()
            {
                5, 3, 4, 7, 2
            };

            //List<string> categroy = new List<string>()
            //    { "Puncher","Paper","Scissor","Clip","Exercise"};

            List <string> categroy = new List <string>();



            List <RequisitionFormsProduct> rfpList = getRequisitionsProducts();
            List <RequisitionForm>         rfList  = getRequisitions();
            List <Product>         plist           = getProduct();
            List <ProductCategory> pcList          = getProductCat();

            List <TrendAnalysisChartDetails> taList = new List <TrendAnalysisChartDetails>();

            int[][] quantity = new int[13][];
            for (int k = 0; k <= 12; k++)
            {
                quantity[k] = new int[19];
            }

            foreach (RequisitionFormsProduct rfp in rfpList)
            {
                Product         _p  = db.Products.Find(rfp.Product.Id);
                RequisitionForm _rf = db.RequisitionForms.Find(rfp.RequisitionForm.Id);
                ProductCategory _pc = db.ProductCategories.Find(_p.ProductCategory.Id);


                for (int i = 0; i <= 12; i++)
                {
                    if (_rf.RFDate.Month == i)
                    {
                        for (int j = 0; j <= 18; j++)
                        {
                            if (_p.ProductCategory.Id == j)
                            {
                                quantity[i][j] = quantity[i][j] + rfp.ProductApproved;
                            }
                        }
                    }
                }
            }
            categroy.Add("");

            foreach (ProductCategory pc in pcList)
            {
                categroy.Add(pc.ProductCategoryName);
            }

            TrendAnalysisChartViewModel vm = new TrendAnalysisChartViewModel();

            vm.category = categroy;

            string[] month = { "", "Jan", "Feb", "Mar", "April", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };


            List <TrendAnalysisChartDetails> trendDetails = new List <TrendAnalysisChartDetails>();

            for (int i = 1; i <= 12; i++)
            {
                TrendAnalysisChartDetails newDetail = new TrendAnalysisChartDetails();
                newDetail.name = month[i];
                newDetail.data = quantity[i].ToList();
                trendDetails.Add(newDetail);
            }

            vm.data = trendDetails;

            return(vm);
        }
Exemplo n.º 20
0
        public bool SaveStationaryRetrievalProducts(List <SRProductViewModel> productlist, Employee emp, string comment, List <int> selectedrequisiton, List <StationeryRetrievalProduct> srpList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())

            {
                try
                {
                    Employee _emp = db.Employees.Find(emp.Id);
                    List <RequisitionForm> rfList = FindRFListByRF(selectedrequisiton);

                    //Create empty srrfList
                    List <StationeryRetrievalRequisitionForm> _srrfList = new List <StationeryRetrievalRequisitionForm>();

                    //Create empty rfpList
                    List <RequisitionFormsProduct> _rfpList = new List <RequisitionFormsProduct>();

                    //Create empty srrfpList
                    List <StationeryRetrievalRequisitionFormProduct> _srrfpList = new List <StationeryRetrievalRequisitionFormProduct>();

                    //Create empty srpList
                    List <StationeryRetrievalProduct> _srpList = new List <StationeryRetrievalProduct>();

                    //Find the list of rfs on that day by the same employee
                    int count = FindStationaryRetrievalFormByDeptTodayCount(_emp) + 1;
                    //Define RF Code
                    string srfCode = "SR" + "/" + DateTime.Now.ToString("ddMMyy") + "/" + count.ToString();

                    //Create New SRF and SRFP

                    //DateTime ddToday = DateTime.Now;
                    StationeryRetrieval srfForm = new StationeryRetrieval()
                    {
                        StoreClerk = _emp,
                        SRCode     = srfCode,
                        SRStatus   = SRStatus.Open,
                        SRComments = comment,
                        SRDate     = DateTime.Now
                    };

                    db.StationeryRetrievals.Add(srfForm);
                    db.SaveChanges();

                    foreach (RequisitionForm rf in rfList)
                    {
                        StationeryRetrievalRequisitionForm _srrf = new StationeryRetrievalRequisitionForm()
                        {
                            StationeryRetrieval = srfForm,
                            RequisitionForm     = rf,
                            SRRFStatus          = SRRFStatus.Open
                        };
                        db.Add(_srrf);
                        _srrfList.Add(_srrf);
                        db.SaveChanges();

                        List <RequisitionFormsProduct> individualrfpList = db.RequisitionFormsProducts
                                                                           .Where(x => x.RequisitionForm == rf)
                                                                           .ToList();
                        foreach (RequisitionFormsProduct individualrfp in individualrfpList)
                        {
                            _rfpList.Add(individualrfp);
                        }
                    }

                    foreach (RequisitionFormsProduct _rfp in _rfpList)
                    {
                        StationeryRetrievalRequisitionFormProduct _srrfp = new StationeryRetrievalRequisitionFormProduct()
                        {
                            SR              = srfForm,
                            RFP             = _rfp,
                            ProductAssigned = 0
                        };
                        _srrfpList.Add(_srrfp);
                        db.Add(_srrfp);
                        db.SaveChanges();
                    }

                    if (productlist == null)
                    {
                        throw new Exception("No products to be stored as a Stationary Retrieval Form");
                    }
                    else
                    {
                        foreach (SRProductViewModel p in productlist)
                        {
                            Product product = db.Products.Where(x => x.ProductName == p.productname).FirstOrDefault();

                            StationeryRetrievalProduct _srfProduct = new StationeryRetrievalProduct();
                            _srfProduct.StationeryRetrieval   = srfForm;
                            _srfProduct.Product               = product;
                            _srfProduct.ProductRequestedTotal = p.productqty;
                            db.StationeryRetrievalProduct.Add(_srfProduct);
                            db.SaveChanges();
                        }
                        foreach (var requ_id in selectedrequisiton)
                        {
                            RequisitionForm requform = db.RequisitionForms.Where(x => x.Id == requ_id).FirstOrDefault();
                            requform.RFStatus = RFStatus.Ongoing;
                            db.SaveChanges();
                        }
                    }

                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Exemplo n.º 21
0
        public bool saveReceivedProds3(List <StationeryRetrievalProduct> srpList,
                                       int SRid,
                                       Employee warehousepacker,
                                       Employee storeclerk,
                                       List <StationeryRetrievalRequisitionForm> srrfList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    //Check for store clerk and warehouse packer
                    Employee _whpacker = empService.FindByUsernameAndPassword(warehousepacker.Username.ToLower(), warehousepacker.Password);
                    Employee _stclerk  = empService.FindByUsernameAndPassword(storeclerk.Username.ToLower(), storeclerk.Password);

                    if (_whpacker.EmployeeType.EmployeeTypeName != "Warehouse Packer")
                    {
                        throw new Exception("The user type is wrong");
                    }

                    if (_stclerk.EmployeeType.EmployeeTypeName != "Store Clerk" && _stclerk.EmployeeType.EmployeeTypeName != "Store Supervisor" && _stclerk.EmployeeType.EmployeeTypeName != "Store Manager")
                    {
                        throw new Exception("The user type is wrong");
                    }

                    if (_whpacker == null || _stclerk == null)
                    {
                        throw new Exception("The username or password is wrong, please login again");
                    }

                    DateTime transactDate = DateTime.Now;

                    //Create RF List
                    List <RequisitionForm> _rfList = new List <RequisitionForm>();

                    //Create new empty list to save to db
                    List <StationeryRetrievalProduct> _srpList = new List <StationeryRetrievalProduct>();

                    //Create new empty list to save to db
                    List <StationeryRetrievalRequisitionForm> _srrfList = new List <StationeryRetrievalRequisitionForm>();

                    //Find sr
                    StationeryRetrieval _sr = db.StationeryRetrievals.Find(SRid);
                    _sr.SRStatus        = SRStatus.PendingAssignment;
                    _sr.WarehousePacker = _whpacker;
                    _sr.SRRetrievalDate = transactDate;
                    _sr.StoreClerk      = _stclerk;
                    db.StationeryRetrievals.Update(_sr);
                    db.SaveChanges();



                    //Define invtrans Code
                    int count = invtService.FindInvTransByTodayCount();

                    foreach (StationeryRetrievalProduct srp in srpList)
                    {
                        if (srp.ProductReceivedTotal < 0)
                        {
                            throw new Exception("This value should not be negative");
                        }

                        count++;

                        StationeryRetrievalProduct _srp = db.StationeryRetrievalProduct.Find(srp.Id);
                        _srp.ProductReceivedTotal = srp.ProductReceivedTotal;
                        _srpList.Add(_srp);
                        db.StationeryRetrievalProduct.Update(_srp);
                        db.SaveChanges();

                        //Check for logic in terms of each RFP should not have more than what was specified


                        //create itCode
                        string invtransCode = "IT" + "/" + DateTime.Now.ToString("ddMMyy") + "/" + count.ToString();

                        //Create It
                        InventoryTransaction _it = new InventoryTransaction()
                        {
                            EmployeeId = _sr.StoreClerk.Id,
                            ProductId  = _srp.Product.Id,
                            Employee   = _sr.StoreClerk,
                            InventoryChangeQuantity = -_srp.ProductReceivedTotal,
                            InventoryTransComments  = _sr.SRCode,
                            InventoryTransDate      = _sr.SRRetrievalDate,
                            ITStatus = ITStatus.Auto,
                            ITCode   = invtransCode,
                            Product  = _srp.Product
                        };

                        db.InventoryTransactions.Add(_it);
                        db.SaveChanges();



                        //Adjust Inventory Quantity
                        Product _p = db.Products.Find(_srp.Product.Id);
                        _p.InventoryQuantity = _p.InventoryQuantity + _it.InventoryChangeQuantity;
                        if (_p.InventoryQuantity < 0)
                        {
                            throw new Exception(_p.InventoryQuantity + " is not enough");
                        }
                        db.Products.Update(_p);
                        db.SaveChanges();
                    }

                    foreach (StationeryRetrievalRequisitionForm srrf in srrfList)
                    {
                        StationeryRetrievalRequisitionForm _srrf = db.StationeryRetrievalRequisitionForms.Find(srrf.Id);
                        _srrf.SRRFStatus = SRRFStatus.PendingAssignment;
                        db.StationeryRetrievalRequisitionForms.Update(_srrf);
                        db.SaveChanges();

                        RequisitionForm _rf = db.RequisitionForms.Find(_srrf.RequisitionForm.Id);
                        _rf.RFStatus = RFStatus.Ongoing;

                        db.RequisitionForms.Update(_rf);
                        db.SaveChanges();
                    }
                    db.SaveChanges();

                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Exemplo n.º 22
0
        public bool ChangeRFStatusToApprovedById(RequisitionForm rf, List <RequisitionFormsProduct> rfpList, Employee deptHead, string comment)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    //Find Employee
                    Employee _emp = db.Employees.Find(deptHead.Id);

                    RequisitionForm _rf = db.RequisitionForms
                                          .Where(x => x.Id == rf.Id)
                                          .FirstOrDefault();

                    _rf.RFStatus       = RFStatus.Approved;
                    _rf.RFHeadReply    = comment;
                    _rf.RFApprovalDate = DateTime.Now;
                    _rf.RFApprovalBy   = _emp;
                    db.RequisitionForms.Update(_rf);



                    List <RequisitionFormsProduct> _rfpList = new List <RequisitionFormsProduct>();


                    foreach (RequisitionFormsProduct rfp in rfpList)
                    {
                        RequisitionFormsProduct _rfp = db.RequisitionFormsProducts.Where(x => x.Id == rfp.Id).FirstOrDefault();
                        _rfp.ProductApproved = rfp.ProductApproved;
                        db.RequisitionFormsProducts.Update(_rfp);
                        _rfpList.Add(_rfp);
                    }

                    //Check if all products are not null
                    bool isAllProductsQuantityLessThanZero = true;

                    foreach (RequisitionFormsProduct _rfp in _rfpList)
                    {
                        if (_rfp.ProductApproved >= 0)
                        {
                            isAllProductsQuantityLessThanZero = false;
                            break;
                        }
                    }

                    if (isAllProductsQuantityLessThanZero == true)
                    {
                        throw new Exception("All items cannot be 0");
                    }

                    db.SaveChanges();
                    transcat.Commit();

                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress("IMS System", "*****@*****.**"));
                    message.To.Add(new MailboxAddress(_rf.Employee.Firstname + " " + _rf.Employee.Lastname, _rf.Employee.Email));
                    message.Subject = "[ " + _rf.RFCode + " ] Status: Approved";
                    message.Body    = new TextPart("plain")
                    {
                        Text = "[ " + _rf.RFCode + " ]: Approved" +
                               "\nDepartment Head Comments: " + _rf.RFHeadReply
                    };
                    EmailUtil eUtil = new EmailUtil();
                    eUtil.SendEmail(message);

                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Exemplo n.º 23
0
        public bool UpdateRequistionProduct(Employee emp, string comment, List <Product> pList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())

            {
                try
                {
                    if (pList == null)
                    {
                        throw new Exception("No products to be stored as a Requisition Form");
                    }
                    bool isAllProductsQuantityLessThanZero = true;
                    foreach (Product p in pList)
                    {
                        if (p.ProductRequested >= 0)
                        {
                            isAllProductsQuantityLessThanZero = false;
                            break;
                        }
                    }

                    if (isAllProductsQuantityLessThanZero == true)
                    {
                        throw new Exception("Quantity of Product should be at least 0");
                    }

                    //find employee
                    Employee _emp = db.Employees.Find(emp.Id);

                    //Find the list of rfs on that day by the same employee
                    List <RequisitionForm> rfCheckList = FindRequisitionFormByDeptToday(_emp);

                    //Find the total no of rfs sent on the same day by the same department
                    int count = rfCheckList.Count + 1;

                    //rfCreateDate
                    DateTime createDate = DateTime.Now;

                    //Define RF Code
                    string rfCode = "RF" + "/" + _emp.Department.DeptCode + "/" + createDate.ToString("ddMMyy") + "/" + count.ToString();

                    //Create New RF
                    RequisitionForm _rf = new RequisitionForm()
                    {
                        RFCode     = rfCode,
                        Employee   = _emp,
                        RFStatus   = RFStatus.Submitted,
                        RFDate     = createDate,
                        RFComments = comment
                    };
                    db.RequisitionForms.Add(_rf);
                    db.SaveChanges();


                    foreach (Product p in pList)
                    {
                        Product _p = db.Products.Find(p.Id);

                        RequisitionFormsProduct _rfp = new RequisitionFormsProduct()
                        {
                            RequisitionForm  = _rf,
                            Product          = _p,
                            ProductRequested = p.ProductRequested
                        };
                        db.RequisitionFormsProducts.Add(_rfp);
                        db.SaveChanges();
                    }

                    transcat.Commit();

                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress("IMS System", "*****@*****.**"));
                    message.To.Add(new MailboxAddress(_emp.SupervisedBy.Firstname + " " + _emp.SupervisedBy.Lastname, _emp.SupervisedBy.Email));
                    message.Subject = "Requisition Form for Approval - " + _rf.RFCode;
                    message.Body    = new TextPart("plain")
                    {
                        Text = "You have an outstanding Requisition Form  - " + _rf.RFCode + "\nthis is pending for approval"
                    };
                    EmailUtil eUtil = new EmailUtil();
                    eUtil.SendEmail(message);

                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
        // GET: RequisitionFormDetails/Details/5
        public ActionResult Details(string id, string sessionId)
        {
            if (sessionId == null || id == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            StoreClerk      storeclerk          = db2.StoreClerks.Where(p => p.SessionId == sessionId).FirstOrDefault();
            StoreManager    storeManager        = db2.StoreManagers.Where(p => p.SessionId == sessionId).FirstOrDefault();
            StoreSupervisor storeSupervisor     = db2.StoreSupervisors.Where(p => p.SessionId == sessionId).FirstOrDefault();
            RequisitionForm request             = db1.RequisitionForms.Where(p => p.FormNumber == id).FirstOrDefault();
            List <RequisitionFormDetail> detail = db.RequisitionFormDetails.Where(x => x.FormNumber == id).ToList();
            string   eId          = request.EmployeeId;
            Employee emp          = db.Employees.Where(y => y.Id == eId).FirstOrDefault();
            string   emailAddress = emp.EmailAddress;
            string   subject      = "Your requisition has been received";
            string   message      = "<p>Dear " + emp.UserName + "." + "</p><br/><p>Your requisition has been received and will be pending</p><br/><p>Stationery Management Team</p>";

            if (storeclerk != null)
            {
                if (request.Status == "Approved" && request.Status != "Completed")
                {
                    util.SendEmail(emailAddress, subject, message);
                    request.DateReceived = DateTime.Now;
                    request.ReceivedBy   = storeclerk.Id;
                    request.Status       = "Read";
                }
                db1.Entry(request).State = EntityState.Modified;
                db1.SaveChanges();
                int num             = db.RequisitionForms.Where(x => x.Status == "Approved").Count();
                int numDisbuserment = db.DisbursementLists.Where(x => x.Status == "Pending").Count();
                int numOutS         = db.OutstandingLists.Where(x => x.Status == "Awaiting Goods").Count();
                int numRetrive      = db.StationeryRetrievalForms.Where(x => x.Status == "Pending").Count();
                int numPO           = db.PurchaseOrders.Where(x => x.Status == "Not Submitted").Count();
                int numStock        = db.StockAdjustmentVouchers.Where(x => x.Status == "Pending").Count();
                ViewData["sumTotal"]  = (num + numDisbuserment + numOutS + numRetrive + numPO + numStock).ToString();
                ViewData["sessionId"] = storeclerk.SessionId;
                ViewData["username"]  = storeclerk.UserName;
                ViewData["tag"]       = "storeclerk";
                return(View(detail));
            }
            else if (storeManager != null)
            {
                int num             = db.RequisitionForms.Where(x => x.Status == "Approved").Count();
                int numDisbuserment = db.DisbursementLists.Where(x => x.Status == "Pending").Count();
                int numOutS         = db.OutstandingLists.Where(x => x.Status == "Awaiting Goods").Count();
                int numRetrive      = db.StationeryRetrievalForms.Where(x => x.Status == "Pending").Count();
                int numPO           = db.PurchaseOrders.Where(x => x.Status == "Not Submitted").Count();
                int numStock        = db.StockAdjustmentVouchers.Where(x => x.Status == "Pending").Count();
                ViewData["sumTotal"]  = (num + numDisbuserment + numOutS + numRetrive + numPO + numStock).ToString();
                ViewData["sessionId"] = storeManager.SessionId;
                ViewData["username"]  = storeManager.UserName;
                ViewData["tag"]       = "storeManager";
                return(View(detail));
            }
            else if (storeSupervisor != null)
            {
                int num             = db.RequisitionForms.Where(x => x.Status == "Approved").Count();
                int numDisbuserment = db.DisbursementLists.Where(x => x.Status == "Pending").Count();
                int numOutS         = db.OutstandingLists.Where(x => x.Status == "Awaiting Goods").Count();
                int numRetrive      = db.StationeryRetrievalForms.Where(x => x.Status == "Pending").Count();
                int numPO           = db.PurchaseOrders.Where(x => x.Status == "Not Submitted").Count();
                int numStock        = db.StockAdjustmentVouchers.Where(x => x.Status == "Pending").Count();
                ViewData["sumTotal"]  = (num + numDisbuserment + numOutS + numRetrive + numPO + numStock).ToString();
                ViewData["sessionId"] = storeSupervisor.SessionId;
                ViewData["username"]  = storeSupervisor.UserName;
                ViewData["tag"]       = "storeSupervisor";
                return(View(detail));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Exemplo n.º 25
0
        public DBSeeder(InventoryManagementSystemContext db,
                        IWebHostEnvironment environment,
                        ProductService pService,
                        DepartmentService dService,
                        ProductCategoryService pcService,
                        DisbursementFormService dfService,
                        StationeryRetrievalFormService srfService,
                        EmployeeTypeService etService,
                        EmployeeService empService,
                        RequisitionService rfService,
                        DelegationService delService,
                        SupplierService supService,
                        SupplierProductService spService,
                        InventoryTransactionService itService)
        {
            _hostingEnvironment = environment;



            var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");

            string filePath6   = Path.Combine(uploads, "ProductCategory.csv");
            string jsonString6 = ReadCSVFileUtil.ReadCSVFile(filePath6);
            List <CSVProductCategory> productCategories = (List <CSVProductCategory>)JsonConvert.DeserializeObject(jsonString6, (typeof(List <CSVProductCategory>)));

            pcService.SaveProductCategoryFromCSV(productCategories);

            string             filePath7   = Path.Combine(uploads, "Supplier.csv");
            string             jsonString7 = ReadCSVFileUtil.ReadCSVFile(filePath7);
            List <CSVSupplier> suppliers   = (List <CSVSupplier>)JsonConvert.DeserializeObject(jsonString7, (typeof(List <CSVSupplier>)));

            supService.SaveSuppliersFromCSV(suppliers);

            string filePath3   = Path.Combine(uploads, "EmployeeType.csv");
            string jsonString3 = ReadCSVFileUtil.ReadCSVFile(filePath3);
            List <CSVEmployeeType> employeeTypes = (List <CSVEmployeeType>)JsonConvert.DeserializeObject(jsonString3, (typeof(List <CSVEmployeeType>)));

            etService.SaveEmployeeTypesFromCSV(employeeTypes);

            ProductCategory pc1  = pcService.findProductCategory("Clip");
            ProductCategory pc2  = pcService.findProductCategory("Envelope");
            ProductCategory pc3  = pcService.findProductCategory("Eraser");
            ProductCategory pc4  = pcService.findProductCategory("Exercise");
            ProductCategory pc5  = pcService.findProductCategory("File");
            ProductCategory pc6  = pcService.findProductCategory("Pen");
            ProductCategory pc7  = pcService.findProductCategory("Puncher");
            ProductCategory pc8  = pcService.findProductCategory("Pad");
            ProductCategory pc9  = pcService.findProductCategory("Paper");
            ProductCategory pc10 = pcService.findProductCategory("Ruler");
            ProductCategory pc11 = pcService.findProductCategory("Scissors");
            ProductCategory pc12 = pcService.findProductCategory("Tape");
            ProductCategory pc13 = pcService.findProductCategory("Sharpener");
            ProductCategory pc14 = pcService.findProductCategory("Shorthand");
            ProductCategory pc15 = pcService.findProductCategory("Stapler");
            ProductCategory pc16 = pcService.findProductCategory("Tacks");
            ProductCategory pc17 = pcService.findProductCategory("Tparency");
            ProductCategory pc18 = pcService.findProductCategory("Tray");

            string            filePath1  = Path.Combine(uploads, "Product.csv");
            string            jsonString = ReadCSVFileUtil.ReadCSVFile(filePath1);
            List <CSVProduct> products   = (List <CSVProduct>)JsonConvert.DeserializeObject(jsonString, (typeof(List <CSVProduct>)));

            pService.SaveProductsFromCSV(products);



            string filePath9   = Path.Combine(uploads, "SupplierProduct.csv");
            string jsonString9 = ReadCSVFileUtil.ReadCSVFile(filePath9);
            List <CSVSupplierProduct> supplierProducts = (List <CSVSupplierProduct>)JsonConvert.DeserializeObject(jsonString9, (typeof(List <CSVSupplierProduct>)));

            spService.SaveSupplierProductsFromCSV(supplierProducts);

            //save the images under images folder to database
            var           imagefolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
            DirectoryInfo Folder      = new DirectoryInfo(imagefolder);

            FileInfo[]    Images     = Folder.GetFiles();
            List <String> imagesList = new List <String>();

            foreach (var image in Images)
            {
                imagesList.Add(String.Format(@"{0}", image.Name));
            }
            pService.SaveProductImages(imagesList);


            EmployeeType empType1 = etService.FindEmployeeTypeByEmployeeTypeName("Store Clerk");
            EmployeeType empType2 = etService.FindEmployeeTypeByEmployeeTypeName("Store Supervisor");
            EmployeeType empType3 = etService.FindEmployeeTypeByEmployeeTypeName("Store Manager");
            EmployeeType empType4 = etService.FindEmployeeTypeByEmployeeTypeName("Employee");
            EmployeeType empType5 = etService.FindEmployeeTypeByEmployeeTypeName("Department Head");
            EmployeeType empType6 = etService.FindEmployeeTypeByEmployeeTypeName("Department Representative");
            EmployeeType empType7 = etService.FindEmployeeTypeByEmployeeTypeName("Warehouse Packer");
            EmployeeType empType8 = etService.FindEmployeeTypeByEmployeeTypeName("Temporary Department Head");


            CollectionPoint cp1 = new CollectionPoint()
            {
                CollectionName = "Stationery Store - Administration Building"
            };
            CollectionPoint cp2 = new CollectionPoint()
            {
                CollectionName = "Management School"
            };
            CollectionPoint cp3 = new CollectionPoint()
            {
                CollectionName = "Medical School"
            };
            CollectionPoint cp4 = new CollectionPoint()
            {
                CollectionName = "Engineering School"
            };
            CollectionPoint cp5 = new CollectionPoint()
            {
                CollectionName = "Science School"
            };
            CollectionPoint cp6 = new CollectionPoint()
            {
                CollectionName = "University Hospital"
            };

            db.Add(cp1);
            db.Add(cp2);
            db.Add(cp3);
            db.Add(cp4);
            db.Add(cp5);
            db.Add(cp6);

            Department dept1 = new Department()
            {
                DepartmentName = "Store", DeptCode = "STOR", CollectionPoint = cp1, PhoneNumber = "12345678"
            };
            Department dept2 = new Department()
            {
                DepartmentName = "English Department", DeptCode = "ENDP", CollectionPoint = cp2, PhoneNumber = "98765432"
            };
            Department dept3 = new Department()
            {
                DepartmentName = "Chinese Department", DeptCode = "CHSL", CollectionPoint = cp2, PhoneNumber = "87654321"
            };
            Department dept4 = new Department()
            {
                DepartmentName = "Engineering Department", DeptCode = "ENGD", CollectionPoint = cp1, PhoneNumber = "76543219"
            };
            Department dept5 = new Department()
            {
                DepartmentName = "Arts Department", DeptCode = "ARTD", CollectionPoint = cp3, PhoneNumber = "53046012"
            };
            Department dept6 = new Department()
            {
                DepartmentName = "Business Department", DeptCode = "BIZD", CollectionPoint = cp4, PhoneNumber = "15397864"
            };
            Department dept7 = new Department()
            {
                DepartmentName = "Science Department", DeptCode = "SCID", CollectionPoint = cp5, PhoneNumber = "68425397"
            };
            Department dept8 = new Department()
            {
                DepartmentName = "Management Department", DeptCode = "MNGD", CollectionPoint = cp6, PhoneNumber = "86957412"
            };
            Department dept9 = new Department()
            {
                DepartmentName = "HQ Department", DeptCode = "HQDP", CollectionPoint = cp3, PhoneNumber = "32540325"
            };
            Department dept10 = new Department()
            {
                DepartmentName = "Music Department", DeptCode = "MSDP", CollectionPoint = cp4, PhoneNumber = "78954120"
            };

            db.Add(dept1);
            db.Add(dept2);
            db.Add(dept3);
            db.Add(dept4);
            db.Add(dept5);
            db.Add(dept6);
            db.Add(dept7);
            db.Add(dept8);
            db.Add(dept9);
            db.Add(dept10);
            db.SaveChanges();

            string             filePath4   = Path.Combine(uploads, "Employee.csv");
            string             jsonString4 = ReadCSVFileUtil.ReadCSVFile(filePath4);
            List <CSVEmployee> employees   = (List <CSVEmployee>)JsonConvert.DeserializeObject(jsonString4, (typeof(List <CSVEmployee>)));

            empService.SaveEmployeesFromCSV(employees);
            empService.SaveEmployeesSupervisedByFromCSV(employees);

            Employee emp1  = empService.GetEmployee("thinn");
            Employee emp2  = empService.GetEmployee("arjun");
            Employee emp3  = empService.GetEmployee("rohan");
            Employee emp4  = empService.GetEmployee("darell");
            Employee emp5  = empService.GetEmployee("yamone");
            Employee emp6  = empService.GetEmployee("sheryl");
            Employee emp7  = empService.GetEmployee("xinqi");
            Employee emp8  = empService.GetEmployee("yanbin");
            Employee emp9  = empService.GetEmployee("darellmgr2");
            Employee emp10 = empService.GetEmployee("thinn2");

            Product pr1 = pService.FindProductById(1);
            Product pr2 = pService.FindProductById(2);
            Product pr3 = pService.FindProductById(3);
            Product pr4 = pService.FindProductById(4);
            Product pr5 = pService.FindProductById(5);
            Product pr6 = pService.FindProductById(6);


            DateTime dd1  = new DateTime(2020, 8, 13, 8, 30, 20);
            DateTime dd2  = new DateTime(2020, 8, 14, 8, 30, 20);
            DateTime dd3  = new DateTime(2020, 8, 12, 8, 40, 20);
            DateTime dd4  = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd13 = new DateTime(2020, 8, 15, 8, 30, 20);



            RequisitionForm rq1 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.Approved, RFDate = dd1, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9
            };
            RequisitionForm rq2 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd2.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.Ongoing, RFDate = dd2, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9
            };
            //RequisitionForm rq3 = new RequisitionForm() { RFCode = "RF/" + emp2.Department.DeptCode + "/" + dd3.ToString("ddMMyy") + "/1", Employee = emp2, RFStatus = Enums.RFStatus.Approved, RFDate = dd3, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9 };
            RequisitionForm rq4 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/2", Employee = emp1, RFStatus = Enums.RFStatus.Submitted, RFDate = dd1
            };
            RequisitionForm rq5 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd2.ToString("ddMMyy") + "/2", Employee = emp1, RFStatus = Enums.RFStatus.Submitted, RFDate = dd2
            };

            db.Add(rq1);
            db.Add(rq2);
            //db.Add(rq3);
            db.Add(rq4);
            db.Add(rq5);



            RequisitionFormsProduct rq1_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr1, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq1_p2 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr2, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq2_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq2, Product = pr1, ProductRequested = 5, ProductApproved = 5
            };
            RequisitionFormsProduct rq2_p2 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq2, Product = pr2, ProductRequested = 3, ProductApproved = 2
            };
            //RequisitionFormsProduct rq3_p1 = new RequisitionFormsProduct() { RequisitionForm = rq3, Product = pr1, ProductRequested = 10, ProductApproved = 5 };
            //RequisitionFormsProduct rq3_p2 = new RequisitionFormsProduct() { RequisitionForm = rq3, Product = pr2, ProductRequested = 10, ProductApproved = 7 };
            RequisitionFormsProduct rq4_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr4, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq5_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr5, ProductRequested = 10, ProductApproved = 1
            };



            db.Add(rq1);
            db.Add(rq2);
            //db.Add(rq3);

            db.Add(rq1_p1);
            db.Add(rq1_p2);
            db.Add(rq2_p1);
            db.Add(rq2_p2);
            //db.Add(rq3_p1);
            //db.Add(rq3_p2);
            db.Add(rq4_p1);
            db.Add(rq5_p1);

            //db.SaveChanges();

            /*For Testing*/
            StationeryRetrieval sr1 = new StationeryRetrieval()
            {
                SRCode = "SR/" + dd1.ToString("ddMMyy") + "/1", SRStatus = Enums.SRStatus.PendingAssignment, SRComments = "Pending Assignment", SRDate = dd1, StoreClerk = emp1, WarehousePacker = emp7, SRRetrievalDate = dd2
            };
            StationeryRetrieval sr2 = new StationeryRetrieval()
            {
                SRCode = "SR/" + dd1.ToString("ddMMyy") + "/2", SRStatus = Enums.SRStatus.Assigned, SRComments = "Assigned", SRDate = dd1, StoreClerk = emp1, WarehousePacker = emp7, SRRetrievalDate = dd2, SRAssignedDate = dd13
            };

            //StationeryRetrieval sr3 = new StationeryRetrieval() { SRCode = "SR/" + dd1.ToString("ddMMyy") + "/3", SRStatus = Enums.SRStatus.Open, SRComments = "Open", SRDate = dd1, StoreClerk = emp1 };
            db.Add(sr1);
            db.Add(sr2);
            //db.Add(sr3);
            db.SaveChanges();

            StationeryRetrievalProduct srpr1 = new StationeryRetrievalProduct()
            {
                Product = pr1, ProductRequestedTotal = 5, StationeryRetrieval = sr1, ProductReceivedTotal = 4
            };
            StationeryRetrievalProduct srpr2 = new StationeryRetrievalProduct()
            {
                Product = pr2, ProductRequestedTotal = 10, StationeryRetrieval = sr1, ProductReceivedTotal = 10
            };
            StationeryRetrievalProduct srpr3 = new StationeryRetrievalProduct()
            {
                Product = pr1, ProductRequestedTotal = 5, StationeryRetrieval = sr2
            };
            StationeryRetrievalProduct srpr4 = new StationeryRetrievalProduct()
            {
                Product = pr2, ProductRequestedTotal = 10, StationeryRetrieval = sr2
            };

            db.Add(srpr1);
            db.Add(srpr2);
            db.Add(srpr3);
            db.Add(srpr4);
            //db.Add(srpr5);
            //db.Add(srpr6);
            db.SaveChanges();

            StationeryRetrievalRequisitionForm sr1_rf_1 = new StationeryRetrievalRequisitionForm()
            {
                RequisitionForm = rq1, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr1
            };
            StationeryRetrievalRequisitionForm sr1_rf_2 = new StationeryRetrievalRequisitionForm()
            {
                RequisitionForm = rq2, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr1
            };

            //StationeryRetrievalRequisitionForm sr2_rf_3 = new StationeryRetrievalRequisitionForm() { RequisitionForm = rq3, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr2 };
            db.Add(sr1_rf_1);
            db.Add(sr1_rf_2);
            //db.Add(sr2_rf_3);
            db.SaveChanges();

            StationeryRetrievalRequisitionFormProduct sr1_rf1_pr_1 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq1_p1
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf1_pr_2 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq1_p2
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf2_pr_1 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq2_p1
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf2_pr_2 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq2_p2
            };

            //StationeryRetrievalRequisitionFormProduct sr1_rf3_pr_1 = new StationeryRetrievalRequisitionFormProduct() { SR = sr1, RFP = rq3_p2 };

            db.Add(sr1_rf1_pr_1);
            db.Add(sr1_rf1_pr_2);
            db.Add(sr1_rf2_pr_1);
            db.Add(sr1_rf2_pr_2);

            db.SaveChanges();
            /*End For Testing*/



            //Testing for RequisitionFormDisplay

            DateTime dd5 = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd6 = new DateTime(2020, 8, 11, 8, 30, 20);
            DateTime dd7 = new DateTime(2020, 8, 10, 8, 30, 20);

            string filePath5              = Path.Combine(uploads, "RequisitionForm.csv");
            string jsonString5            = ReadCSVFileUtil.ReadCSVFile(filePath5);
            List <CSVRequisitionForm> rfs = (List <CSVRequisitionForm>)JsonConvert.DeserializeObject(jsonString5, (typeof(List <CSVRequisitionForm>)));

            rfService.SaveRFFromCSV(rfs);

            RequisitionForm rq6 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd5.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.NotCompleted, RFDate = dd5, RFApprovalDate = dd6, RFApprovalBy = emp9
            };
            RequisitionFormsProduct rfp1 = new RequisitionFormsProduct()
            {
                Product = pr1, ProductRequested = 10, RequisitionForm = rq6, ProductCollectedTotal = 9, ProductApproved = 10
            };
            RequisitionFormsProduct rfp2 = new RequisitionFormsProduct()
            {
                Product = pr2, ProductRequested = 20, RequisitionForm = rq6, ProductCollectedTotal = 7, ProductApproved = 10
            };

            db.Add(rq6);
            db.Add(rfp1);
            db.Add(rfp2);

            DisbursementForm df1 = new DisbursementForm()
            {
                CollectionPoint = cp1, DFCode = "DF/" + emp2.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/1", DeptRep = emp2, StoreClerk = emp4, DFDeliveryDate = dd2, DFStatus = Enums.DFStatus.Created, DFDate = dd1
            };
            DisbursementForm df2 = new DisbursementForm()
            {
                CollectionPoint = cp2, DFCode = "DF/" + emp2.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/2", DeptRep = emp2, StoreClerk = emp4, DFDeliveryDate = dd2, DFStatus = Enums.DFStatus.Completed, DFDate = dd1
            };
            DisbursementFormRequisitionForm dfrf1 = new DisbursementFormRequisitionForm()
            {
                DisbursementForm = df1, DFRFStatus = Enums.DFRFStatus.Assigned, RequisitionForm = rq1
            };
            DisbursementFormRequisitionForm dfrf2 = new DisbursementFormRequisitionForm()
            {
                DisbursementForm = df1, DFRFStatus = Enums.DFRFStatus.Assigned, RequisitionForm = rq2
            };
            DisbursementFormRequisitionFormProduct dfrfp1 = new DisbursementFormRequisitionFormProduct()
            {
                DisbursementForm = df1, RequisitionFormsProduct = rfp1, ProductCollected = 9
            };
            DisbursementFormRequisitionFormProduct dfrfp2 = new DisbursementFormRequisitionFormProduct()
            {
                DisbursementForm = df1, RequisitionFormsProduct = rfp2, ProductCollected = 7
            };

            db.Add(df1);
            db.Add(df2);
            db.Add(dfrf1);
            db.Add(dfrf2);
            db.Add(dfrfp1);
            db.Add(dfrfp2);
            db.SaveChanges();

            //DisbursementFormRequisitionForm dfrf3 = new DisbursementFormRequisitionForm() { DFRFStatus = Enums.DFRFStatus.PendingDelivery, DisbursementForm = df1, RequisitionForm = rq1 };
            //DisbursementFormRequisitionForm dfrf4 = new DisbursementFormRequisitionForm() { DFRFStatus = Enums.DFRFStatus.PendingDelivery, DisbursementForm = df1, RequisitionForm = rq2 };
            //db.Add(dfrf3);
            //db.Add(dfrf4);
            db.SaveChanges();
            DisbursementFormProduct dfp1 = new DisbursementFormProduct()
            {
                DisbursementForm = df1, Product = pr1, ProductToDeliverTotal = 10
            };
            DisbursementFormProduct dfp2 = new DisbursementFormProduct()
            {
                DisbursementForm = df1, Product = pr2, ProductToDeliverTotal = 40
            };

            db.Add(dfp1);
            db.Add(dfp2);
            db.SaveChanges();


            Supplier sup1  = db.Suppliers.Find(1);
            Supplier sup2  = db.Suppliers.Find(2);
            Supplier sup3  = db.Suppliers.Find(3);
            Supplier sup4  = db.Suppliers.Find(4);
            Supplier sup5  = db.Suppliers.Find(5);
            Supplier sup6  = db.Suppliers.Find(6);
            Supplier sup7  = db.Suppliers.Find(7);
            Supplier sup8  = db.Suppliers.Find(8);
            Supplier sup9  = db.Suppliers.Find(9);
            Supplier sup10 = db.Suppliers.Find(10);
            Supplier sup11 = db.Suppliers.Find(11);
            Supplier sup12 = db.Suppliers.Find(12);
            Supplier sup13 = db.Suppliers.Find(13);
            Supplier sup14 = db.Suppliers.Find(14);
            Supplier sup15 = db.Suppliers.Find(15);
            Supplier sup16 = db.Suppliers.Find(16);
            Supplier sup17 = db.Suppliers.Find(17);
            Supplier sup18 = db.Suppliers.Find(18);
            Supplier sup19 = db.Suppliers.Find(19);
            Supplier sup20 = db.Suppliers.Find(20);

            //db.Add(sup1);
            //db.Add(sup2);
            //db.Add(sup3);
            //db.Add(sup4);
            db.SaveChanges();

            DateTime dd8  = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd9  = new DateTime(2020, 8, 22, 8, 30, 20);
            DateTime dd10 = new DateTime(2020, 7, 10, 8, 40, 20);
            DateTime dd11 = new DateTime(2020, 9, 12, 8, 30, 20);
            DateTime dd12 = new DateTime(2020, 9, 13, 9, 30, 20);

            SupplierProduct sp1 = db.SupplierProducts.Find(1);
            SupplierProduct sp2 = db.SupplierProducts.Find(6);
            SupplierProduct sp3 = db.SupplierProducts.Find(3);
            SupplierProduct sp4 = db.SupplierProducts.Find(4);

            //db.Add(sp1);
            //db.Add(sp2);
            //db.Add(sp3);
            //db.Add(sp4);
            db.SaveChanges();

            PurchaseOrder po1 = new PurchaseOrder()
            {
                supplier = sup1, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd9, IssuedBy = emp7, POStatus = Enums.POStatus.Issued, POComments = "Order affected by COVID", POCode = "PO/" + dd8.ToString("ddMMyy") + "/1", POIssueDate = dd8
            };
            PurchaseOrder po2 = new PurchaseOrder()
            {
                supplier = sup2, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd11, IssuedBy = emp7, POStatus = Enums.POStatus.Completed, POComments = "Some Items may be out of stock", POCode = "PO/" + dd10.ToString("ddMMyy") + "/1", POIssueDate = dd10
            };
            PurchaseOrder po3 = new PurchaseOrder()
            {
                supplier = sup2, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd12, IssuedBy = emp7, POStatus = Enums.POStatus.NotCompleted, POComments = "Urgent", POCode = "PO/" + dd10.ToString("ddMMyy") + "/2", POIssueDate = dd10
            };

            db.Add(po1);
            db.Add(po2);
            db.Add(po3);


            PurchaseOrderSupplierProduct posr1 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp1, POQuantityRequested = 10, POUnitPrice = sp1.ProductPrice, PurchaseOrder = po1
            };
            PurchaseOrderSupplierProduct posr2 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp2, POQuantityRequested = 15, POUnitPrice = sp2.ProductPrice, PurchaseOrder = po1
            };
            PurchaseOrderSupplierProduct posr3 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp3, POQuantityRequested = 5, POUnitPrice = sp3.ProductPrice, PurchaseOrder = po1
            };

            PurchaseOrderSupplierProduct posr4 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp1, POQuantityRequested = 3, POUnitPrice = sp1.ProductPrice, PurchaseOrder = po2
            };
            PurchaseOrderSupplierProduct posr5 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp2, POQuantityRequested = 5, POUnitPrice = sp2.ProductPrice, PurchaseOrder = po2
            };

            PurchaseOrderSupplierProduct posr6 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp3, POQuantityRequested = 3, POUnitPrice = sp3.ProductPrice, PurchaseOrder = po3
            };
            PurchaseOrderSupplierProduct posr7 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp4, POQuantityRequested = 5, POUnitPrice = sp4.ProductPrice, PurchaseOrder = po3
            };

            db.Add(posr1);
            db.Add(posr2);
            db.Add(posr3);
            db.Add(posr4);
            db.SaveChanges();
            //--------------------------

            DeliveryOrder do2 = new DeliveryOrder()
            {
                DeliveryOrderNo = "D0121567", DOReceivedDate = dd11, PurchaseOrder = po2, Supplier = sup1, DOCode = "DO/" + dd11.ToString("ddMMyy") + "/1", ReceivedBy = emp7
            };
            DeliveryOrder do3 = new DeliveryOrder()
            {
                DeliveryOrderNo = "D011267", DOReceivedDate = dd12, PurchaseOrder = po3, Supplier = sup2, DOCode = "DO/" + dd12.ToString("ddMMyy") + "/1", ReceivedBy = emp7
            };

            db.Add(do2);
            db.Add(do3);
            db.SaveChanges();

            DeliveryOrderSupplierProduct dosr4 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr4, DOQuantityReceived = 3, DeliveryOrder = do2
            };
            DeliveryOrderSupplierProduct dosr5 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr5, DOQuantityReceived = 5, DeliveryOrder = do2
            };

            DeliveryOrderSupplierProduct dosr6 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr6, DOQuantityReceived = 3, DeliveryOrder = do3
            };
            DeliveryOrderSupplierProduct dosr7 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr7, DOQuantityReceived = 3, DeliveryOrder = do3
            };

            db.Add(dosr4);
            db.Add(dosr5);
            db.Add(dosr6);
            db.Add(dosr7);

            DateTime dd19 = new DateTime(2020, 8, 15, 0, 0, 0);
            DateTime dd20 = new DateTime(2020, 9, 15, 0, 0, 0);
            DateTime dd21 = new DateTime(2020, 7, 15, 10, 10, 0);

            DateTime dd22 = new DateTime(2020, 10, 15, 0, 0, 0);
            DateTime dd23 = new DateTime(2020, 11, 15, 0, 0, 0);


            DelegationForm delForm1 = new DelegationForm()
            {
                startDate       = dd19,
                endDate         = dd20,
                delegateComment = "Hello There",
                Delegatee       = emp10,
                DelegatedType   = empType8,
                DepartmentHead  = emp9,
                DLAssignedDate  = dd21,
                DLStatus        = Enums.DLStatus.Ongoing
            };

            DelegationForm delForm2 = new DelegationForm()
            {
                startDate       = dd22,
                endDate         = dd23,
                delegateComment = "Hello There",
                Delegatee       = emp10,
                DelegatedType   = empType8,
                DepartmentHead  = emp9,
                DLAssignedDate  = dd21,
                DLStatus        = Enums.DLStatus.Assigned
            };

            //DelegationForm delForm3 = new DelegationForm()
            //{
            //    startDate = dd22,
            //    endDate = dd23,
            //    delegateComment = "Hello There",
            //    Delegatee = emp10,
            //    DelegatedType = empType6,
            //    DepartmentHead = emp9,
            //    DLAssignedDate = dd21,
            //    DLStatus = Enums.DLStatus.Assigned
            //};

            db.Add(delForm1);
            db.Add(delForm2);

            db.SaveChanges();
        }