示例#1
0
        public void noShow(string id)
        {
            var disbursementList = _context.DisbursementList.Find(id);

            disbursementList.Status       = "No Show";
            disbursementList.CompleteDate = DateTime.Now;
            _context.DisbursementList.Update(disbursementList);
            _context.SaveChanges();

            //update out and stock
            var itemToReturn = _context.RecordDetails.Where(x => x.Rrid == id);

            if (itemToReturn != null)
            {
                foreach (var item in itemToReturn.ToList())
                {
                    int quantityRequested = item.Quantity;
                    var q = _context.Catalogue.FirstOrDefault(x => x.ItemNumber == item.ItemNumber);
                    if (q != null)
                    {
                        int outQty   = q.Out;
                        int preStock = q.Stock;
                        q.Stock = preStock + quantityRequested;
                        q.Out   = outQty - quantityRequested;

                        _context.Catalogue.Update(q);
                        _context.SaveChanges();
                    }
                }
            }

            return;
        }
示例#2
0
        public IActionResult Submit()
        {
            // Make new EmployeeRequestRecord
            Models.EmployeeRequestRecord e = new Models.EmployeeRequestRecord();
            id = b.IDGenerator(dept);
            DateTime requestDate = DateTime.Now.Date;
            int      empId       = userid;
            var      findHeadId  = context.Department.Where(x => x.DepartmentCode == dept).First();
            int      headId      = findHeadId.HeadId;
            string   deptCode    = dept;
            string   status      = "Submitted";

            e.Rrid        = id;
            e.RequestDate = requestDate;
            e.DepEmpId    = empId;
            e.DepHeadId   = headId;
            e.DepCode     = deptCode;
            e.Status      = status;
            context.EmployeeRequestRecord.Add(e);
            context.SaveChanges();

            //Make new Record Details
            for (int k = 0; k < QuantityList.Count; k++)
            {
                Models.RecordDetails r = new Models.RecordDetails();
                r.Rrid       = id;
                r.ItemNumber = ItemNumberList[k];
                r.Quantity   = QuantityList[k];
                context.RecordDetails.Add(r);
                context.SaveChanges();
            }
            return(RedirectToAction("Details", new { id }));
        }
示例#3
0
        public List <string> GetdetailList(string id)
        {
            AdjustmentRecord ad = _context.AdjustmentRecord.Where(s => s.VoucherNo == id).ToList().First();

            if (id.Contains("VTemp") && ad == null)
            {
                var adjustmentRecord = new AdjustmentRecord()
                {
                    VoucherNo = id,
                    IssueDate = DateTime.Today,
                    ClerkId   = int.Parse(id.Replace("VTemp", "")),
                    Status    = "draft"
                };
                _context.AdjustmentRecord.Add(adjustmentRecord);
                _context.SaveChanges();
            }
            List <string> result = new List <string>();
            //int idID = _context.CollectionPoint.Where(s => s.CollectionPointName.Contains(id)).ToList().First().CollectionPointId;
            List <RecordDetails> dis = _context.RecordDetails.Where(s => s.Rrid == id).ToList();

            if (dis == null)
            {
                return(null);
            }
            foreach (RecordDetails i in dis)
            {
                result.Add(i.Rdid.ToString());
            }
            return(result);
        }
        public async Task <IActionResult> Index(string[] itemSubmitted)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

            List <string> identity = userCheck.checkUserIdentityAsync(user);
            int           userID   = user.WorkID;

            dept = identity[0];
            role = identity[1];

            if (itemSubmitted.Length != 0)
            {
                rrid = b.IDGenerator(dept);
                foreach (var item in tempNewRequests)
                {
                    if (Array.Exists(itemSubmitted, i => i == item.ItemNumber.ToString()))
                    {
                        //add items to request
                        RecordDetails r = new RecordDetails();
                        r.Rrid              = rrid;
                        r.ItemNumber        = item.ItemNumber;
                        r.Quantity          = item.Quantity;
                        r.QuantityDelivered = 0;
                        _context.RecordDetails.Add(r);
                        _context.SaveChanges();
                    }
                }

                //check if item exists in record details
                var record = _context.RecordDetails.FirstOrDefault(x => x.Rrid == rrid);
                if (record != null)
                {
                    // Make new EmployeeRequestRecord
                    EmployeeRequestRecord e = new EmployeeRequestRecord();
                    DateTime requestDate    = DateTime.Now.Date;
                    int      empId          = userid;
                    var      findHeadId     = _context.Department.Where(x => x.DepartmentCode == dept).First();
                    int      headId         = findHeadId.HeadId;
                    string   deptCode       = dept;
                    string   status         = "Pending Approval";
                    e.Rrid        = rrid;
                    e.RequestDate = requestDate;
                    e.DepEmpId    = empId;
                    e.DepHeadId   = headId;
                    e.DepCode     = deptCode;
                    e.Status      = status;
                    _context.EmployeeRequestRecord.Add(e);
                    _context.SaveChanges();

                    TempData["Submitted"] = "New request has been created successfully!";
                }
            }

            tempNewRequests = new List <TempNewRequest>();
            List <RecordDetails> rdList = _context.RecordDetails.Where(x => x.Rrid == rrid).ToList();

            //return RedirectToAction("Details", new { id = rrid });
            return(Json(new { redirecturl = "NewRequest/Details/" + rrid }));
        }
        public IActionResult ApproveOrder()
        {
            EmployeeRequestRecord e1 = b.findEmployeeRecord(rrid);

            e1.Status = "Approved";
            context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
示例#6
0
        //Save Changes for Department Rep
        public void SaveNewDeptRep(BriefDept briefDept)
        {
            string dept = briefDept.deptCode;

            var        q = context.Department.Where(x => x.DepartmentCode == dept).First();
            Department d = q;

            d.RepId = briefDept.repId;
            context.SaveChanges();
        }
        public async Task <IActionResult> Index(User u)
        {
            if (ModelState.IsValid)
            {
                int        newUserId = u.UserId;
                Department d2        = new Department();
                d2       = context.Department.Where(x => x.DepartmentCode == dept).First();
                d2.RepId = newUserId;

                var t = context.DisbursementList.Where(x => x.DepartmentCode == dept && x.Status == "Pending Delivery");
                if (t.Any())
                {
                    DisbursementList d3 = new DisbursementList();
                    d3       = t.First();
                    d3.RepId = newUserId;
                }

                context.SaveChanges();
                TempData["Alert1"] = "Department representative changed successfully!";

                //send email to new dept rep
                var    q     = context.User.Where(x => x.UserId == u.UserId).First();
                string email = q.EmailAddress;
                await _emailSender.SendEmailAsync(email, "Department Representative Appointment", "Dear " + q.Name + ",<br>You have been appointed as the department representative for stationery collection.");

                //send email to old dept rep
                var    q2     = context.User.Where(x => x.UserId == oldrepid).First();
                string email2 = q2.EmailAddress;
                await _emailSender.SendEmailAsync(email2, "Department Representative Replacement", "Dear " + q2.Name + ",<br>You have been replaced as department representative.");

                return(RedirectToAction("Index"));
            }
            TempData["Alert2"] = "Please try again";
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AdjustmentRecordDelete(string id)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

            List <string> identity = userCheck.checkUserIdentityAsync(user);
            int           userID   = user.WorkID;

            AdjustmentRecord adjustmentRecordToBeDeleted = _context.AdjustmentRecord.FirstOrDefault(x => x.VoucherNo == id);

            _context.AdjustmentRecord.Remove(adjustmentRecordToBeDeleted);
            _context.SaveChanges();
            b.RemoveRecordDetails(id);

            AdjustmentRecord                 ar = _context.AdjustmentRecord.FirstOrDefault(x => x.ClerkId == userID && !x.VoucherNo.Contains("Vtemp"));
            List <AdjustmentRecord>          tempAdjustmentRecords = new List <AdjustmentRecord>();
            List <AdjustmentRecordViewModel> arViewModelList       = new List <AdjustmentRecordViewModel>();

            if (ar != null)
            {
                tempAdjustmentRecords = _context.AdjustmentRecord.Where(x => x.ClerkId == userID && !x.VoucherNo.Contains("Vtemp") && x.Status == "Draft").OrderByDescending(x => x.VoucherNo).ToList();
                arViewModelList       = b.CreateAdjustmentRecordViewModel(tempAdjustmentRecords);
            }
            else
            {
                NotFound();
            }
            return(PartialView("_TempAdjustmentRecords", arViewModelList));
        }
示例#9
0
        public async Task <IActionResult> ApproveOrder()
        {
            EmployeeRequestRecord e1 = context.EmployeeRequestRecord.Where(x => x.Rrid == rrid).First();

            e1.Status = "Approved";
            DateTime today = DateTime.Now.Date;

            e1.CompleteDate = today;
            context.SaveChanges();
            int userid = e1.DepEmpId;

            //send success email to staff
            var    approvedstaff = context.User.Where(x => x.UserId == userid).First();
            string email         = approvedstaff.EmailAddress;
            await _emailSender.SendEmailAsync(email, "Approval of New Request", "Dear " + approvedstaff.Name + "<br>Your submitted stationery request has been rejected.");

            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult Index(User u)
 {
     if (ModelState.IsValid)
     {
         Models.Department d2 = b.getDepartmentDetails(dept);
         d2.RepId = u.UserId;
         context.SaveChanges();
         TempData["Alert1"] = "Department Representative Changed Successfully";
         return(RedirectToAction("Index"));
     }
     TempData["Alert2"] = "Please Try Again";
     return(RedirectToAction("Index"));
 }
示例#11
0
        public IActionResult Index(User u, DateTime startdate, DateTime enddate)
        {
            if (startdate > enddate || startdate < DateTime.Now.Date.AddDays(-1))
            {
                TempData["DateAlert"] = "Please enter valid dates!";
                return(RedirectToAction("Index"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    Models.Department d1 = context.Department.Where(x => x.DepartmentCode == dept).First();
                    d1.CoveringHeadId = u.UserId;

                    if (edit == true)
                    {
                        var q = context.DepartmentCoveringHeadRecord.Where(x => x.UserId == currentDeputyHeadId).First();
                        Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                        d2           = q;
                        d2.UserId    = u.UserId;
                        d2.StartDate = startdate;
                        d2.EndDate   = enddate;
                    }
                    else
                    {
                        Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                        d2.UserId    = u.UserId;
                        d2.StartDate = startdate;
                        d2.EndDate   = enddate;
                        context.Add(d2);
                    }
                    context.SaveChanges();
                    TempData["Success"] = "Edits Saved Successfully";
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }
        }
示例#12
0
        //Generate Disbursement List for a department
        public List <RecordDetails> GenerateDisbursementListDetails(string depCode)
        {
            DateTime start  = StationeryRetrivalStartDate();
            DateTime cutoff = StationeryRetrivalCutoffDate();

            //DisbursementListDetails for a department
            List <RecordDetails> result = new List <RecordDetails>();

            //Check if a pending delivery disbursement list exists
            List <DisbursementList> dlList = _context.DisbursementList
                                             .Where(x => x.DepartmentCode == depCode && x.Status == "Pending Delivery").ToList();

            //Get EmployeeRequestRecord of a department, check if it's null
            List <EmployeeRequestRecord> errList = _context.EmployeeRequestRecord
                                                   .Where(x => x.CompleteDate >= start && x.CompleteDate <= cutoff && x.DepCode == depCode && x.Status == "Approved")
                                                   .ToList();

            //Get all RecordDetails
            List <RecordDetails> rdList = _context.RecordDetails.ToList();

            // Check if the disbursement list exists in the database
            var dl = _context.DisbursementList.FirstOrDefault(x => x.DepartmentCode == depCode && x.Status == "Pending Delivery");

            if (errList != null)
            {
                if (dl == null)
                {
                    //create a new dl
                    dl = new DisbursementList()
                    {
                        Dlid              = IDGenerator("DL"),
                        StartDate         = DateTime.Now,
                        DepartmentCode    = depCode,
                        EstDeliverDate    = null,
                        CompleteDate      = null,
                        RepId             = _context.Department.Find(depCode).RepId,
                        CollectionPointId = _context.Department.Find(depCode).CollectionPointId,
                        Status            = "Pending Delivery"
                    };
                    Console.WriteLine(dl.StartDate);
                    _context.DisbursementList.Add(dl);
                    _context.SaveChanges();
                }

                //Find all needed EmployeeRequestRecordID, add to a list
                List <string> rridList = new List <string>();
                foreach (EmployeeRequestRecord err in errList)
                {
                    rridList.Add(err.Rrid);
                }

                //Select out needed EmployeeRequestRecord details
                List <RecordDetails> selectederrList = new List <RecordDetails>();
                foreach (RecordDetails r in rdList)
                {
                    if (rridList.Contains(r.Rrid))
                    {
                        selectederrList.Add(r);
                    }
                }

                foreach (RecordDetails r in selectederrList)
                {
                    //check if dl record exists
                    var rd = _context.RecordDetails.FirstOrDefault(x => x.Rrid == dl.Dlid && x.ItemNumber == r.ItemNumber && x.Remark == null);
                    rd.Quantity = 0;
                    if (rd == null)
                    {
                        rd = new RecordDetails()
                        {
                            Rrid = dl.Dlid, ItemNumber = r.ItemNumber, Quantity = r.Quantity
                        };
                        _context.RecordDetails.Add(rd);
                    }
                    else
                    {
                        rd.Quantity += r.Quantity;
                    }
                    _context.SaveChanges();
                }

                result = _context.RecordDetails.Where(x => x.Rrid == dl.Dlid).ToList();
            }
            return(result);
        }
示例#13
0
 private void Save()
 {
     context.SaveChanges();
 }
示例#14
0
        public async Task <IActionResult> Index(User u, DateTime startdate, DateTime enddate)
        {
            DateTime dtpDefault = new DateTime(0001, 1, 1, 0, 0, 0);

            if (startdate != null && enddate != null)
            {
                if (startdate.Equals(dtpDefault) || enddate.Equals(dtpDefault))
                {
                    TempData["NoDetails"] = "Please fill in all details.";
                    @ViewData["Show"]     = null;
                    return(RedirectToAction("Index"));
                }
                if (startdate <= enddate && startdate >= DateTime.Now.Date && enddate >= DateTime.Now.Date)
                {
                    if (ModelState.IsValid)
                    {
                        Models.Department d1 = context.Department.Where(x => x.DepartmentCode == dept).First();
                        d1.CoveringHeadId = u.UserId;

                        if (edit == true)
                        {
                            var q = context.DepartmentCoveringHeadRecord.Where(x => x.UserId == currentDeputyHeadId).FirstOrDefault();
                            Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                            d2           = q;
                            d2.UserId    = u.UserId;
                            d2.StartDate = startdate;
                            d2.EndDate   = enddate;

                            context.SaveChanges();
                            TempData["EditSuccess"] = "Changes were saved successfully!";

                            //send email to old deputy head
                            var    oldhead = context.User.Where(x => x.UserId == currentDeputyHeadId).First();
                            string email2  = oldhead.EmailAddress;
                            await _emailSender.SendEmailAsync(email2, "Department Deputy Head Replacement", "Dear " + oldhead.Name + ",<br>You have been replaced as department deputy head.");
                        }
                        else
                        {
                            Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                            d2.UserId    = u.UserId;
                            d2.StartDate = startdate;
                            d2.EndDate   = enddate;
                            context.Add(d2);
                            context.SaveChanges();
                            TempData["NewSuccess"] = "New deputy head appointed!";

                            //send email to new deputy head
                            var    newhead = context.User.Where(x => x.UserId == u.UserId).First();
                            string email   = newhead.EmailAddress;
                            await _emailSender.SendEmailAsync(email, "Department Deputy Head Appointment", "Dear " + newhead.Name + ",<br>You have been appointed as the department deputy head.");
                        }
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["FilterError"] = "Assignment was not completed. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    if (startdate > enddate && (startdate < DateTime.Now.Date || enddate < DateTime.Now.Date))
                    {
                        TempData["StartAndEndDateError"] = "End date cannot be earlier than start date. Start date and end date cannot be earlier than today. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    if (startdate > enddate)
                    {
                        TempData["EndDateError"] = "End date cannot be earlier than start date. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    if (startdate < DateTime.Now.Date || enddate < DateTime.Now.Date)
                    {
                        TempData["StartDateError"] = "Start date and end date cannot be earlier than today. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["NoDetails"] = "Please fill in all details!";
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                TempData["NoDetails"] = "Please fill in all details!";
                return(RedirectToAction("Index"));
            }
        }
示例#15
0
        public async Task <IActionResult> Details(string id, int rowID, string itemNumber, int quantityDelivered, int quantityForVoucher, string remarkForDelivery, string remarkForVoucher, string confirmationPassword, int quantityDeliveredModalName, int addToVoucherModalName, int confirmDeliveryModalName, int noShowModalName, int backToListModalName)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

            List <string> identity = userCheck.checkUserIdentityAsync(user);
            int           userID   = user.WorkID;

            //viewbag for status check
            ViewBag.DisbursementListStatus = _context.DisbursementList.FirstOrDefault(x => x.Dlid == id).Status;

            if (addToVoucherModalName == 1)
            {
                if (quantityForVoucher == 0)
                {
                    TempData["QuantityError"] = "Please select a quantity to add to voucher. Quantity cannot be 0.";
                    return(RedirectToAction("Details", new { id }));
                }
                else
                {
                    b.CreateNewVoucherItem(userID, itemNumber, quantityForVoucher, remarkForVoucher);
                }
            }
            else if (quantityDeliveredModalName == 1)
            {
                var q = _context.RecordDetails.Where(x => x.Rrid == id && x.ItemNumber == itemNumber).FirstOrDefault();
                int quantityNeeded = q.Quantity;
                if (quantityDelivered > quantityNeeded)
                {
                    TempData["ExcessError"] = "Quantity delivered cannot be greater than quantity requested. Please try again.";
                    return(RedirectToAction("Details", new { id }));
                }
                if (quantityDelivered < quantityNeeded && (remarkForDelivery == null || remarkForDelivery == ""))
                {
                    ViewData["InsufficientCheck"] = "true";
                    TempData["InsufficientError"] = "As quantity delivered is lesser than quantity requested, please key in remarks. Please try again.";
                    return(RedirectToAction("Details", new { id }));
                }
                foreach (DisbursementListDetails dlDetails in tempDisbursementListDetails)
                {
                    if (dlDetails.RowID == rowID)
                    {
                        dlDetails.QuantityDelivered = quantityDelivered;
                        dlDetails.Remark            = remarkForDelivery;
                    }
                }
            }
            else if (confirmDeliveryModalName == 1)
            {
                string depCode            = _context.DisbursementList.Find(id).DepartmentCode;
                string collectionPassword = _context.Department.Find(depCode).CollectionPassword;

                //check if password is correct
                if (confirmationPassword == collectionPassword)
                {
                    //update out quantity
                    string dlID = b.IDGenerator("DL");
                    foreach (var item in tempDisbursementListDetails)
                    {
                        string itemNo       = item.ItemNumber;
                        int    qtyDelivered = item.QuantityDelivered;
                        int    rdid         = item.RDID;
                        string remark       = item.Remark;

                        //generate a disbursement list if partial fulfilled
                        if (qtyDelivered != item.Quantity)
                        {
                            int qty = item.Quantity - qtyDelivered;
                            b.GenerateDisbursementListForPartialFulfillment(itemNo, qty, remark, depCode, dlID);
                        }

                        b.UpdateCatalogueOutAfterDelivery(itemNo, qtyDelivered);
                        b.UpdateQuantityDeliveredAfterDelivery(qtyDelivered, rdid);

                        int balance = _context.Catalogue.Find(itemNo).Stock;
                        b.UpdateInventoryTransRecord(itemNo, id, -qtyDelivered, balance);
                    }

                    //update disbursement list status
                    var disbursementList = _context.DisbursementList.Find(id);
                    disbursementList.Status       = "Completed";
                    disbursementList.CompleteDate = DateTime.Now;
                    _context.DisbursementList.Update(disbursementList);
                    _context.SaveChanges();

                    TempData["CorrectPassword"] = "******";

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    //check
                    //show incorrect password
                    TempData["IncorrectPassword"] = "******";
                }
            }
            else if (noShowModalName == 1)
            {
                //update disbursement list status
                var disbursementList = _context.DisbursementList.Find(id);
                disbursementList.Status       = "No Show";
                disbursementList.CompleteDate = DateTime.Now;
                _context.DisbursementList.Update(disbursementList);
                _context.SaveChanges();

                //update out and stock
                var itemToReturn = _context.RecordDetails.Where(x => x.Rrid == id);
                if (itemToReturn != null)
                {
                    foreach (var item in itemToReturn.ToList())
                    {
                        int quantityRequested = item.Quantity;
                        var q = _context.Catalogue.FirstOrDefault(x => x.ItemNumber == item.ItemNumber);
                        if (q != null)
                        {
                            int outQty   = q.Out;
                            int preStock = q.Stock;
                            //out number cannot be negative
                            if (outQty >= quantityRequested)
                            {
                                q.Stock = preStock + quantityRequested;
                                q.Out   = outQty - quantityRequested;
                            }
                            else
                            {
                                q.Stock = preStock + outQty;
                                q.Out   = 0;
                            }

                            _context.Catalogue.Update(q);
                            _context.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            else if (backToListModalName == 1)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(tempDisbursementListDetails));
        }