public UseStatusLogic(EnrolledEmployee emp, IEnumerable <RawData> rData, DateTime dateToProcess) { this.employee = emp; this.rawData = rData.ToList(); this.dateToProcess = dateToProcess; this._unitOfWork = new UnitOfWork(); }
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 UseSchedulesLogic(EnrolledEmployee emp, IEnumerable <RawData> rData, DateTime dateToProcess) { this.employee = emp; this.rawData = rData.ToList(); //this.shift = shift; this.dateToProcess = dateToProcess; _unitOfWork = new UnitOfWork(); }
private string GetCurrentAttTable(EnrolledEmployee emp, DateTime dtAttend) { try { AttendanceBase objAtt; string strTableName = string.Empty; if (emp.type == enEmpType.Casual) { objAtt = unitOfWork.AttCasuals.All() .Where(x => x.attenddt.Month == dtAttend.Date.Month) .FirstOrDefault(); if (objAtt != null) { strTableName = "Trn_AttCasual"; } else { strTableName = "Trn_AttCasual_" + dtAttend.ToString("yyyyMM"); } } else if (emp.type == enEmpType.Permanent) { strTableName = "Trn_AttPermanent"; objAtt = unitOfWork.AttPermanents.All() .Where(x => x.attenddt.Month == dtAttend.Date.Month) .FirstOrDefault(); if (objAtt != null) { strTableName = "Trn_AttPermanent"; } else { strTableName = "Trn_AttPermanent_" + dtAttend.ToString("yyyyMM"); } } else if (emp.type == enEmpType.Contract) { objAtt = unitOfWork.AttContracts.All() .Where(x => x.attenddt.Month == dtAttend.Date.Month) .FirstOrDefault(); if (objAtt != null) { strTableName = "Trn_AttContract"; } else { strTableName = "Trn_AttContract_" + dtAttend.ToString("yyyyMM"); } } return(strTableName); } catch (Exception ex) { Common.Common._processedOk = false; Common.Common._exception = ex; return(string.Empty); } }
public ProcessAttendanceResult ProcessAtt(string dtFrom, string dtTo, string strEmpIds, string machineName, string ipAddress) { log4net.Config.XmlConfigurator.Configure(); var dtF = dtFrom.ToDate(); if (!dtF.HasValue) { _log.Info("Client Machine Attendance Processing Request Failed: Conversion Error"); return(CouldNotConvertToDateException(dtFrom)); } var dtT = dtTo.ToDate(); if (!dtT.HasValue) { _log.Info("Client Machine Attendance Processing Request Failed: Conversion Error"); return(CouldNotConvertToDateException(dtTo)); } string strMachineIP = "[" + machineName + " - " + ipAddress + "]"; _log.Info(strMachineIP + " Attendance Processing Request Started at " + DateTime.Now + " for Date Range : " + dtF.ToString() + " To " + dtT.ToString()); //------------------------------------------------------------------------------------------ //Pause currently running scheduled attendance job to avoid db update concurrency conflicts //------------------------------------------------------------------------------------------- IScheduler sched = new StdSchedulerFactory().GetScheduler(); //DataTable jobsTable = GetJobs(sched); JobKey updateJobKey = null; var executingJobs = sched.GetCurrentlyExecutingJobs(); foreach (var job in executingJobs) { JobKey jobKey = job.JobDetail.Key; updateJobKey = jobKey; if (jobKey.Name == "updateAtt") { sched.PauseJob(jobKey); break; } } //--------------------------------------------------------------------------------------------- // -----To do : If no job currently running check if its about to start and reschedule the job //--------------------------------------------------------------------------------------------- string[] EmpIds = GetPostedEmpIds(strEmpIds); double empCount = 0; foreach (var empId in EmpIds) { int employeeId = Convert.ToInt16(empId); EnrolledEmployee emp = unitOfWork.EnrolledEmployees.All() .Where(x => x.workstatus == true) .Where(x => x.isdeleted == false) .Where(x => x.id == employeeId) .FirstOrDefault(); if (emp != null) { string tableName = GetCurrentAttTable(emp, DateTime.Parse(dtF.ToString())); foreach (DateTime punchDate in Common.Common.GetDateRange(DateTime.Parse(dtFrom.ToString()), DateTime.Parse(dtTo.ToString()))) { empCount++; ProcessRawData(emp, punchDate, punchDate.AddDays(1), tableName); if (Common.Common._processedOk == false) { _log.Info("Exception encountered while processing attendance update for :" + strMachineIP + " at " + DateTime.Now, Common.Common._exception); } } } } _log.Info(strMachineIP + " Attendance Processing Request Finished at " + DateTime.Now + ". No of Attendance Records Updated : " + empCount + " From " + dtFrom.ToString() + " to " + dtTo.ToString()); //---------Resume paused job Here..--------------------- if (updateJobKey != null) { sched.ResumeJob(updateJobKey); } return(new ProcessAttendanceResult { Count = empCount, Message = "Attendance has been processed successfully! Dates: " + dtFrom + " to " + dtTo }); }
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 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); } }