public ActionResult IndexCutiK() { if (Session["nik"] == null) { return(RedirectToAction("Index", "Login")); } if (Session["jabatan"].ToString() != "k") { return(RedirectToAction("Admin", "Login")); } int id = Convert.ToInt32(Session["nik"]); cuti_user cek = db.cuti_user.Find(id); ViewBag.jatah = cek.jatah_cuti; ViewBag.sisa = cek.sisa_cuti; ViewBag.validjatah = cek.valid_jatah; ViewBag.validsisa = cek.valid_sisa; return(View()); }
public ActionResult NewCuti(cuti cute) { try { var cutitit = db.cutis.Where(u => u.nik == cute.nik && ((u.durasi_awal >= cute.durasi_awal && u.durasi_awal <= cute.durasi_akhir) || (u.durasi_akhir <= cute.durasi_akhir && u.durasi_akhir >= cute.durasi_awal))).FirstOrDefault(); if (cutitit != null) { return(Json(new { success = false, message = "Cuti sudah ada di hari yang sama!" }, JsonRequestBehavior.AllowGet)); } cute.tanggal = DateTime.Today; cute.oleh = Session["nama"].ToString(); db.cutis.Add(cute); cuti_user cutis = db.cuti_user.Find(cute.nik); int totalhari = Convert.ToInt32((cute.durasi_akhir - cute.durasi_awal).TotalDays); totalhari += 1; if (totalhari <= 0) { return(Json(new { success = false, message = "Periksa kembali tanggal yang diinput!" }, JsonRequestBehavior.AllowGet)); } if (cutis.sisa_cuti >= totalhari) { cutis.sisa_cuti -= totalhari; } else { cutis.jatah_cuti = (cutis.jatah_cuti + cutis.sisa_cuti) - totalhari; cutis.sisa_cuti = 0; } db.Entry(cutis).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, html = Global.RenderRazorViewToString(this, "RiwayatCuti", GetRiwayatCuti()), message = "Input Cuti Sukses!" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit(user emp, cuti_user jatahcuti, saldo_medical saldo) { //try //{ int id = Convert.ToInt32(Session["nik"]); user users = db.users.Find(id); if (users.email != emp.email) { var cekemail = db.users.Where(u => u.email == emp.email).FirstOrDefault(); if (cekemail != null) { return(Json(new { success = false, message = "E-Mail sudah terdaftar" }, JsonRequestBehavior.AllowGet)); } } if (emp.foto != null) { var fotolama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(fotolama.foto_profil); if (emp.foto.ContentType.Contains("image")) { } else { return(Json(new { success = false, message = "Format foto profil salah" }, JsonRequestBehavior.AllowGet)); } if (fotolama.foto_profil != "~/AppFiles/Images/default.png") { if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } } string fileName = Path.GetFileNameWithoutExtension(emp.foto.FileName); string extension = Path.GetExtension(emp.foto.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; users.foto_profil = "~/AppFiles/Images/" + fileName; emp.foto.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName)); } if (emp.filektp != null) { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_ktp); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } string fileName = Path.GetFileNameWithoutExtension(emp.filektp.FileName); string extension = Path.GetExtension(emp.filektp.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; users.file_ktp = "~/AppFiles/FileUser/" + fileName; emp.filektp.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.filenpwp != null) { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_npwp); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } string fileName = Path.GetFileNameWithoutExtension(emp.filenpwp.FileName); string extension = Path.GetExtension(emp.filenpwp.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; users.file_npwp = "~/AppFiles/FileUser/" + fileName; emp.filenpwp.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.filerekening != null) { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_rekening); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } string fileName = Path.GetFileNameWithoutExtension(emp.filerekening.FileName); string extension = Path.GetExtension(emp.filerekening.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; users.file_rekening = "~/AppFiles/FileUser/" + fileName; emp.filerekening.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.fileijasah != null) { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_ijasah); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } string fileName = Path.GetFileNameWithoutExtension(emp.fileijasah.FileName); string extension = Path.GetExtension(emp.fileijasah.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; users.file_ijasah = "~/AppFiles/FileUser/" + fileName; emp.fileijasah.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } users.nama = emp.nama; users.email = emp.email; users.no_hp = emp.no_hp; users.tempat_lahir = emp.tempat_lahir; if (emp.tanggal_lahir != null) { users.tanggal_lahir = emp.tanggal_lahir; } if (emp.nip != null) { users.nip = emp.nip; } users.oleh = Session["nama"].ToString(); users.jenis_kelamin = emp.jenis_kelamin; users.alamat_domisili = emp.alamat_domisili; users.pendidikan_akhir = emp.pendidikan_akhir; users.no_ktp = emp.no_ktp; users.alamat_ktp = emp.alamat_ktp; users.jurusan = emp.jurusan; users.agama = emp.agama; users.npwp = emp.npwp; users.bpjs = emp.bpjs; users.status_pajak = emp.status_pajak; users.status_kerja = emp.status_kerja; users.no_rekening = emp.no_rekening; users.jabatan = emp.jabatan; users.penempatan = emp.penempatan; db.Entry(users).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, html = Global.RenderRazorViewToString(this, "Details", GetDetail()), message = "Edit Data Sukses" }, JsonRequestBehavior.AllowGet)); // } //catch (Exception ex) //{ // return Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet); //} }
public ActionResult Validate(user user, string returnUrl) { using (dbOpsModel db = new dbOpsModel()) { string email = Convert.ToString(user.email).ToUpper().Trim(); string pass = md5.encryption(user.password); //string pass = user.password; var userDetails = db.users.Where(x => x.email.ToUpper() == email && x.password == pass).FirstOrDefault(); if (userDetails == null) { ViewBag.msg = "<script>Swal.fire({ type: 'error', title: 'Login Gagal!', text: 'E-Mail atau Password salah'});</script>"; return(View("Index")); } else if (userDetails.status_kerja == "Tidak Aktif") { ViewBag.msg = "<script>Swal.fire({ type: 'error', title: 'Login Gagal!', text: 'Akun anda sudah dinon-aktifkan!'});</script>"; return(View("Index")); } else { FormsAuthentication.SetAuthCookie(user.email, false); Session["nik"] = userDetails.nik; Session["nama"] = userDetails.nama; Session["jabatan"] = userDetails.jabatan; if (userDetails.jabatan == "a" || userDetails.jabatan == "s") { return(RedirectToAction("Admin", "Login")); } else if (userDetails.jabatan == "k") { //renewal cuti cuti_user cek = db.cuti_user.Find(userDetails.nik); if (cek.valid_jatah <= DateTime.Today) { while (cek.valid_jatah <= DateTime.Today) { DateTime validdate2 = cek.valid_jatah; cek.valid_jatah = validdate2.AddYears(1); } DateTime validdate = cek.valid_jatah; if (cek.jatah_cuti > 0) { cek.sisa_cuti = cek.jatah_cuti; cek.jatah_cuti += 12; cek.jatah_cuti -= cek.sisa_cuti; cek.valid_sisa = validdate.AddMonths(6); } else { cek.jatah_cuti += 12; cek.valid_sisa = validdate.AddMonths(6); } } if (cek.valid_sisa <= DateTime.Today) { cek.sisa_cuti = 0; } db.Entry(cek).State = EntityState.Modified; db.SaveChanges(); //akhir renewal cuti //renewal saldo medical saldo_medical valid = db.saldo_medical.Find(userDetails.nik); saldo_awal saldoawal = db.saldo_awal.Find(1); if (valid.valid_rawat <= DateTime.Today) { valid.saldo_rawatinap = saldoawal.default_inap; valid.saldo_rawatjalan = saldoawal.default_jalan; if (valid.valid_rawat == userDetails.join_date.AddMonths(3)) { DateTime validdate = userDetails.join_date; valid.valid_rawat = validdate.AddYears(1); while (valid.valid_rawat <= DateTime.Today) { DateTime validdate2 = valid.valid_rawat; valid.valid_rawat = validdate2.AddYears(1); } } else { DateTime validdate = valid.valid_rawat; valid.valid_rawat = validdate.AddYears(1); } } if (valid.valid_kacamata <= DateTime.Today) { valid.saldo_kacamata = saldoawal.default_kacamata; if (valid.valid_kacamata == userDetails.join_date.AddMonths(3)) { DateTime validkacamata = userDetails.join_date; valid.valid_kacamata = validkacamata.AddYears(2); while (valid.valid_kacamata <= DateTime.Today) { DateTime validdate2 = valid.valid_kacamata; valid.valid_kacamata = validdate2.AddYears(2); } int tai = Convert.ToInt32(userDetails.join_date.Year); if (tai % 2 == 0) { DateTime validdate2 = valid.valid_kacamata; valid.valid_kacamata = validdate2.AddYears(1); } } else { DateTime validkacamata = valid.valid_kacamata; valid.valid_kacamata = validkacamata.AddYears(2); } } db.Entry(valid).State = EntityState.Modified; //end renewalmedical db.SaveChanges(); return(RedirectToAction("Karyawan", "Login")); } else { return(View("../Home/Index")); } } } }
public ActionResult AddorEdit(user emp, cuti_user cuti, saldo_medical saldo) { try { user users = db.users.Find(emp.nik); if (emp.nik == 0) { var cekemail = db.users.Where(u => u.email == emp.email).FirstOrDefault(); if (cekemail != null) { return(Json(new { success = false, message = "E-Mail sudah terdaftar" }, JsonRequestBehavior.AllowGet)); } var ceknip = db.users.Where(u => u.nip == emp.nip).FirstOrDefault(); if (ceknip != null) { return(Json(new { success = false, message = "NIP sudah terdaftar" }, JsonRequestBehavior.AllowGet)); } } else { if (users.email != emp.email) { var cekemail = db.users.Where(u => u.email == emp.email).FirstOrDefault(); if (cekemail != null) { return(Json(new { success = false, message = "E-Mail sudah terdaftar" }, JsonRequestBehavior.AllowGet)); } } if (users.nip != emp.nip) { var ceknip = db.users.Where(u => u.nip == emp.nip).FirstOrDefault(); if (ceknip != null) { return(Json(new { success = false, message = "NIP sudah terdaftar" }, JsonRequestBehavior.AllowGet)); } } } if (emp.foto != null) { string fileName = Path.GetFileNameWithoutExtension(emp.foto.FileName); string extension = Path.GetExtension(emp.foto.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; if (emp.nik == 0) { emp.foto_profil = "~/AppFiles/Images/" + fileName; } else { var fotolama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(fotolama.foto_profil); if (emp.foto.ContentType.Contains("image")) { } else { return(Json(new { success = false, message = "Format foto profil salah" }, JsonRequestBehavior.AllowGet)); } if (fotolama.foto_profil != "~/AppFiles/Images/default.png") { if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } } users.foto_profil = "~/AppFiles/Images/" + fileName; } emp.foto.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName)); } if (emp.filektp != null) { string fileName = Path.GetFileNameWithoutExtension(emp.filektp.FileName); string extension = Path.GetExtension(emp.filektp.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; if (emp.nik == 0) { emp.file_ktp = "~/AppFiles/FileUser/" + fileName; } else { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_ktp); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } users.file_ktp = "~/AppFiles/FileUser/" + fileName; } emp.filektp.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.filenpwp != null) { string fileName = Path.GetFileNameWithoutExtension(emp.filenpwp.FileName); string extension = Path.GetExtension(emp.filenpwp.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; if (emp.nik == 0) { emp.file_npwp = "~/AppFiles/FileUser/" + fileName; } else { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_npwp); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } users.file_npwp = "~/AppFiles/FileUser/" + fileName; } emp.filenpwp.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.filerekening != null) { string fileName = Path.GetFileNameWithoutExtension(emp.filerekening.FileName); string extension = Path.GetExtension(emp.filerekening.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; if (emp.nik == 0) { emp.file_rekening = "~/AppFiles/FileUser/" + fileName; } else { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_npwp); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } users.file_rekening = "~/AppFiles/FileUser/" + fileName; } emp.filerekening.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.fileijasah != null) { string fileName = Path.GetFileNameWithoutExtension(emp.fileijasah.FileName); string extension = Path.GetExtension(emp.fileijasah.FileName); fileName = fileName + emp.nama + DateTime.Now.ToString("yymmssffff") + extension; if (emp.nik == 0) { emp.file_ijasah = "~/AppFiles/FileUser/" + fileName; } else { var filelama = db.users.Where(u => u.nik == emp.nik).FirstOrDefault(); var fullpath = Request.MapPath(filelama.file_ijasah); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } users.file_ijasah = "~/AppFiles/FileUser/" + fileName; } emp.fileijasah.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/FileUser/"), fileName)); } if (emp.nik == 0) { //input data jatah cuti,dll saat nik di buat emp.password = md5.encryption(emp.password); cuti.nik = emp.nik; cuti.jatah_cuti = 0; cuti.sisa_cuti = 0; DateTime joindate = emp.join_date; cuti.valid_jatah = joindate.AddYears(1); cuti.valid_sisa = joindate.AddMonths(18); saldo.nik = emp.nik; saldo.saldo_kacamata = 0; saldo.saldo_rawatinap = 0; saldo.saldo_rawatjalan = 0; saldo.valid_rawat = joindate.AddMonths(3); saldo.valid_kacamata = joindate.AddMonths(3); db.cuti_user.Add(cuti); db.saldo_medical.Add(saldo); db.users.Add(emp); db.SaveChanges(); } else { users.nip = emp.nip; users.nama = emp.nama; users.email = emp.email; users.no_hp = emp.no_hp; if (emp.tanggal_lahir != null) { users.tanggal_lahir = emp.tanggal_lahir; } users.tempat_lahir = emp.tempat_lahir; users.jenis_kelamin = emp.jenis_kelamin; users.alamat_domisili = emp.alamat_domisili; users.pendidikan_akhir = emp.pendidikan_akhir; users.no_ktp = emp.no_ktp; users.alamat_ktp = emp.alamat_ktp; users.jurusan = emp.jurusan; users.agama = emp.agama; users.npwp = emp.npwp; users.status_pajak = emp.status_pajak; users.status_kerja = emp.status_kerja; users.no_rekening = emp.no_rekening; users.jabatan = emp.jabatan; users.penempatan = emp.penempatan; users.posisi = emp.posisi; users.bpjs = emp.bpjs; db.Entry(users).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, html = Global.RenderRazorViewToString(this, "ViewAll", GetAllUser()), message = "Edit data sukses" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, html = Global.RenderRazorViewToString(this, "ViewAll", GetAllUser()), message = "Input Sukses" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }