public ActionResult DeleteConfirmed(int id) { ms_approval_range ms_approval_range = db.ms_approval_range.Find(id); db.ms_approval_range.Remove(ms_approval_range); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "range_id,range_type,range_code,range_min,range_max,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_approval_range ms_approval_range) { if (ModelState.IsValid) { db.Entry(ms_approval_range).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_approval_range)); }
// GET: approval_range/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_approval_range ms_approval_range = db.ms_approval_range.Find(id); if (ms_approval_range == null) { return(HttpNotFound()); } return(View(ms_approval_range)); }
public ActionResult request([Bind(Include = "asset_id, asset_number, asset_name, current_location_id, location_name, current_department_id, department_name, current_employee_id, employee_name, transfer_to_location_id, transfer_to_dept_id, transfer_to_emp_id, asset_original_value")] AssetMutationViewModel mutation_req) { //Cek apakah disposal sudah di proses sebelumnya (kecuali reject) var _MutationExist = (from dr in db.tr_mutation_request where (dr.fl_active == true && dr.deleted_date == null) && dr.asset_id == mutation_req.asset_id select dr).ToList <tr_mutation_request>(); if (_MutationExist.Count > 0) { ModelState.AddModelError("asset_number", "Asset Already Exists in Disposal Request Data."); } //input data request disposal with transaction if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { //Save Request Disposal tr_mutation_request mutation_request = new tr_mutation_request(); mutation_request.request_code = MutationNumberNew(mutation_req.asset_id); mutation_request.asset_id = mutation_req.asset_id; mutation_request.request_date = DateTime.Now; //mutation_request.request_location_id = UserProfile.location_id; //mutation_request.request_dept_id = UserProfile.department_id; //mutation_request.request_emp_id = UserProfile.employee_id; mutation_request.request_location_id = mutation_req.current_location_id; mutation_request.request_dept_id = mutation_req.current_department_id; mutation_request.request_emp_id = mutation_req.current_employee_id; mutation_request.request_status = 1; mutation_request.transfer_to_location_id = mutation_req.transfer_to_location_id; mutation_request.transfer_to_dept_id = mutation_req.transfer_to_dept_id; mutation_request.transfer_to_emp_id = mutation_req.transfer_to_emp_id; mutation_request.fl_active = true; mutation_request.created_date = DateTime.Now; mutation_request.created_by = UserProfile.UserId; mutation_request.updated_date = DateTime.Now; mutation_request.updated_by = UserProfile.UserId; mutation_request.deleted_date = null; mutation_request.deleted_by = null; mutation_request.org_id = UserProfile.OrgId; mutation_request = db.tr_mutation_request.Add(mutation_request); db.SaveChanges(); var x = UserProfile.OrgId; //Save Approval List Mutation Untuk Dept Head //Hendy 22 Feb 2020 var _qry = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == mutation_req.current_location_id && sa.job_level_id == 2 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null //&& b.department_id == UserProfile.department_id && b.org_id == UserProfile.OrgId) && b.department_id == mutation_req.current_department_id && b.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id orderby sa.order_no ascending select new AssetMutationViewModel() { //request_location_id = b.loca request_dept_id = b.department_id, request_emp_id = b.employee_id, request_level_id = a.job_level_id, current_employee_id = c.employee_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <AssetMutationViewModel>(); if (_qry != null) { foreach (AssetMutationViewModel refApproval in _qry) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = refApproval.request_dept_id; mutation_approval.approval_employee_id = refApproval.request_emp_id; mutation_approval.approval_level_id = refApproval.request_level_id; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.OrgId; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } //Check KTT //check range approval decimal ktt_asset_value = Convert.ToDecimal(mutation_req.asset_original_value); bool isKTTApproval = false; ms_approval_range range_ktt = db.ms_approval_range.Where(r => r.range_code == "M_lv2").FirstOrDefault(); if (range_ktt != null) { isKTTApproval = (range_ktt.range_min <= ktt_asset_value); } if (isKTTApproval) { var x_ktt = UserProfile.OrgId; //Save Approval List Mutation Untuk Dept Head //Hendy 22 Feb 2020 var _qry_ktt = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == mutation_req.current_location_id && sa.job_level_id == 3 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null) && b.company_id == UserProfile.company_id join c in db.ms_employee on b.employee_id equals c.employee_id where c.employee_id == UserProfile.employee_id orderby sa.order_no ascending select new AssetMutationViewModel() { //request_location_id = b.loca request_dept_id = b.department_id, request_emp_id = b.employee_id, request_level_id = a.job_level_id, current_employee_id = c.employee_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <AssetMutationViewModel>(); if (_qry_ktt != null) { foreach (AssetMutationViewModel refApproval in _qry_ktt) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = refApproval.request_dept_id; mutation_approval.approval_employee_id = refApproval.request_emp_id; mutation_approval.approval_level_id = refApproval.request_level_id; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.OrgId; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } } decimal asset_value = Convert.ToDecimal(mutation_req.asset_original_value); bool isBODApproval = false; ms_approval_range range = db.ms_approval_range.Where(r => r.range_code == "M_BOD").FirstOrDefault(); if (range != null) { isBODApproval = (range.range_min <= asset_value); } if (isBODApproval) { //Approval BOD berdasarkan data ms_department >> employee_bod_id ms_department dept = db.ms_department.Find(UserProfile.department_id); if (dept != null) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = dept.department_id; mutation_approval.approval_employee_id = dept.employee_bod_id; mutation_approval.approval_level_id = 9; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.company_id; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } #region "kirim email ke approval level 1" sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _qry.FirstOrDefault().employee_email; sy_email_log.elog_subject = string.Format("Asset Mutation Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_02"; #region "body mail" var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_02")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", _qry.FirstOrDefault().employee_name); strBodyMail = strBodyMail.Replace("[assetnumber]", mutation_req.asset_number); strBodyMail = strBodyMail.Replace("[assetname]", mutation_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", mutation_req.location_name); strBodyMail = strBodyMail.Replace("[department]", mutation_req.department_name); strBodyMail = strBodyMail.Replace("[employee]", mutation_req.employee_name); //strBodyMail = strBodyMail.Replace("[link]", ""); sy_email_log.elog_body = strBodyMail; #endregion var EmailHelper = new EmailHelper() { ToAddress = sy_email_log.elog_to, Email_Template = sy_email_log.elog_template, MailSubject = sy_email_log.elog_subject, MailBody = sy_email_log.elog_body }; EmailHelper.Send(); #endregion #region "Save Sy_Message_notification ke approval" int empid = Convert.ToInt32(_qry.FirstOrDefault().current_employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_03"; msg.notify_user = msuser.user_name; msg.notify_ip = _qry.FirstOrDefault().ip_address; msg.notify_message = "Ada permintaan approval untuk asset mutasi."; msg.fl_active = true; msg.created_date = DateTime.Now; msg.created_by = UserProfile.UserId; msg.fl_shown = 0; db.sy_message_notification.Add(msg); db.SaveChanges(); #endregion transaction.Commit(); ViewBag.ResultMessage = "Record inserted into table successfully."; return(RedirectToAction("Index")); } catch (Exception ex) { // roll back all database operations, if any thing goes wrong transaction.Rollback(); string msgErr = string.Format("Error occured, records rolledback. {0}", ex.Message); if (ex.InnerException != null) { msgErr += string.Format(" Inner Exception: {0}", ex.InnerException.Message); } ModelState.AddModelError("", msgErr); } } } #region "for dropdown Employee" //var _employeelist = from s in db.ms_disposal_type // select s; var _employeelist = db.ms_employee.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.employee_id, t.employee_nik, t.employee_name }).ToList(); SelectList itemsType = new SelectList(_employeelist, "employee_id", "employee_name"); ViewBag.transfer_to_emp_id = itemsType; #endregion #region "for dropdown Department" var _departmentlist = db.ms_department.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.department_id, t.department_code, t.department_name }).ToList(); SelectList itemsType2 = new SelectList(_departmentlist, "department_id", "department_name"); ViewBag.transfer_to_dept_id = itemsType2; #endregion #region "for dropdown Location" var _locationlist = db.ms_asset_location.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.location_id, t.location_code, t.location_name }).ToList(); SelectList itemsType3 = new SelectList(_locationlist, "location_id", "location_name"); ViewBag.transfer_to_location_id = itemsType3; #endregion return(View(mutation_req)); }
public JsonResult CrudApproval() { decimal RangeMin = 0, RangeMax = 0; if (Request.Form["oper"] == "add") { if (Request.Form["range_min"] != null) { Decimal.TryParse(Request.Form["range_min"].Replace(",", ""), out RangeMin); } if (Request.Form["range_max"] != null) { Decimal.TryParse(Request.Form["range_max"].Replace(",", ""), out RangeMax); } //prepare for insert data ms_approval_range ms_approval_range = new ms_approval_range(); ms_approval_range.range_code = Request.Form["range_code"]; ms_approval_range.range_type = Request.Form["range_type"]; ms_approval_range.range_min = RangeMin; ms_approval_range.range_max = RangeMax; ms_approval_range.fl_active = Request.Form["rec_isactive"].ToLower() == "yes" ? true : false; ms_approval_range.created_by = UserProfile.UserId; ms_approval_range.created_date = DateTime.Now; ms_approval_range.updated_by = UserProfile.UserId; ms_approval_range.updated_date = DateTime.Now; ms_approval_range.org_id = UserProfile.OrgId; ms_approval_range.deleted_by = null; ms_approval_range.deleted_date = null; db.Entry(ms_approval_range).State = EntityState.Added; db.SaveChanges(); return(Json("Insert Approval Range Data Success!", JsonRequestBehavior.AllowGet)); } else if (Request.Form["oper"] == "edit") { if (Request.Form["range_min"] != null) { Decimal.TryParse(Request.Form["range_min"].Replace(",", ""), out RangeMin); } if (Request.Form["range_max"] != null) { Decimal.TryParse(Request.Form["range_max"].Replace(",", ""), out RangeMax); } if (IsNumeric(Request.Form["range_id"].ToString())) { //prepare for update data int id = Convert.ToInt32(Request.Form["range_id"]); ms_approval_range ms_approval_range = db.ms_approval_range.Find(id); ms_approval_range.range_code = Request.Form["range_code"]; ms_approval_range.range_type = Request.Form["range_type"]; ms_approval_range.range_min = RangeMin; ms_approval_range.range_max = RangeMax; ms_approval_range.fl_active = Request.Form["rec_isactive"].ToLower() == "yes" ? true : false; ms_approval_range.updated_by = UserProfile.UserId; ms_approval_range.updated_date = DateTime.Now; db.Entry(ms_approval_range).State = EntityState.Modified; db.SaveChanges(); return(Json("Update Asset Register PIC Data Success!", JsonRequestBehavior.AllowGet)); } else { //prepare for insert data ms_approval_range ms_approval_range = new ms_approval_range(); ms_approval_range.range_code = Request.Form["range_code"]; ms_approval_range.range_type = Request.Form["range_type"]; ms_approval_range.range_min = RangeMin; ms_approval_range.range_max = RangeMax; ms_approval_range.fl_active = Request.Form["rec_isactive"].ToLower() == "yes" ? true : false; ms_approval_range.created_by = UserProfile.UserId; ms_approval_range.created_date = DateTime.Now; ms_approval_range.updated_by = UserProfile.UserId; ms_approval_range.updated_date = DateTime.Now; ms_approval_range.org_id = UserProfile.OrgId; ms_approval_range.deleted_by = null; ms_approval_range.deleted_date = null; db.Entry(ms_approval_range).State = EntityState.Added; db.SaveChanges(); return(Json("Insert Approval Range Data Success!", JsonRequestBehavior.AllowGet)); } } else { if (Request.Form["oper"] == "del") { //for delete process string ids = Request.Form["id"]; string[] values = ids.Split(','); for (int i = 0; i < values.Length; i++) { values[i] = values[i].Trim(); //prepare for soft delete data int id = Convert.ToInt32(values[i]); ms_approval_range ms_approval_range = db.ms_approval_range.Find(id); ms_approval_range.fl_active = false; ms_approval_range.deleted_by = UserProfile.UserId; ms_approval_range.deleted_date = DateTime.Now; db.Entry(ms_approval_range).State = EntityState.Modified; db.SaveChanges(); } } return(Json("Deleted Success!")); } }