public AssociatesHoursWorked(string StartDate, string EndDate) { Data objData = new Data(); AssociateHoursWorked objInfo; Associates objA = new Associates(); iTotalMinutesWorked = 0; List <int> AssocsWithHours = objA.GetAssociateIdsWithHoursByDate(StartDate, EndDate); foreach (int associd in AssocsWithHours) { AssociateClockInHistories objACH = new AssociateClockInHistories(); var ret = objACH.GetAllClockinsUnfiltered(StartDate, StartDate, associd); objInfo = new AssociateHoursWorked(StartDate, EndDate, associd); iTotalMinutesWorked += (objInfo.TotalHoursWorked * 60) + objInfo.TotalMinutesWorked; infoList.Add(objInfo); } iTotalHoursWorked += Convert.ToInt16(iTotalMinutesWorked / 60); iTotalMinutesWorked = iTotalMinutesWorked % 60; }
public AssociateHoursWorked(string StartDate, string EndDate, int AssociateID) { TimeSpan span; int minutes = 0; initialize(); //StartDate = "4/1/2019"; //EndDate = "4/6/2019"; objACHs = new AssociateClockInHistories(StartDate, EndDate, AssociateID); foreach (AssociateClockInHistory item in objACHs) { strAssociateName = item.FirstName + " " + item.LastName; iAssociateID = item.AssociateID; if (!item.IsLunch) { // calculate work time if (item.LogoutDatetime != DateTime.MinValue) { span = item.LogoutDatetime - item.LoginDatetime; iTotalHoursWorked += Convert.ToInt16(Math.Floor(span.TotalMinutes / 60)); minutes = Convert.ToInt16(Math.Floor(span.TotalMinutes % 60)); iTotalMinutesWorked += minutes; } //Debug.WriteLine(iTotalHoursWorked.ToString() + " :: " + item.AssociateClockInHistoryID + ": " + span.Hours.ToString() + " - " + span.Minutes.ToString()); } } var lunches = from x in objACHs.Where(t => t.IsLunch == true) group x by x.LoginDatetime.Date into xy select new { Day = xy.Key, LunchDuration = xy.Sum(y => (y.MinutesWorked)) //LunchDuration = xy.Sum(y => (y.LogoutDatetime - y.LoginDatetime).Minutes) }; foreach (var group in lunches) { if (group.LunchDuration > 30) { iTotalLunchMinutes += 30; } else { iTotalLunchMinutes += group.LunchDuration; } } iTotalMinutesWorked += iTotalLunchMinutes; iTotalHoursWorked += Convert.ToInt16(iTotalMinutesWorked / 60); iTotalMinutesWorked = iTotalMinutesWorked % 60; }
private void ClockOut() { try { AHDDManagerClass.AssociateClockInHistories ClockinHist = new AssociateClockInHistories(); List <AHDDManagerClass.AssociateClockInHistory> objACHs = ClockinHist.GetAllClockinsUnfiltered(DateTime.Now.AddDays(-1).ToShortDateString(), DateTime.Now.ToShortDateString(), AssociateID); TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); DateTime targeTodaytDT = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, targetZone); var achs = objACHs.OrderByDescending(r => r.LoginDatetime).Where(t => t.LoginDatetime.ToShortDateString() == DateTime.Now.ToShortDateString()); blnClockedIn = false; //clock in the associate automatically and update to fire the trigger Update(); if (achs != null) { var todayCIH = achs.First(); //check to see if the last entry has a logout date if (todayCIH != null && todayCIH.LogoutDatetime == DateTime.MinValue) {//DOES have a logout date todayCIH.LogoutDatetime = targeTodaytDT; todayCIH.Update(); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
//the user just logged in. checking to see if they are clocked in. if private void ClockIn() { AHDDManagerClass.AssociateClockInHistories ClockinHist = new AssociateClockInHistories(); List <AHDDManagerClass.AssociateClockInHistory> objACHs = ClockinHist.GetAllClockinsUnfiltered(DateTime.Now.AddDays(-90).ToShortDateString(), DateTime.Now.ToShortDateString(), AssociateID); AHDDManagerClass.AssociateClockInHistory objACH = null; TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); DateTime targeTodaytDT = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, targetZone); // regardless if first time for the day clocking in or returning log in, check to see if there is an open CIH, meaning they did not clock out, and close it // get yesterday's cihs //var today = objACHs.OrderByDescending(r => r.LoginDatetime).Where(t => t.LoginDatetime.ToShortDateString() == DateTime.Now.ToShortDateString()); // see if there are any today //if (today == null) // no records for today, now check yeaterday and earlier //{ // ******************************************************************************************************** // CHECK FOR PREVIOUS OPEN CIH. IF FOUND, CLOSE IT OUT. // THIS CHECK IS DONE EVERTIME, JUST IN CASE // see if there are any CIH before today var lastNotToday = objACHs.OrderByDescending(r => r.LoginDatetime).Where(t => t.LoginDatetime.ToShortDateString() != DateTime.Now.ToShortDateString()); if (lastNotToday.ToList().Count > 0 && lastNotToday.First().LogoutDatetime == DateTime.MinValue) {//if the lastest cih from yesterday does not have a log out it means they did not logout. var cih_yest = lastNotToday.First(); //auto log yesterday's cih out //cih_yest.LogoutDatetime = Convert.ToDateTime(cih_yest.LoginDatetime.ToShortDateString() + " 5:30:00 PM"); var clockOutDate = new DateTime(cih_yest.LoginDatetime.Year, cih_yest.LoginDatetime.Month, cih_yest.LoginDatetime.Day, 17, 30, 0); //TODO: HARDCODE if (clockOutDate > cih_yest.LoginDatetime) { cih_yest.LogoutDatetime = clockOutDate; } else { cih_yest.LogoutDatetime = cih_yest.LoginDatetime; } cih_yest.Update(); } //} // ******************************************************************************************************** // ******************************************************************************************************** // CHECK TODAY'S CIH //today's CIH var achs = objACHs.OrderByDescending(r => r.LoginDatetime).Where(t => t.LoginDatetime.ToShortDateString() == DateTime.Now.ToShortDateString()); if (achs.Count() == 0) {// there are NO CIH entries for today //create a new CIH entry objACH = new AssociateClockInHistory(); objACH.AssociateID = AssociateID; objACH.LoginDatetime = targeTodaytDT; objACH.IsLunch = false; objACH.Update(); } else {// there are CIH event //get todays latest CIH entry var todayCIH = achs.First(); //check to see if the last entry has a logout date if (todayCIH.LogoutDatetime != DateTime.MinValue) {//DOES have a logout date //do lunch check and insert if needed //check to see any today's CIH has a lunch var lunch = achs.Where(w => w.IsLunch == true); if (lunch.ToList().Count == 0) {// there was no lunch CIH today //create a new CIH lunch entry objACH = new AssociateClockInHistory(); objACH.AssociateID = AssociateID; objACH.LoginDatetime = todayCIH.LogoutDatetime; objACH.LogoutDatetime = targeTodaytDT; objACH.IsLunch = true; objACH.Update(); } //create a new CIH entry objACH = new AssociateClockInHistory(); objACH.AssociateID = AssociateID; objACH.LoginDatetime = targeTodaytDT; objACH.IsLunch = false; objACH.Update(); } else { //this should not happen } } // are they clocked in? IF NO, THEN SET CLOCKED IN FIELD TO TRUE IN DB if (!blnClockedIn) // user is clocked OUT { blnClockedIn = true; Update(); } }