Ejemplo n.º 1
0
        public async Task <IActionResult> Main(string itemid, int?id)
        {
            MyUser            user   = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault();
            int               userID = user.UserId;
            AdjustmentVoucher AV;

            if (id == 0)
            {
                AV = new AdjustmentVoucher
                {
                    UserId = userID,
                    Status = "Pending"
                };
                _context.Add(AV);
                await _context.SaveChangesAsync();

                id = AV.AdjustId;
            }
            else
            {
                AV = _context.AdjustmentVoucher.Find(id);
            }
            AVDetails checkAVD = _context.Avdetails.Where(d => d.AdjustId == AV.AdjustId & d.ItemId == itemid).SingleOrDefault();
            AVDetails avd;

            if (checkAVD == null)
            {
                avd          = new AVDetails();
                avd.AdjustId = AV.AdjustId;
                avd.ItemId   = itemid;
                _context.Add(avd);
                await _context.SaveChangesAsync();
            }
            return(Redirect("~/AVDetails/ViewAv/" + id));
        }
        // 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());
            }
        }
        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"));
        }
Ejemplo n.º 4
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)));
        }
        public async Task <IActionResult> Index(List <int> numlist)
        {
            PurchaseOrder po          = new PurchaseOrder();
            var           itemContext = from m in _context.Item.Include(p => p.Cat) where m.Cat.Supplier1 == supplierId || m.Cat.Supplier2 == supplierId || m.Cat.Supplier3 == supplierId select m;

            try
            {
                po.SupplierId   = supplierId;
                po.PurchaseDate = DateTime.Now.Date;
                _context.Add(po);
                await _context.SaveChangesAsync();

                var pocontext = from m in _context.PurchaseOrder select m;
                List <PurchaseOrder> polist = await pocontext.ToListAsync();

                int PoId = polist[polist.Count - 1].PoId;

                foreach (string s in idlist)
                {
                    PODetails pods = new PODetails();
                    pods.ItemId     = s;
                    pods.Item       = itemContext.Where(p => p.ItemId == s).ToList().First();
                    pods.PoId       = PoId;
                    pods.QtyOrdered = numlist[idlist.IndexOf(s)];
                    _context.Add(pods);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                System.Console.Write(e.ToString());
                return(NotFound());
            }
            List <PODetails> podlist = new List <PODetails>();

            idlist   = new List <string>();
            IsPosted = true;
            return(RedirectToAction(nameof(ViewOrderHistory)));
        }
Ejemplo n.º 6
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"));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Action(string SubmitButton, int id, [Bind("RequestId,UserId,Remarks,IsCompleted")] Request request)
        {
            MyUser employee = new MyUser();

            employee = _context.MyUser.Where(x => x.UserId == request.UserId).ToList().FirstOrDefault();

            #region Email to remind the requester.
            var message = new MimeMessage();
            message.From.Add(new MailboxAddress("SSIS", "*****@*****.**"));
            message.To.Add(new MailboxAddress(employee.Name, employee.Email));
            message.Subject = "Your Request is handled";
            message.Body    = new TextPart("plain")
            {
                Text = "Dear " + employee.Name + ", " +
                       "" +
                       "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."
            };
            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate("*****@*****.**", "team2team2");
                client.Send(message);
                client.Disconnect(true);
            }
            #endregion

            if (id != request.RequestId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    List <RequestDetails> rdlist = _context.RequestDetails.Where(m => m.RequestId == request.RequestId).ToList();
                    string buttonClicked         = SubmitButton;
                    if (buttonClicked == "Approved")
                    {
                        request.Status       = "Approved";
                        request.Approvaltime = DateTime.Now;

                        for (int i = 0; i < rdlist.Count; i++)
                        {
                            string rdlistitemid    = rdlist[i].ItemId;
                            int    rdlistitemstock = rdlist[i].RequestedQty;
                            Item   item            = await _context.Item.SingleOrDefaultAsync(m => m.ItemId == rdlistitemid);

                            int itemStock = (int)item.Stock;

                            if (item.Stock <= 0)
                            {
                                rdlist[i].Type = "Preorder";
                                _context.Update(rdlist[i]);
                                await _context.SaveChangesAsync();
                            }
                            else if (rdlistitemstock <= itemStock)
                            {
                                rdlist[i].Type = "Order";
                                _context.Update(rdlist[i]);
                                item.Stock = itemStock - rdlistitemstock;
                                _context.Update(item);
                                await _context.SaveChangesAsync();
                            }

                            else
                            {
                                int preorderqty = rdlist[i].RequestedQty - itemStock;
                                rdlist[i].RequestedQty = itemStock;
                                rdlist[i].Type         = "Order";
                                _context.Update(rdlist[i]);

                                RequestDetails rdnew = new RequestDetails();
                                rdnew.RequestId    = rdlist[i].RequestId;
                                rdnew.ItemId       = rdlist[i].ItemId;
                                rdnew.RequestedQty = preorderqty;
                                rdnew.Type         = "Preorder";
                                _context.Add(rdnew);
                                item.Stock = 0;
                                _context.Update(item);
                                await _context.SaveChangesAsync();
                            }
                        }
                        _context.Update(request);
                        await _context.SaveChangesAsync();
                    }
                    else if (buttonClicked == "Rejected")
                    {
                        request.Status       = "Rejected";
                        request.Approvaltime = DateTime.Now;
                        _context.Update(request);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestExists(request.RequestId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Pending)));
            }
            ViewData["UserId"] = new SelectList(_context.MyUser, "UserId", "Email", request.UserId);
            return(View(request));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> changeCollectionPoint([Bind("DeptId,Name,DeptRep,Cpid")] Department department, CollectionPoint collectionPoint)
        {
            MyUser user = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault();
            int?   id   = user.DeptId;

            if (id != department.DeptId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.DeptId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                List <MyUser> allclerks = new List <MyUser>();
                allclerks = _context.MyUser.Where(x => x.RoleId == 5).ToList();
                CollectionPoint cp = new CollectionPoint();
                cp = _context.CollectionPoint.Where(x => x.Cpid == collectionPoint.Cpid).FirstOrDefault();

                #region Email
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("SSIS", "*****@*****.**"));
                //message.To.Add(new MailboxAddress("tqy", "*****@*****.**"));
                message.Subject = "New collection point";
                foreach (MyUser clerk in allclerks)
                {
                    message.To.Add(new MailboxAddress(clerk.Name, clerk.Email));

                    message.Body = new TextPart("plain")
                    {
                        Text = "Dear " + clerk.Name + ", " +
                               "This letter is to let you know we have selected the collection point " +
                               "and delivery timing as " + cp.Name + "." +
                               "Please check and find details of the location below:" +
                               Environment.NewLine +
                               cp.Details +
                               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
                return(RedirectToAction("About", "Home"));
            }
            return(View());
        }
Ejemplo n.º 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));
        }