internal void AddLeave(int empId) { /* * --------------------------- START -------------------------------- * 1. get the list of leaves for the given branch. * 2. get the joining date of the employee. * 3. compute the total remaining months out of the whole year from joiningdate * pendingMnths = (employee joining month) - ( total months in year) * 4. loop through the list of leaves. * 5. get the leaves per month for the particular leave type * 6. compute the total elegible leaves for the employee from the date of joining till the year end * total eligible leaves = pendingMnths * leaves per month * 7. push the values to the employees leave object. * 8. push the values to the database. * * --------------------------- END -------------------------------- * */ using (HrDataContext dbContext = new HrDataContext()) { List <OtherLeave> leavelist = dbContext.OtherLeaves.Where(x => x.BranchId == sessionObj.BRANCHID).ToList(); var JoiningDate = dbContext.EmployeeWorkDetails.Where(x => x.EmployeeId == empId).Select(x => x.JoiningDate).FirstOrDefault(); int month = JoiningDate.Month; int remainingmonths = 12 - (month - 1); foreach (OtherLeave leave in leavelist) { decimal leavespermonth = 0; decimal totalleavesperyear = 0; try { leavespermonth = leavelist.Where(x => x.LeaveTypeId == leave.LeaveTypeId).Select(x => x.LeavesPerMonth.Value).FirstOrDefault(); totalleavesperyear = remainingmonths * leavespermonth; } catch (Exception ex) { } LeaveTran leavetrasaction = new LeaveTran() { BranchId = sessionObj.BRANCHID, CreatedBy = sessionObj.USERID, CreatedOn = UTILITY.SINGAPORETIME, CurrentLeaves = leave.LeavesPerYear == null ? 0 : totalleavesperyear, PreviousLeaves = leave.LeavesPerYear == null ? 0 : totalleavesperyear, EmployeeId = empId, FromDt = UTILITY.SINGAPORETIME, ToDt = UTILITY.SINGAPORETIME, ModifiedBy = sessionObj.USERID, ModifiedOn = UTILITY.SINGAPORETIME, LeaveType = leave.LeaveTypeId }; Add(leavetrasaction); } } }
internal void UpdateLeave(int empId) { using (HrDataContext dbContext = new HrDataContext()) { List <OtherLeave> leavelist = dbContext.OtherLeaves.Where(x => x.BranchId == sessionObj.BRANCHID).ToList(); foreach (OtherLeave leave in leavelist) { LeaveTran leavetrasaction = new LeaveTran() { BranchId = sessionObj.BRANCHID, CreatedBy = sessionObj.USERID, CreatedOn = UTILITY.SINGAPORETIME, CurrentLeaves = leave.LeavesPerYear == null ? 0 : leave.LeavesPerYear.Value, PreviousLeaves = leave.LeavesPerYear == null ? 0 : leave.LeavesPerYear.Value, EmployeeId = empId, FromDt = UTILITY.SINGAPORETIME, ToDt = UTILITY.SINGAPORETIME, ModifiedBy = sessionObj.USERID, ModifiedOn = UTILITY.SINGAPORETIME, LeaveType = leave.LeaveTypeId }; Update(leavetrasaction); } } }
public void Delete(LeaveTran transaction) { try { leaveTrasactionRepository.Delete(transaction); } catch (Exception ex) { throw ex; } }
public static void CalculateLeaveFromTransaction(LeaveTran LeaveTransaction, EmployeeLeaveList obj, LeaveListCalc leaveListCalc, bool flag) { if (flag) { leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; leaveListCalc.currentLeaves = leaveListCalc.currentLeaves != 0 ? leaveListCalc.currentLeaves - obj.Days.Value : leaveListCalc.currentLeaves; } else { leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; leaveListCalc.currentLeaves = leaveListCalc.currentLeaves + obj.Days.Value; //leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; } /*No need to check for each leave*/ //else if (obj.LeaveTypeId == UTILITY.PAIDLEAVE) //{ // if (flag) // { // leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; // leaveListCalc.currentLeaves = leaveListCalc.currentLeaves != 0 ? // leaveListCalc.currentLeaves - obj.Days.Value : leaveListCalc.currentLeaves; // } // else // { // leaveListCalc.currentLeaves = leaveListCalc.currentLeaves + obj.Days.Value; // leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; // } //} //if (obj.LeaveTypeId == UTILITY.SICKLEAVE) //{ // if (flag) // { // leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; // leaveListCalc.currentLeaves = leaveListCalc.currentLeaves != 0 ? leaveListCalc.currentLeaves - obj.Days.Value : leaveListCalc.currentLeaves; // } // else // { // leaveListCalc.currentLeaves = leaveListCalc.currentLeaves + obj.Days.Value; // leaveListCalc.previousLeaves = leaveListCalc.currentLeaves; // } //} }
public void CancelLeave(int employeeLeaveID, string remarks) { EmployeeLeaveList empLeaveObj = GetById(employeeLeaveID); empLeaveObj.Status = "Cancelled"; empLeaveObj.Remarks = remarks; Add(empLeaveObj); LeaveTran leavetransaction = leaveTransBO.GetByProperty(x => x.BranchId == sessionObj.BRANCHID && x.EmployeeId == sessionObj.EMPLOYEEID && x.LeaveType == empLeaveObj.LeaveTypeId); LeaveListCalc leaveListCalc = null; if (leavetransaction != null) { leaveListCalc = new LeaveListCalc( leavetransaction.CurrentLeaves, leavetransaction.PreviousLeaves ); CalculateLeavesTransaction.CalculateLeaveFromTransaction( leavetransaction, empLeaveObj, leaveListCalc, false); } LeaveTran leaveTransaction = new LeaveTran() { BranchId = sessionObj.BRANCHID, CreatedBy = sessionObj.USERID, CreatedOn = UTILITY.SINGAPORETIME, CurrentLeaves = leaveListCalc.currentLeaves, PreviousLeaves = leaveListCalc.previousLeaves, EmployeeId = sessionObj.EMPLOYEEID, FromDt = empLeaveObj.FromDate, ToDt = empLeaveObj.ToDate, LeaveType = empLeaveObj.LeaveTypeId }; leaveTransBO.Add(leaveTransaction); }
public decimal GetLeavesCount(int BranchID, int EmployeeID, int LeaveType, DateTime fromDate) { DateTime date = fromDate; //int currentMonth = date.Month; int currentYear = date.Year; decimal eligibleLeaves = 0; decimal appliedLeave = 0; using (HrDataContext dbContext = new HrDataContext()) { OtherLeave leave = dbContext.OtherLeaves.Where(x => x.BranchId == BranchID && x.LeaveTypeId == LeaveType).FirstOrDefault(); LeaveTran leaveTransaction = dbContext.LeaveTrans.Where(x => x.EmployeeId == EmployeeID && x.BranchId == BranchID && x.LeaveType == LeaveType) .OrderByDescending(x => x.TransactionId) .ThenByDescending(x => x.CreatedOn).FirstOrDefault(); DateTime now = date; var startDate = new DateTime(now.Year, now.Month, 1); var endDate = startDate.AddMonths(1).AddDays(-1); List <EmployeeLeaveList> leaveList = dbContext.EmployeeLeaveLists .Where(x => x.EmployeeId == EmployeeID && x.BranchId == BranchID && x.LeaveTypeId == LeaveType && x.FromDate >= startDate && x.ToDate <= endDate && x.Status != UTILITY.LEAVECANCELLED).ToList(); decimal?DaysCount = 0; foreach (EmployeeLeaveList item in leaveList) { DaysCount += item.Days; } if (leaveTransaction != null) { LeaveMaster lMaster = new LeaveMaster(); if (LeaveType == lMaster.MEDICALLEAVE(BranchID)) { appliedLeave = leave.LeavesPerYear.Value - leaveTransaction.CurrentLeaves; if (leave.IsCarryForward) { eligibleLeaves = (currentYear * leave.LeavesPerYear.Value) - appliedLeave; } else { eligibleLeaves = leave.LeavesPerYear.Value - appliedLeave; } } if (LeaveType == lMaster.CASUALLEAVE(BranchID)) { appliedLeave = leave.LeavesPerYear.Value - leaveTransaction.CurrentLeaves; if (leave.IsCarryForward) { eligibleLeaves = (currentYear * leave.LeavesPerYear.Value) - appliedLeave; } else if (DaysCount == 0) { eligibleLeaves = leave.LeavesPerYear.Value; } else { eligibleLeaves = leave.LeavesPerYear.Value - appliedLeave; } } if (LeaveType == lMaster.ANNUALLEAVE(BranchID)) { appliedLeave = leave.LeavesPerYear.Value - leaveTransaction.CurrentLeaves; if (leave.IsCarryForward) { eligibleLeaves = (currentYear * leave.LeavesPerYear.Value) - appliedLeave; } else { eligibleLeaves = leave.LeavesPerYear.Value - appliedLeave; } } //else if (LeaveType == UTILITY.PAIDLEAVE) //{ // appliedLeave = leave.LeavesPerYear.Value - leaveTransaction.CurrentLeaves; // eligibleLeaves = (currentMonth * leave.LeavesPerMonth.Value) - appliedLeave; //} //else if (LeaveType == UTILITY.PAIDLEAVE) //{ // appliedLeave = leave.LeavesPerYear.Value - leaveTransaction.CurrentLeaves; // eligibleLeaves = (currentMonth * leave.LeavesPerMonth.Value) - appliedLeave; //} } return(eligibleLeaves); } }