public void ProcessRawData(EnrolledEmployee emp, DateTime dtFrom, DateTime dtTo, string tableName = "") { try { //ShiftType shift = new ShiftType(); enClockMode clockMode; //IEnumerable<RawData> rData = this.GetRawData(false,emp.enrollno,dtFrom,dtTo).ToList(); IEnumerable <RawData> rData; using (var db = new iTimeServiceContext()) { rData = db.Set <RawData>() .Where(x => x.ENROLL_NO == emp.enrollno) .Where(x => DbFunctions.TruncateTime(x.PUNCH_TIME) >= dtFrom.Date && DbFunctions.TruncateTime(x.PUNCH_TIME) <= dtTo.Date) .OrderBy(x => x.PUNCH_TIME) .ToList(); } //if (rData.Count() > 0) //{ if (emp.shift > 0) { Common.Common.SetShiftParams(dtFrom, emp.ShiftType); clockMode = emp.ShiftType.clockmode; //foreach (DateTime dateToProcess in Common.Common.GetDateRange(dtFrom,dtTo)) //{ if (clockMode == enClockMode.Schedules) { logic = new UseSchedulesLogic(emp, rData, dtFrom); } else if (clockMode == enClockMode.StatusCode) { logic = new UseStatusLogic(emp, rData, dtFrom); } else if (clockMode == enClockMode.Device) { logic = new UseDeviceLogic(emp, rData, dtFrom); } else if (clockMode == enClockMode.WorkCodes) { logic = new UseWorkCodeLogic(emp, rData, dtFrom); } if (logic != null) { ClockModeLogicProvider _provider = new ClockModeLogicProvider(logic, emp.ShiftType.type); _provider.ProcessAttendance(tableName); } //} } //} //else //{ //} } catch (Exception ex) { Common.Common._processedOk = false; Common.Common._exception = ex; //_log.Debug("ProcessRawData encountered a problem : " + ex.InnerException); } }
public static bool isHolidayDate(DateTime punchDate, ShiftType shift) { try { bool isHol; using (var db = new iTimeServiceContext()) { isHol = db.Set <Holiday>() .Where(x => DbFunctions.TruncateTime(x.holdate) == punchDate.Date) .Where(x => x.compid == _compId && x.isactive == true && x.isdeleted == false) .Count() > 0; } if (!isHol) { if (punchDate.DayOfWeek == DayOfWeek.Saturday && shift.issatwkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Sunday && shift.issunwkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Monday && shift.ismonwkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Tuesday && shift.istuewkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Wednesday && shift.iswedwkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Thursday && shift.isthuwkday != true) { isHol = true; } else if (punchDate.DayOfWeek == DayOfWeek.Friday && shift.isfriwkday != true) { isHol = true; } } return(isHol); } catch (Exception ex) { _processedOk = false; _exception = ex; return(false); } }
public void Execute(IJobExecutionContext context) { try { using (var db = new iTimeServiceContext()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE log4net"); } } catch (Exception ex) { log.Info("Exception while truncating log data", ex); } }
public void Execute(IJobExecutionContext context) { try { log4net.Config.XmlConfigurator.Configure(); log.Info("Starting job [UpdateAttendanceRecordsJob] at : " + DateTime.Now); int daysToUpdateVal = int.Parse(ConfigurationManager.AppSettings.Get("daysToUpdateVal").ToString()); //set company id....TO DO: remember to retrieve from //Common.Common.SetCompID(); /*date to update * typical scenario is that we will be updating yesterdays attendance record today */ //DateTime dtFrom = Convert.ToDateTime("2015-12-27 09:22:37.000"); //DateTime dtTo = dtFrom.AddDays(1); DateTime dtFrom = Convert.ToDateTime(DateTime.Now.AddDays(-(daysToUpdateVal))); DateTime dtTo = dtFrom.AddDays(daysToUpdateVal); //Common.Common.SYSTEMTIME dt = Common.Common.GetTime(); //get all enrolled employees using (var dbContext = new iTimeServiceContext()) { //get all enrolled, active employees // for each empployee call processrawdata from attendanceupdateservice //process raw data should return boolean try { IEnumerable <EnrolledEmployee> employees = dbContext.Set <EnrolledEmployee>() .Where(x => x.workstatus == true) .Where(x => x.isdeleted == false) //.Where(x => x.enrollno == 266) .ToList(); foreach (DateTime punchDate in Common.Common.GetDateRange(dtFrom, dtTo)) { foreach (var emp in employees) { Common.Common._compId = emp.compid; IAttendanceUpdateService _service = new AttendanceUpdateService(); _service.ProcessRawData(emp, punchDate, punchDate.AddDays(1)); if (Common.Common._processedOk == true) { log.Info("Attendance record of date [" + punchDate.Date + "] for employee : " + emp.empcode + " successfully updated at " + DateTime.Now); } else { log.Info("Error encountered while processing attendance record of date [" + punchDate.Date + "] for employee : " + emp.empcode + " at " + DateTime.Now, Common.Common._exception); } } } } catch (Exception ex) { //throw new Exception(ex.Message, ex.InnerException); log.Debug("Error occured at [UpdateAttendanceRecordsJob] at :" + DateTime.UtcNow, ex.InnerException); } } } catch (JobExecutionException ex) { log.Debug("Error occured at [UpdateAttendanceRecordsJob] at :" + DateTime.UtcNow, ex.InnerException); } }
public void StartDownload() { try { IEnumerable <Device> devices; string strDeviceModel = ""; //get valid devices using (var db = new iTimeServiceContext()) { devices = db.Set <Device>() .Where(x => (x.isdeleted == false || x.isdeleted == null)) .Where(x => x.isactive == true) .ToList(); } if (devices.Count() > 0) { foreach (var dev in devices) { string ipAdd = tripIpAdd(dev.ip); if (dev.model == enDeviceModel.Black_White) { strDeviceModel = "Black n White"; } else { strDeviceModel = "MultiMedia"; } Ping ping = new Ping(); PingReply reply; try { reply = ping.Send(ipAdd); if (reply.Status == IPStatus.Success) { if (dev.sdkname == enSDK_Name.ZKemKeeper) { string idwEnrollNumber; int enrollNo, idwVerifyMode; int idwInOutMode, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwErrorCode; int idwSecond, idwWorkCode, idwReserved; DateTime punchTime; var glCount = 0; idwWorkCode = 0; idwErrorCode = 0; idwReserved = 0; bool isConnected; //ipAdd = "192.168.1.206"; isConnected = czKEM.Connect_Net(ipAdd, dev.port); if (isConnected) { if (czKEM.ReadGeneralLogData(dev.devno)) { if (dev.model == enDeviceModel.MultiMedia) { while (this.czKEM.SSR_GetGeneralLogData(dev.devno, out idwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, idwWorkCode) == true) { punchTime = instance.ToDateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond, 0); bool rawDataExists = false; using (var db = new iTimeServiceContext()) { enrollNo = Int32.Parse(idwEnrollNumber.ToString()); rawDataExists = db.Set <RawData>() .Where(x => x.ENROLL_NO == enrollNo && x.DT_YR == idwYear) .Where(x => x.DT_MNTH == idwMonth && x.DT_DAY == idwDay) .Where(x => x.DT_HR == idwHour && x.DT_MIN == idwMinute && x.DT_SEC == idwSecond) .Where(x => x.DEV_ID == dev.devno) .Count() > 0; } if (!rawDataExists) { RawData rData = new RawData { ENROLL_NO = enrollNo, DT_YR = idwYear, DT_MNTH = idwMonth, DT_DAY = idwDay, DT_HR = idwHour, DT_MIN = idwMinute, DT_SEC = idwSecond, VER = idwVerifyMode, R_IO = idwInOutMode, R_WORK = idwWorkCode, DEV_ID = dev.devno, R_LOG = idwReserved, DATE_LOG = DateTime.Now, PUNCH_TIME = punchTime }; using (var db = new iTimeServiceContext()) { db.RawData.Add(rData); db.SaveChanges(); } Common.Common._insertedOk = true; } } czKEM.ClearGLog(dev.devno); } } } else { czKEM.GetLastError(idwErrorCode); if (idwErrorCode != 0) { _log.Info("Device data download failed. Error Code:" + idwErrorCode); } else { _log.Info("Device returns no data"); } Common.Common._insertedOk = false; } } else if (dev.sdkname == enSDK_Name.BioBridgeSDK) { //DownLoadBioBridge(dev, ipAdd); frmAxBioBridge bioBrdgeContainer = new frmAxBioBridge(); string strDevModel = "Black n White"; int icomKey = Int32.Parse(dev.comkey.ToString()); int EnrollNo = 0; int yr = 0; int mth = 0; int day_Renamed = 0; int hr = 0; int min = 0; int sec = 0; int ver = 0; int io = 0; int work = 0; int rlog = 0; DateTime punchTime; if (bioBrdgeContainer.axBioBridgeSDK1.Connect_TCPIP(strDevModel, dev.devno, ipAdd, dev.port, icomKey) == 0) { if (dev.model == enDeviceModel.Black_White) { if (bioBrdgeContainer.axBioBridgeSDK1.ReadGeneralLog(ref rlog) == 0) { //while (bioBrdgeContainer.axBioBridgeSDK1.GetGeneralLogData(dev.devno, EnrollNo, ver, io, yr, mth, day_Renamed, hr, min, sec, work) == 0) while (bioBrdgeContainer.axBioBridgeSDK1.GetGeneralLog(ref EnrollNo, ref yr, ref mth, ref day_Renamed, ref hr, ref min, ref sec, ref ver, ref io, ref work) == 0) { punchTime = instance.ToDateTime(yr, mth, day_Renamed, hr, min, sec, 0); bool rawDataExists = false; using (var db = new iTimeServiceContext()) { rawDataExists = db.Set <RawData>() .Where(x => x.ENROLL_NO == EnrollNo && x.DT_YR == yr) .Where(x => x.DT_MNTH == mth && x.DT_DAY == day_Renamed) .Where(x => x.DT_HR == hr && x.DT_MIN == min && x.DT_SEC == sec) .Where(x => x.DEV_ID == dev.devno) .Count() > 0; } if (!rawDataExists) { RawData rData = new RawData { ENROLL_NO = EnrollNo, DT_YR = yr, DT_MNTH = mth, DT_DAY = day_Renamed, DT_HR = hr, DT_MIN = min, DT_SEC = sec, VER = ver, R_IO = io, R_WORK = work, DEV_ID = dev.devno, R_LOG = rlog, DATE_LOG = DateTime.Now, PUNCH_TIME = punchTime }; using (var db = new iTimeServiceContext()) { db.RawData.Add(rData); db.SaveChanges(); Common.Common._insertedOk = true; } } } } bioBrdgeContainer.axBioBridgeSDK1.DeleteGeneralLog(); } } else { Common.Common._insertedOk = false; _log.Info("Connection to device IP : " + ipAdd + " Failed."); } bioBrdgeContainer.Dispose(); } } else if (reply.Status == IPStatus.DestinationHostUnreachable) { Common.Common._insertedOk = false; _log.Info("Device name " + dev.name + " with IP address: " + ipAdd + " was not reachable at " + DateTime.Now); } } catch (Exception ex) { Common.Common._insertedOk = false; Common.Common._exception = ex; //_log.Debug("Network connection to device :" + dev.name + " [IP: " + ipAdd + "] Failed", ex.InnerException); } } } } catch (Exception ex) { Common.Common._insertedOk = false; Common.Common._exception = ex; } }
public static void UpdateAttendanceData(IUnitOfWork _unitOfWork, AttendanceBase objAtt, EnrolledEmployee employee, string strTableName, bool isClientCall) { try { if (isClientCall == false) { if (employee.type == enEmpType.Casual) { AttCasual objC = (AttCasual)objAtt; if (objAtt.isNewRecord) { _unitOfWork.AttCasuals.Insert(objC); } else { _unitOfWork.AttCasuals.Update(objC); } } else if (employee.type == enEmpType.Permanent) { AttPermanent objC = (AttPermanent)objAtt; if (objAtt.isNewRecord) { _unitOfWork.AttPermanents.Insert(objC); } else { _unitOfWork.AttPermanents.Update(objC); } } else if (employee.type == enEmpType.Contract) { AttContract objC = (AttContract)objAtt; if (objAtt.isNewRecord) { _unitOfWork.AttContracts.Insert(objC); } else { _unitOfWork.AttContracts.Update(objC); } } _unitOfWork.Commit(); } else { using (var db = new iTimeServiceContext()) { var debug = new SqlParameter("@debug", false); var Table_Name = strTableName != null ? new SqlParameter("@Table_Name", strTableName) : new SqlParameter("@Table_Name", SqlDbType.VarChar); var empid = objAtt.empid != null ? new SqlParameter("@empid", objAtt.empid) : new SqlParameter("@empid", SqlDbType.Int); var id = objAtt.id != null ? new SqlParameter("@id", objAtt.id) : new SqlParameter("@id", SqlDbType.Int); var shiftid = objAtt.shiftid != null ? new SqlParameter("@shiftid", objAtt.shiftid) : new SqlParameter("@shiftid", SqlDbType.Int); var daytype = objAtt.daytype != null ? new SqlParameter("@daytype", objAtt.daytype) : new SqlParameter("@daytype", SqlDbType.Int); var shifttype = objAtt.shifttype != null ? new SqlParameter("@shifttype", objAtt.shifttype) : new SqlParameter("@shifttype", SqlDbType.VarChar); var isabsent = objAtt.isabsent != null ? new SqlParameter("@isabsent", objAtt.isabsent) : new SqlParameter("@isabsent", SqlDbType.Bit); var attstatus = objAtt.attstatus != null ? new SqlParameter("@attstatus", objAtt.attstatus) : new SqlParameter("@attstatus", SqlDbType.Int); var timein = objAtt.timein != null ? new SqlParameter("@timein", objAtt.timein) : new SqlParameter("@timein", DBNull.Value); var timeout = objAtt.timeout != null ? new SqlParameter("@timeout", objAtt.timeout) : new SqlParameter("@timeout", DBNull.Value); var timeinE = objAtt.timeinE != null ? new SqlParameter("@timeinE", objAtt.timeinE) : new SqlParameter("@timeinE", DBNull.Value); var timeoutE = objAtt.timeoutE != null ? new SqlParameter("@timeoutE", objAtt.timeoutE) : new SqlParameter("@timeoutE", DBNull.Value); var breakout = objAtt.breakout != null ? new SqlParameter("@breakout", objAtt.breakout) : new SqlParameter("@breakout", DBNull.Value); var breakin = objAtt.breakin != null ? new SqlParameter("@breakin", objAtt.breakin) : new SqlParameter("@breakin", DBNull.Value); var totalhrscount = objAtt.totalhrscount != null ? new SqlParameter("@totalhrscount", objAtt.totalhrscount) : new SqlParameter("@totalhrscount", SqlDbType.Float); var totalhrsworked = objAtt.totalhrsworked != null ? new SqlParameter("@totalhrsworked", objAtt.totalhrsworked) : new SqlParameter("@totalhrsworked", SqlDbType.Float); var normalhrsworked = objAtt.normalhrsworked != null ? new SqlParameter("@normalhrsworked", objAtt.normalhrsworked) : new SqlParameter("@normalhrsworked", SqlDbType.Float); var otHD = objAtt.otHD != null ? new SqlParameter("@otHD", objAtt.otHD) : new SqlParameter("@otHD", SqlDbType.Float); var otND = objAtt.otND != null ? new SqlParameter("@otND", objAtt.otND) : new SqlParameter("@otND", SqlDbType.Float); var breaktm = objAtt.breaktm != null ? new SqlParameter("@breaktm", objAtt.breaktm) : new SqlParameter("@breaktm", SqlDbType.Float); var leaveouts = objAtt.leaveouts != null ? new SqlParameter("@leaveouts", objAtt.leaveouts) : new SqlParameter("@leaveouts", SqlDbType.Float); var losthrs = objAtt.losthrs != null ? new SqlParameter("@losthrs", objAtt.losthrs) : new SqlParameter("@losthrs", SqlDbType.Float); var adjot = objAtt.adjot != null ? new SqlParameter("@adjot", objAtt.adjot) : new SqlParameter("@adjot", SqlDbType.Float); var timeinM = objAtt.timeinM != null ? new SqlParameter("@timeinM", objAtt.timeinM) : new SqlParameter("@timeinM", SqlDbType.Bit); var timeoutM = objAtt.timeoutM != null ? new SqlParameter("@timeoutM", objAtt.timeoutM) : new SqlParameter("@timeoutM", SqlDbType.Bit); var weekday = objAtt.weekday != null ? new SqlParameter("@weekday", objAtt.weekday) : new SqlParameter("@weekday", SqlDbType.Int); var comment = objAtt.comment != null ? new SqlParameter("@comment", objAtt.comment) : new SqlParameter("@comment", SqlDbType.VarChar); var earlygo = objAtt.earlygo != null ? new SqlParameter("@earlygo", objAtt.earlygo) : new SqlParameter("@earlygo", SqlDbType.Float); var latein = objAtt.latein != null ? new SqlParameter("@latein", objAtt.latein) : new SqlParameter("@latein", SqlDbType.Float); var timeinP = objAtt.timeinP != null ? new SqlParameter("@timeinP", objAtt.timeinP) : new SqlParameter("@timeinP", SqlDbType.Float); var timeoutP = objAtt.timeoutP != null ? new SqlParameter("@timeoutP", objAtt.timeoutP) : new SqlParameter("@timeoutP", SqlDbType.Float); var lunchP = objAtt.lunchP != null ? new SqlParameter("@lunchP", objAtt.lunchP) : new SqlParameter("@lunchP", SqlDbType.Float); var chlocked = objAtt.chlocked != null ? new SqlParameter("@chlocked", objAtt.chlocked) : new SqlParameter("@chlocked", SqlDbType.Bit); var finallost = objAtt.finallost != null ? new SqlParameter("@finallost", objAtt.finallost) : new SqlParameter("@finallost", SqlDbType.Float); var adjlost = objAtt.adjlost != null ? new SqlParameter("@adjlost", objAtt.adjlost) : new SqlParameter("@adjlost", SqlDbType.Float); var finalot = objAtt.finalot != null ? new SqlParameter("@finalot", objAtt.finalot) : new SqlParameter("@finalot", SqlDbType.Float); var lunchlost = objAtt.lunchlost != null ? new SqlParameter("@lunchlost", objAtt.lunchlost) : new SqlParameter("@lunchlost", SqlDbType.Float); db.Database.ExecuteSqlCommand("spDynamicAttendanceUpdate @debug,@Table_Name,@empid,@id," + "@shiftid,@daytype,@shifttype,@isabsent,@attstatus,@timein,@timeout,@timeinE,@timeoutE," + "@breakout,@breakin,@totalhrscount,@totalhrsworked,@normalhrsworked,@otHD,@otND,@breaktm," + "@leaveouts,@losthrs,@adjot,@timeinM,@timeoutM,@weekday,@comment,@earlygo,@latein,@timeinP," + "@timeoutP,@lunchP,@chlocked,@finallost,@adjlost,@finalot,@lunchlost", debug, Table_Name, empid, id, shiftid, daytype, shifttype, isabsent, attstatus, timein, timeout, timeinE, timeoutE, breakout, breakin, totalhrscount, totalhrsworked, normalhrsworked, otHD, otND, breaktm, leaveouts, losthrs, adjot, timeinM, timeoutM, weekday, comment, earlygo, latein, timeinP, timeoutP, lunchP, chlocked, finallost, adjlost, finalot, lunchlost); _processedOk = true; } } } catch (Exception ex) { _processedOk = false; _exception = ex; } }
public static void SetShiftParams(DateTime punchTime, ShiftType shift) { try { CompanySettings compSettings; using (var db = new iTimeServiceContext()) { compSettings = db.Set <CompanySettings>() .Where(x => x.compid == _compId) //use global .Where(x => x.isdeleted == false) .FirstOrDefault(); } _timeInMode = compSettings.timein; _timeOutMode = compSettings.timeout; _otDef = compSettings.otdefinition; _useRoster = compSettings.useroster; _graceIn = shift.gracein; _graceOut = shift.graceout; _otNDCalcMode = shift.otndtype; _shiftInPenalty = shift.shiftinpenalty; _shiftOutPenalty = shift.shiftoutpenalty; _lunchMinDuration = shift.lunchmin; _lunchPenalty = shift.lunchpenalty; _minWorkHrs = shift.minhrsdaily; //_maxOTHrs = shift.maxot; _minOTHrs = shift.minot; var timeEnd = "23:59:59"; var timeStart = "00:00:00"; var uptoTime = "11:59:59"; _dayEnd = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(timeEnd.ToString())); DateTime nxtDay = punchTime.AddDays(1); _nextDayStart = DateTime.Parse(nxtDay.ToShortDateString()).Add(TimeSpan.Parse(timeStart.ToString())); _nextDayUpto = DateTime.Parse(nxtDay.ToShortDateString()).Add(TimeSpan.Parse(uptoTime.ToString())); _isHoliday = isHolidayDate(punchTime, shift); _isNextDayHol = isHolidayDate(nxtDay, shift); if (_isHoliday) { _stdHrsHD = shift.stdhrshdd; _stdHrsHDD = shift.stdhrshdd; _stdHrsHDN = shift.stdhrshdn; } if (punchTime.DayOfWeek == DayOfWeek.Saturday) { _shiftInD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinsatd.ToShortTimeString())); _shiftInN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinsatn.ToShortTimeString())); _shiftOutD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutsatd.ToShortTimeString())); _shiftOutN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutsatn.ToShortTimeString())); if (_shiftOutN.ToString("tt") == "AM") { _shiftOutN.AddDays(1); } _timeInStartD = _shiftInD.AddMinutes(-(shift.shiftinallow)); _timeInStartN = _shiftInN.AddMinutes(-(shift.shiftinallow)); _breakOutDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutsatd.ToShortTimeString())); _breakOutDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutsatn.ToShortTimeString())); _breakInDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinsatd.ToShortTimeString())); _breakInDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinsatn.ToShortTimeString())); _breakOutStartD = _breakOutDefD.AddMinutes(-(shift.brkoutallow)); _breakOutStartN = _breakOutDefN.AddMinutes(-(shift.brkoutallow)); _breakInEndD = _breakInDefD.AddMinutes((shift.brkinallow)); _breakInEndN = _breakInDefN.AddMinutes((shift.brkinallow)); _maxWorkHrsD = shift.maxhrssatd; _maxWorkHrsN = shift.maxhrssatn; _timeOutEndD = _shiftOutD.AddMinutes((double)shift.shiftoutallow); _timeOutEndN = _shiftOutN.AddHours((double)shift.shiftoutallow); //_timeOutEndD = _shiftInD.AddHours((double)_maxWorkHrsD); //_timeOutEndN = _shiftInN.AddHours((double)_maxWorkHrsN); _shiftGraceInD = _shiftInD.AddMinutes((double)_graceIn); _shiftGraceInN = _shiftInN.AddMinutes((double)_graceIn); _shiftGraceOutD = _shiftOutD.AddMinutes(-(double)_graceOut); _shiftGraceOutN = _shiftOutN.AddMinutes(-(double)_graceOut); _allowedBreakD = _breakInDefD.Subtract(_breakOutDefD); _allowedBreakN = _breakInDefN.Subtract(_breakOutDefN); _stdHrsNDD = shift.stdhrssatd; _stdHrsNDN = shift.stdhrssatn; _maxOTHrsN = shift.otsatn; _maxOTHrsD = shift.otsatd; } else if (punchTime.DayOfWeek == DayOfWeek.Sunday) { _shiftInD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinsund.ToShortTimeString())); _shiftInN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinsunn.ToShortTimeString())); _shiftOutD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutsund.ToShortTimeString())); _shiftOutN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutsunn.ToShortTimeString())); if (_shiftOutN.ToString("tt") == "AM") { _shiftOutN.AddDays(1); } _timeInStartD = _shiftInD.AddMinutes(-(shift.shiftinallow)); _timeInStartN = _shiftInN.AddMinutes(-(shift.shiftinallow)); _breakOutDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutsund.ToShortTimeString())); _breakOutDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutsunn.ToShortTimeString())); _breakInDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinsund.ToShortTimeString())); _breakInDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinsunn.ToShortTimeString())); _breakOutStartD = _breakOutDefD.AddMinutes(-(shift.brkoutallow)); _breakOutStartN = _breakOutDefN.AddMinutes(-(shift.brkoutallow)); _breakInEndD = _breakInDefD.AddMinutes((shift.brkinallow)); _breakInEndN = _breakInDefN.AddMinutes((shift.brkinallow)); _maxWorkHrsD = shift.maxhrssund; _maxWorkHrsN = shift.maxhrssunn; _timeOutEndD = _shiftOutD.AddMinutes((double)shift.shiftoutallow); _timeOutEndN = _shiftOutN.AddHours((double)shift.shiftoutallow); //_timeOutEndD = _shiftInD.AddHours((double)_maxWorkHrsD); //_timeOutEndN = _shiftInN.AddHours((double)_maxWorkHrsN); _shiftGraceInD = _shiftInD.AddMinutes((double)_graceIn); _shiftGraceInN = _shiftInN.AddMinutes((double)_graceIn); _shiftGraceOutD = _shiftOutD.AddMinutes(-(double)_graceOut); _shiftGraceOutN = _shiftOutD.AddMinutes(-(double)_graceOut); _allowedBreakD = _breakInDefD.Subtract(_breakOutDefD); _allowedBreakN = _breakInDefN.Subtract(_breakOutDefN); _stdHrsNDD = shift.stdhrssund; _stdHrsNDN = shift.stdhrssunn; _maxOTHrsN = shift.otsunn; _maxOTHrsD = shift.otsund; } else // day is within mon to friday { _shiftInD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinwkdayd.ToShortTimeString())); _shiftInN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftinwkdayn.ToShortTimeString())); _shiftOutD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutwkdayd.ToShortTimeString())); _shiftOutN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.shiftoutwkdayn.ToShortTimeString())); if (_shiftOutN.ToString("tt") == "AM") { _shiftOutN.AddDays(1); } _timeInStartD = _shiftInD.AddMinutes(-(shift.shiftinallow)); _timeInStartN = _shiftInN.AddMinutes(-(shift.shiftinallow)); _breakOutDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutwkdayd.ToShortTimeString())); _breakOutDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkoutwkdayn.ToShortTimeString())); _breakInDefD = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinwkdayd.ToShortTimeString())); _breakInDefN = DateTime.Parse(punchTime.ToShortDateString()).Add(TimeSpan.Parse(shift.brkinwkdayn.ToShortTimeString())); _breakOutStartD = _breakOutDefD.AddMinutes(-(shift.brkoutallow)); _breakOutStartN = _breakOutDefN.AddMinutes(-(shift.brkoutallow)); _breakInEndD = _breakInDefD.AddMinutes((shift.brkinallow)); _breakInEndN = _breakInDefN.AddMinutes((shift.brkinallow)); _maxWorkHrsD = shift.maxhrswkdayd; _maxWorkHrsN = shift.maxhrswkdayn; _timeOutEndD = _shiftOutD.AddMinutes((double)shift.shiftoutallow); _timeOutEndN = _shiftOutN.AddHours((double)shift.shiftoutallow); //_timeOutEndD = _shiftInD.AddHours((double)_maxWorkHrsD); //_timeOutEndN = _shiftInN.AddHours((double)_maxWorkHrsN); _shiftGraceInD = _shiftInD.AddMinutes((double)_graceIn); _shiftGraceInN = _shiftInN.AddMinutes((double)_graceIn); _shiftGraceOutD = _shiftOutD.AddMinutes(-(double)_graceOut); _shiftGraceOutN = _shiftOutD.AddMinutes(-(double)_graceOut); _allowedBreakD = _breakInDefD.Subtract(_breakOutDefD); _allowedBreakN = _breakInDefN.Subtract(_breakOutDefN); _stdHrsNDD = shift.stdhrswkdayd; _stdHrsNDN = shift.stdhrswkdayn; _maxOTHrsN = shift.otwkdayn; _maxOTHrsD = shift.otwkdayd; } } catch (FormatException ex) { _processedOk = false; _exception = ex.InnerException; } }
public static AttendanceBase InitializeAttendanceObject(IUnitOfWork unitOfWork, EnrolledEmployee emp, DateTime dateToProcess, string tableName) { try { AttendanceBase objAtt = new AttendanceBase(); if (tableName == "") { if (emp.type == enEmpType.Casual) { objAtt = unitOfWork.AttCasuals.All() .Where(x => x.empid == emp.id) .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date) .FirstOrDefault(); if (objAtt == null) // insert new rec { objAtt = new AttCasual { empid = emp.id, attenddt = dateToProcess.Date, weekday = (int)dateToProcess.DayOfWeek, attstatus = (int)enAttStatus.Work, isNewRecord = true, compid = emp.compid, userid = 999 }; } objAtt = (AttCasual)objAtt; } else if (emp.type == enEmpType.Permanent) { objAtt = unitOfWork.AttPermanents.All() .Where(x => x.empid == emp.id) .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date) .FirstOrDefault(); //if no record for this casual emp then initialize record and continue if (objAtt == null) // insert new rec { objAtt = new AttPermanent { empid = emp.id, attenddt = dateToProcess.Date, weekday = (int)dateToProcess.DayOfWeek, attstatus = (int)enAttStatus.Work, isNewRecord = true, compid = emp.compid, userid = 999 }; } objAtt = (AttPermanent)objAtt; } else if (emp.type == enEmpType.Contract) { objAtt = unitOfWork.AttContracts.All() .Where(x => x.empid == emp.id) .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date) .FirstOrDefault(); if (objAtt == null) // insert new rec { objAtt = new AttContract { empid = emp.id, attenddt = dateToProcess.Date, weekday = (int)dateToProcess.DayOfWeek, attstatus = (int)enAttStatus.Work, isNewRecord = true, compid = emp.compid, userid = 999 }; } objAtt = (AttContract)objAtt; } } else { using (var db = new iTimeServiceContext()) { object[] parameters = { tableName, emp.id, dateToProcess.Date }; string strFillObj = "SELECT * FROM " + tableName + " WHERE empid =" + emp.id + " AND " + " CONVERT(VARCHAR(10), attenddt,120) ='" + dateToProcess.Date.ToString("yyyy-MM-dd") + "'"; var obj = db.Database.SqlQuery <AttendanceBase>(strFillObj).FirstOrDefault(); objAtt = (AttendanceBase)obj; } } return(objAtt); } catch (Exception ex) { _processedOk = false; _exception = ex; return(null); } }
public void processAttendance(enShiftType shiftType, string tableName = "") { try { IEnumerable <RawData> rawDataToProcess = this.rawData.Where(x => x.PUNCH_TIME.Date == dateToProcess.Date) .OrderBy(x => x.PUNCH_TIME) .ToList(); AttendanceBase objAtt = Common.Common.InitializeAttendanceObject(_unitOfWork, employee, dateToProcess, tableName); objAtt = Common.Common.ObjAttStatus(objAtt, _unitOfWork, employee, dateToProcess); if (objAtt.chlocked) { return; } IEnumerable <int> indevices, outdevices, brkindevices, brkoutdevices; using (var db = new iTimeServiceContext()) { indevices = db.Set <Device>().Where(x => x.isdeleted == false).Where(x => x.isactive == true && x.transmode == enDeviceTransMode.TimeIn).Select(x => x.id).ToList(); brkoutdevices = db.Set <Device>().Where(x => x.isdeleted == false).Where(x => x.isactive == true && x.transmode == enDeviceTransMode.BreakOut).Select(x => x.id).ToList(); brkindevices = db.Set <Device>().Where(x => x.isdeleted == false).Where(x => x.isactive == true && x.transmode == enDeviceTransMode.BreakIn).Select(x => x.id).ToList(); outdevices = db.Set <Device>().Where(x => x.isdeleted == false).Where(x => x.isactive == true && x.transmode == enDeviceTransMode.TimeOut).Select(x => x.id).ToList(); } //bool found = false; if (objAtt.shifttype == null) { if (shiftType == enShiftType.FixedDay) { myDynamicShft = "DAY"; } else if (shiftType == enShiftType.FixedNight) { myDynamicShft = "NIGHT"; } else if (shiftType == enShiftType.Dynamic) { objAtt.isDynamic = true; if (!Common.Common._useRoster) { foreach (RawData rawD in rawDataToProcess) { if (indevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME.ToString("tt") == "AM") { myDynamicShft = "DAY"; break; } else if (rawD.PUNCH_TIME.ToString("tt") == "PM") { myDynamicShft = "NIGHT"; break; } } } } else { var empRoster = _unitOfWork.EmpRoster.All() .Where(x => x.empid == employee.id && x.month == dateToProcess.Month && x.year == dateToProcess.Year) .FirstOrDefault(); int dayVal = dateToProcess.Day; string shft = "_"; if (empRoster != null) { shft = Common.Common.GetShiftFromRoster(dayVal, empRoster); } if (shft == "D") { myDynamicShft = "DAY"; } else if (shft == "N") { myDynamicShft = "NIGHT"; } else { myDynamicShft = null; } } } } else { myDynamicShft = objAtt.shifttype; } if (myDynamicShft == "DAY") { if (objAtt.timeinM == false && objAtt.timeoutM == false) // only process if client has not modified timein or timeout { foreach (var rawD in rawDataToProcess) { if (indevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _timeInStartD && rawD.PUNCH_TIME < _breakOutStartD && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD && objAtt.breakin == null) { objAtt.breakin = rawD.PUNCH_TIME; } } if (brkoutdevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME > _breakInEndD && rawD.PUNCH_TIME < _timeOutEndD) { objAtt.timeoutE = rawD.PUNCH_TIME; } } if (brkindevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD) { objAtt.breakin = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _timeInStartD && rawD.PUNCH_TIME < _breakOutStartD && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } } if (outdevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME > _breakInEndD && rawD.PUNCH_TIME < _timeOutEndD) { objAtt.timeoutE = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } } } if (objAtt.breakout != null && objAtt.breakin != null && objAtt.breakin < objAtt.breakout) { DateTime?temp = objAtt.breakin; objAtt.breakin = objAtt.breakout; objAtt.breakout = temp; } if (objAtt.timeinE == null && objAtt.breakout != null) { objAtt.timeinE = objAtt.breakout; } if (objAtt.timeinE > objAtt.breakout && objAtt.breakout != null) { objAtt.breakout = objAtt.timeinE; } if (objAtt.timeoutE == null && objAtt.breakin != null) { objAtt.timeoutE = objAtt.breakin; } if (objAtt.breakin == null && objAtt.breakout != null && objAtt.timeoutE != null) { objAtt.breakin = objAtt.timeoutE; } if (objAtt.timeoutE < objAtt.breakin && objAtt.breakin != null) { objAtt.timeoutE = objAtt.breakin; } //set time in according to grace in allowed and company setting if (objAtt.timeinE != null) { if (objAtt.timeinE > _shiftGraceInD) { objAtt.timein = objAtt.timeinE; } else if ((objAtt.timeinE >= _shiftInD && objAtt.timeinE <= _shiftGraceInD)) { objAtt.timein = _shiftInD; } else { if (_timeInMode == enGlobalTimeInOutMode.DynamicTime) { objAtt.timein = objAtt.timeinE; } else if (_timeInMode == enGlobalTimeInOutMode.ExactShiftTime) { objAtt.timein = _shiftInD; } } } //set timeout accordin to grace out allowed and company setting if (objAtt.timeoutE != null) { if (objAtt.timeoutE < _shiftGraceOutD) { objAtt.timeout = objAtt.timeoutE; } else if ((objAtt.timeoutE >= _shiftGraceOutD && objAtt.timeoutE <= _shiftOutD)) { objAtt.timeout = _shiftOutD; } else { if (_timeOutMode == enGlobalTimeInOutMode.ExactShiftTime) { objAtt.timeout = _shiftOutD; } else if (_timeOutMode == enGlobalTimeInOutMode.DynamicTime) { objAtt.timeout = objAtt.timeoutE; } } } } objAtt.allowedbreak = _allowedBreakD; objAtt.maxhrsAllowed = _maxWorkHrsD; objAtt.stdhrsAllowed = _stdHrsAllowedD; objAtt.shiftInTime = _shiftInD; objAtt.shiftOutTime = _shiftOutD; objAtt.maxOTHrs = Common.Common._maxOTHrsD; } else if (myDynamicShft == "NIGHT") { if (objAtt.timeinM == false && objAtt.timeoutM == false) { IEnumerable <RawData> nxtDayData = this.rawData.Where(x => x.PUNCH_TIME <= _nextDayUpto).ToList(); foreach (var rawD in nxtDayData) { if (indevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _timeInStartN && rawD.PUNCH_TIME < _dayEnd && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _breakOutStartN && rawD.PUNCH_TIME < _breakInEndN && objAtt.breakin == null) { objAtt.breakin = rawD.PUNCH_TIME; } } if (brkoutdevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _breakOutStartN && rawD.PUNCH_TIME < _breakInEndN && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME > _breakInEndN && rawD.PUNCH_TIME < _nextDayUpto) { objAtt.timeoutE = rawD.PUNCH_TIME; } } if (brkindevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD) { objAtt.breakin = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _timeInStartD && rawD.PUNCH_TIME < _breakOutStartD && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } } if (outdevices.Contains(rawD.DEV_ID)) { if (rawD.PUNCH_TIME > _breakInEndN && rawD.PUNCH_TIME < _nextDayUpto) { objAtt.timeoutE = rawD.PUNCH_TIME; } if (rawD.PUNCH_TIME >= _breakOutStartN && rawD.PUNCH_TIME < _breakInEndN && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } } } //if (objAtt.timeoutE == null && objAtt.breakout != null) objAtt.timeoutE = objAtt.breakout; //if (objAtt.timeoutE < objAtt.breakin && objAtt.breakin != null) objAtt.timeoutE = objAtt.breakin; //if (objAtt.timeinE == null && objAtt.breakin != null) objAtt.timeinE = objAtt.breakin; //if (objAtt.timeinE > objAtt.breakout && objAtt.breakout != null) objAtt.timeoutE = objAtt.breakout; if (objAtt.timeoutE == null && objAtt.breakout != null) { objAtt.timeoutE = objAtt.breakout; } if (objAtt.timeoutE < objAtt.breakin && objAtt.breakin != null) { objAtt.timeoutE = objAtt.breakin; } if (objAtt.timeinE == null && objAtt.breakin != null) { objAtt.timeinE = objAtt.breakin; } if (objAtt.timeinE > objAtt.breakout && objAtt.breakout != null) { objAtt.timeoutE = objAtt.breakout; } //set time in according to grace in allowed and company setting if (objAtt.timeinE != null) { if (objAtt.timeinE > _shiftGraceInN) { objAtt.timein = objAtt.timeinE; } else if ((objAtt.timeinE >= _shiftInN && objAtt.timeinE <= _shiftGraceInN)) { objAtt.timein = _shiftInN; } else { if (_timeInMode == enGlobalTimeInOutMode.DynamicTime) { objAtt.timein = objAtt.timeinE; } else if (_timeInMode == enGlobalTimeInOutMode.ExactShiftTime) { objAtt.timein = _shiftInN; } } } //set timeout accordin to grace out allowed and company setting if (objAtt.timeoutE != null) { if (objAtt.timeoutE < _shiftGraceOutN) { objAtt.timeout = objAtt.timeoutE; } else if ((objAtt.timeoutE >= _shiftGraceOutN && objAtt.timeoutE <= _shiftOutN)) { objAtt.timeout = _shiftOutN; } else { if (_timeOutMode == enGlobalTimeInOutMode.ExactShiftTime) { objAtt.timeout = _shiftOutN; } else if (_timeOutMode == enGlobalTimeInOutMode.DynamicTime) { objAtt.timeout = objAtt.timeoutE; } } } } objAtt.allowedbreak = _allowedBreakN; objAtt.maxhrsAllowed = _maxWorkHrsN; objAtt.stdhrsAllowed = _stdHrsAllowedN; objAtt.shiftInTime = _shiftInN; objAtt.shiftOutTime = _shiftOutN; objAtt.maxOTHrs = Common.Common._maxOTHrsN; } objAtt.breakType = employee.breaks; objAtt.shiftid = employee.shift; objAtt.deptid = employee.department; objAtt.shifttype = myDynamicShft; if (!string.IsNullOrEmpty(objAtt.shifttype)) { objAtt.isHol = _isHoliday; objAtt.calcTTHrsCount(); objAtt.calcTTBreaks(); objAtt.calcLunchLost(); objAtt.calcTTHrsWorked(); objAtt.calcNormalHrsWorked(); objAtt.setDayType(); objAtt.calcLateIn(); objAtt.calcEarlyGo(); objAtt.calcOTSeparate(); objAtt.calcLostSeparate(); if (Common.Common._otNDCalcMode == enOTND.DeductLostHrs) { objAtt.calcOT(); } //----------------Reset values if Holiday ------------// objAtt.adjustOnHoliday(); } else { objAtt.isabsent = true; } objAtt.setComment(); //---------------Update database--------------------------------------------------- bool isClientCall = tableName == "" ? false : true; Common.Common.UpdateAttendanceData(_unitOfWork, objAtt, employee, tableName, isClientCall); Common.Common._processedOk = true; } catch (Exception ex) { Common.Common._processedOk = false; Common.Common._exception = ex; } }