Example #1
0
        public async Task <ActionResult> ConfirmedList(List <DeptRequest> deptRequests)
        {
            int DeptId            = 0;
            int deptRequestsCount = deptRequests.Count();

            for (int i = 0; i < deptRequestsCount; i++)
            {
                DeptRequest existing = _context.DeptRequest.Find(deptRequests[i].DeptReqId);
                DeptId = existing.DeptId;
                existing.IsCompleted = true;
                _context.Update(existing);
                await _context.SaveChangesAsync();
            }

            // to update IsComplete from "false" to "true" in RequestDetails table
            List <int> incompleteRequestsByDept = _context.Request.Where(x => x.User.DeptId == DeptId & x.Status == "Approved" & x.IsCompleted != true & x.Approvaltime < deptRequests[deptRequestsCount - 1].GeneratedTime).Select(x => x.RequestId).ToList();

            List <RequestDetails> initialList = new List <RequestDetails>();
            List <RequestDetails> incompleteReqDetailsByDept = new List <RequestDetails>();

            foreach (int i in incompleteRequestsByDept)
            {
                initialList = _context.RequestDetails.Where(x => x.RequestId == i & x.Type == "Order").ToList();
                incompleteReqDetailsByDept.AddRange(initialList);
            }

            foreach (RequestDetails rd in incompleteReqDetailsByDept)
            {
                rd.IsComplete = true;
                _context.Update(rd);
                await _context.SaveChangesAsync();
            }

            // to update IsComplete to "true" in Request table ( only if all the request details under this request Type is "order" and IsComplete is True

            List <int> retrieveRequestID = _context.Request.Where(x => x.Status == "Approved" & x.IsCompleted != true).Select(x => x.RequestId).ToList();

            List <RequestDetails> ha = new List <RequestDetails>();

            foreach (int i in retrieveRequestID)
            {
                ha = _context.RequestDetails.Where(x => x.RequestId == i & (x.Type != "Order" || x.IsComplete != true)).ToList();
                if (!ha.Any())
                {
                    Request r = _context.Request.Find(i);
                    r.IsCompleted = true;
                    _context.Update(r);
                    await _context.SaveChangesAsync();
                }
            }
            return(RedirectToAction(nameof(ConfirmedList)));
        }
        // GET: show the view of the items.
        public async Task <IActionResult> Index(string searchString, string id)
        {
            if (HttpContext.User.Identity.IsAuthenticated && (HttpContext.User.IsInRole("clerk") || HttpContext.User.IsInRole("supervisor")))
            {
                var item = from m in _context.Item select m;
                if (!String.IsNullOrEmpty(searchString))
                {
                    item = item.Where(s => s.ItemName.Contains(searchString));
                }

                //* yx:set the submit to a get method
                if (id == "preorder")
                {
                    var         pre   = from m in _context.RequestDetails.Where(p => p.Type == "preorder").Include(p => p.Item) select m;
                    List <Item> ilist = await item.ToListAsync();

                    List <RequestDetails> rdlist = await pre.ToListAsync();

                    foreach (Item i in ilist)
                    {
                        foreach (RequestDetails rds in rdlist)
                        {
                            if (i.ItemId == rds.ItemId && i.Stock >= rds.RequestedQty)
                            {
                                try
                                {
                                    rds.Type = "Order";
                                    _context.Update(rds);

                                    i.Stock -= rds.RequestedQty;
                                    _context.Update(i);
                                    await _context.SaveChangesAsync();

                                    break;
                                }
                                catch (DbUpdateConcurrencyException)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    item = from m in _context.Item select m;
                }
                return(View(await item.ToListAsync()));
            }
            else
            {
                return(NotFound());
            }
        }
Example #3
0
 public void ClerkUpdateAdjustmentVoucherById(string AdjustmentVoucherId)
 {
     try
     {
         AdjustmentVoucher av = FindAdjustmentVoucherById(AdjustmentVoucherId);
         if (av == null)
         {
             throw new Exception();
         }
         av.Status = Status.AdjVoucherStatus.created;
         dbcontext.Update(av);
         dbcontext.SaveChanges();
     }
     catch
     {
         throw new Exception("Error finding adjustment voucher by this id");
     }
 }
Example #4
0
        //GET: Get the pending requests within the department.
        public async Task <IActionResult> Pending()
        {
            if (HttpContext.User.Identity.IsAuthenticated && (HttpContext.User.IsInRole("head") || HttpContext.User.IsInRole("actinghead")))
            {
                MyUser     user           = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).Include(p => p.Dept).ToList().FirstOrDefault();
                int        deptheadDEPTID = (int)user.DeptId;
                Delegation deleg          = await(from m in _context.Delegation.Where(p => p.DeptId == deptheadDEPTID) select m).FirstOrDefaultAsync();
                if (deleg != null && HttpContext.User.IsInRole("head"))
                {
                    if (DateTime.Compare((DateTime)user.Dept.Delegation.FirstOrDefault().Startdate, DateTime.Now) < 0 && DateTime.Compare((DateTime)user.Dept.Delegation.FirstOrDefault().Enddate, DateTime.Now) > 0)
                    {
                        return(Redirect("~/Departments/dutyoff"));
                    }
                }
                else if (user.Dept.Delegation.FirstOrDefault() != null && HttpContext.User.IsInRole("actinghead"))
                {
                    if (DateTime.Compare((DateTime)user.Dept.Delegation.FirstOrDefault().Startdate, DateTime.Now) > 0 || DateTime.Compare((DateTime)user.Dept.Delegation.FirstOrDefault().Enddate, DateTime.Now) < 0)
                    {
                        user.RoleId = 1;
                        _context.Update(user);
                        ApplicationUser _user1 = await _userManager.FindByEmailAsync(user.Email);

                        await _userManager.RemoveFromRoleAsync(_user1, "actinghead");

                        await _userManager.AddToRoleAsync(_user1, "employee");

                        return(Redirect("~/Departments/expired"));
                    }
                }
                var sSISContext = _context.Request.Include(r => r.User).Where(d => d.User.DeptId == deptheadDEPTID & d.Status != "Pending");
                return(View(await sSISContext.ToListAsync()));
            }
            else
            {
                return(NotFound());
            }
        }
Example #5
0
        // GET: display all the collection points
        public async Task <IActionResult> changeCollectionPoint()
        {
            if (HttpContext.User.Identity.IsAuthenticated && (HttpContext.User.IsInRole("head") || HttpContext.User.IsInRole("actinghead") || HttpContext.User.IsInRole("representative")))
            {
                MyUser     user  = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault();
                int?       id    = user.DeptId;
                Delegation deleg = await(from m in _context.Delegation.Where(p => p.DeptId == id) select m).FirstOrDefaultAsync();
                if (deleg != null && HttpContext.User.IsInRole("head"))
                {
                    if (DateTime.Compare((DateTime)deleg.Startdate, DateTime.Now) < 0 && DateTime.Compare((DateTime)deleg.Enddate, DateTime.Now) > 0)
                    {
                        return(Redirect("~/Departments/dutyoff"));
                    }
                }
                else if (deleg != null && HttpContext.User.IsInRole("actinghead"))
                {
                    if (DateTime.Compare((DateTime)deleg.Startdate, DateTime.Now) > 0 || DateTime.Compare((DateTime)deleg.Enddate, DateTime.Now) < 0)
                    {
                        user.RoleId = 1;
                        _context.Update(user);

                        ApplicationUser _user1 = await _userManager.FindByEmailAsync(user.Email);

                        await _userManager.RemoveFromRoleAsync(_user1, "actinghead");

                        await _userManager.AddToRoleAsync(_user1, "employee");

                        return(Redirect("~/Departments/expired"));
                    }
                }
                if (id == null)
                {
                    return(NotFound());
                }

                var department = await _context.Department.SingleOrDefaultAsync(m => m.DeptId == id);

                if (department == null)
                {
                    return(NotFound());
                }

                List <CollectionPoint> cp = _context.CollectionPoint.ToList();
                ViewData["Cpid"] = cp;

                return(View(department));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <IActionResult> ViewAV(List <AVDetails> avDetails)
        {
            MyUser user     = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault();
            int    userID   = user.UserId;
            int    avdCount = avDetails.Count();

            for (int i = 0; i < avdCount; i++)
            {
                AVDetails existing = _context.Avdetails.Find(avDetails[i].AVDid);
                existing.Qtychanged = avDetails[i].Qtychanged;
                existing.Operations = avDetails[i].Operations;
                existing.Remarks    = avDetails[i].Remarks;
                _context.Update(existing);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Index", "Adjustmentvouchers"));
        }
Example #7
0
        public async Task <IActionResult> raisedReqDetails(List <RequestDetails> requestDetails)
        {
            MyUser u = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).Include(p => p.Dept).ToList().FirstOrDefault();

            if (requestDetails != null)
            {
                int j = 0;
                foreach (RequestDetails rd in requestDetails)
                {
                    if ((rd.RequestedQty > 0) && (rd.RequestedQty < 1000))
                    {
                        j = j + 1;
                    }
                }
                if (requestDetails.Count() == j)
                {
                    {
                        Request thisRequest = _context.Request.Where(x => x.RequestId == requestDetails[0].RequestId).FirstOrDefault();
                        thisRequest.Status = "Submitted";
                        _context.Update(thisRequest);
                        await _context.SaveChangesAsync();

                        int requestDetailsCount = requestDetails.Count();
                        for (int i = 0; i < requestDetailsCount; i++)
                        {
                            RequestDetails existing = _context.RequestDetails.Find(requestDetails[i].ReqDetailsId);
                            existing.RequestedQty = requestDetails[i].RequestedQty;
                            _context.Update(existing);
                            await _context.SaveChangesAsync();
                        }

                        #region Email
                        bool       flag             = true;
                        MyUser     headofdepartment = new MyUser();
                        Department department       = await(from m in _context.Department.Where(p => p.DeptId == u.DeptId) select m).FirstOrDefaultAsync();
                        Delegation deleg            = await(from m in _context.Delegation.Where(p => p.DeptId == u.DeptId) select m).FirstOrDefaultAsync();
                        if (deleg != null)
                        {
                            if ((DateTime.Compare((DateTime)deleg.Startdate, DateTime.Now) > 0) || DateTime.Compare((DateTime)deleg.Enddate, DateTime.Now) < 0)
                            {
                                flag = false;
                            }
                        }
                        headofdepartment = _context.MyUser.Where(x => x.RoleId == 6 && x.DeptId == department.DeptId).ToList().FirstOrDefault();
                        if (headofdepartment == null || flag == false)
                        {
                            headofdepartment = _context.MyUser.Where(x => x.RoleId == 2 && x.DeptId == department.DeptId).ToList().FirstOrDefault();
                        }
                        if (headofdepartment != null)
                        {
                            var message = new MimeMessage();
                            message.From.Add(new MailboxAddress("SSIS", "*****@*****.**"));

                            message.To.Add(new MailboxAddress(headofdepartment.Name, headofdepartment.Email));
                            message.Subject = "New order request";
                            message.Body    = new TextPart("plain")
                            {
                                Text = "Dear " + headofdepartment.Name + ", " +
                                       "There is a new order request by your employee. " +
                                       "Please login to SSIS system for further action. " +
                                       Environment.NewLine +
                                       Environment.NewLine +
                                       "This is an auto-generated email. Please do not reply."
                            };
                            using (var client = new SmtpClient())
                            {
                                client.Connect("smtp.gmail.com", 587, false);
                                client.Authenticate("*****@*****.**", "team2team2");
                                client.Send(message);
                                client.Disconnect(true);
                            }
                        }
                        #endregion
                    }
                    return(RedirectToAction("viewRequests", "Requests"));
                }
                else
                {
                    return(RedirectToAction("raisedReqDetails"));
                }
            }
            else
            {
                return(RedirectToAction("viewRequests", "Requests"));
            }
        }
Example #8
0
        public async Task <IActionResult> Action(string SubmitButton, int id, [Bind("AdjustId,UserId")] AdjustmentVoucher adjustmentVoucher)
        {
            #region Email to remind adjustment voucher approved/rejected
            if (adjustmentVoucher != null)
            {
                var    message = new MimeMessage();
                MyUser e       = _context.MyUser.Where(p => p.UserId == adjustmentVoucher.UserId).FirstOrDefault();
                message.From.Add(new MailboxAddress("Department Head", "*****@*****.**"));
                message.To.Add(new MailboxAddress(e.Name, e.Email));
                message.Subject = "Your Request is handled";
                message.Body    = new TextPart("plain")
                {
                    Text = "Dear staff, " +
                           "" +
                           "Your order request has been processed by your department head. You may login to SSIS system to check for results." +
                           "" +
                           "This is an automatic-generated email. Please do not reply." +
                           "" +
                           "Sincerely," +
                           "Department Head"
                };
                using (var client = new SmtpClient())
                {
                    client.Connect("smtp.gmail.com", 587, false);
                    client.Authenticate("*****@*****.**", "team2team2");
                    client.Send(message);
                    client.Disconnect(true);
                }
            }
            #endregion

            if (id != adjustmentVoucher.AdjustId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    List <AVDetails> rdlist        = _context.Avdetails.Where(m => m.AdjustId == adjustmentVoucher.AdjustId).ToList();
                    string           buttonClicked = SubmitButton;
                    if (buttonClicked == "Approved")
                    {
                        adjustmentVoucher.Status = "Approved";
                        _context.Update(adjustmentVoucher);
                        await _context.SaveChangesAsync();

                        foreach (AVDetails avd in rdlist)
                        {
                            Item thisItem = _context.Item.Find(avd.ItemId);
                            if (avd.Operations == "-")
                            {
                                thisItem.Stock -= avd.Qtychanged;
                                _context.Update(thisItem);
                                await _context.SaveChangesAsync();
                            }
                            else if (avd.Operations == "+")
                            {
                                thisItem.Stock += avd.Qtychanged;
                                _context.Update(thisItem);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                    else if (buttonClicked == "Rejected")
                    {
                        adjustmentVoucher.Status = "Rejected";
                        _context.Update(adjustmentVoucher);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdjustmentVoucherExists(adjustmentVoucher.AdjustId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Pending)));
            }
            return(View(adjustmentVoucher));
        }
Example #9
0
        public async Task <IActionResult> changeOrAddDelegation(string SubmitButton, string searchString, Delegation delegation)
        {
            MyUser head = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault();
            int    id   = head.DeptId;

            if (ModelState.IsValid)
            {
                try
                {
                    Delegation de = _context.Delegation.Where(m => m.DeptId == id).FirstOrDefault();
                    MyUser     u;
                    if (de == null)
                    {
                        Delegation d = new Delegation();
                        d.DeptId    = id;
                        d.UserId    = delegation.UserId;
                        d.Startdate = delegation.Startdate;
                        d.Enddate   = delegation.Enddate;
                        _context.Add(d);
                        await _context.SaveChangesAsync();

                        de = _context.Delegation.Where(m => m.DeptId == id).FirstOrDefault();
                    }

                    else
                    {
                        string buttonClicked = SubmitButton;
                        if (buttonClicked == "Cancel")
                        {
                            u = _context.MyUser.Where(em => em.RoleId == 6 & em.DeptId == id).ToList().FirstOrDefault();
                            if (u != null)
                            {
                                u.RoleId = 1;
                                _context.Update(u);
                                ApplicationUser _user1 = await _userManager.FindByEmailAsync(u.Email);

                                await _userManager.RemoveFromRoleAsync(_user1, "actinghead");

                                await _userManager.AddToRoleAsync(_user1, "employee");
                            }
                            _context.Remove(de);

                            await _context.SaveChangesAsync();

                            return(RedirectToAction("About", "Home"));
                            //after cancel,directly return,no need to do the next step since have already changed the role.
                        }
                        else
                        {
                            de.DeptId    = id;
                            de.UserId    = delegation.UserId;
                            de.Startdate = delegation.Startdate;
                            de.Enddate   = delegation.Enddate;
                            _context.Update(de);
                            await _context.SaveChangesAsync();
                        }
                    }
                    //Deal with the delegation(null or not null) first,then deal with the role all together at last.
                    u = _context.MyUser.Where(em => em.RoleId == 6 & em.DeptId == id).FirstOrDefault();
                    if (u != null)
                    {
                        u.RoleId = 1;
                        _context.Update(u);
                        //*
                        ApplicationUser _user1 = await _userManager.FindByEmailAsync(u.Email);

                        await _userManager.RemoveFromRoleAsync(_user1, "actinghead");

                        await _userManager.AddToRoleAsync(_user1, "employee");
                    }
                    int eid = await _context.Delegation.Where(d => d.DeptId == id).Select(d => d.UserId).SingleAsync();

                    MyUser e = _context.MyUser.Find(eid);
                    e.RoleId = 6;
                    _context.Update(e);
                    //*
                    ApplicationUser _user = await _userManager.FindByEmailAsync(e.Email);

                    await _userManager.RemoveFromRoleAsync(_user, "employee");

                    await _userManager.AddToRoleAsync(_user, "actinghead");

                    await _context.SaveChangesAsync();

                    #region Email to remind the delegation within the department.
                    List <MyUser> alldepemployees = new List <MyUser>();

                    alldepemployees = _context.MyUser.Where(x => x.DeptId == id).ToList();
                    DateTime startdate       = delegation.Startdate.Value;
                    String   stringstartdate = startdate.ToShortDateString();
                    DateTime enddate         = delegation.Enddate.Value;
                    String   stringenddate   = enddate.ToShortDateString();
                    MyUser   actinghead      = new MyUser();
                    actinghead = _context.MyUser.Where(x => x.DeptId == id && x.RoleId == 6).FirstOrDefault();
                    Department department = _context.Department.Where(x => x.DeptId == id).FirstOrDefault();

                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress("SSIS", "*****@*****.**"));
                    foreach (MyUser e1 in alldepemployees)
                    {
                        message.To.Add(new MailboxAddress(e1.Name, e1.Email));
                        message.Subject = "New department actinghead";
                        message.Body    = new TextPart("plain")
                        {
                            Text = "Dear " + e1.Name + "," +
                                   "I will be on leave from " + stringstartdate + " till " + stringenddate + "." + " I may not be able to respond to the emails or requests"
                                   + " due to limited email access overseas. During this period, " + actinghead.Name + " will be the acting head of" +
                                   " our department to be in charge of all matters regarding to stationery. " +
                                   Environment.NewLine +
                                   "This is an automatically generated email. Please do not reply." +
                                   Environment.NewLine +
                                   "Regards" +
                                   Environment.NewLine +
                                   department.Name + " department"
                        };
                    }
                    using (var client = new SmtpClient())
                    {
                        client.Connect("smtp.gmail.com", 587, false);
                        client.Authenticate("*****@*****.**", "team2team2");
                        client.Send(message);
                        client.Disconnect(true);
                    }
                    #endregion
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DelegationExists(delegation.DeptId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("About", "Home"));
            }

            ViewData["CurrentFilter"] = searchString;
            var employees = _context.MyUser.Where(u => u.DeptId == id && (u.RoleId == 1 || u.RoleId == 6));
            if (!String.IsNullOrEmpty(searchString))
            {
                employees = employees.Where(x => x.Name.Contains(searchString));
            }
            List <MyUser> ulist = employees.ToList();
            ViewData["User"] = ulist;
            return(View(delegation));
        }