Exemple #1
0
        public async Task <ActionResult> Complete(int?id)
        {
            if (id == null)
            {
                return(View("error", new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urnForm;

            using (UrnDbContext db = new UrnDbContext())
            {
                urnForm = await db.UrnForms.FirstOrDefaultAsync(urn => urn.Id == id);

                if (TryUpdateModel(urnForm))
                {
                    urnForm.Status        = "Completed";
                    urnForm.TimeCompleted = DateTime.Now;

                    if (Request["raNumber"] != string.Empty || Request["serial"] != string.Empty)
                    {
                        urnForm.RaNumber     = Request["raNumber"];
                        urnForm.SerialNumber = Request["serial"];
                    }

                    urnForm.CompletedBy     = HttpContext.User.Identity.Name;
                    db.Entry(urnForm).State = EntityState.Modified;
                }

                TempData["message"] = $"Work order { urnForm.RrNumber } has been successfully completed.";
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("index", "home", null));
        }
Exemple #2
0
        public async Task <ActionResult> Backorder(int?id)
        {
            if (id == null)
            {
                return(View("error", new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urn;

            using (UrnDbContext db = new UrnDbContext())
            {
                urn = await db.UrnForms.FirstOrDefaultAsync(u => u.Id == id);

                if (TryUpdateModel(urn))
                {
                    urn.Status             = "Backorder";
                    urn.ReasonForBackorder = Request["ReasonForBackorder"];
                    urn.BackorderDate      = DateTime.Now;
                    db.Entry(urn).State    = EntityState.Modified;
                }
                TempData["message"] = $"Work order { urn.RrNumber } successfully sent to backorder";
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("index", "home", null));
        }
Exemple #3
0
        // GET: ~/
        public async Task <ActionResult> Index()
        {
            DashboardViewModels dashboard = new DashboardViewModels();

            using (UrnDbContext db = new UrnDbContext())
            {
                dashboard.CompleteWorkOrders =
                    await db.UrnForms.Where(urn => urn.Status == "Completed" && urn.CompletedBy == HttpContext.User.Identity.Name).
                    AsNoTracking().CountAsync();

                dashboard.ShippedWorkOrders =
                    await db.UrnForms.Where(urn => urn.Status == "Shipped" && urn.CompletedBy == HttpContext.User.Identity.Name)
                    .AsNoTracking().CountAsync();

                dashboard.TotalWorkOrders = await db.UrnForms.AsNoTracking().CountAsync();

                dashboard.AllQueuedWorkOrders = await db.UrnForms.Where(urn => urn.Status == "Queued")
                                                .AsNoTracking().CountAsync();

                dashboard.AllCompletedWorkOrders = await db.UrnForms.Where(urn => urn.Status == "Completed")
                                                   .AsNoTracking().CountAsync();

                dashboard.AllIncompleteWorkOrders = await db.UrnForms.Where(urn => urn.Status == "Incomplete")
                                                    .AsNoTracking().CountAsync();

                dashboard.AllShippedWorkOrders = await db.UrnForms.Where(urn => urn.Status == "Shipped")
                                                 .AsNoTracking().CountAsync();

                dashboard.AllBackOrders = await db.UrnForms.Where(urn => urn.Status == "Backorder")
                                          .AsNoTracking().CountAsync();
            }

            return(View(dashboard));
        }
Exemple #4
0
        public async Task <ActionResult> Queue(int?id)
        {
            if (id == null)
            {
                return(View("error", new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urnForm;

            using (UrnDbContext db = new UrnDbContext())
            {
                urnForm = await db.UrnForms.FirstOrDefaultAsync(urn => urn.Id == id);

                if (TryUpdateModel(urnForm))
                {
                    urnForm.Status          = "Queued";
                    db.Entry(urnForm).State = EntityState.Modified;
                }

                TempData["message"] = $"Work order { urnForm.RrNumber } has succesfully been queued.";
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("index", "home", null));
        }
Exemple #5
0
        public async Task <ActionResult> UrnForm(UrnForm form)
        {
            using (UrnDbContext db = new UrnDbContext())
            {
                // TODO: Enforce form data validity.
                if (ModelState.IsValid)
                {
                    form.SubmittedBy = HttpContext.User.Identity.Name;

                    if (form.AllRelevantNumbersChecked == true && form.StoreRackChecked == true && form.StoreTrolleyChecked == true &&
                        form.NoUnpackedStock == true && form.ReworkTrolleyChecked == true)
                    {
                        db.UrnForms.Add(form);
                        await db.SaveChangesAsync();

                        TempData["message"] = "Work order successfully placed in queue.";
                        return(RedirectToAction("index", "home"));
                    }
                    else
                    {
                        ModelState.AddModelError
                            ("", "Please ensure that all numbers, racks & trolleys are in check and that there's no unpacked stock.");
                    }
                }

                return(View(form));
            }
        }
Exemple #6
0
        public async Task <ActionResult> UpdateWo(int?id)
        {
            UrnForm workOrder;

            using (UrnDbContext _db = new UrnDbContext())
            {
                workOrder = await _db.UrnForms.FirstOrDefaultAsync(wo => wo.Id == id);

                if (ModelState.IsValid)
                {
                    try
                    {
                        if (TryUpdateModel(workOrder))
                        {
                            _db.Entry(workOrder).State = EntityState.Modified;
                            await _db.SaveChangesAsync();

                            TempData["message"] = $"Work order { workOrder.RrNumber } successfully updated.";
                            return(RedirectToAction("index", "queue", null));
                        }
                    }
                    catch (DataException ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                    }
                }
            }
            return(View(workOrder));
        }
Exemple #7
0
        public async Task <ActionResult> Ship(int?id)
        {
            if (id == null)
            {
                return(View("error", new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urnForm;

            using (UrnDbContext db = new UrnDbContext())
            {
                urnForm = await db.UrnForms.FirstOrDefaultAsync(urn => urn.Id == id);

                if (TryUpdateModel(urnForm))
                {
                    urnForm.Status                = "Shipped";
                    urnForm.TimeShipped           = DateTime.Now;
                    urnForm.ShippedBy             = HttpContext.User.Identity.Name;
                    urnForm.ReasonForIncompletion = "";

                    if (Request["issueResolution"] != string.Empty)
                    {
                        urnForm.ResolutionStatus = Request["issueResolution"];
                    }

                    db.Entry(urnForm).State = EntityState.Modified;
                }

                await db.SaveChangesAsync();
            }

            TempData["message"] = $"Work order { urnForm.RrNumber } has successfully been shipped.";

            return(RedirectToAction("index", "completed", null));
        }
Exemple #8
0
        public async Task <ActionResult> Undo(int?id)
        {
            if (id == null)
            {
                return(View("error", new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urnForm;

            using (UrnDbContext db = new UrnDbContext())
            {
                urnForm = await db.UrnForms.FirstOrDefaultAsync(urn => urn.Id == id);

                if (TryUpdateModel(urnForm))
                {
                    urnForm.Status = "Incomplete";
                    urnForm.ReasonForIncompletion = Request["ReasonForIncompletion"];
                    db.Entry(urnForm).State       = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
            }

            TempData["error"] = $"Work order { urnForm.RrNumber } has been marked as not complete.";

            return(RedirectToAction("index", "home", null));
        }
Exemple #9
0
        public async Task <ActionResult> UpdateWorkOrder(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            UrnForm workOrder;

            using (UrnDbContext _db = new UrnDbContext())
            {
                workOrder = await _db.UrnForms.FirstOrDefaultAsync(wo => wo.Id == id);
            }

            return(View(workOrder));
        }
Exemple #10
0
        // GET: ~/Home/Info/{id}
        public async Task <ActionResult> Info(int?id)
        {
            if (id == null)
            {
                return(View("error",
                            new string[] { "HTTP Error 400. Bad Request, please check the url and try again." }));
            }

            UrnForm urn;

            using (UrnDbContext db = new UrnDbContext())
                urn = await db.UrnForms.FirstOrDefaultAsync(u => u.Id == id);

            if (urn == null)
            {
                return(View("error",
                            new string[] { "404: Not Found. The entity requested is not found. Please check the url and try again." }));
            }

            return(View(urn));
        }
Exemple #11
0
        // GET: ~/Queue/?{q}
        public async Task <ActionResult> Index(string q, int?page)
        {
            List <UrnForm> queue;

            using (UrnDbContext db = new UrnDbContext())
            {
                if (!string.IsNullOrEmpty(q))
                {
                    queue = await db.UrnForms.Where(f => f.Status == "Queued" && f.To.Contains(q) || f.From.Contains(q) ||
                                                    f.RrNumber.ToString().Contains(q) || f.DateEntered.ToString().Contains(q) || f.AssyName.Contains(q) || f.Quantity.ToString().Contains(q) ||
                                                    f.Priority.Contains(q) || f.Urgency.Contains(q) || f.AssyNumber.ToString().Contains(q)).OrderByDescending(f => f.Id).ToListAsync();
                }
                else
                {
                    queue = await db.UrnForms.Where(f => f.Status == "Queued").OrderByDescending(wo => wo.TimeShipped).ToListAsync();
                }
            }

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(queue.ToPagedList(pageNumber, pageSize)));
        }
Exemple #12
0
        public async Task <ActionResult> Export()
        {
            List <UrnForm> workOrders;

            using (UrnDbContext db = new UrnDbContext())
            {
                workOrders = await db.UrnForms.AsNoTracking().Where(urn => urn.Status == "Queued")
                             .OrderByDescending(urn => urn.DateEntered).ToListAsync();
            }

            DataTable table = new DataTable($"Queue { DateTime.Today.ToShortDateString() }");

            table.Columns.AddRange(new DataColumn[24]
            {
                new DataColumn("To"),
                new DataColumn("From"),
                new DataColumn("Branch"),
                new DataColumn("Customer"),
                new DataColumn("CSR Name"),
                new DataColumn("Assy Name"),
                new DataColumn("Assy Number"),
                new DataColumn("Date Entered"),
                new DataColumn("Authority Name"),
                new DataColumn("Model Name"),
                new DataColumn("Description"),
                new DataColumn("Priority"),
                new DataColumn("Quantity"),
                new DataColumn("RR Number"),
                new DataColumn("System Downtime"),
                new DataColumn("Critical Time"),
                new DataColumn("Urgency"),
                new DataColumn("Overtime Required"),
                new DataColumn("Stock"),
                new DataColumn("Replacement"),
                new DataColumn("Qty in RWC"),
                new DataColumn("Comments"),
                new DataColumn("Status"),
                new DataColumn("Submitted By")
            });

            foreach (UrnForm workOrder in workOrders)
            {
                table.Rows.Add(
                    workOrder.To,
                    workOrder.From,
                    workOrder.Branch,
                    workOrder.Customer,
                    workOrder.CsrName,
                    workOrder.AssyName,
                    workOrder.AssyNumber,
                    workOrder.DateEntered,
                    workOrder.AuthorityName,
                    workOrder.ModelName,
                    workOrder.Description,
                    workOrder.Priority,
                    workOrder.Quantity,
                    workOrder.RrNumber,
                    workOrder.SystemDowntime,
                    workOrder.CriticalTime,
                    workOrder.Urgency,
                    workOrder.OvertimeRequired,
                    workOrder.Stock,
                    workOrder.Replacement,
                    workOrder.QtyInRwc,
                    workOrder.Comments,
                    workOrder.Status,
                    workOrder.SubmittedBy
                    );
            }

            using (XLWorkbook workbook = new XLWorkbook())
            {
                workbook.Worksheets.Add(table);
                workbook.Author = HttpContext.User.Identity.Name;

                using (MemoryStream stream = new MemoryStream())
                {
                    workbook.SaveAs(stream);
                    return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"Queue { DateTime.Today }.xlsx"));
                }
            }
        }
Exemple #13
0
        public async Task <ActionResult> Export()
        {
            List <UrnForm> urnForms;

            using (UrnDbContext db = new UrnDbContext())
            {
                urnForms = await db.UrnForms.Where(urn => urn.Status == "Shipped")
                           .OrderByDescending(urn => urn.TimeShipped).AsNoTracking().ToListAsync();
            }

            DataTable table = new DataTable("Shipped Work Orders");

            table.Columns.AddRange(new DataColumn[30]
            {
                new DataColumn("To"),
                new DataColumn("From"),
                new DataColumn("Branch"),
                new DataColumn("Customer"),
                new DataColumn("CSR Name"),
                new DataColumn("Assy Name"),
                new DataColumn("Assy Number"),
                new DataColumn("Date Entered"),
                new DataColumn("Date Completed"),
                new DataColumn("Date Shipped"),
                new DataColumn("Authority Name"),
                new DataColumn("Model Name"),
                new DataColumn("Description"),
                new DataColumn("Priority"),
                new DataColumn("Quantity"),
                new DataColumn("RR Number"),
                new DataColumn("System Downtime"),
                new DataColumn("Critical Time"),
                new DataColumn("Urgency"),
                new DataColumn("Overtime Required"),
                new DataColumn("Stock"),
                new DataColumn("Replacement"),
                new DataColumn("Qty in RWC"),
                new DataColumn("Comments"),
                new DataColumn("Employee Number"),
                new DataColumn("Submitted By"),
                new DataColumn("Shipped By"),
                new DataColumn("Resolution Status"),
                new DataColumn("RA Number"),
                new DataColumn("Serial Number")
            });

            foreach (UrnForm urnForm in urnForms)
            {
                table.Rows.Add(
                    urnForm.To,
                    urnForm.From,
                    urnForm.Branch,
                    urnForm.Customer,
                    urnForm.CsrName,
                    urnForm.AssyName,
                    urnForm.AssyNumber,
                    urnForm.DateEntered,
                    urnForm.TimeCompleted,
                    urnForm.TimeShipped,
                    urnForm.AuthorityName,
                    urnForm.ModelName,
                    urnForm.Description,
                    urnForm.Priority,
                    urnForm.Quantity,
                    urnForm.RrNumber,
                    urnForm.SystemDowntime,
                    urnForm.CriticalTime,
                    urnForm.Urgency,
                    urnForm.OvertimeRequired,
                    urnForm.Stock,
                    urnForm.Replacement,
                    urnForm.QtyInRwc,
                    urnForm.Comments,
                    urnForm.CompletedBy,
                    urnForm.SubmittedBy,
                    urnForm.ShippedBy,
                    urnForm.ResolutionStatus,
                    urnForm.RaNumber,
                    urnForm.SerialNumber
                    );
            }
            using (XLWorkbook workBook = new XLWorkbook())
            {
                workBook.Worksheets.Add(table);
                workBook.Author = HttpContext.User.Identity.Name;

                using (MemoryStream stream = new MemoryStream())
                {
                    workBook.SaveAs(stream);
                    return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"Shipped { DateTime.Today }.xlsx"));
                }
            }
        }