} // public IActionResult Count_Absense(int?id) //遲到 { int UserID = 0; int Month = 0; if (id != null) { UserID = (int)id; Month = DateTime.Now.Date.Month; } else { UserID = int.Parse(HttpContext.Session.GetString("CURRENT_LOGINED_USERID")); Month = DateTime.Now.Date.Month - 1; } ViewBag.MONTH = Month; var table = from i in MyHR.TAbsences //計算遲到總數 where (i.CEmployeeId == UserID && i.CStatus.Contains("遲到") && i.CDate.Value.Month == Month) && i.CDate.Value.Year == DateTime.Now.Date.Year group i by i.CStatus into g select new { countLate = g.Count(), below30 = g.Count(c => c.COn.Value.Minutes < 30), up30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59), moneybelow30 = g.Count(c => c.COn.Value.Minutes < 30) * 44, moneyup30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59) * 96 }; List <CSalaryViewModel> T = new List <CSalaryViewModel>(); foreach (var item in table) { CSalaryViewModel obj = new CSalaryViewModel() { CountTotalLate = item.countLate, Count_Latebelow30 = item.below30, Count_Lateup30 = item.up30, CAmont_Latebelow30 = item.moneybelow30, CAmont_Lateup30 = item.moneyup30, CAmont_TAbsense = item.moneybelow30 + item.moneyup30, }; T.Add(obj); } return(PartialView("Count_Absense", T)); }
public IActionResult Count_Leave(int?id) //請假 { int UserID = 0; int Month = 0; if (id != null) { UserID = (int)id; Month = DateTime.Now.Date.Month; } else { UserID = int.Parse(HttpContext.Session.GetString("CURRENT_LOGINED_USERID")); Month = DateTime.Now.Date.Month - 1; } ViewBag.MONTH = Month; var table = (from i in MyHR.TLeaveApplications.AsEnumerable() where i.CEmployeeId == UserID && DateTime.Parse(i.CLeaveStartTime).Month == Month && DateTime.Parse(i.CLeaveStartTime).Year == DateTime.Now.Date.Year && i.CCheckStatus == 2 //搜尋 "請假起始日"的月為上一個月 (上面也要減) orderby i.CLeaveCategory group i by i.CLeaveCategory into g select new { Category = g.Key, CategoryCount = g.Sum(n => n.CLeaveHours), }).ToList(); List <CSalaryViewModel> T = new List <CSalaryViewModel>(); foreach (var item in table) { CSalaryViewModel obj = new CSalaryViewModel() { CSalary_LeaveCate = item.Category, CSalary_LeaveCateCount = (int)item.CategoryCount, Leave_HaveToPay = Leave_Shouldtopay(item.Category, (int)item.CategoryCount) //各個假別要付的錢 }; T.Add(obj); } return(PartialView("Count_Leave", T)); } //
public IActionResult Detail(int Id) //主管導入詳細資料的薪資單 檢視當月 { var table = MyHR.TUsers .Include(c => c.CDepartment) .Include(c => c.CJobTitle) .Include(c => c.TLeaveApplications) .Include(c => c.TTravelExpenseApplications) .Include(c => c.TAbsences) .Where(c => c.CEmployeeId == Id).AsEnumerable() .Select(c => new CSalaryViewModel { CEmployeeName = c.CEmployeeName, CDepartment = c.CDepartment.CDepartment, CEmployeeId = c.CEmployeeId, CJobTitle = c.CJobTitle.CJobTitle, CJobTitleSalary = c.CJobTitle.CJobTitleSalary, CAmont_Travel = (int)c.TTravelExpenseApplications.Where(c => c.CTravelStartTime.Value.Month == (DateTime.Now.Date.Month) && c.CCheckStatus == 2).Sum(n => (n.CAmont)) //CLeaveHours = c.TLeaveApplications.Sum(c=>c.CLeaveHours), //CLeaveHours = c.TLeaveApplications.Where(c=>DateTime.Parse(c.CLeaveStartTime).Month == DateTime.Now.Date.Month).Sum(c => c.CLeaveHours), }); //------------------------------------------------------------------以下為了取得請假項目的碼 var table2 = (from i in MyHR.TLeaveApplications.AsEnumerable() where i.CEmployeeId == Id && DateTime.Parse(i.CLeaveStartTime).Month == (DateTime.Now.Date.Month) && i.CCheckStatus == 2 //搜尋 "請假起始日"的月為上一個月 (下面也要減) orderby i.CLeaveCategory group i by i.CLeaveCategory into g select new { Category = g.Key, CategoryCount = g.Sum(n => n.CLeaveHours), }).ToList(); List <CSalaryViewModel> T = new List <CSalaryViewModel>(); foreach (var item in table2) { CSalaryViewModel obj = new CSalaryViewModel() { CSalary_LeaveCate = item.Category, CSalary_LeaveCateCount = (int)item.CategoryCount, Leave_HaveToPay = Leave_Shouldtopay(item.Category, (int)item.CategoryCount) //各個假別要付的錢 }; T.Add(obj); ViewBag.Leave = T; //這邊算完是放入ViewBag傳送過去的...糟糕 } //------------------------------------------------------------------以下為了取得遲到項目的碼 var table3 = from i in MyHR.TAbsences //計算遲到總數 where (i.CEmployeeId == Id && i.CStatus.Contains("遲到") && i.CDate.Value.Month == (DateTime.Now.Date.Month)) //為啥 =="'遲到'"不行 group i by i.CStatus into g select new { countLate = g.Count(), below30 = g.Count(c => c.COn.Value.Minutes < 30), up30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59), moneybelow30 = g.Count(c => c.COn.Value.Minutes < 30) * 44, moneyup30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59) * 96 }; List <CSalaryViewModel> T2 = new List <CSalaryViewModel>(); foreach (var item in table3) { CSalaryViewModel obj = new CSalaryViewModel() { CAmont_TAbsense = item.moneybelow30 + item.moneyup30, }; T2.Add(obj); ViewBag.Late = T2; } return(View(table.ToList())); }
} //AJAX 員工檢視過去薪資 (PA) public IActionResult SalaryList() //薪資單 (一般員工檢視) 檢視上個月 { int UserID = int.Parse(HttpContext.Session.GetString("CURRENT_LOGINED_USERID")); var table = MyHR.TUsers .Include(c => c.CDepartment) .Include(c => c.CJobTitle) .Include(c => c.TLeaveApplications) .Include(c => c.TTravelExpenseApplications) .Include(c => c.TAbsences) .Where(c => c.CEmployeeId == UserID).AsEnumerable() .Select(c => new CSalaryViewModel { CEmployeeName = c.CEmployeeName, CDepartment = c.CDepartment.CDepartment, CEmployeeId = c.CEmployeeId, CJobTitle = c.CJobTitle.CJobTitle, CJobTitleSalary = c.CJobTitle.CJobTitleSalary, CAmont_Travel = (int)c.TTravelExpenseApplications.Where(c => c.CTravelStartTime.Value.Month == (DateTime.Now.Date.Month) - 1 && c.CTravelStartTime.Value.Year == (DateTime.Now.Date.Year) && c.CCheckStatus == 2).Sum(n => (n.CAmont)) //CLeaveHours = c.TLeaveApplications.Sum(c=>c.CLeaveHours), //CLeaveHours = c.TLeaveApplications.Where(c=>DateTime.Parse(c.CLeaveStartTime).Month == DateTime.Now.Date.Month).Sum(c => c.CLeaveHours), }); //List<CSalaryViewModel> T = new List<CSalaryViewModel>(); //foreach (var item in table) //{ // CSalaryViewModel obj = new CSalaryViewModel() // { // CEmployeeName = item.CEmployeeName, // CDepartment = item.CDepartment, // CEmployeeId = item.CEmployeeId, // CJobTitle = item.CJobTitle, // CJobTitleSalary = item.CJobTitleSalary, // CLeaveHours = item.CLeaveHours // }; // T.Add(obj); //} //------------------------------------------------------------------以下為了取得請假項目的碼 var table2 = (from i in MyHR.TLeaveApplications.AsEnumerable() where i.CEmployeeId == UserID && DateTime.Parse(i.CLeaveStartTime).Month == (DateTime.Now.Date.Month) - 1 && DateTime.Parse(i.CLeaveStartTime).Year == DateTime.Now.Date.Year && i.CCheckStatus == 2 //搜尋 "請假起始日"的月為上一個月 (下面也要減) orderby i.CLeaveCategory group i by i.CLeaveCategory into g select new { Category = g.Key, CategoryCount = g.Sum(n => n.CLeaveHours), }).ToList(); List <CSalaryViewModel> T = new List <CSalaryViewModel>(); foreach (var item in table2) { CSalaryViewModel obj = new CSalaryViewModel() { CSalary_LeaveCate = item.Category, CSalary_LeaveCateCount = (int)item.CategoryCount, Leave_HaveToPay = Leave_Shouldtopay(item.Category, (int)item.CategoryCount) //各個假別要付的錢 }; T.Add(obj); ViewBag.Leave = T; //這邊算完是放入ViewBag傳送過去的...糟糕 } var a = T.ToList(); //------------------------------------------------------------------以下為了取得遲到項目的碼 (30分鐘內44塊錢 一小時內 97) var table3 = from i in MyHR.TAbsences //計算遲到總數 where (i.CEmployeeId == UserID && i.CStatus.Contains("遲到") && i.CDate.Value.Month == (DateTime.Now.Date.Month) - 1 && i.CDate.Value.Year == DateTime.Now.Date.Year) group i by i.CStatus into g select new { countLate = g.Count(), below30 = g.Count(c => c.COn.Value.Minutes < 30), up30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59), moneybelow30 = g.Count(c => c.COn.Value.Minutes < 30) * 44, moneyup30 = g.Count(c => c.COn.Value.Minutes > 30 && c.COn.Value.Minutes < 59) * 97 }; List <CSalaryViewModel> T2 = new List <CSalaryViewModel>(); foreach (var item in table3) { CSalaryViewModel obj = new CSalaryViewModel() { //CountTotalLate = item.countLate, (取消無相關的欄位) //Count_Latebelow30 = item.below30, //Count_Lateup30 = item.up30, //CAmont_Latebelow30 = item.moneybelow30, //CAmont_Lateup30 = item.moneyup30, CAmont_TAbsense = item.moneybelow30 + item.moneyup30, }; T2.Add(obj); ViewBag.Late = T2; } return(View(table.ToList())); }