public ActionResult Edit(T_Expense ObjExpense) { try { if (ModelState.IsValid) { if (!string.IsNullOrWhiteSpace(Convert.ToString(ObjExpense.Id))) { var vObj = _blExpense.GetById(ObjExpense.Id); if (vObj != null) { vObj.EventDate = ObjExpense.EventDate; vObj.ExpenseTypeId = ObjExpense.ExpenseTypeId; vObj.Amount = ObjExpense.Amount; vObj.Remark = ObjExpense.Remark; vObj.ModifyDate = DateTime.Now; vObj.ModifyBy = _objAuthentication.UserName; _blExpense.Update(vObj); } } } } catch (Exception ex) { throw ex; } return(RedirectToAction("Index", "Expense")); }
public ActionResult ExportToExcel() { T_Expense ObjPurchaseOrder = new T_Expense(); var vObjList = _blExpense.GetList(ObjPurchaseOrder); // ExcelPackageF dll Need OfficeOpenXml.ExcelPackage Ep = new OfficeOpenXml.ExcelPackage(); OfficeOpenXml.ExcelWorksheet workSheet = Ep.Workbook.Worksheets.Add("Report"); string sEndColumn = "E1"; workSheet.Cells[string.Format("A1:{0}", sEndColumn)].Style.Font.Bold = true; workSheet.Cells[string.Format("A1:{0}", sEndColumn)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; workSheet.Cells[string.Format("A1:{0}", sEndColumn)].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightSeaGreen); var allCells = workSheet.Cells[string.Format("A1:{0}", sEndColumn)]; var cellFont = allCells.Style.Font; workSheet.Cells["A1"].Value = "Date"; //sheet["A3:A4"].Merge(); workSheet.Cells["B1"].Value = "Enpense Type"; workSheet.Cells["C1"].Value = "Amount"; workSheet.Cells["D1"].Value = "Remark"; workSheet.Cells["E1"].Value = "Create Date"; string dateformat = "dd-MM-yyyy"; int row = 2; foreach (var item in vObjList) { workSheet.Cells[string.Format("A{0}", row)].Value = item.EventDate; workSheet.Cells[string.Format("A{0}", row)].Style.Numberformat.Format = dateformat; workSheet.Cells[string.Format("B{0}", row)].Value = item.ExpenseTypeName; workSheet.Cells[string.Format("C{0}", row)].Value = item.Amount; workSheet.Cells[string.Format("D{0}", row)].Value = item.Remark; workSheet.Cells[string.Format("E{0}", row)].Value = item.CreatedDate; workSheet.Cells[string.Format("E{0}", row)].Style.Numberformat.Format = dateformat; row++; } workSheet.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "Expense.csv" + DateTime.Now.ToString("s")); Response.BinaryWrite(Ep.GetAsByteArray()); Response.End(); return(View()); }
public ActionResult GetList(T_Expense ObjExpense) { List <T_Expense> ObjList = new List <T_Expense>(); try { ObjList = _blExpense.GetList(ObjExpense); } catch (Exception ex) { throw ex; } return(Json(ObjList, JsonRequestBehavior.AllowGet)); }
public T_Expense Delete(T_Expense ObjExpense) { try { using (_objUnitOfWork = new UnitOfWork()) { _objUnitOfWork._T_Expense_Repository.Delete(ObjExpense.Id); _objUnitOfWork.Save(); } } catch (Exception ex) { throw ex; } return(ObjExpense); }
public T_Expense GetById(Guid UserId) { var ObjExpense = new T_Expense(); try { using (_objUnitOfWork = new UnitOfWork()) { ObjExpense = _objUnitOfWork._T_Expense_Repository.GetById(UserId); } } catch (Exception ex) { throw ex; } return(ObjExpense); }
public ActionResult Delete(T_Expense ObjExpense) { try { if (!string.IsNullOrWhiteSpace(Convert.ToString(ObjExpense.Id))) { var vObj = _blExpense.GetById(ObjExpense.Id); if (vObj != null) { _blExpense.Delete(ObjExpense); } } } catch (Exception ex) { throw ex; } return(Json(ObjExpense)); }
public List <T_Expense> GetList(T_Expense ObjExpense) { var ObjList = new List <T_Expense>(); try { using (_objUnitOfWork = new UnitOfWork()) { var queryExpense = _objUnitOfWork._T_Expense_Repository.Query(); var queryExpenseType = _objUnitOfWork._M_ExpenseType_Repository.Query(); if (!string.IsNullOrWhiteSpace(Convert.ToString(ObjExpense.ExpenseTypeId)) && Convert.ToString(ObjExpense.ExpenseTypeId) != "00000000-0000-0000-0000-000000000000") { queryExpense = queryExpense.Where(x => x.ExpenseTypeId == ObjExpense.ExpenseTypeId); } var vqueryExpense = queryExpense.Join(queryExpenseType, expense => expense.ExpenseTypeId, eType => eType.Id, (expense, eType) => new { expense, eType }).ToList(); var vObjModelList = vqueryExpense.Select(x => new T_Expense() { Id = x.expense.Id, EventDate = x.expense.EventDate, ExpenseTypeId = x.expense.ExpenseTypeId, ExpenseTypeName = x.eType.Name, Amount = x.expense.Amount, Remark = x.expense.Remark, CreatedDate = x.expense.CreatedDate, CreatedBy = x.expense.CreatedBy, }).ToList(); ObjList = vObjModelList; } } catch (Exception ex) { throw ex; } return(ObjList); }
public ActionResult Create(T_Expense ObjExpense) { try { bool bAnyError = false; if (ModelState.IsValid) { T_Expense _Obj_T_Expense = new T_Expense() { Id = Guid.NewGuid(), ExpenseTypeId = ObjExpense.ExpenseTypeId, EventDate = Convert.ToDateTime(ObjExpense.EventDate), ExpenseTypeName = ObjExpense.ExpenseTypeName, Amount = ObjExpense.Amount, Remark = ObjExpense.Remark, CreatedBy = _objAuthentication.UserName, CreatedDate = DateTime.Now }; var vReturnObj = _blExpense.Create(_Obj_T_Expense); bAnyError = false; } if (bAnyError) { var vExpenseTypeList = _blExpense.GetExpenseTypeList().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }); ViewBag.ExpenseTypeList = vExpenseTypeList; return(View(ObjExpense)); } return(RedirectToAction("Index", "Expense")); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(string Id) { T_Expense vModel = new T_Expense(); if (!string.IsNullOrWhiteSpace(Id)) { var vDetails = _blExpense.GetById(new Guid(Id)); if (vDetails != null) { vModel.Id = vDetails.Id; vModel.EventDate = vDetails.EventDate; vModel.ExpenseTypeId = vDetails.ExpenseTypeId; vModel.Amount = vDetails.Amount; vModel.Remark = vDetails.Remark; } } var vExpenseTypeList = _blExpense.GetExpenseTypeList().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }); ViewBag.ExpenseTypeList = vExpenseTypeList; return(View(vModel)); }
public JsonResult Check(string UserName, int approveID, int status, string memo, string nextapprove, string company, string number, string ExpStatus) { using (TransactionScope sc = new TransactionScope()) { try { string curName = Server.UrlDecode(Request.Cookies["Name"].Value); string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); int TotalStep = db.T_ExpenseApproveConfig.ToList().Count; T_ExpenseApprove approve = db.T_ExpenseApprove.SingleOrDefault(a => a.ID == approveID && a.ApproveStatus == -1 && (a.ApproveName == curName || a.ApproveName == Nickname)); if (approve == null) { return(Json(new { State = "Faile", Message = "该数据已审核" }, JsonRequestBehavior.AllowGet)); } approve.ApproveStatus = status; approve.ApproveDate = DateTime.Now; approve.Remark = memo; T_Expense model = db.T_Expense.Find(approve.Reunbursement_id); if (nextapprove != null && nextapprove != "") { model.Cashier = nextapprove; } if (ExpStatus != null && ExpStatus != "") { model.ExpStatus = ExpStatus; } int Step = model.Step; Step++; if (status == 2) { model.Status = 2; model.Step = 0; db.SaveChanges(); } else { if (TotalStep == Step) { if (company == "==请选择==") { return(Json(new { State = "Faile", Message = "请选择公司" }, JsonRequestBehavior.AllowGet)); } model.Status = status; model.SpendingCompany = company; model.SpendingNumber = number; //实付 string codes1 = "KF-FK-"; string date1 = DateTime.Now.ToString("yyyyMMdd"); //查找当前已有的编号 List <T_PP> list1 = db.T_PP.Where(a => a.BillCode.Contains(date1)).OrderByDescending(c => c.ID).ToList(); if (list1.Count == 0) { codes1 += date1 + "-" + "0001"; } else { string old = list1[0].BillCode.Substring(15); int newcode = int.Parse(old) + 1; codes1 += date1 + "-" + newcode.ToString().PadLeft(4, '0'); } //实付 T_PP pp = new T_PP { BillCode = codes1, BillCompany = model.Reun_Bank, BillFromCode = model.Reun_Code, BillMoney = Convert.ToDouble(model.Reun_Cost), BillType = "报销申请", CreateTime = DateTime.Now, CreatUser = UserName, PayMoney = Convert.ToDouble("-" + model.Reun_Cost) }; db.T_PP.Add(pp); db.SaveChanges(); } else { if (status != 2) { T_ExpenseApproveConfig ModelConFig = db.T_ExpenseApproveConfig.SingleOrDefault(a => a.Step == Step); T_ExpenseApprove newApprove = new T_ExpenseApprove(); newApprove.ApproveStatus = -1; if (Step == 4) { newApprove.ApproveName = model.Cashier; nextapprove = model.Cashier; } else { newApprove.ApproveName = ModelConFig.ApproveUser; nextapprove = ModelConFig.ApproveUser; } newApprove.ApproveDate = null; newApprove.Reunbursement_id = approve.Reunbursement_id; db.T_ExpenseApprove.Add(newApprove); T_User u = db.T_User.FirstOrDefault(a => a.Nickname.Equals(nextapprove)); model.ExpenseNextApprove = u.ID; model.Status = 0; } } model.Step = Step; db.SaveChanges(); } ModularByZP(); sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }
//详情页面数据加载 public JsonResult GetDetail(int ID, string UserName) { T_User MOD_User = db.T_User.FirstOrDefault(a => a.Nickname == UserName); //真名 string name = MOD_User.Name; string result = ""; //主表 T_Expense mod = db.T_Expense.Find(ID); mainItem list = new mainItem(); list.ID = mod.ID; list.Department = mod.Department; list.Reun_Reason = mod.Reun_Reason; list.ExpenseNextApprove = mod.ExpenseNextApprove; list.Reun_Cost = mod.Reun_Cost; list.PostUser = mod.PostUser; list.CrateDate = mod.CrateDate; list.Reun_Code = mod.Reun_Code; list.AccountType = mod.AccountType; list.Reun_Bank = mod.Reun_Bank; list.Shop = mod.Shop; list.Reun_Name = mod.Reun_Name; list.Car_Number = mod.Car_Number; list.Status = mod.Status; list.Step = mod.Step; list.IsExpenseMatch = mod.IsExpenseMatch; list.IsExpenseEnclosure = mod.IsExpenseEnclosure; list.Pz_BXStatus = mod.Pz_BXStatus; list.MatchBorrowNumber = mod.MatchBorrowNumber; string modJson = JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()); //详情 IQueryable <T_ExpenseProduct> mod_Detail = db.T_ExpenseProduct.Where(a => a.ReunId == ID); string modDetail = JsonConvert.SerializeObject(mod_Detail, Lib.Comm.setTimeFormat()); //审核记录 IQueryable <T_ExpenseApprove> mod_Approve = db.T_ExpenseApprove.Where(a => a.Reunbursement_id == ID); string approve = JsonConvert.SerializeObject(mod_Approve, Lib.Comm.setTimeFormat()); T_Expense lossreport = db.T_Expense.Find(ID); //用于判断是不是 财务主管 int nextMan = 0; int Step = db.T_ExpenseApproveConfig.ToList().Count; if (mod.Step != Step - 1) { nextMan = 1; } //用于判断是不是我审核 0不是 1是 int myCheck = 0; T_ExpenseApprove MyApprove = db.T_ExpenseApprove.FirstOrDefault(a => a.Reunbursement_id == ID && a.ApproveName == UserName && a.ApproveDate == null); if (MyApprove != null) { myCheck = 1; } //审核人 List <SelectListItem> getCheckMan = new List <SelectListItem>(); var approveusers = db.T_ExpenseApproveConfig.FirstOrDefault(a => a.Step == 4); if (approveusers != null) { //如果是动态获取当前部门主管 string[] array = approveusers.ApproveUser.Split(','); List <SelectListItem> items = new List <SelectListItem>(); foreach (var item in array) { T_User user = db.T_User.FirstOrDefault(a => a.Nickname.Equals(item) || a.Name.Equals(item)); if (user != null) { items.Add(new SelectListItem { Text = user.Nickname, Value = user.ID.ToString() }); } } getCheckMan = items; } else { getCheckMan = null; } string CheckManJson = JsonConvert.SerializeObject(getCheckMan); string ExpStatus = JsonConvert.SerializeObject(Com.ExpenseStatus()); //未审核记录ID T_ExpenseApprove Approve = db.T_ExpenseApprove.FirstOrDefault(s => !s.ApproveDate.HasValue && s.Reunbursement_id == ID); if (Approve == null) { Approve = db.T_ExpenseApprove.FirstOrDefault(s => s.ApproveDate.HasValue && s.Reunbursement_id == ID); } result += "{\"Main\":[" + modJson + "],\"Detail\":" + modDetail + ",\"Approve\":" + approve + ",\"Step\":" + mod.Step + ",\"approveId\":" + Approve.ID + ",\"myCheck\":" + myCheck + ",\"ExpStatus\":" + ExpStatus + ",\"CheckList\":" + CheckManJson + ",\"Company\":" + JsonConvert.SerializeObject(Com.ExpenseCompany()) + "}"; return(Json(result, JsonRequestBehavior.AllowGet)); }