public string ApproveLeaveApplication(VMESSPCommon vmESSPCommon, VMLoggedUser LoggedInUser, string Message) { //gets the First entry and comment box for the approval of the leave application LeaveApplication lvapplication = LeaveApplicationRepository.GetSingle((int)vmESSPCommon.PID); //if (DDService.IsDateLieBetweenActivePayroll(lvapplication.FromDate)) //{ //Gets Employee Information about the access of the location and company of the employee. List <VHR_EmployeeProfile> _emp = DDService.GetEmployeeInfo(LoggedInUser).Where(aa => aa.PEmployeeID == lvapplication.EmpID).ToList(); VHR_EmployeeProfile employee = DDService.GetEmployeeInfo(LoggedInUser).Where(aa => aa.PEmployeeID == lvapplication.EmpID).First(); //Gets Employee Leave policy on the Type of leave applied LeavePolicy lvPolicy = AssistantLeave.GetEmployeeLeavePolicyID(_emp, lvapplication.LeaveTypeID, DDService.GetLeavePolicy().ToList()); Expression <Func <PayrollPeriod, bool> > SpecificEntries96 = c => lvapplication.FromDate >= c.PRStartDate && lvapplication.FromDate <= c.PREndDate && c.PeriodStageID == "C"; List <PayrollPeriod> dbPayrollPeriods = PayrollPeriodService.GetIndexSpecific(SpecificEntries96).ToList(); if (dbPayrollPeriods.Count() > 0) { Message = "Cannot Approve leaves of Closed Payroll Period"; } if (Message == "") { //Check the Leave balance if there are some leaves remaining of the employee whose leave is being approved. if (LeaveApplicationService.CheckLeaveBalance(lvapplication, lvPolicy)) { //Changes Leave Stage ID to "A" (Approved). lvapplication.LeaveStageID = "A"; //Gets the leave Type through generic service. LeaveType lvType = DDService.GetLeaveType().First(aa => aa.PLeaveTypeID == lvapplication.LeaveTypeID); LeaveApplicationService.BalanceLeaves(lvapplication, lvType, AssistantLeave.GetPayRollPeriodID(DDService.GetPayrollPeriod().ToList(), lvapplication.FromDate)); LeaveApplicationRepository.Edit(lvapplication); LeaveApplicationRepository.Save(); UnitOfWork.Commit(); //Adds leave to leave data frim where its impact is generated on the reports. LeaveApplicationService.AddLeaveToLeaveData(lvapplication, lvType, lvPolicy); //Add Leaves to Att Data where Daily and Monthy Reporcessing of attendance occurs on the day LeaveApplicationService.AddLeaveToAttData(lvapplication, lvType); VHR_UserEmployee LMUser = DDService.GetEmployeeUser(lvapplication.LineManagerID, null); VHR_UserEmployee EmpUser = DDService.GetEmployeeUser(null, lvapplication.EmpID); // Add notification to the Employee that leave has been approved. DDService.SaveNotification((int)EmpUser.PUserID, "/ESSP/ESSPLeaveApp/Index", Convert.ToInt32(NTLeaveEnum.LeaveApproved), true, lvapplication.LineManagerID, lvapplication.PLeaveAppID); //Add entry in the flow table SaveLeaveApplicationFlow((int)EmpUser.PUserID, lvapplication.LineManagerID, lvapplication.LeaveStageID, lvapplication.PLeaveAppID, "", vmESSPCommon.Comment); //Save Email in the Notification Email table from where through services email is generated to employee about the approval of the leave Application. Expression <Func <VAT_LeaveApplication, bool> > SpecificEntries3 = c => c.PLeaveAppID == lvapplication.PLeaveAppID; VAT_LeaveApplication vlvApplication = VEPESSPLeaveApplicationReporsitory.FindBy(SpecificEntries3).First(); DDService.GenerateEmail(EmpUser.OfficialEmailID, "", "Leave Application # " + lvapplication.PLeaveAppID.ToString(), ESSPText.GetApprovedLeaveText(vlvApplication, EmpUser.UserEmployeeName, LMUser.UserEmployeeName, LMUser.DesignationName), LoggedInUser.PUserID, Convert.ToInt32(NTLeaveEnum.LeaveApproved)); // Disable Notification of the pending Leave. int notiTypeID1 = Convert.ToInt32(NTLeaveEnum.LeavePending); Expression <Func <Notification, bool> > SpecificEntries = c => (c.UserID == LoggedInUser.PUserID && c.Status == true && (c.NotificationTypeID == notiTypeID1) && c.PID == lvapplication.PLeaveAppID); DDService.DeleteNotification(SpecificEntries); } } return(Message); }
public void ApprovalCode(VMESSPCommon vmESSPCommon, VMLoggedUser LoggedInUser, LeaveApplication lvapplication, LeavePolicy lvPolicy) { if (LeaveApplicationService.CheckLeaveBalance(lvapplication, lvPolicy)) { //Changes Leave Stage ID to "A" (Approved). lvapplication.LeaveStageID = "A"; //Gets the leave Type through generic service. LeaveType lvType = DDService.GetLeaveType().First(aa => aa.PLeaveTypeID == lvapplication.LeaveTypeID); LeaveApplicationService.BalanceLeaves(lvapplication, lvType, AssistantLeave.GetPayRollPeriodID(DDService.GetPayrollPeriod().ToList(), lvapplication.FromDate)); LeaveApplicationRepository.Edit(lvapplication); LeaveApplicationRepository.Save(); UnitOfWork.Commit(); //Adds leave to leave data frim where its impact is generated on the reports. LeaveApplicationService.AddLeaveToLeaveData(lvapplication, lvType, lvPolicy); //Add Leaves to Att Data where Daily and Monthy Reporcessing of attendance occurs on the day LeaveApplicationService.AddLeaveToAttData(lvapplication, lvType); VHR_UserEmployee LMUser = DDService.GetEmployeeUser(lvapplication.LineManagerID, null); VHR_UserEmployee EmpUser = DDService.GetEmployeeUser(null, lvapplication.EmpID); // Add notification to the Employee that leave has been approved. DDService.SaveNotification((int)EmpUser.PUserID, "/ESSP/ESSPLeaveApp/Index", Convert.ToInt32(NTLeaveEnum.LeaveApproved), true, lvapplication.LineManagerID, lvapplication.PLeaveAppID); //Add entry in the flow table SaveLeaveApplicationFlow((int)EmpUser.PUserID, lvapplication.LineManagerID, lvapplication.LeaveStageID, lvapplication.PLeaveAppID, "", vmESSPCommon.Comment); //Save Email in the Notification Email table from where through services email is generated to employee about the approval of the leave Application. Expression <Func <VAT_LeaveApplication, bool> > SpecificEntries3 = c => c.PLeaveAppID == lvapplication.PLeaveAppID; VAT_LeaveApplication vlvApplication = VEPESSPLeaveApplicationReporsitory.FindBy(SpecificEntries3).First(); DDService.GenerateEmail(EmpUser.OfficialEmailID, "", "Leave Application # " + lvapplication.PLeaveAppID.ToString(), ESSPText.GetApprovedLeaveText(vlvApplication, EmpUser.UserEmployeeName, LMUser.UserEmployeeName, LMUser.DesignationName), LoggedInUser.PUserID, Convert.ToInt32(NTLeaveEnum.LeaveApproved)); // Disable Notification of the pending Leave. int notiTypeID1 = Convert.ToInt32(NTLeaveEnum.LeavePending); Expression <Func <Notification, bool> > SpecificEntries = c => (c.UserID == LoggedInUser.PUserID && c.Status == true && (c.NotificationTypeID == notiTypeID1) && c.PID == lvapplication.PLeaveAppID); DDService.DeleteNotification(SpecificEntries); // Disable Notification of the pending Leave. int notiTypeID2 = Convert.ToInt32(NTLeaveEnum.LeaveRecommend); Expression <Func <Notification, bool> > SpecificEntries2 = c => (c.UserID == LoggedInUser.PUserID && c.Status == true && (c.NotificationTypeID == notiTypeID2) && c.PID == lvapplication.PLeaveAppID); DDService.DeleteNotification(SpecificEntries2); } }
public ActionResult Create(LeaveApplication lvapplication) { VMLoggedUser LoggedInUser = Session["LoggedInUser"] as VMLoggedUser; if (lvapplication.FromDate.Date > lvapplication.ToDate.Date) { ModelState.AddModelError("FromDate", "From Date should be smaller than To Date"); } FinancialYear dbFinancialYear = DDService.GetFinancialYear().Where(aa => aa.PFinancialYearID == lvapplication.FinancialYearID).First(); if (lvapplication.ToDate > dbFinancialYear.FYEndDate || lvapplication.ToDate < dbFinancialYear.FYStartDate) { ModelState.AddModelError("FromDate", "To Date must lie in selected financial year"); } Expression <Func <PayrollPeriod, bool> > SpecificEntries3 = c => c.PeriodStageID == "O"; PayrollPeriod dbpayrollperiod = PayrollPeriodService.GetIndexSpecific(SpecificEntries3).First(); if (lvapplication.FromDate < dbpayrollperiod.PRStartDate) { ModelState.AddModelError("FromDate", "Cannot Create leaves in the Closed Payroll Period"); } string _EmpNo = Request.Form["EmpNo"].ToString(); List <VHR_EmployeeProfile> _emp = DDService.GetEmployeeInfo(LoggedInUser).Where(aa => aa.OEmpID == _EmpNo).ToList(); Expression <Func <VHR_EmployeeProfile, bool> > SpecificEntries121 = c => c.OEmpID == _EmpNo; VHR_EmployeeProfile employee = VHR_EmployeeProfile.GetIndexSpecific(SpecificEntries121).First(); lvapplication.EmpID = employee.PEmployeeID; var RBValue = Request.Form["HalfLvHA"]; if (RBValue == "false") { lvapplication.IsHalf = false; } else { lvapplication.IsHalf = true; } LeavePolicy lvPolicy = new LeavePolicy(); LeaveType lvType = DDService.GetLeaveType().First(aa => aa.PLeaveTypeID == lvapplication.LeaveTypeID); if (_emp.Count == 0) { ModelState.AddModelError("EmpID", "Invalid Department Access or Employee Resigned."); } else { if (_emp.First().Status == "Resigned") { if (_emp.First().ResignDate <= lvapplication.ToDate) { ModelState.AddModelError("ToDate", "Cannot Apply leaves of Resigned Employee."); } } lvapplication.EmpID = employee.PEmployeeID; lvPolicy = AssistantLeave.GetEmployeeLeavePolicyID(_emp, lvapplication.LeaveTypeID, DDService.GetLeavePolicy().ToList()); //lvType = db.Att_LeaveType.First(aa => aa.LvTypeID == lvapplication.LeaveTypeID); Expression <Func <VAT_LeaveApplication, bool> > SpecificEntries = aa => aa.EmpID == lvapplication.EmpID && lvapplication.FromDate >= aa.FromDate && lvapplication.FromDate <= aa.ToDate && lvapplication.ToDate > aa.FromDate; if (VATLeaveApplicationService.GetIndexSpecific(SpecificEntries).Count() > 0) { ModelState.AddModelError("FromDate", "Duplicate leave applied for one or more days"); } } if (lvapplication.IsHalf == false && lvapplication.IsDeducted == false) { List <DailyAttendance> att = new List <DailyAttendance>(); Expression <Func <DailyAttendance, bool> > SpecificEntries2 = aa => aa.EmpID == lvapplication.EmpID && aa.AttDate >= lvapplication.FromDate && aa.AttDate <= lvapplication.ToDate; att = DailyAttendanceService.GetIndexSpecific(SpecificEntries2); if (att.Count > 0) { foreach (var at in att) { if (at.TimeIn != null || at.TimeOut != null) { ModelState.AddModelError("LeaveTypeID", "This employee has attendance for Specific day, Please clear his attendance first to proceed further"); } } } } // CL cannot be taken after next to AL consective day if (lvapplication.LeaveTypeID == 2) { if (LeaveApplicationService.CheckForALConsectiveDay(lvapplication)) { ModelState.AddModelError("FromDate", "You have applied AL leave for previous date"); } } float noofDays = LeaveApplicationService.CalculateNoOfDays(lvapplication, lvType, lvPolicy); if (lvapplication.LeaveTypeID == 11) { if (noofDays < lvPolicy.MinimumDays) { ModelState.AddModelError("LeaveTypeID", "Cannot Apply Academic for Less than" + lvPolicy.MinimumDays.ToString() + " days"); } } { if (noofDays < lvPolicy.MinimumDays) { ModelState.AddModelError("LeaveTypeID", "Cannot Apply CME/Workshop for Less than" + lvPolicy.MinimumDays.ToString() + " days"); } } if (lvapplication.IsHalf != true) { Expression <Func <VAT_JobCardApplication, bool> > SpecificEntries1 = aa => aa.OEmpID == _EmpNo && aa.DateStarted == lvapplication.FromDate && aa.DateStarted <= lvapplication.ToDate && aa.DateEnded > lvapplication.FromDate; if (JobcardAppService.GetIndexSpecific(SpecificEntries1).Count() > 0) { ModelState.AddModelError("FromDate", "Job card exist for same date"); } } Expression <Func <Shift, bool> > SpecificEntries97 = c => c.PShiftID == employee.ShiftID; Shift shifts = ShiftService.GetIndexSpecific(SpecificEntries97).First(); if (shifts.GZDays == true) { List <Holiday> holiday = DDService.GetHolidays().Where(aa => aa.HolidayDate == lvapplication.FromDate).ToList(); if (holiday.Count > 0) { ModelState.AddModelError("FromDate", "Cannot apply leave of the Gazetted Holiday"); } } Expression <Func <PayrollPeriod, bool> > SpecificEntries96 = c => lvapplication.FromDate >= c.PRStartDate && lvapplication.FromDate <= c.PREndDate && c.PeriodStageID == "C"; List <PayrollPeriod> dbPayrollPeriods = PayrollPeriodService.GetIndexSpecific(SpecificEntries96).ToList(); if (dbPayrollPeriods.Count() > 0) { ModelState.AddModelError("FromDate", "Cannot enter leaves in Closed Payroll Period"); } //if (!DDService.IsDateLieBetweenActivePayroll(lvapplication.FromDate)) // ModelState.AddModelError("FromDate", "Payroll Period is Closed for this date"); if (ModelState.IsValid) { if (LeaveApplicationService.CheckDuplicateLeave(lvapplication)) { // max days float CalenderDays = LeaveApplicationService.CalculateCalenderDays(lvapplication, lvType, lvPolicy); lvapplication.ReturnDate = LeaveApplicationService.GetReturnDate(lvapplication, lvType, lvPolicy); lvapplication.NoOfDays = noofDays; lvapplication.CalenderDays = CalenderDays; int _UserID = LoggedInUser.PUserID; lvapplication.CreatedBy = _UserID; if (lvPolicy.PLeavePolicyID == 0) { LeaveApplicationService.CreateLeave(lvapplication, lvType, LoggedInUser, lvPolicy); return(Json("OK", JsonRequestBehavior.AllowGet)); } else { //check for employee eligible for leave if (AssistantLeave.EmployeeEligbleForLeave(lvPolicy, _emp)) { if (lvPolicy.UpdateBalance == true) { if (LeaveApplicationService.HasLeaveQuota(lvapplication.EmpID, lvPolicy, (int)lvapplication.FinancialYearID)) { if (LeaveApplicationService.CheckLeaveBalance(lvapplication, lvPolicy)) { //if (LeaveApplicationService.CheckForMaxMonthDays(lvapplication, lvPolicy, LvProcessController.GetFinancialYearID(db.PR_FinancialYear.ToList(), lvapplication.FromDate))) { LeaveApplicationService.CreateLeave(lvapplication, lvType, LoggedInUser, lvPolicy); return(Json("OK", JsonRequestBehavior.AllowGet)); } //else // ModelState.AddModelError("FromDate", "Leave Monthly Quota Exceeds"); } else { ModelState.AddModelError("LeaveTypeID", "Leave Balance Exceeds!!!"); } } else { ModelState.AddModelError("LeaveTypeID", "Leave Quota does not exist"); } } else { LeaveApplicationService.CreateLeave(lvapplication, lvType, LoggedInUser, lvPolicy); return(Json("OK", JsonRequestBehavior.AllowGet)); } } else { ModelState.AddModelError("LeaveTypeID", "Employee is not eligible for leave"); } } } else { ModelState.AddModelError("FromDate", "This Employee already has leave in this range of dates"); } } HelperMethod(lvapplication); return(PartialView("Create", lvapplication)); }
public ActionResult Create(LeaveApplication lvapplication) { VMLoggedUser LoggedInUser = Session["LoggedInUser"] as VMLoggedUser; if (lvapplication.LeaveAddress == "" || lvapplication.LeaveAddress == null) { ModelState.AddModelError("LeaveAddress", "Contact number is mandatory !"); } if (lvapplication.LeaveAddress != null) { Match match = Regex.Match(lvapplication.LeaveAddress, @"^-*[0-9,\-]+$"); if (!match.Success) { ModelState.AddModelError("LeaveAddress", "Enter a valid Contact No"); } } if (lvapplication.FromDate.Date > lvapplication.ToDate.Date) { ModelState.AddModelError("FromDate", "From Date should be smaller than To Date"); } FinancialYear dbFinancialYear = DDService.GetFinancialYear().Where(aa => aa.PFinancialYearID == lvapplication.FinancialYearID).First(); if (lvapplication.ToDate >= dbFinancialYear.FYEndDate || lvapplication.ToDate <= dbFinancialYear.FYStartDate) { ModelState.AddModelError("FromDate", "To Date must lie in selected financial year"); } if (lvapplication.ToDate > AppAssistant.MaxDate) { ModelState.AddModelError("ToDate", "Date cannot be greater than " + AppAssistant.MaxDate.ToString("dd-MM-yyyy")); } if (lvapplication.FromDate < AppAssistant.MinDate) { ModelState.AddModelError("FromDate", "Date cannot be less than " + AppAssistant.MinDate.ToString("dd-MM-yyyy")); } string _EmpNo = Request.Form["EmpNo"].ToString(); List <VHR_EmployeeProfile> _emp = DDService.GetEmployeeInfo(LoggedInUser).Where(aa => aa.OEmpID == _EmpNo).ToList(); VHR_EmployeeProfile employee = DDService.GetEmployeeInfo(LoggedInUser).Where(aa => aa.OEmpID == _EmpNo).First(); var RBValue = Request.Form["HalfLvHA"]; if (_emp.First().LineManagerID == null) { ModelState.AddModelError("EmpID", "There is no Line Manager associated with your profile. Please contact HR"); } { LeavePolicy lvPolicy = new LeavePolicy(); LeaveType lvType = DDService.GetLeaveType().First(aa => aa.PLeaveTypeID == lvapplication.LeaveTypeID); if (_emp.Count == 0) { ModelState.AddModelError("FromDate", "Emp No not exist"); } else { lvapplication.EmpID = _emp.FirstOrDefault().PEmployeeID; lvPolicy = AssistantLeave.GetEmployeeLeavePolicyID(_emp, lvapplication.LeaveTypeID, DDService.GetLeavePolicy().ToList()); //lvType = db.Att_LeaveType.First(aa => aa.LvTypeID == lvapplication.LeaveTypeID); } if (lvapplication.IsHalf == false && lvapplication.IsDeducted == false) { List <DailyAttendance> att = new List <DailyAttendance>(); Expression <Func <DailyAttendance, bool> > SpecificEntries = aa => aa.EmpID == lvapplication.EmpID && aa.AttDate >= lvapplication.FromDate && aa.AttDate <= lvapplication.ToDate; att = DailyAttendanceService.GetIndexSpecific(SpecificEntries); if (att.Count > 0) { foreach (var at in att) { if (at.TimeIn != null || at.TimeOut != null) { ModelState.AddModelError("LeaveTypeID", "This employee has attendance for Specific day, Please clear his attendance first to proceed further"); } } } } // CL cannot be taken after next to AL consective day float noofDays = LeaveApplicationService.CalculateNoOfDays(lvapplication, lvType, lvPolicy); if (lvapplication.LeaveTypeID == 2) { if (LeaveApplicationService.CheckForALConsectiveDay(lvapplication)) { ModelState.AddModelError("FromDate", "You have applied AL leave for previous date"); } } // Check for Minimum Days of Attachment of Sick Leave if (lvapplication.LeaveTypeID == 3) { if (noofDays < lvPolicy.MinimumDays) { ModelState.AddModelError("LeaveTypeID", "Cannot Apply SL for Less than" + lvPolicy.MinimumDays.ToString() + " days"); } } //if (LeaveForHoliday(lvapplication)) //{ // ModelState.AddModelError("LeaveTypeID", "This employee has Rest Or GZ for specific Day"); //} //if (!CheckForLvTypeHasLvPolicyForEmp(_emp, lvType)) //{ // ModelState.AddModelError("LeaveTypeID", "This employee does not have Leave Policy, Please add Leave Policy first"); //} //if (!DDService.IsDateLieBetweenActivePayroll(lvapplication.FromDate)) // ModelState.AddModelError("FromDate", "Payroll Period is Closed for this date"); Expression <Func <Shift, bool> > SpecificEntries97 = c => c.PShiftID == employee.ShiftID; Shift shifts = ShiftService.GetIndexSpecific(SpecificEntries97).First(); if (shifts.GZDays == true) { List <Holiday> holiday = DDService.GetHolidays().Where(aa => aa.HolidayDate == lvapplication.FromDate).ToList(); if (holiday.Count > 0) { ModelState.AddModelError("FromDate", "Cannot apply leave of the Gazetted Holiday"); } } Expression <Func <PayrollPeriod, bool> > SpecificEntries96 = c => lvapplication.FromDate >= c.PRStartDate && lvapplication.FromDate <= c.PREndDate && c.PeriodStageID == "C"; List <PayrollPeriod> dbPayrollPeriods = PayrollPeriodService.GetIndexSpecific(SpecificEntries96).ToList(); if (dbPayrollPeriods.Count() > 0) { ModelState.AddModelError("FromDate", "Cannot enter leaves in Closed Payroll Period"); } if (ModelState.IsValid) { if (LeaveApplicationService.CheckDuplicateLeave(lvapplication)) { // max days float CalenderDays = LeaveApplicationService.CalculateCalenderDays(lvapplication, lvType, lvPolicy); lvapplication.ReturnDate = LeaveApplicationService.GetReturnDate(lvapplication, lvType, lvPolicy); lvapplication.IsDeducted = false; lvapplication.NoOfDays = noofDays; lvapplication.CalenderDays = CalenderDays; int _UserID = LoggedInUser.PUserID; lvapplication.CreatedBy = _UserID; if (lvPolicy.PLeavePolicyID == 0) { ESSPLeaveService.CreateLeave(lvapplication, lvType, LoggedInUser); return(RedirectToAction("Index")); } else { //check for employee eligible for leave if (AssistantLeave.EmployeeEligbleForLeave(lvPolicy, _emp)) { if (lvPolicy.UpdateBalance == true) { if (LeaveApplicationService.HasLeaveQuota(lvapplication.EmpID, lvPolicy, (int)lvapplication.FinancialYearID)) { if (LeaveApplicationService.CheckLeaveBalance(lvapplication, lvPolicy)) { //if (LeaveApplicationService.CheckForMaxMonthDays(lvapplication, lvPolicy, LvProcessController.GetFinancialYearID(db.PR_FinancialYear.ToList(), lvapplication.FromDate))) { lvapplication.LineManagerID = (int)_emp.First().LineManagerID; ESSPLeaveService.CreateLeave(lvapplication, lvType, LoggedInUser); ToasterMessages.Add("Leave applied successfully."); Session["ToasterMessages"] = ToasterMessages; return(Json(lvapplication.PLeaveAppID, JsonRequestBehavior.AllowGet)); } //else // ModelState.AddModelError("FromDate", "Leave Monthly Quota Exceeds"); } else { ModelState.AddModelError("LeaveTypeID", "Leave Balance Exceeds, Please check the balance"); } } else { ModelState.AddModelError("LeaveTypeID", "Leave Quota does not exist"); } } else { } } else { ModelState.AddModelError("LeaveTypeID", "Employee is not eligible for leave"); } } } else { ModelState.AddModelError("FromDate", "This Employee already has leave in this range of dates"); } } HelperMethod(lvapplication); return(PartialView("Create", lvapplication)); } }