public ActionResult Create(LeaveApplication leaveapplication) { if (ModelState.IsValid) { db.LeaveApplications.AddObject(leaveapplication); db.SaveChanges(); return RedirectToAction("Index"); } return View(leaveapplication); }
public ActionResult Edit(LeaveApplication leaveapplication) { if (ModelState.IsValid) { db.LeaveApplications.Attach(leaveapplication); db.ObjectStateManager.ChangeObjectState(leaveapplication, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(leaveapplication); }
public Task <LeaveApplication> CreateAsync(LeaveApplication item) { return(LeaveApplications.CreateAsync(item)); }
public Task <LeaveApplication> UpdateAsync(LeaveApplication item) { return(LeaveApplications.UpdateAsync(item)); }
public void PostDelete(LeaveApplication lvApp) { LeaveAppRepo.Delete(lvApp); LeaveAppRepo.Save(); }
private void ComputeUnits() { try { txtUnits.Text = LeaveApplication.GetLeaveUnits(dtpDateStart.Value, dtpDateEnd.Value, clsValidator.CheckFloat(cmbTimeFrom.SelectedValue.ToString()), clsValidator.CheckFloat(cmbTimeTo.SelectedValue.ToString()), cmbRequestor.SelectedValue.ToString()).ToString(); } catch { } }
public void UpdateLeaveBalance(LeaveApplication lvappl, int PayrollPeriodID) { try { float LvDays = (float)lvappl.NoOfDays; List <LeaveQuotaYear> _lvConsumed = new List <LeaveQuotaYear>(); Expression <Func <LeaveQuotaYear, bool> > SpecificEntries = aa => aa.EmployeeID == lvappl.EmpID && aa.FinancialYearID == lvappl.FinancialYearID && aa.LeaveTypeID == lvappl.LeaveTypeID; _lvConsumed = LeaveQuotaYearRepo.FindBy(SpecificEntries); if (_lvConsumed.Count > 0) { if (lvappl.LeaveTypeID == 1) { if (lvappl.IsAccum == true) { _lvConsumed.FirstOrDefault().GrandRemaining = (float)(_lvConsumed.FirstOrDefault().GrandRemaining + LvDays); _lvConsumed.FirstOrDefault().CFRemaining = (float)(_lvConsumed.FirstOrDefault().CFRemaining + LvDays); } else { if (_lvConsumed.FirstOrDefault().YearlyRemaining >= 0) { _lvConsumed.FirstOrDefault().YearlyRemaining = (float)(_lvConsumed.FirstOrDefault().YearlyRemaining + LvDays); } _lvConsumed.FirstOrDefault().GrandRemaining = (float)(_lvConsumed.FirstOrDefault().GrandRemaining + LvDays); if (_lvConsumed.FirstOrDefault().YearlyRemaining > _lvConsumed.FirstOrDefault().YearlyTotal) { _lvConsumed.FirstOrDefault().CFRemaining = _lvConsumed.FirstOrDefault().YearlyRemaining - _lvConsumed.FirstOrDefault().YearlyTotal; _lvConsumed.FirstOrDefault().YearlyRemaining = _lvConsumed.FirstOrDefault().YearlyTotal; } } } else if (lvappl.LeaveTypeID == 4) { if (_lvConsumed.FirstOrDefault().YearlyRemaining > 0) { _lvConsumed.FirstOrDefault().YearlyRemaining = (float)(_lvConsumed.FirstOrDefault().YearlyRemaining + LvDays); } _lvConsumed.FirstOrDefault().GrandRemaining = (float)(_lvConsumed.FirstOrDefault().GrandRemaining + LvDays); // Add leave from LeaveCPLBalance Expression <Func <LeaveCPLEmpBalance, bool> > SpecificEntrie3 = aa => aa.EmployeeID == lvappl.EmpID && aa.IsExpire == false; List <LeaveCPLEmpBalance> dbLeaveCPLBalances = LeaveCPLEmpBalanceRepo.FindBy(SpecificEntrie3).OrderBy(aa => aa.PLeaveCPLEmpBalanceID).ToList(); if (dbLeaveCPLBalances.Count == 1) { LeaveCPLEmpBalance dbLeaveCPLBalance = dbLeaveCPLBalances.First(); dbLeaveCPLBalance.Used = (float)(dbLeaveCPLBalance.Used - lvappl.NoOfDays); dbLeaveCPLBalance.RemainingDays = (float)(dbLeaveCPLBalance.RemainingDays + lvappl.NoOfDays); LeaveCPLEmpBalanceRepo.Edit(dbLeaveCPLBalance); LeaveCPLEmpBalanceRepo.Save(); } else if (dbLeaveCPLBalances.Count > 1) { double?NoOfdays = lvappl.NoOfDays; foreach (var dbLeaveCPLBalance in dbLeaveCPLBalances.OrderByDescending(aa => aa.PLeaveCPLEmpBalanceID).ToList()) { if (NoOfdays > 0 && dbLeaveCPLBalance.Used > 0) { dbLeaveCPLBalance.Used = (float)(dbLeaveCPLBalance.Used - NoOfdays); dbLeaveCPLBalance.RemainingDays = (float)(dbLeaveCPLBalance.RemainingDays + NoOfdays); if (dbLeaveCPLBalance.Used < 0) { NoOfdays = -1.0 * dbLeaveCPLBalance.Used; dbLeaveCPLBalance.Used = 0; dbLeaveCPLBalance.RemainingDays = dbLeaveCPLBalance.TotalDays; } else { NoOfdays = 0; } LeaveCPLEmpBalanceRepo.Edit(dbLeaveCPLBalance); LeaveCPLEmpBalanceRepo.Save(); } } } } else { if (_lvConsumed.FirstOrDefault().YearlyRemaining > 0) { _lvConsumed.FirstOrDefault().YearlyRemaining = (float)(_lvConsumed.FirstOrDefault().YearlyRemaining + LvDays); } _lvConsumed.FirstOrDefault().GrandRemaining = (float)(_lvConsumed.FirstOrDefault().GrandRemaining + LvDays); } LeaveQuotaYearRepo.Edit(_lvConsumed.FirstOrDefault()); 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(); } atLQp.ConsumedDays = atLQp.ConsumedDays - lvappl.NoOfDays; atLQp.RemainingDays = atLQp.StartNoOfDays - atLQp.ConsumedDays; LeaveQuotaPeriodRepo.Edit(atLQp); LeaveQuotaPeriodRepo.Save(); } } catch (Exception) { } }
public float CalculateNoOfDays(LeaveApplication lvapplication, LeaveType lvType, LeavePolicy lvPolicy) { List <Holiday> holidays = new List <Holiday>(); holidays = DDService.GetHolidays(); float val = 0; if (lvapplication.IsHalf == true) { val = (float)0.5; } else { val = (lvapplication.ToDate - lvapplication.FromDate).Days + 1; Expression <Func <Employee, bool> > SpecificEntries = aa => aa.PEmployeeID == lvapplication.EmpID; Employee emp = EmployeeRepo.FindBy(SpecificEntries).FirstOrDefault(); Shift shift = emp.Shift; Expression <Func <VAT_RosterDetail, bool> > SpecificEntries2 = aa => aa.CriteriaData == emp.CrewID && aa.RosterDate >= lvapplication.FromDate && aa.RosterDate <= lvapplication.ToDate; List <VAT_RosterDetail> rosterDetails = RosterDetailRepo.FindBy(SpecificEntries2); if ((lvPolicy.CountRestDays != true || lvPolicy.CountGZDays != true) && lvPolicy.PLeavePolicyID != 0) { DateTime dts = lvapplication.FromDate; while (dts <= lvapplication.ToDate) { if (rosterDetails.Where(aa => aa.RosterDate == dts).Count() > 0) { VAT_RosterDetail rd = rosterDetails.First(aa => aa.RosterDate == dts); if (holidays.Where(aa => aa.HolidayDate == dts).Count() > 0 && shift.GZDays == true) { if (lvPolicy.CountGZDays == false) { val = val - 1; } } else { if (rd.WorkMin == 0) { val = val - 1; } } } else { if (holidays.Where(aa => aa.HolidayDate == dts).Count() > 0 && shift.GZDays == true) { if (lvPolicy.CountGZDays == false) { val = val - 1; } } else { if (CurrentDayNotRest(shift, dts)) { val = val - 1; } } } dts = dts.AddDays(1); } } } return(val); }
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); }
public bool CheckLeaveBalance(LeaveApplication _lvapp, LeavePolicy LeaveType) { bool balance = false; decimal RemainingLeaves; if (LeaveType.UpdateBalance == true) { //Get the list of leave quota year in which balance of the leave is present .in the specific Financial year List <LeaveQuotaYear> _lvConsumed = new List <LeaveQuotaYear>(); Expression <Func <LeaveQuotaYear, bool> > SpecificEntries = aa => aa.EmployeeID == _lvapp.EmpID && aa.FinancialYearID == _lvapp.FinancialYearID && aa.LeaveTypeID == _lvapp.LeaveTypeID; _lvConsumed = LeaveQuotaYearRepo.FindBy(SpecificEntries); if (_lvConsumed.Count > 0) { if (_lvapp.LeaveTypeID == 1) { if (_lvapp.IsAccum == true) { RemainingLeaves = (decimal)_lvConsumed.FirstOrDefault().CFRemaining; if ((RemainingLeaves - Convert.ToDecimal(_lvapp.NoOfDays)) >= 0) { balance = true; } else { balance = false; } } else { RemainingLeaves = (decimal)_lvConsumed.FirstOrDefault().GrandRemaining; if ((RemainingLeaves - Convert.ToDecimal(_lvapp.NoOfDays)) >= 0) { balance = true; } else { balance = false; } } } else { RemainingLeaves = (decimal)_lvConsumed.FirstOrDefault().GrandRemaining; if ((RemainingLeaves - Convert.ToDecimal(_lvapp.NoOfDays)) >= 0) { balance = true; } else { balance = false; } } } else { balance = false; } } else { balance = true; } return(balance); }
public void LeaveApplicationCreate(LeaveApplicationDTOs Record) { LeaveApplication data = _unitOfWork.LeaveApplicationRepository.Create(LeaveApplicationMapper.LeaveApplicationDTOsToLeaveApplication(Record)); }
public LeaveApplicationDTOs LeaveDetails(int LeaveId, int empcode) { LeaveApplication Detail = _unitOfWork.LeaveApplicationRepository.All().Where(x => x.LeaveId == LeaveId).FirstOrDefault(); return(LeaveApplicationMapper.LeaveApplicationToLeaveApplicationDTOss(Detail)); }
public ActionResult Edit([Bind(Include = "LeaveAccId,EmployeeCode,LeaveTypeName,LeaveFromDate,LeaveToDate,NoOfDays,AppDate,IsApproved,IsDeleted,CreatedDate")] LeaveApplication leaveApplication) { try { decimal balanceLeaveM = 0; int count = (from a in db.LeaveLedgers where a.EmployeeCode == leaveApplication.EmployeeCode && a.LeaveType == leaveApplication.LeaveTypeName select a.BalanceLeaves).Count(); var balanceLeave = (from a in db.LeaveLedgers where a.EmployeeCode == leaveApplication.EmployeeCode && a.LeaveType == leaveApplication.LeaveTypeName && a.BalanceLeaves >= leaveApplication.NoOfDays select a.BalanceLeaves).FirstOrDefault(); var email = (from a in db.EmployeePIs where a.EmployeeCode == leaveApplication.EmployeeCode select a.EmpEmailId).FirstOrDefault(); if (ModelState.IsValid) { int lt = Convert.ToInt32(leaveApplication.LeaveTypeName); var leavetype = (from a in db.LeaveTypeMasters where a.LeaveTypeId == lt select a.LeaveTypeName).FirstOrDefault(); leaveApplication.LeaveTypeName = leavetype; if (count == 0) { balanceLeaveM = (from a in db.LeaveMasters where a.LeaveTypeId == lt select a.LeaveCount).FirstOrDefault(); balanceLeave = balanceLeaveM; } if (leaveApplication.IsApproved == true) { leaveApplication.Status = "Approved"; } else { leaveApplication.Status = "Not Approved"; } db.Entry(leaveApplication).State = EntityState.Modified; db.SaveChanges(); ///////////////// LeaveLedger leaveledger = new Models.LeaveLedger(); leaveledger.EmployeeCode = leaveApplication.EmployeeCode; leaveledger.ConsumedLeaves = leaveApplication.NoOfDays; leaveledger.BalanceLeaves = balanceLeave - leaveApplication.NoOfDays; leaveledger.LeaveType = leaveApplication.LeaveTypeName; DateTime appdt = Convert.ToDateTime(leaveApplication.AppDate); leaveledger.FiscalYear = appdt.Year.ToString() + "-" + (appdt.Year + 1).ToString().Substring(2, 2); db.LeaveLedgers.Add(leaveledger); db.SaveChanges(); ////////////////// //MailMessage Msg = new MailMessage(); //// Sender e-mail address. //Msg.From = new MailAddress(email); //// Recipient e-mail address. //Msg.To.Add(email); //Msg.Subject = "Leave Application Status"; //Msg.Body = "Your Leave Application is " + leaveApplication.Status;//"some body message"; //SmtpClient smtp = new SmtpClient(); //smtp.Host = "relay-hosting.secureserver.net";// "smptout.secureserver.net";// "relay-hosting.secureserver.net"; //smtp.Send(Msg); /////////////////New Code for Email/ EmailModel model = new EmailModel(); model.Email = "*****@*****.**"; model.Password = "******"; model.Subject = "Leave Application Status"; model.Body = "Your Leave Application is " + leaveApplication.Status; model.To = email; using (MailMessage mm = new MailMessage(model.Email, model.To)) { mm.Subject = model.Subject; mm.Body = model.Body; //if (model.Attachment.ContentLength > 0) //{ // string fileName = Path.GetFileName(model.Attachment.FileName); // mm.Attachments.Add(new Attachment(model.Attachment.InputStream, fileName)); //} mm.IsBodyHtml = false; using (SmtpClient smtp = new SmtpClient()) { smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(model.Email, model.Password); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); ViewBag.Message = "Email sent."; } } ////////////////// //SmtpClient smtpClient = new SmtpClient(); //var emailmessage = new System.Web.Mail.MailMessage() // { // Subject = "Leave Application Status", // Body ="Your Leave Application is "+ leaveApplication.Status, // From = email, // To = email, // BodyFormat = System.Web.Mail.MailFormat.Text, // Priority = System.Web.Mail.MailPriority.High // }; //smtpClient.Host = "smptout.secureserver.net"; //System.Web.Mail.SmtpMail.Send(emailmessage); ///////////////// TempData["msg"] = "<script>alert('Mail is Successfully Send');</script>"; return(RedirectToAction("Index")); } ///////////////// return(View(leaveApplication)); } catch (Exception ext) { TempData["msg"] = "<script>alert('Mail is failed due to Server error');</script>"; return(RedirectToAction("Index")); } }