Пример #1
0
        public ActionResult Index(String CompanyURL, Models.TimesheetViewModel Model)
        {
            PopulateModel(Model);

            if (Model.LoginId == 0)
            {
                return(Expired(CompanyURL));
            }

            Model.SelectedEmployeeId = Model.LoginId;
            if (Model.IsSave == true)
            {
                SaveTimesheet(CompanyURL, Model);
            }


            if (Model.IsReviseRequsted == true)
            {
                var Timesheet = Context.Timesheets.Where(t => t.PeriodId == Model.SelectedPeriodId && t.EmployeeId == Model.SelectedEmployeeId).FirstOrDefault();
                Timesheet.LockStatusId         = 2;
                Context.Entry(Timesheet).State = System.Data.Entity.EntityState.Modified;
                Context.SaveChanges();
            }


            Model.IsSave   = false;
            Model.IsSubmit = false;

            PopulateTimesheetModel(Model, Model.SelectedPeriodId, 0);
            ModelState.Clear();
            return(View(Model));
            //return RedirectPermanent("/" + CompanyURL + "/time?SelectedPeriodId=" +Model.SelectedPeriodId);
        }
Пример #2
0
        public ActionResult Index(String CompanyURL, int?SelectedPeriodId)
        {
            var Model = new Models.TimesheetViewModel();

            PopulateModel(Model);

            if (Model.LoginId == 0)
            {
                return(Expired(CompanyURL));
            }

            PopulateTimesheetModel(Model, 0, 0);
            return(View(Model));
        }
Пример #3
0
        public ActionResult AdminTime(String CompanyURL)
        {
            var Model = new Models.TimesheetViewModel();

            PopulateModel(Model);

            if (Model.LoginId == 0)
            {
                return(Expired(CompanyURL));
            }

            PopulateAdminTimeModel(Model);

            return(View(Model));
        }
Пример #4
0
        public ActionResult RemoveLine(int?LineId)
        {
            var Model = new Models.TimesheetViewModel();

            PopulateModel(Model);

            if (Model.LoginId == 0)
            {
                return(Expired(Model.CompanyURL));
            }

            var Line = Context.TimesheetLines.Where(l => l.LineId == LineId).FirstOrDefault();

            if (Line != null)
            {
                Context.Entry(Line).State = System.Data.Entity.EntityState.Deleted;
                Context.SaveChanges();
            }

            return(RedirectPermanent("/" + Model.CompanyURL + "/time"));
        }
Пример #5
0
        public void PopulateTimesheetModel(Models.TimesheetViewModel Model, int SelectedPeriodId, int SelectedEmployeeId)
        {
            if (SelectedEmployeeId == 0)
            {
                SelectedEmployeeId = Model.LoginId;
            }

            var Periods = Context.Periods.Where(p => p.CompanyId == Model.CompanyId).ToList();

            Model.PeriodListItems = Periods.Select(f => new SelectListItem {
                Value = f.PeriodId.ToString(),
                Text  = ((DateTime)f.PeriodStart).ToString("dd-MMM-yy") + " to " + ((DateTime)f.PeriodEnd).ToString("dd-MMM-yy")
            });
            if (SelectedPeriodId != 0)
            {
                Model.SelectedPeriodId = (int)SelectedPeriodId;
            }
            if (Model.SelectedPeriodId == 0)
            {
                Model.SelectedPeriodId = int.Parse(Model.PeriodListItems.FirstOrDefault().Value);
            }


            var TaskAlloweds = Context.TaskAlloweds.Where(ta => ta.IsActive == true && ta.EmployeeId == SelectedEmployeeId).ToList();
            List <SelectListItem> TaskListItems = TaskAlloweds.Select(f => new SelectListItem {
                Value = f.Task.TaskId.ToString(),
                Text  = f.Task.TaskName
            }).ToList();

            TaskListItems.Insert(0, new SelectListItem()
            {
                Text = "[SELECT A TASK]", Value = ""
            });
            Model.TaskListItems = TaskListItems;

            var SelectedPeriod = Periods.Where(p => p.PeriodId == Model.SelectedPeriodId).FirstOrDefault();
            var tmpDate        = (DateTime)SelectedPeriod.PeriodStart;


            Model.SelectedPeriodDates = new List <DateTime>();
            while (tmpDate <= SelectedPeriod.PeriodEnd)
            {
                Model.SelectedPeriodDates.Add(tmpDate);
                tmpDate = tmpDate.AddDays(1);
            }


            var Timesheet = Context.Timesheets.Where(t => t.PeriodId == Model.SelectedPeriodId && t.EmployeeId == SelectedEmployeeId).FirstOrDefault();

            if (Timesheet != null)
            {
                Model.EmployeeNotes    = Timesheet.EmployeeNotes;
                Model.IsLocked         = (Timesheet.LockStatusId != 0);
                Model.LastSubmitted    = Timesheet.SubmittedOn;
                Model.PayroleNotes     = Timesheet.ApproverNotes;
                Model.LockStatusId     = Timesheet.LockStatusId;
                Model.ApprovalStatusId = Timesheet.ApprovalStatusId;

                Model.LastApproved = Timesheet.ApprovedOn;

                var    Lines         = Context.TimesheetLines.Where(tl => tl.TimesheetId == Timesheet.TimesheetId);
                String TimesheetData = "";

                foreach (Data.TimesheetLine Line in Lines)
                {
                    TimesheetData += Line.LineId + "|";
                    TimesheetData += ((DateTime)Line.StartTime).ToString("MM/dd/yyyy HH:mm") + "|";
                    TimesheetData += ((DateTime)Line.EndTime).ToString("MM/dd/yyyy HH:mm") + "|";
                    TimesheetData += Line.TaskId + "\n";
                }
                Model.TimesheetData = TimesheetData;
            }
            else
            {
                Model.EmployeeNotes    = "";
                Model.IsLocked         = false;
                Model.LastSubmitted    = null;
                Model.PayroleNotes     = "";
                Model.LockStatusId     = 0;
                Model.ApprovalStatusId = 0;

                Model.LastApproved  = null;
                Model.TimesheetData = "";
            }
        }
Пример #6
0
        public void SaveTimesheet(String CompanyURL, Models.TimesheetViewModel Model)
        {
            var Timesheet = Context.Timesheets.Where(t => t.PeriodId == Model.SelectedPeriodId && t.EmployeeId == Model.SelectedEmployeeId).FirstOrDefault();

            if (Timesheet == null)
            {
                Timesheet = new Data.Timesheet();

                Timesheet.CompanyId        = Model.CompanyId;
                Timesheet.PeriodId         = Model.SelectedPeriodId;
                Timesheet.EmployeeId       = Model.SelectedEmployeeId;
                Timesheet.LockStatusId     = 0;
                Timesheet.ApprovalStatusId = 0;
                //Timesheet.ApprovalStatusId = Model.ApprovalStatusId;
            }


            Timesheet.EmployeeNotes = Model.EmployeeNotes;
            Timesheet.SavedOn       = DateTime.UtcNow;
            Timesheet.RevisedById   = Model.LoginId;

            if (Model.IsSubmit == true)
            {
                Timesheet.LockStatusId     = 1;
                Timesheet.ApprovalStatusId = 1;
                Timesheet.SubmittedOn      = DateTime.UtcNow;
            }

            if (Model.IsApprove == true)
            {
                Timesheet.ApprovedOn       = DateTime.UtcNow;
                Timesheet.ApprovedById     = Model.LoginId;
                Timesheet.ApprovalStatusId = 2;
                Timesheet.LockStatusId     = 1;
            }

            Context.Entry(Timesheet).State = Timesheet.TimesheetId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
            Context.SaveChanges();

            if (!String.IsNullOrEmpty(Model.TimesheetData))
            {
                var TimeLines = Model.TimesheetData.Split('\n');
                foreach (var TimeLine in TimeLines)
                {
                    if (TimeLine != "")
                    {
                        var LineDetails = TimeLine.Split('|');

                        var Line = new Data.TimesheetLine();
                        if (LineDetails[0] != "")
                        {
                            int tmpLineId = int.Parse(LineDetails[0]);
                            Line = Context.TimesheetLines.Where(tl => tl.LineId == tmpLineId).FirstOrDefault();
                        }

                        Line.TimesheetId = Timesheet.TimesheetId;
                        Line.StartTime   = DateTime.Parse(LineDetails[1]);
                        Line.EndTime     = DateTime.Parse(LineDetails[2]);
                        Line.TaskId      = int.Parse(LineDetails[3]);

                        if (Model.IsApprove == true)
                        {
                            Line.ApprovalStatusId = 2;
                            Line.ApprovedById     = Model.LoginId;
                            Line.ApprovedOn       = DateTime.UtcNow;
                        }

                        Context.Entry(Line).State = Line.LineId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                        Context.SaveChanges();
                    }
                }
            }
        }