Ejemplo n.º 1
0
        public SalaryPaymentHistory Lateness(SalaryPaymentHistory model)
        {
            // model.TotalLatenessDeduction
            model.TotalLatenessDeduction = 0;
            DateTime theTime = DateHelper.NigeriaTime(DateTime.Now);
            List <LatenessDeduction> theLatenessDeduction = new List <LatenessDeduction>();

            theLatenessDeduction = work.LatenessDeductionRepository.Get().ToList();
            //  List<AttendanceStaff> theAttendanceFortheMonth = work.AttendanceStaffRepository.Get(a =>a.DateTaken.Month == theTime.Month && a.DateTaken.Year == theTime.Month).OrderByDescending(a=>a.DateTaken).ToList();
            PrimarySchoolStaff theCurrentStaff = work.PrimarySchoolStaffRepository.Get(a => a.UserID == model.StaffID).First();

            if (theLatenessDeduction.Count > 0 && theCurrentStaff.LatenessDeduction == true)
            {
                // int numberOfAbsentDays = 0;
                for (int k = 1; k < 31; k++)
                {
                    List <AttendanceStaff> theAttendanceFortheMonth = work.AttendanceStaffRepository.Get(a => a.DateTaken.Month == theTime.Month && a.DateTaken.Year == theTime.Year).OrderByDescending(a => a.DateTaken).ToList();

                    theAttendanceFortheMonth = theAttendanceFortheMonth.Where(a => a.DateTaken.Day == k).ToList();

                    if (theAttendanceFortheMonth.Count > 0)
                    {
                        theAttendanceFortheMonth = theAttendanceFortheMonth.Where(a => a.StaffID == Convert.ToString(model.StaffID)).ToList();
                        if (theAttendanceFortheMonth.Count > 0)
                        {
                            AttendanceStaff theStaffAttendance = theAttendanceFortheMonth[0];
                            if (theStaffAttendance.Present == true)
                            {
                                AttendanceStaff attendanceForthisDay = theAttendanceFortheMonth[0];

                                int    theHour   = Convert.ToInt16(theLatenessDeduction[0].Hour);
                                int    theMinute = Convert.ToInt16(theLatenessDeduction[0].Minute);
                                double setTime   = Convert.ToDouble(theHour + "." + theMinute);
                                double timeTaken = Convert.ToDouble(attendanceForthisDay.DateTaken.Hour + "." + attendanceForthisDay.DateTaken.Minute);
                                if (timeTaken > setTime)
                                // if (setTime < timeTaken )
                                {
                                    model.TotalLatenessDeduction = model.TotalLatenessDeduction + theLatenessDeduction[0].AmountToBeDeducted;
                                }
                            }
                            else
                            {
                                // model.TotalLatenessDeduction = model.TotalLatenessDeduction + 100;
                            }
                        }
                    }
                }
                return(model);
            }
            else
            {
                return(model);
            }
        }
Ejemplo n.º 2
0
        public SalaryPaymentHistory Abscent(SalaryPaymentHistory model)
        {
            model.TotalAbscentDeduction = 0;
            DateTime theTime = DateHelper.NigeriaTime(DateTime.Now);
            List <LatenessDeduction> theLatenessDeduction = work.LatenessDeductionRepository.Get().ToList();
            //  List<AttendanceStaff> theAttendanceFortheMonth = work.AttendanceStaffRepository.Get(a =>a.DateTaken.Month == theTime.Month && a.DateTaken.Year == theTime.Month).OrderByDescending(a=>a.DateTaken).ToList();

            List <AbscentDeduction> theAbscentDeduction = new List <AbscentDeduction>();

            theAbscentDeduction = work.AbscentDeductionRepository.Get().ToList();
            //  List<AttendanceStaff> theAttendanceFortheMonth = work.AttendanceStaffRepository.Get(a =>a.DateTaken.Month == theTime.Month && a.DateTaken.Year == theTime.Month).OrderByDescending(a=>a.DateTaken).ToList();
            PrimarySchoolStaff theCurrentStaff = work.PrimarySchoolStaffRepository.Get(a => a.UserID == model.StaffID).First();

            if (theAbscentDeduction.Count > 0 && theCurrentStaff.AbscentDeduction == true)
            {
                // int numberOfAbsentDays = 0;
                for (int k = 1; k < 31; k++)
                {
                    List <AttendanceStaff> theAttendanceFortheMonth = work.AttendanceStaffRepository.Get(a => a.DateTaken.Month == theTime.Month && a.DateTaken.Year == theTime.Year).OrderByDescending(a => a.DateTaken).ToList();

                    theAttendanceFortheMonth = theAttendanceFortheMonth.Where(a => a.DateTaken.Day == k).ToList();

                    if (theAttendanceFortheMonth.Count > 0)
                    {
                        theAttendanceFortheMonth = theAttendanceFortheMonth.Where(a => a.StaffID == Convert.ToString(model.StaffID)).ToList();
                        if (theAttendanceFortheMonth.Count > 0)
                        {
                            AttendanceStaff theStaffAttendance = theAttendanceFortheMonth[0];
                            if (theStaffAttendance.Present == true || theStaffAttendance.NotPresentButTookPermission == true)
                            {
                            }
                            else
                            {
                                model.TotalAbscentDeduction = model.TotalAbscentDeduction + theAbscentDeduction[0].AmountToBeDeducted;
                            }
                        }
                    }
                }
            }
            return(model);
        }
        // [Authorize(Roles = "SuperAdmin")]
        public ActionResult Edit(AttendanceStaffViewModel model)
        {
            try
            {
                var            info       = TimeZoneInfo.FindSystemTimeZoneById("W. Central Africa Standard Time");
                DateTimeOffset theOldDate = TimeZoneInfo.ConvertTime(DateTime.Now, info);

                string   stringDate = Convert.ToString(theOldDate);
                DateTime theDate    = Convert.ToDateTime(stringDate);
                //if (!(string.IsNullOrEmpty(attendanceDate)))
                //{
                //    theDate = Convert.ToDateTime(attendanceDate);
                //}
                List <AttendanceStaff> takenAttendanceStaff = work.AttendanceStaffRepository.Get().OrderBy(a => a.DateTaken).ToList();
                takenAttendanceStaff = takenAttendanceStaff.Where(s => s.DateTaken.Date == theDate.Date).OrderByDescending(a => a.StaffID).ToList();
                ////takenAttendanceStaff = takenAttendanceStaff.Where(s => s.DateTaken.Date == DateTime.Now.Date).OrderByDescending(a => a.StaffID).ToList();
                if (takenAttendanceStaff.Count() > 0)
                {
                    //  UnitOfWork work1 = new UnitOfWork();
                    foreach (AttendanceStaff a in model.TheAttendanceStaff)
                    {
                        AttendanceStaff att = work.AttendanceStaffRepository.GetByID(a.AttendanceStaffID);
                        if (att.Present == false && a.Present == true)
                        {
                            a.DateTaken = Convert.ToDateTime(theDate); //DateTime.Now;
                            work1.AttendanceStaffRepository.Update(a);
                        }
                        if (att.NotPresentButTookPermission == false && a.NotPresentButTookPermission == true)
                        {
                            a.DateTaken = theDate; //DateTime.Now;
                            work1.AttendanceStaffRepository.Update(a);
                        }

                        if (att.Present == true && a.Present == false)
                        {
                            a.DateTaken = theDate; //DateTime.Now;
                            work1.AttendanceStaffRepository.Update(a);
                        }
                        if (att.NotPresentButTookPermission == true && a.NotPresentButTookPermission == false)
                        {
                            a.DateTaken = theDate; //DateTime.Now;
                            work1.AttendanceStaffRepository.Update(a);
                        }
                    }
                    work1.Save();
                }
                else
                {
                    foreach (AttendanceStaff a in model.TheAttendanceStaff)
                    {
                        a.DateTaken = DateTime.Now;
                        work.AttendanceStaffRepository.Insert(a);
                    }
                    work.Save();
                }
                if (User.Identity.Name != "5000001")
                {
                    AuditTrail audit = new AuditTrail {
                        Date = DateTime.Now, Action = "Marked Staff Attendance", UserID = User.Identity.Name
                    };
                    work.AuditTrailRepository.Insert(audit);
                    work.Save();
                }


                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }