public async Task <IActionResult> Edit(PayslipMaster payslipMaster) { try { if (ModelState.IsValid) { if (payslipMaster.Month == "" || payslipMaster.Month == null) { ModelState.AddModelError(string.Empty, "Please select month and try again."); ViewBag.EmployeeCode = new SelectList(_userManager.Users.OrderBy(p => p.EmployeeCode), "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } if (payslipMaster.Year < 2019) { ModelState.AddModelError(string.Empty, "Please select year and try again."); ViewBag.EmployeeCode = new SelectList(_userManager.Users.OrderBy(p => p.EmployeeCode), "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } // var exists = db.PayslipMasters.Any(p => // p.Month == payslipMaster.Month && // p.Year == payslipMaster.Year && // p.EmployeeCode == payslipMaster.EmployeeCode); MonthsEnum month = GetFinDate(payslipMaster.Month); payslipMaster.UpdatedBy = User.Identity.Name; payslipMaster.UpdatedDate = DateTime.Now; payslipMaster.FinDate = new DateTime(payslipMaster.Year, (int)month, (int)month == 3 ? 31 : 1); // if (exists) // { // ModelState.AddModelError(string.Empty, "Payslip already exist for this month."); // ViewBag.EmployeeCode = new SelectList(_userManager.Users, "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); // return View(payslipMaster); // } //_dbContext.PayslipMasters.Add(payslipMaster); db.Entry(payslipMaster).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.EmployeeCode = new SelectList(_userManager.Users.OrderBy(p => p.EmployeeCode), "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } catch (Exception ex) { if (ex.InnerException.Message.Contains("IX_PayslipMasters_Month_Year_EmployeeCode")) { ViewBag.Message = " Payslip already exist for this month."; } ViewBag.EmployeeCode = new SelectList(_userManager.Users.OrderBy(p => p.EmployeeCode), "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } }
/// <summary> /// Initializes a new instance of the <see cref="Body8" /> class. /// </summary> /// <param name="confirmation">confirmation.</param> /// <param name="months">months (required).</param> public Body8(bool?confirmation = default(bool?), MonthsEnum months = default(MonthsEnum)) { // to ensure "months" is required (not null) if (months == null) { throw new InvalidDataException("months is a required property for Body8 and cannot be null"); } else { this.Months = months; } this.Confirmation = confirmation; }
public static int GetTotalDays(this MonthsEnum month, int?year = null) { var date = new DateTime((year ?? DateTime.Now.Year), (int)month, 1); var iterDate = new DateTime(date.Year, date.Month, 1); var d = 0; while (date.Month == iterDate.Month) { d += 1; iterDate = iterDate.AddDays(1); } return(d); }
public static IEnumerable <int> GetMonthWeekNumber(this MonthsEnum month, int?year = null) { var date = new DateTime((year ?? DateTime.Now.Year), (int)month, 1); var iterDate = new DateTime(date.Year, date.Month, 1); var rtn = new List <int>(); while (date.Month == iterDate.Month) { rtn.Add(GetDayWeekNumber(iterDate)); iterDate = iterDate.AddDays(1); } return(rtn.Distinct().ToList()); }
public async Task <IActionResult> Create(PayslipMaster payslipMaster) { if (ModelState.IsValid) { if (payslipMaster.Month == "" || payslipMaster.Month == null) { ModelState.AddModelError(string.Empty, "Please select month and try again."); ViewBag.EmployeeCode = new SelectList(_userManager.Users, "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } if (payslipMaster.Year < 2019) { ModelState.AddModelError(string.Empty, "Please select year and try again."); ViewBag.EmployeeCode = new SelectList(_userManager.Users, "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } var exists = db.PayslipMasters.Any(p => p.Month == payslipMaster.Month && p.Year == payslipMaster.Year && p.EmployeeCode == payslipMaster.EmployeeCode); MonthsEnum month = GetFinDate(payslipMaster.Month); payslipMaster.CreatedBy = User.Identity.Name; payslipMaster.CreatedDate = DateTime.Now; payslipMaster.FinDate = new DateTime(payslipMaster.Year, (int)month, (int)month == 3 ? 31 : 1); if (exists) { ModelState.AddModelError(string.Empty, "Payslip already exist for this month."); ViewBag.EmployeeCode = new SelectList(_userManager.Users, "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); } _dbContext.PayslipMasters.Add(payslipMaster); await _dbContext.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.EmployeeCode = new SelectList(_userManager.Users, "EmployeeCode", "EmployeeCode", payslipMaster.EmployeeCode); return(View(payslipMaster)); }
private MonthsEnum GetFinDate(string mon) { MonthsEnum month = new MonthsEnum(); switch (mon) { case "January": month = MonthsEnum.January; break; case "February": month = MonthsEnum.February; break; case "March": month = MonthsEnum.March; break; case "April": month = MonthsEnum.April; break; case "May": month = MonthsEnum.May; break; case "June": month = MonthsEnum.June; break; case "July": month = MonthsEnum.July; break; case "August": month = MonthsEnum.August; break; case "September": month = MonthsEnum.September; break; case "October": month = MonthsEnum.October; break; case "November": month = MonthsEnum.November; break; case "December": month = MonthsEnum.December; break; default: month = MonthsEnum.NotSet; break; } return(month); }
//, out int count public List <PayslipMaster> GetRec(PaySlipMasterViewModel model) { List <PayslipMaster> payslipMasters = new List <PayslipMaster>(); var fileName = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\files"}" + "\\" + model.ExcelFile.FileName; System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //int cnt = 0; using (var stream = System.IO.File.Open(fileName, FileMode.Open, FileAccess.Read)) { using (var reader = ExcelReaderFactory.CreateReader(stream)) { while (reader.Read()) { if (!reader.GetValue(0).ToString().Contains("SNO")) { bool exists = db.PayslipMasters.Any(p => p.Month == model.Month && p.Year == model.Year && p.EmployeeCode == reader.GetValue(1).ToString()); if (exists) { continue; } MonthsEnum month = GetFinDate(model.Month); var payslip = new PayslipMaster() { EmployeeCode = reader.GetValue(1).ToString(), WorkingDays = Convert.ToInt32(reader.GetValue(2).ToString()), //GrossPay = Convert.ToDouble(reader.GetValue(3).ToString()), Basic = Convert.ToDouble(reader.GetValue(3).ToString()), HRA = Convert.ToDouble(reader.GetValue(4).ToString()), TA = Convert.ToDouble(reader.GetValue(5).ToString()), LTA = Convert.ToDouble(reader.GetValue(6).ToString()), CEA = Convert.ToDouble(reader.GetValue(7).ToString()), SPL = Convert.ToDouble(reader.GetValue(8).ToString()), Arrears = Convert.ToDouble(reader.GetValue(9).ToString()), MonthlyGross = Convert.ToDouble(reader.GetValue(10).ToString()), EmpEPF = Convert.ToDouble(reader.GetValue(11).ToString()), EmpESI = Convert.ToDouble(reader.GetValue(12).ToString()), TAX = Convert.ToDouble(reader.GetValue(13).ToString()), TDS = Convert.ToDouble(reader.GetValue(14).ToString()), OtherDeduction = Convert.ToDouble(reader.GetValue(15).ToString()), TotalDeductions = Convert.ToDouble(reader.GetValue(16).ToString()), TakeHome = Convert.ToDouble(reader.GetValue(17).ToString()), Month = model.Month, Year = model.Year, CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now, FinDate = new DateTime(model.Year, (int)month, (int)month == 3 ? 31 : 1) }; payslipMasters.Add(payslip); //cnt++; } } } } //Inserted = true; //count = cnt; return(payslipMasters); }
public static int GetMonthFestivity(this MonthsEnum month, int?year = null) { return((new DateTime((year ?? DateTime.Now.Year), (int)month, 1)).Year.GetFestivityInYear() .Where(m => m.Month == (int)month) .Count()); }
public CalendarElementModel(int year, MonthsEnum month) { Month = month; _firstDay = new DateTime(year, (int)month, 1, 0, 0, 0); }
public static int GetMonthInt(MonthsEnum month) { return((int)month); }