public ActionResult CreateSchedule(int?id)
        {
            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            if (rubberRoller == null || rubberRoller.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM))
            {
                return(RedirectToAction("CreateSearch"));
            }
            ViewData["roller"] = rubberRoller;
            LogAction.log(this._controllerName, "GET", "Requested Schedule-CreateSchedule webpage", User.Identity.GetUserId());
            return(View("ScheduleCreateEditForm"));
        }
        public ActionResult CreateSchedule(Schedule schedule, FormCollection collection)
        {
            Schedule existingSched = _db.schedules.FirstOrDefault(s => s.rollerID == schedule.rollerID && s.startDateTime == schedule.startDateTime && s.operationLine == schedule.operationLine);

            if (existingSched != null)
            {
                ViewData["schedule"] = existingSched;
                return(View("BeforeChecklist"));
            }

            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == schedule.rollerID);

            schedule.RubberRoller        = rubberRoller;
            schedule.tinplateSize        = $"{collection["thickness"]}x{collection["width"]}x{collection["length"]}";
            schedule.status              = ScheduleStatus.PENDING_BEFORE_CHECKLIST;
            schedule.RubberRoller.status = RollerStatus.getStatus(RollerStatus.IN_USE);

            // Update roller opening stock date
            if (rubberRoller.opening_stock_date == null || rubberRoller.isRefurbished)
            {
                rubberRoller.opening_stock_date = DateTime.Now;
            }

            // Reset roller isRefurbish status
            if (rubberRoller.isRefurbished)
            {
                rubberRoller.isRefurbished = false;
            }

            _db.schedules.Add(schedule);

            int result = _db.SaveChanges();

            if (result > 0)
            {
                TempData["formStatus"]    = true;
                TempData["formStatusMsg"] = "<b>STATUS</b>: New schedule record has been successfully added.";
                ViewData["schedule"]      = schedule;
                LogAction.log(this._controllerName, "POST", "New schedule details successfully added", User.Identity.GetUserId());
                return(View("BeforeChecklist"));
            }
            else
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The schedule record has not been successfully added.";
                LogAction.log(this._controllerName, "POST", "Errpr adding wew schedule detail.", User.Identity.GetUserId());
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
Exemple #3
0
        public ActionResult RollerReceived(FormCollection collection)
        {
            try
            {
                var         ID          = Int32.Parse(collection["maintenanceID"]);
                Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == ID);
                if (maintenance == null || maintenance.status != 2)
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }

                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);

                maintenance.status = 4;
                maintenance.RubberRoller.status = RollerStatus.getStatus(2);

                // Set roller isRefurbish status
                if (maintenance.sendForRefurbished)
                {
                    maintenance.RubberRoller.isRefurbished = true;
                }

                // Update roller location record
                bool updateLocatResult = CentralUtilities.UpdateRollerLocation(maintenance.RubberRoller, collection["rackLocation"]);

                int result = _db.SaveChanges();
                if (result > 0 && updateLocatResult)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Roller {maintenance.RubberRoller.rollerID} has been received back from maintenance.";
                    LogAction.log(this._controllerName, "POST", $"Roller {maintenance.RubberRoller.rollerID} has been received back from maintenance", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. Unable to mark maintenance report #{ID} as completed.";
                    LogAction.log(this._controllerName, "POST", $"Error marking maintenance report #{maintenance.maintenanceID} as completed", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong.";
                LogAction.log(this._controllerName, "POST", $"Error marking maintenance report as completed {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
        // Display search roller form - 1st step of adding a new schedule/operation
        public ActionResult CreateSearch()
        {
            // Retrieve rollers
            var rubberRollers = _db.rubberRollers
                                .AsEnumerable()
                                .Select(r => new
            {
                ID       = r.id,
                rollerID = $"{r.rollerID} - {r.RollerCategory.size} {r.RollerCategory.description}",
                r.status
            }).Where(r => r.status == RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM)).ToList();

            ViewData["rollerList"] = new SelectList(rubberRollers, "ID", "rollerID");
            LogAction.log(this._controllerName, "GET", "Requested Schedule-CreateSearch webpage", User.Identity.GetUserId());
            return(View("SearchRoller"));
        }
Exemple #5
0
        // GET: Returns create form
        public ActionResult Create(RubberRoller rubberRoller)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null ||
                (rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM) &&
                 rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM_ON_HOLD)
                )
                )
            {
                return(RedirectToAction("CreateSearch"));
            }

            ViewData["rubber"] = rubber;
            LogAction.log(this._controllerName, "GET", "Requested Maintenance-Create form webpage", User.Identity.GetUserId());
            return(View("CreateEditMaintenance"));
        }
Exemple #6
0
        public ActionResult ApproveReport(FormCollection collection)
        {
            try
            {
                var         ID          = Int32.Parse(collection["maintenanceID"]);
                Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == ID);
                if (maintenance == null || maintenance.status == 2)
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }

                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);

                maintenance.status              = 2;
                maintenance.statusRemark        = null;
                maintenance.approveDateTime     = DateTime.Now;
                maintenance.verfiedBy           = user;
                maintenance.RubberRoller.status = RollerStatus.getStatus(5);

                // Update roller location record
                bool updateLocatResult = CentralUtilities.UpdateRollerLocation(maintenance.RubberRoller, $"Sent to {maintenance.sendTo} for maintenance");

                int result = _db.SaveChanges();
                if (result > 0 && updateLocatResult)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Maintenance report #{ID} has been successfully approved.";
                    LogAction.log(this._controllerName, "POST", $"Approved maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. Maintenance report #{ID} has not been successfully approved.";
                    LogAction.log(this._controllerName, "POST", $"Error approving maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong.";
                LogAction.log(this._controllerName, "POST", $"Error approving maintenance report: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
Exemple #7
0
        public ActionResult RejectReport(FormCollection collection)
        {
            try
            {
                var         ID          = Int32.Parse(collection["maintenanceID"]);
                Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == ID);
                if (maintenance == null || maintenance.status == 3)
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }

                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);

                maintenance.status              = 3;
                maintenance.statusRemark        = collection["rejectReason"];
                maintenance.approveDateTime     = DateTime.Now;
                maintenance.verfiedBy           = user;
                maintenance.RubberRoller.status = RollerStatus.getStatus(2);

                int result = _db.SaveChanges();
                if (result > 0)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Maintenance report #{ID} has been rejected successfully.";
                    LogAction.log(this._controllerName, "POST", $"Rejected maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. Maintenance report #{ID} has not been rejected successfully.";
                    LogAction.log(this._controllerName, "POST", $"Error rejecting maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong.";
                LogAction.log(this._controllerName, "POST", $"Error rejecting maintenance report: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
Exemple #8
0
        public ActionResult Create(Maintenance maintenance)
        {
            try
            {
                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);
                maintenance.RubberRoller        = _db.rubberRollers.FirstOrDefault(r => r.id == maintenance.rollerID);
                maintenance.reportDateTime      = DateTime.Now;
                maintenance.reportedBy          = user;
                maintenance.RubberRoller.status = RollerStatus.getStatus(4);
                maintenance.status = 1;

                _db.maintenances.Add(maintenance);
                int result = _db.SaveChanges();

                if (result > 0)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = "<b>STATUS</b>: Maintenance report has been successfully filed!";
                    LogAction.log(this._controllerName, "POST", $"Created new maintenance record #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. Maintenance report has not been successfully filed.";
                    LogAction.log(this._controllerName, "POST", "Error creating new maintenance record", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. Please try again later.";
                LogAction.log(this._controllerName, "POST", $"Error creating new maintenance record: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult CompleteOperation(FormCollection collection)
        {
            try
            {
                // Retrieve schedule record
                var      schedID  = Int32.Parse(collection["scheduleID"]);
                Schedule schedule = _db.schedules.FirstOrDefault(s => s.scheduleID == schedID);
                if (schedule == null)
                {
                    return(RedirectToAction("ActiveOperation"));
                }

                // Create new after production checklist
                AfterRollerProductionChecklist after = new AfterRollerProductionChecklist();
                after.dateTime         = DateTime.Now;
                after.rollerAppearance = collection["rollerAppearance"];
                after.remarks          = collection["remarks"];
                after.scheduleID       = schedule.scheduleID;
                after.Schedule         = schedule;
                after.preparedBy       = getCurrentUser();
                after.rollerSendTo     = collection["rollerSendTo"];

                // Update schedule details
                after.Schedule.endMileage  = after.Schedule.startMileage + Int32.Parse(collection["mileageRun"]);
                after.Schedule.endDateTime = DateTime.Parse(collection["endDT"]);
                after.Schedule.quantity    = Int32.Parse(collection["mileageRun"]);
                after.Schedule.status      = ScheduleStatus.COMPLETED;

                // Update roller details
                after.Schedule.RubberRoller.last_usage_date = DateTime.Now;
                after.Schedule.RubberRoller.status          = collection["rollerSendTo"] == "Roller Room" ?
                                                              RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM) :
                                                              RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM_ON_HOLD);

                // Update roller location
                bool updateLocatResult = CentralUtilities.UpdateRollerLocation(after.Schedule.RubberRoller,
                                                                               (collection["rollerSendTo"] == "Roller Room" ? collection["roomLocation"] : "Roller is on-hold/Waiting to be sent to maintenance after operation"));

                // Add new records
                _db.afterRollerProductionChecklists.Add(after);
                int result = _db.SaveChanges();

                if (result > 0 && updateLocatResult)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = "<b>STATUS</b>: Operation has been completed!";
                    LogAction.log(this._controllerName, "POST", "Added new after roller operation checklist", User.Identity.GetUserId());
                    return(RedirectToAction("ActiveOperation"));
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The after production checklist has not been successfully added.";
                    LogAction.log(this._controllerName, "POST", "Error adding new after roller operation checklist", User.Identity.GetUserId());
                    return(Redirect(Request.UrlReferrer.ToString()));
                }
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The operation were unable to successfully marked as completed.";
                LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
                return(RedirectToAction("ActiveOperation"));
            }
        }