public int Insert(AttendanceBase attendance) { int pkid; SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_PKID, SqlDbType.Int).Direction = ParameterDirection.Output; cmd.Parameters.Add(_EmployeeId, SqlDbType.Int).Value = attendance.EmployeeId; cmd.Parameters.Add(_Name, SqlDbType.NVarChar, 50).Value = attendance.Name; cmd.Parameters.Add(_Days, SqlDbType.Decimal).Value = attendance.Days; cmd.Parameters.Add(_AddDutyDays, SqlDbType.Decimal).Value = attendance.AddDutyDays; cmd.Parameters.Add(_TheDay, SqlDbType.DateTime).Value = attendance.TheDay; EarlyLeaveAttendance early; LaterAttendance late; if (attendance is AbsentAttendance) { cmd.Parameters.Add(_Munite, SqlDbType.Int).Value = 0; cmd.Parameters.Add(_AttendanceType, SqlDbType.Int).Value = AttendanceTypeEmnu.Absenter; } else if ((early = attendance as EarlyLeaveAttendance) != null) { cmd.Parameters.Add(_Munite, SqlDbType.Int).Value = early.EarlyLeaveMinutes; cmd.Parameters.Add(_AttendanceType, SqlDbType.Int).Value = AttendanceTypeEmnu.Early; } else if ((late = attendance as LaterAttendance) != null) { cmd.Parameters.Add(_Munite, SqlDbType.Int).Value = late.LaterMinutes; cmd.Parameters.Add(_AttendanceType, SqlDbType.Int).Value = AttendanceTypeEmnu.Late; } SqlHelper.ExecuteNonQueryReturnPKID("EmployeeAttendanceInsert", cmd, out pkid); return(pkid); }
public void Delete(int _AttendanceId) { foreach (DictionaryEntry entry in _BadAttendanceTable) { AttendanceBase attendance = entry.Value as AttendanceBase; if (attendance != null && attendance.AttendanceId.Equals(_AttendanceId)) { _BadAttendanceTable.Remove(entry.Key); break; } } }
public void DeleteEmployeeAttendanceByEmpAndTime(int EmpId, DateTime theDay) { foreach (DictionaryEntry entry in _BadAttendanceTable) { AttendanceBase attendance = entry.Value as AttendanceBase; if (attendance != null && attendance.EmployeeId.Equals(EmpId) && attendance.TheDay.Equals(theDay)) { _BadAttendanceTable.Remove(entry.Key); break; } } }
public List <AttendanceBase> GetAttendanceByEmpId(int EmpId) { List <AttendanceBase> allAttendances = new List <AttendanceBase>(); foreach (DictionaryEntry entry in _BadAttendanceTable) { AttendanceBase attendance = entry.Value as AttendanceBase; if (attendance != null && attendance.EmployeeId.Equals(EmpId)) { allAttendances.Add(attendance); } } return(allAttendances); }
public static AttendanceBase ObjAttStatus(AttendanceBase objAtt, IUnitOfWork unitOfWork, EnrolledEmployee emp, DateTime dateToProcess) { try { LeaveApplication la = unitOfWork.LeaveApplications.All() .Where(x => dateToProcess.Date >= DbFunctions.TruncateTime(x.dtstart) && dateToProcess.Date <= DbFunctions.TruncateTime(x.dtend)) .Where(x => x.isapproved == true && x.isdeleted == false) .Where(x => x.empid == emp.id) .FirstOrDefault(); if (la != null) { objAtt.attstatus = la.LeaveType.attstatus; if (la.LeaveType.attstatus == (int)enAttStatus.Sick) { if (la.ishalfday == true) { objAtt.attstatus = (int)enAttStatus.Sick2; } } else if (la.LeaveType.attstatus == (int)enAttStatus.Off) { if (la.ishalfday == true) { objAtt.attstatus = (int)enAttStatus.Off2; } } } else { objAtt.attstatus = 0; } return(objAtt); } catch (Exception ex) { _processedOk = false; _exception = ex; return(objAtt); } }
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; } //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 (rawD.R_IO == (int)enStatusCodes.TimeIn) { 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) { foreach (var rawD in rawDataToProcess) { if (rawD.R_IO == (int)enStatusCodes.TimeIn) { if (rawD.PUNCH_TIME >= _timeInStartD && rawD.PUNCH_TIME < _breakOutStartD && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.BreakOut) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.BreakIn) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD) { objAtt.breakin = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.TimeOut) { if (rawD.PUNCH_TIME > _breakInEndD && rawD.PUNCH_TIME < _timeOutEndD) { objAtt.timeoutE = 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 (rawD.R_IO == (int)enStatusCodes.TimeIn) { if (rawD.PUNCH_TIME >= _timeInStartN && rawD.PUNCH_TIME < _dayEnd && objAtt.timeinE == null) { objAtt.timeinE = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.BreakOut) { if (rawD.PUNCH_TIME >= _breakOutStartN && rawD.PUNCH_TIME < _breakInEndN && objAtt.breakout == null) { objAtt.breakout = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.BreakIn) { if (rawD.PUNCH_TIME >= _breakOutStartD && rawD.PUNCH_TIME < _breakInEndD) { objAtt.breakin = rawD.PUNCH_TIME; } } if (rawD.R_IO == (int)enStatusCodes.TimeOut) { if (rawD.PUNCH_TIME > _breakInEndN && rawD.PUNCH_TIME < _nextDayUpto) { objAtt.timeoutE = rawD.PUNCH_TIME; } } } 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 > _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; } }
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 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 int Insert(AttendanceBase attendance) { attendance.AttendanceId = _BadAttendanceId; _BadAttendanceTable.Add(_BadAttendanceId, attendance); return(_BadAttendanceId++); }
protected override bool IsTheSameAttendanceType(AttendanceBase attendance) { return(attendance is AbsentAttendance); }
protected bool AlreadyHaveTheSameDay(AttendanceBase attendance) { return(attendance.TheDay.ToShortDateString().Equals(_TheDay.ToShortDateString())); }
//protected abstract void ValidationSelf(); //需要应用模板的类去判断,这个类型是否是与自己的实体类相同的类型 protected abstract bool IsTheSameAttendanceType(AttendanceBase attendance);
protected override bool IsTheSameAttendanceType(AttendanceBase attendance) { return(attendance is EarlyLeaveAttendance); }
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); // ---- Check if the attendance record for that day is locked to proceed ---- // if (objAtt.chlocked) { return; } int count = rawDataToProcess.Count(); DateTime[] Punches = new DateTime[count]; int j = 0; foreach (var r in rawDataToProcess) { Punches[j] = r.PUNCH_TIME; j++; } int i = 0, index = 0; if (objAtt.shifttype == null) { if (shiftType == enShiftType.FixedDay) { myDynamicShft = "DAY"; } else if (shiftType == enShiftType.FixedNight) { myDynamicShft = "NIGHT"; } else if (shiftType == enShiftType.Dynamic) { if (!Common.Common._useRoster) { bool found = false; foreach (var rawD in rawDataToProcess) { if (rawD.PUNCH_TIME >= _timeInStartN && rawD.PUNCH_TIME <= _dayEnd && !found) { myDynamicShft = "NIGHT"; found = true; index = i; } else if (rawD.PUNCH_TIME >= _timeInStartD && rawD.PUNCH_TIME <= _breakOutStartD && !found) { myDynamicShft = "DAY"; found = true; index = i; } } } 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) { switch (count) { case 0: objAtt.timeinE = null; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; break; case 1: if (Punches[0] >= _timeInStartD && Punches[0] < _breakOutStartD) { objAtt.timeinE = Punches[0]; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; } else { objAtt.timeinE = null; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; } break; case 2: if (Punches[0] >= _timeInStartD && Punches[0] < _breakOutStartD) { objAtt.timeinE = Punches[0]; } else { objAtt.timeinE = null; } if (Punches[1] >= _breakOutStartD && Punches[1] < _breakInEndD) { objAtt.breakout = Punches[1]; } else { objAtt.breakout = null; } if (Punches[1] >= _breakInEndD && Punches[1] < _timeOutEndD) { objAtt.timeoutE = Punches[1]; } else { objAtt.timeoutE = null; } break; case 3: if (Punches[0] >= _timeInStartD && Punches[0] < _breakOutStartD) { objAtt.timeinE = Punches[0]; } else { objAtt.timeinE = null; } if (Punches[1] >= _breakOutStartD && Punches[1] < _breakInEndD) { objAtt.breakout = Punches[1]; } else { objAtt.breakout = null; } if (Punches[2] >= _breakOutStartD && Punches[2] < _breakInEndD) { objAtt.breakin = Punches[2]; } else { objAtt.breakin = null; } if (Punches[2] >= _breakInEndD && Punches[2] < _timeOutEndD) { objAtt.timeoutE = Punches[2]; } else { objAtt.timeoutE = null; } break; default: for (i = 0; i < Punches.Length; i++) { if (Punches[i] >= _timeInStartD && Punches[i] <= _breakOutStartD) { if (objAtt.timeinE == null) { objAtt.timeinE = Punches[i]; } } if (objAtt.breakout == null) { if (Punches[i] >= _breakOutStartD && Punches[i] <= _breakInEndD) { objAtt.breakout = Punches[i]; } if (objAtt.timeinE == objAtt.breakout) { objAtt.breakout = null; } } if (objAtt.breakout != null) { if ((Punches[i] >= _breakOutStartD && Punches[i] <= _breakInEndD) && Punches[i] >= objAtt.breakout) { objAtt.breakin = Punches[i]; } } if (Punches[i] >= _breakInEndD && Punches[i] < _timeOutEndD) { objAtt.timeoutE = Punches[i]; } } break; } if (objAtt.timeinE == null && objAtt.breakout != null) { objAtt.timeinE = objAtt.breakout; } 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; } //---------------UPDATE TIME IN/TIMEOUT FOR DYNAMIC DAY------------------------------------- //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 != true || objAtt.timeoutM != true) { IEnumerable <RawData> nxtDayData = this.rawData.Where(x => x.PUNCH_TIME <= _nextDayUpto).ToList(); count = nxtDayData.Count(); Punches = new DateTime[count]; for (i = index; i < count; i++) { Punches[i] = nxtDayData.ElementAt(i).PUNCH_TIME; } switch (count) { case 0: objAtt.timeinE = null; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; break; case 1: if (Punches[0] >= _timeInStartN && Punches[0] < _dayEnd) { objAtt.timeinE = Punches[0]; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; } else { objAtt.timeinE = null; objAtt.breakout = null; objAtt.breakin = null; objAtt.timeoutE = null; } break; case 2: if (Punches[0] >= _timeInStartN && Punches[0] < _dayEnd) { objAtt.timeinE = Punches[0]; } else { objAtt.timeinE = null; } if (Punches[1] >= _breakOutStartN && Punches[1] < _breakInEndN) { objAtt.breakout = Punches[1]; } else { objAtt.breakout = null; } if (Punches[1] >= _breakInEndN && Punches[1] < _timeOutEndN) { objAtt.timeoutE = Punches[1]; } else { objAtt.timeoutE = null; } break; case 3: if (Punches[0] >= _timeInStartN && Punches[0] < _dayEnd) { objAtt.timeinE = Punches[0]; } else { objAtt.timeinE = null; } if (Punches[1] >= _breakOutStartN && Punches[1] < _breakInEndN) { objAtt.breakout = Punches[1]; } else { objAtt.breakout = null; } if (Punches[2] >= _breakOutStartN && Punches[2] < _breakInEndN) { objAtt.breakin = Punches[2]; } else { objAtt.breakin = null; } if (Punches[2] >= _breakInEndN && Punches[2] < _timeOutEndN) { objAtt.timeoutE = Punches[2]; } else { objAtt.timeoutE = null; } break; default: for (i = 0; i < Punches.Length; i++) { if (objAtt.timeinE == null) { if (Punches[i] >= _timeInStartN && Punches[i] <= _dayEnd) { if (objAtt.timeinE == null) { objAtt.timeinE = Punches[i]; } } } if (Punches[i] >= _breakOutStartN && Punches[i] <= _breakInEndN) { if (objAtt.breakout == null) { objAtt.breakout = Punches[i]; } } if (objAtt.timeinE == objAtt.breakout) { objAtt.breakout = null; } if (objAtt.breakout != null) { if ((Punches[i] >= _breakOutStartN && Punches[i] <= _breakInEndN) && Punches[i] >= objAtt.breakout) { objAtt.breakin = Punches[i]; } } if (Punches[i] >= _breakInEndN && Punches[i] < _timeOutEndN) { objAtt.timeoutE = Punches[i]; } } break; } if (objAtt.timeinE == null && objAtt.breakout != null) { objAtt.timeinE = objAtt.breakout; } 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; } //---------------UPDATE TIME IN/TIMEOUT FOR DYNAMIC NIGHT------------------------------------- //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.isDynamic = true; 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; } }