public ActionResult SetSchedule([FromBody] Schedule schedule) { if (session.GetString("Role") == null) { return(LocalRedirect("/")); } var message = ""; if (ModelState.IsValid) { var data = db.Schedule.Any(s => s.ComId == schedule.ComId && s.EmpId == schedule.EmpId && s.FromDate.Date <= schedule.FromDate.Date && s.ToDate.Date <= schedule.ToDate.Date); if (!data) { db.Schedule.Add(schedule); db.SaveChanges(); message = "Schedule Submited"; } else { message = "Shedule allready exist"; } } else { message = "Sorry, something wrong"; } return(Json(message)); }
public ActionResult SetCompanyWeekEnd([FromBody] WeekdayDefault weekdayDefault) { var message = ""; if (ModelState.IsValid) { WeekdayDefault data = db.WeekdayDefault.FirstOrDefault(w => w.ComId == weekdayDefault.ComId); if (data != null) { data.ComId = weekdayDefault.ComId; data.Sunday = weekdayDefault.Sunday; data.Monday = weekdayDefault.Monday; data.Tuesday = weekdayDefault.Tuesday; data.Wednesday = weekdayDefault.Wednesday; data.Thursday = weekdayDefault.Thursday; data.Friday = weekdayDefault.Friday; data.Saturday = weekdayDefault.Saturday; db.WeekdayDefault.Update(data); db.SaveChanges(); message = "Weekend Update succeded"; } else { db.WeekdayDefault.Add(weekdayDefault); db.SaveChanges(); message = "Weekend submit succeded"; } } else { message = "Sorry, Something wrong"; } return(Json(message)); }
public ActionResult ScheduleApprove([FromBody] Schedule schedule) { var message = ""; if (ModelState.IsValid) { List <SetWorkingTime> setworkedTime = db.SetWorkingTime.Where(s => s.ScheduleId == schedule.Id).ToList(); db.SetWorkingTime.RemoveRange(setworkedTime); db.Schedule.Update(schedule); db.SaveChanges(); message = "Schedule Approved"; } else { message = "Sorry, somthing wrong"; } return(Json(message)); }
public string LeaveAproval(LeaveAvailable leave) { string comId = session.GetString("ComId"); LeaveAvailable leaveAvailable = new LeaveAvailable(); LeaveBalance leaveBalance = db.LeaveBalance.FirstOrDefault(l => l.ComId == comId && l.EmpId == leave.EmpId); if (leaveBalance != null) { LeaveAvailable lAvail = new LeaveAvailable(); int count = 0; switch (leave.LeaveType) { case "CL": count = Convert.ToInt32(leaveBalance.Bcl); if (count >= leave.LeaveApprove) { leaveBalance.Acl += leave.LeaveApprove; leaveBalance.Bcl -= leave.LeaveApprove; db.Update(leaveBalance); lAvail = SetData(leave); db.LeaveAvailable.Add(lAvail); db.SaveChanges(); message = "Leave entry succeed"; } else { message = "The employee has leave available" + count + "Day"; } break; case "SL": count = Convert.ToInt32(leaveBalance.Bsl); if (count >= leave.LeaveApprove) { leaveBalance.Asl += leave.LeaveApprove; leaveBalance.Bsl -= leave.LeaveApprove; lAvail = SetData(leave); db.LeaveAvailable.Add(lAvail); db.SaveChanges(); message = "Leave entry succeed"; } else { message = "The employee has leave available" + count + "Day"; } break; case "EL": count = Convert.ToInt32(leaveBalance.Bel); if (count >= leave.LeaveApprove) { leaveBalance.Ael += leave.LeaveApprove; leaveBalance.Bel -= leave.LeaveApprove; lAvail = SetData(leave); db.LeaveAvailable.Add(lAvail); db.SaveChanges(); message = "Leave entry succeed"; } else { message = "The employee has leave available" + count + "Day"; } break; case "ML": count = Convert.ToInt32(leaveBalance.Bml); if (count >= leave.LeaveApprove) { leaveBalance.Aml += leave.LeaveApprove; leaveBalance.Bml -= leave.LeaveApprove; lAvail = SetData(leave); db.LeaveAvailable.Add(lAvail); db.SaveChanges(); message = "Leave entry succeed"; } else { message = "The employee has leave available" + count + "Day"; } break; default: message = "Leave type is not valid"; break; } //db.LeaveAvailable.Add(lAvail); //db.SaveChanges(); } else { message = "No leave balnce of this employee"; } return(message); }
public string AttPross(ProcessData process) { // shift time TimeSpan startTime = new TimeSpan(0, 0, 0, 0); TimeSpan r = new TimeSpan(0, 8, 0, 0); TimeSpan sStart = new TimeSpan(0, 9, 0, 0); TimeSpan sEnd = new TimeSpan(0, 18, 0, 0); DateTime shiftStart = process.PunchDate.Value.Date.Add(sStart); DateTime shiftEnd = process.PunchDate.Value.Date.Add(sEnd); DateTime rHour = Convert.ToDateTime(process.PunchDate.Value.Date.Add(startTime)); DateTime regularHour = process.PunchDate.Value.Date.Add(r); List <ProcessData> listOfProcess = new List <ProcessData>(); List <ProcessData> listOfData = db.ProcessData.Where(e => e.PunchDate.Value.Date == process.PunchDate.Value.Date && e.ComId == "comId").ToList(); List <EmployeeInfo> employees = db.EmployeeInfo.Where(e => e.ComId == comId).ToList(); List <RawData> rawDatas = db.RawData.Where(e => e.PunchDate == process.PunchDate.Value.Date && e.ComId == comId).ToList(); if (rawDatas.Count != 0) { foreach (EmployeeInfo row in employees) { ProcessData processData = new ProcessData(); IEnumerable <RawData> datas = rawDatas.Where(e => e.EmpId == row.Id).ToList(); RawData minPunchTime = (from i in datas let minTime = datas.Min(m => m.PunchTime) where i.PunchTime == minTime select i).FirstOrDefault(); RawData maxPunchTime = (from i in datas let maxTime = datas.Max(m => m.PunchTime) where i.PunchTime == maxTime select i).FirstOrDefault(); LeaveAvailable leave = db.LeaveAvailable.FirstOrDefault(l => l.ComId == comId && l.EmpId == row.Id && l.DateFrom >= DateTime.Today.Date && l.DateTo <= DateTime.Today.Date); //DateTime totalWorked = minPunchTime!=null ? Convert.ToDateTime(Convert.ToString(maxPunchTime.PunchTime - minPunchTime.PunchTime)):rHour; DateTime totalWorked = rHour; if (minPunchTime != null) { DateTime date1 = maxPunchTime.PunchTime; DateTime date2 = minPunchTime.PunchTime; TimeSpan diff = date1.Subtract(date2); totalWorked = process.PunchDate.Value.Date.Add(diff); } // --- Set process Data processData.EmpId = row.Id; processData.ComId = row.ComId; processData.EmpCode = row.Code; processData.PunchDate = rHour; processData.SectionId = row.SectionId; processData.DesignationId = row.DesignationId; processData.TimeIn = minPunchTime != null ? minPunchTime.PunchTime : rHour; processData.TimeOut = maxPunchTime != null ? maxPunchTime.PunchTime : rHour; //processData.Status = "P"; processData.Late = rHour; processData.RegularHour = regularHour; if (totalWorked > regularHour) { TimeSpan test = totalWorked - regularHour; DateTime ttt = process.PunchDate.Value.Date.Add(test); processData.OtHour = ttt; } else { processData.OtHour = rHour; } //processData.OtHour = totalWorked > regularHour ? Convert.ToDateTime(Convert.ToString(totalWorked - regularHour)) : rHour; // ---- Check Status ---- if (leave != null) { processData.Status = leave.LeaveType; processData.TimeIn = processData.TimeOut = rHour; } else if (minPunchTime != null && (minPunchTime.PunchTime == maxPunchTime.PunchTime)) { processData.Status = "A"; } else if (minPunchTime != null && (minPunchTime.PunchTime <= shiftStart)) { processData.Status = "P"; } else if (minPunchTime != null && (minPunchTime.PunchTime > shiftStart)) { processData.Status = "L"; processData.Late = Convert.ToDateTime(Convert.ToString(minPunchTime.PunchTime - sStart)); } else { processData.Status = "A"; } db.ProcessData.Add(processData); } List <ProcessData> processes = db.ProcessData.Where(p => p.PunchDate == rHour && p.ComId == comId).ToList(); if (processes != null) { foreach (ProcessData item in processes) { db.ProcessData.Remove(item); } } rowEffect = db.SaveChanges(); return(rowEffect > 0 ? "Data process successfully of the day " + process.PunchDate : "Sorry, something wrong"); } else { return("No Punch Data of the day " + process.PunchDate); } }