Beispiel #1
0
 public void CreateLeave(LeaveApplication lvapplication, LeaveType lvType, VMLoggedUser user, LeavePolicy lvPolicy)
 {
     try
     {
         //Saves the Leave application vlaue in the leave application table on creation of the leave
         lvapplication.LeaveDate = DateTime.Today;
         int _userID = user.PUserID;
         lvapplication.CreatedBy = _userID;
         lvapplication.Active    = true;
         LeaveAppRepo.Add(lvapplication);
         LeaveAppRepo.Save();
         //Creates the leave Data of the leave application to be implemented in the leave application
         AddLeaveToLeaveData(lvapplication, lvType, lvPolicy);
         //Checks for the leave application balance
         BalanceLeaves(lvapplication, lvType, AssistantLeave.GetPayRollPeriodID(DDService.GetPayrollPeriod().ToList(), lvapplication.FromDate));
         LeaveAppRepo.Edit(lvapplication);
         LeaveAppRepo.Save();
         AddLeaveToAttData(lvapplication, lvType);
     }
     catch (Exception)
     {
     }
 }
Beispiel #2
0
        public bool BalanceLeaves(LeaveApplication lvappl, LeaveType LeaveType, int PayrollPeriodID)
        {
            bool isAccLeave = false;
            List <LeaveQuotaYear> _lvConsumedYear = new List <LeaveQuotaYear>();
            Expression <Func <LeaveQuotaYear, bool> > SpecificEntries = aa => aa.EmployeeID == lvappl.EmpID && aa.FinancialYearID == lvappl.FinancialYearID && aa.LeaveTypeID == lvappl.LeaveTypeID;

            _lvConsumedYear = LeaveQuotaYearRepo.FindBy(SpecificEntries);
            float _NoOfDays = lvappl.NoOfDays;

            if (_lvConsumedYear.Count > 0)
            {
                // For Yearly Leave Quota
                if (lvappl.LeaveTypeID == 1) // AL
                {
                    if (lvappl.IsAccum == true)
                    {
                        _lvConsumedYear.FirstOrDefault().CFRemaining    = (float)(_lvConsumedYear.FirstOrDefault().CFRemaining - _NoOfDays);
                        _lvConsumedYear.FirstOrDefault().GrandRemaining = (float)(_lvConsumedYear.FirstOrDefault().GrandRemaining - _NoOfDays);
                        if (_lvConsumedYear.FirstOrDefault().CFRemaining < 0)
                        {
                            _lvConsumedYear.FirstOrDefault().YearlyRemaining = (float)(_lvConsumedYear.FirstOrDefault().YearlyRemaining + _lvConsumedYear.FirstOrDefault().CFRemaining);
                            //_lvConsumedYear.FirstOrDefault().GrandRemaining = (float)(_lvConsumedYear.FirstOrDefault().GrandRemaining + _lvConsumedYear.FirstOrDefault().CFRemaining);
                            _lvConsumedYear.FirstOrDefault().CFRemaining = 0;
                        }
                    }
                    else
                    {
                        if (_lvConsumedYear.FirstOrDefault().YearlyRemaining > 0)
                        {
                            _lvConsumedYear.FirstOrDefault().YearlyRemaining = (float)(_lvConsumedYear.FirstOrDefault().YearlyRemaining - _NoOfDays);
                        }
                        _lvConsumedYear.FirstOrDefault().GrandRemaining = (float)(_lvConsumedYear.FirstOrDefault().GrandRemaining - _NoOfDays);
                    }
                }
                else if (lvappl.LeaveTypeID == 4) //CPL
                {
                    if (_lvConsumedYear.FirstOrDefault().YearlyRemaining > 0)
                    {
                        _lvConsumedYear.FirstOrDefault().YearlyRemaining = (float)(_lvConsumedYear.FirstOrDefault().YearlyRemaining - _NoOfDays);
                    }
                    _lvConsumedYear.FirstOrDefault().GrandRemaining = (float)(_lvConsumedYear.FirstOrDefault().GrandRemaining - _NoOfDays);
                    // Subtract leave from LeaveCPLBalance
                    Expression <Func <LeaveCPLEmpBalance, bool> > SpecificEntrie3 = aa => aa.EmployeeID == lvappl.EmpID && aa.IsExpire == false && aa.RemainingDays > 0;
                    List <LeaveCPLEmpBalance> dbLeaveCPLBalances = LeaveCPLEmpBalanceRepo.FindBy(SpecificEntrie3).OrderBy(aa => aa.PLeaveCPLEmpBalanceID).ToList();
                    if (dbLeaveCPLBalances.Count == 1)
                    {
                        LeaveCPLEmpBalance dbLeaveCPLBalance = dbLeaveCPLBalances.First();
                        dbLeaveCPLBalance.Used          = (float)(dbLeaveCPLBalance.Used + _NoOfDays);
                        dbLeaveCPLBalance.RemainingDays = (float)(dbLeaveCPLBalance.RemainingDays - _NoOfDays);
                        LeaveCPLEmpBalanceRepo.Edit(dbLeaveCPLBalance);
                        LeaveCPLEmpBalanceRepo.Save();
                    }
                    else if (dbLeaveCPLBalances.Count > 1)
                    {
                        double?NoOfdays = _NoOfDays;
                        foreach (var dbLeaveCPLBalance in dbLeaveCPLBalances)
                        {
                            if (dbLeaveCPLBalance.RemainingDays > 0 && NoOfdays > 0)
                            {
                                dbLeaveCPLBalance.Used          = (float)(dbLeaveCPLBalance.Used + NoOfdays);
                                dbLeaveCPLBalance.RemainingDays = (float)(dbLeaveCPLBalance.RemainingDays - NoOfdays);
                                if (dbLeaveCPLBalance.RemainingDays < 0)
                                {
                                    NoOfdays = -1.0 * dbLeaveCPLBalance.RemainingDays;
                                    dbLeaveCPLBalance.Used          = (float)(dbLeaveCPLBalance.Used - NoOfdays);
                                    dbLeaveCPLBalance.RemainingDays = 0;
                                }
                                else
                                {
                                    NoOfdays = 0;
                                }
                                LeaveCPLEmpBalanceRepo.Edit(dbLeaveCPLBalance);
                                LeaveCPLEmpBalanceRepo.Save();
                            }
                        }
                    }
                }
                else // All others
                {
                    if (_lvConsumedYear.FirstOrDefault().YearlyRemaining > 0)
                    {
                        _lvConsumedYear.FirstOrDefault().YearlyRemaining = (float)(_lvConsumedYear.FirstOrDefault().YearlyRemaining - _NoOfDays);
                    }
                    _lvConsumedYear.FirstOrDefault().GrandRemaining = (float)(_lvConsumedYear.FirstOrDefault().GrandRemaining - _NoOfDays);
                }
                LeaveQuotaYearRepo.Edit(_lvConsumedYear.First());
                LeaveQuotaYearRepo.Save();

                LeaveQuotaPeriod atLQp = new LeaveQuotaPeriod();
                Expression <Func <LeaveQuotaPeriod, bool> > SpecificEntrie2 = aa => aa.EmployeeID == lvappl.EmpID && aa.PayrollPeriodID == PayrollPeriodID && aa.LeaveTypeID == lvappl.LeaveTypeID;

                if (LeaveQuotaPeriodRepo.FindBy(SpecificEntrie2).Count() > 0)
                {
                    atLQp = LeaveQuotaPeriodRepo.FindBy(SpecificEntrie2).First();
                }
                else
                {
                    atLQp.EmployeeID      = lvappl.EmpID;
                    atLQp.LeaveTypeID     = lvappl.LeaveTypeID;
                    atLQp.PayrollPeriodID = PayrollPeriodID;
                    atLQp.ConsumedDays    = 0;
                    atLQp.StartNoOfDays   = _lvConsumedYear.FirstOrDefault().GrandRemaining + _NoOfDays;
                    LeaveQuotaPeriodRepo.Add(atLQp);
                    LeaveQuotaPeriodRepo.Save();
                }
                atLQp = AssistantLeave.AddBalancceMonthQuota(_lvConsumedYear, lvappl, atLQp);
                LeaveQuotaPeriodRepo.Edit(atLQp);
                // Check for Post edit
                LeaveQuotaPeriodRepo.Save();
            }
            return(isAccLeave);
        }