private string MutationNumberNew(int?asset_id) { tr_asset_registration tr_asset = db.tr_asset_registration.Find(asset_id); ms_asmin_company company = db.ms_asmin_company.Find(tr_asset.company_id); ms_department department = db.ms_department.Find(tr_asset.department_id); ms_asset_category category = db.ms_asset_category.Find(tr_asset.category_id); string code = string.Empty; code += "M"; code += company.company_code; code += department.department_code; code += category.category_code; code += DateTime.Today.Year; code += DateTime.Today.Month.ToString().PadLeft(2, '0'); var _lastno = (from dr in db.tr_disposal_request where dr.disposal_number.Contains(code) orderby dr.request_id descending select dr).ToList <tr_disposal_request>(); if (_lastno.Count > 0) { tr_disposal_request lastno = _lastno.FirstOrDefault(); string currentno = (Convert.ToInt32(lastno.disposal_number.Substring((lastno.disposal_number.Length - 2), 2)) + 1).ToString(); code += currentno.PadLeft(2, '0'); } else { code += "01"; } code += "-"; code += tr_asset.asset_number.Substring((tr_asset.asset_number.Length - 2), 2); return(code); }
public ActionResult DeleteConfirmed(int id) { ms_department ms_department = db.ms_department.Find(id); db.ms_department.Remove(ms_department); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "department_id,department_code,department_name,department_email,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_department ms_department) { if (ModelState.IsValid) { db.Entry(ms_department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_department)); }
public ActionResult Create([Bind(Include = "department_code,department_name,department_email")] ms_department ms_department) { if (ModelState.IsValid) { db.ms_department.Add(ms_department); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_department)); }
// GET: department/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_department ms_department = db.ms_department.Find(id); if (ms_department == null) { return(HttpNotFound()); } return(View(ms_department)); }
public ActionResult Create([Bind(Include = "asset_parent_id,asset_number,company_id,asset_reg_location_id,asset_reg_pic_id,category_id,asset_po_number,asset_do_number,asset_name,asset_merk,asset_serial_number,vendor_id,asset_receipt_date,location_id,department_id,employee_id,asset_description,asset_file_attach")] subasset_registrationViewModel asset_reg) { if (ModelState.IsValid) { using (DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { #region SUBASSET tr_asset_registration asset_parent = db.tr_asset_registration.Find(asset_reg.asset_parent_id); int _last_no = db.tr_asset_registration.Where(a => a.asset_parent_id == asset_reg.asset_parent_id).Count(); /*no aktifa seq*/ _last_no++; string no_activa = _last_no.ToString().PadLeft(2, '0'); string[] complex_no = asset_parent.asset_number.Split(new char[3] { '.', '-', '/' }); asset_reg.asset_number = complex_no[0] + "-" + no_activa; tr_asset_registration ass_reg = new tr_asset_registration(); ass_reg.asset_type_id = (int)Enum_asset_type_Key.AssetChild; //child ass_reg.asset_parent_id = asset_reg.asset_parent_id; ass_reg.tr_asset_registration2 = asset_parent; ass_reg.asset_number = asset_reg.asset_number; ass_reg.company_id = asset_reg.company_id; ass_reg.asset_reg_location_id = asset_reg.asset_reg_location_id; ass_reg.asset_reg_pic_id = asset_reg.asset_reg_pic_id; ass_reg.category_id = asset_reg.category_id; ass_reg.asset_po_number = asset_reg.asset_po_number; ass_reg.asset_do_number = asset_reg.asset_do_number; ass_reg.asset_name = asset_reg.asset_name; ass_reg.asset_merk = asset_reg.asset_merk; ass_reg.asset_serial_number = asset_reg.asset_serial_number; ass_reg.vendor_id = asset_reg.vendor_id; ass_reg.asset_receipt_date = asset_reg.asset_receipt_date; ass_reg.location_id = asset_reg.location_id; ass_reg.current_location_id = asset_reg.location_id; ass_reg.department_id = asset_reg.department_id; ass_reg.current_department_id = asset_reg.department_id; ass_reg.asset_description = asset_reg.asset_description; ass_reg.employee_id = asset_reg.employee_id; ass_reg.current_employee_id = asset_reg.employee_id; ass_reg.fl_active = true; ass_reg.created_date = DateTime.Now; ass_reg.created_by = UserProfile.UserId; ass_reg.updated_date = DateTime.Now; ass_reg.updated_by = UserProfile.UserId; ass_reg.deleted_date = null; ass_reg.deleted_by = null; ass_reg.org_id = UserProfile.OrgId; ass_reg = db.tr_asset_registration.Add(ass_reg); db.SaveChanges(); #endregion #region FILEASSET //ass_reg.asset_file_attach = asset_reg.asset_file_attach; if (Request.Files.Count > 0) { //var file = Request.Files[0]; app_root_path = Server.MapPath("~/"); if (string.IsNullOrWhiteSpace(base_image_path)) { base_image_path = subasset_registrationViewModel.path_file_asset; } string img_path = Server.MapPath(base_image_path); if (!Directory.Exists(img_path)) { Directory.CreateDirectory(img_path); } var file = Request.Files["asset_img_file"]; if (file != null && file.ContentLength > 0) { var fileName = "asset" + ass_reg.asset_id.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(img_path, fileName); file.SaveAs(path); tr_asset_image _ass_img = new tr_asset_image() { asset_id = ass_reg.asset_id, asset_img_address = fileName, asset_qrcode = GenerateQRCode(asset_reg.asset_number) }; db.tr_asset_image.Add(_ass_img); db.SaveChanges(); } } #endregion dbTran.Commit(); } catch (Exception _exc) { dbTran.Rollback(); throw new Exception("Fail to save create new sub-asset." + _exc.Message); } } #region "Send Email Notif to accounting department" try { ms_disposal_type Dept3 = db.ms_disposal_type.Find(3); int acct_id = Convert.ToInt32(Dept3.disposal_by_dept_id); var _qry = (from dept in db.ms_department.Where(dept => dept.department_id == acct_id) select dept).ToList().FirstOrDefault(); if (_qry == null) { throw new Exception("Department not found"); } sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _qry.department_email; sy_email_log.elog_subject = string.Format("Sub Asset Registration"); sy_email_log.elog_template = "EMAIL_TEMPLATE_90"; var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_90")).FirstOrDefault(); if (_bodymail == null) { throw new Exception("Email Template 01 not found"); } string strBodyMail = _bodymail.app_value; strBodyMail = strBodyMail.Replace("[to]", _qry.department_name + " Department"); strBodyMail = strBodyMail.Replace("[action]", "Dispose"); strBodyMail = strBodyMail.Replace("[assetnumber]", asset_reg.asset_number); strBodyMail = strBodyMail.Replace("[assetname]", asset_reg.asset_name); ms_asset_location loc = db.ms_asset_location.Find(asset_reg.location_id); if (loc == null) { throw new Exception("Sub Asset Location not found"); } strBodyMail = strBodyMail.Replace("[assetlocation]", loc.location_name); ms_department deptment = db.ms_department.Find(asset_reg.department_id); if (deptment == null) { throw new Exception("Department not found"); } strBodyMail = strBodyMail.Replace("[department]", deptment.department_name); sy_email_log.elog_body = strBodyMail; 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(); } catch { } #endregion return(RedirectToAction("Index")); } #region complete the VM if (asset_reg.asset_parent_list == null) { asset_reg.asset_parent_list = db.tr_asset_registration.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.company_list == null) { asset_reg.company_list = db.ms_asmin_company.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_reg_location_list == null) { asset_reg.asset_reg_location_list = db.ms_asset_register_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_reg_pic_list == null) { asset_reg.asset_reg_pic_list = db.ms_asset_register_pic.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_category_list == null) { asset_reg.asset_category_list = db.ms_asset_category.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.vendor_list == null) { asset_reg.vendor_list = db.ms_vendor.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_location_list == null) { asset_reg.asset_location_list = db.ms_asset_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.department_list == null) { asset_reg.department_list = db.ms_department.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.employee_list == null) { asset_reg.employee_list = db.ms_employee.AsEnumerable().Where(r => r.fl_active == true && r.deleted_date == null).Select(e => new ms_employee { employee_id = e.employee_id, employee_name = "[" + e.employee_nik + "] - " + e.employee_name, employee_email = e.employee_email }).ToList(); } #endregion return(View(asset_reg)); }
public JsonResult CrudDepartment() { if (UserProfile.UserId != 0) { if (Request.Form["oper"] == "add") { //prepare for insert data ms_department ms_department = new ms_department(); ms_department.department_code = Request.Form["department_code"]; ms_department.department_name = Request.Form["department_name"]; ms_department.department_email = Request.Form["department_email"]; if (Request.Form["employee_name"] != null && Request.Form["employee_name"] != "") { ms_department.employee_bod_id = Convert.ToInt32(Request.Form["employee_name"]); } ms_department.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; //ms_department.fl_active = true; ms_department.created_by = UserProfile.UserId; ms_department.created_date = DateTime.Now; ms_department.updated_by = UserProfile.UserId; ms_department.updated_date = DateTime.Now; ms_department.org_id = UserProfile.OrgId; ms_department.deleted_by = null; ms_department.deleted_date = null; //db.ms_department.Add(ms_department); db.Entry(ms_department).State = EntityState.Added; db.SaveChanges(); return(Json("Insert", JsonRequestBehavior.AllowGet)); } else if (Request.Form["oper"] == "edit") { if (IsNumeric(Request.Form["department_id"].ToString())) { //prepare for update data int id = Convert.ToInt32(Request.Form["department_id"]); ms_department ms_department = db.ms_department.Find(id); ms_department.department_code = Request.Form["department_code"]; ms_department.department_name = Request.Form["department_name"]; ms_department.department_email = Request.Form["department_email"]; if (Request.Form["employee_name"] != null && Request.Form["employee_name"] != "") { ms_department.employee_bod_id = Convert.ToInt32(Request.Form["employee_name"]); } ms_department.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; ms_department.updated_by = UserProfile.UserId; ms_department.updated_date = DateTime.Now; db.Entry(ms_department).State = EntityState.Modified; db.SaveChanges(); return(Json("Update", JsonRequestBehavior.AllowGet)); } else { //prepare for insert data ms_department ms_department = new ms_department(); ms_department.department_code = Request.Form["department_code"]; ms_department.department_name = Request.Form["department_name"]; ms_department.department_email = Request.Form["department_email"]; if (Request.Form["employee_name"] != null && Request.Form["employee_name"] != "") { ms_department.employee_bod_id = Convert.ToInt32(Request.Form["employee_name"]); } ms_department.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; ms_department.created_by = UserProfile.UserId; ms_department.created_date = DateTime.Now; ms_department.updated_by = UserProfile.UserId; ms_department.updated_date = DateTime.Now; ms_department.org_id = UserProfile.OrgId; ms_department.deleted_by = null; ms_department.deleted_date = null; db.Entry(ms_department).State = EntityState.Added; db.SaveChanges(); return(Json("Insert", 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_department ms_department = db.ms_department.Find(id); ms_department.deleted_by = UserProfile.UserId; ms_department.deleted_date = DateTime.Now; ms_department.fl_active = false; db.Entry(ms_department).State = EntityState.Modified; db.SaveChanges(); } return(Json("Delete", JsonRequestBehavior.AllowGet)); } else { return(Json("Error", JsonRequestBehavior.AllowGet)); } } } else { return(Json("Session", JsonRequestBehavior.AllowGet)); } }
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 ActionResult Create([Bind(Include = "asset_id, asset_number,asset_name, location_id, location_name, department_name, request_description")] disposalViewModel disposal_req) { if (Request.Files.Count > 0) { var fileexist = Request.Files["asset_img_address"]; if (fileexist == null || fileexist.ContentLength == 0) { ModelState.AddModelError("asset_img_address", "Asset image is mandatory."); } } //input data request disposal with transaction if (ModelState.IsValid) { //Int32 z = Convert.ToInt32("a"); using (var transaction = db.Database.BeginTransaction()) { try { #region "Save Request Disposal" tr_disposal_request disposal_request = new tr_disposal_request(); disposal_request.disposal_number = DisposalNumberNew(disposal_req.asset_id); disposal_request.asset_id = disposal_req.asset_id; disposal_request.request_date = DateTime.Now; disposal_request.request_description = disposal_req.request_description; disposal_request.request_location_id = disposal_req.location_id; disposal_request.request_dept_id = UserProfile.department_id; disposal_request.request_emp_id = UserProfile.employee_id; disposal_request.request_status_id = 1; disposal_request.fl_active = true; disposal_request.created_date = DateTime.Now; disposal_request.created_by = UserProfile.UserId; disposal_request.updated_date = DateTime.Now; disposal_request.update_by = UserProfile.UserId; disposal_request.deleted_date = null; disposal_request.deleted_by = null; disposal_request.org_id = UserProfile.OrgId; disposal_request = db.tr_disposal_request.Add(disposal_request); db.SaveChanges(); //Save Approval Dept. Head var _qry = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == disposal_req.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.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id where c.fl_active == true && c.deleted_date == null orderby sa.order_no ascending select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <disposalViewModel>(); int count = 1; int approval_id = 0; if (_qry != null) { foreach (disposalViewModel refApproval in _qry) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval.department_id; disposal_approval.approval_employee_id = refApproval.employee_id; disposal_approval.approval_level_id = refApproval.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); if (count == 1) { //untuk kebutuhan link email count++; approval_id = disposal_approval.approval_id; } } } //Save Approval Dept. Head var _qry_ktt = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == disposal_req.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.fl_active == true && c.deleted_date == null orderby sa.order_no ascending select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <disposalViewModel>(); int count_ktt = 1; int approval_id_ktt = 0; if (_qry_ktt != null) { foreach (disposalViewModel refApproval in _qry_ktt) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval.department_id; disposal_approval.approval_employee_id = refApproval.employee_id; disposal_approval.approval_level_id = refApproval.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); if (count_ktt == 1) { //untuk kebutuhan link email count_ktt++; approval_id_ktt = disposal_approval.approval_id; } } } //Approval BOD berdasarkan data ms_department >> employee_bod_id ms_department dept = db.ms_department.Find(UserProfile.department_id); if (dept != null) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = dept.department_id; disposal_approval.approval_employee_id = dept.employee_bod_id; disposal_approval.approval_level_id = 9; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); } if (Request.Files.Count > 0) { //var file = Request.Files[0]; app_root_path = Server.MapPath("~/"); if (string.IsNullOrWhiteSpace(base_image_path)) { base_image_path = asset_registrationViewModel.path_file_disposal; } string img_path = Server.MapPath(base_image_path); if (!Directory.Exists(img_path)) { Directory.CreateDirectory(img_path); } var file = Request.Files["asset_img_address"]; if (file != null && file.ContentLength > 0) { var fileName = "asset" + disposal_req.asset_id.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(img_path, fileName); file.SaveAs(path); tr_disposal_image _ass_img = new tr_disposal_image() { request_id = disposal_request.request_id, asset_id = Convert.ToInt32(disposal_req.asset_id), asset_img_address = fileName, }; db.tr_disposal_image.Add(_ass_img); db.SaveChanges(); } } #endregion #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 Disposal Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_04"; var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_04")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", _qry.FirstOrDefault().employee_name); strBodyMail = strBodyMail.Replace("[action]", "Dispose"); strBodyMail = strBodyMail.Replace("[assetnumber]", disposal_req.asset_number); strBodyMail = strBodyMail.Replace("[aseetname]", disposal_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", disposal_req.location_name); strBodyMail = strBodyMail.Replace("[department]", disposal_req.department_name); int empid = Convert.ToInt32(_qry.FirstOrDefault().employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); //token untuk link approval di email string token = string.Format("DisposalApproval|Approval/{0}|{1}|{2}|{3}", approval_id, msuser.user_name, UserProfile.company_id, UserProfile.asset_reg_location_id); token = CryptorHelper.Encrypt(token, "MD5", true).Replace("+", "plus").Replace("=", "equal"); string linkapp = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~/Account/Login?ReturnUrl=%2f&token=" + token)); string strImg = string.Format("http://{0}/Content/EmailImage/button_approval_disposal.png", Request.Url.Authority); linkapp = string.Format(@"<a href={0}><img src=""{1}"" alt=""click for approval""/></a>", linkapp, strImg); strBodyMail = strBodyMail.Replace("[link]", linkapp); sy_email_log.elog_body = strBodyMail; 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" sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_04"; msg.notify_user = msuser.user_name; msg.notify_ip = _qry.FirstOrDefault().ip_address; msg.notify_message = "Ada permintaan approval untuk Asset disposal."; 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("An unknown error has occurred , Please contact your system administrator. {0}", ex.Message); if (ex.InnerException != null) { msgErr += string.Format(" Inner Exception: {0}", ex.InnerException.Message); } ModelState.AddModelError("", msgErr); } } } return(View(disposal_req)); }