//Lấy thông tin chi tiết đơn hàng public OrderDetailOuputModel GetOrderDetail(int id) { try { OrderDetailOuputModel data = new OrderDetailOuputModel(); Order o = cnn.Orders.Find(id); data.ID = o.ID; data.CusName = o.Customer.Name; data.CusPhone = o.Customer.Phone; data.CusEmail = o.Customer.Email; data.Code = o.Code; data.TotalPrice = o.TotalPrice; data.Discount = o.Discount; data.CreatedDate = o.CreatedDate; data.Note = o.Note; data.AdminNote = !String.IsNullOrEmpty(o.AdminNote) ? o.AdminNote : "Chưa cập nhật"; data.ServiceName = o.ServicePlan.Name; data.LocationRequest = !String.IsNullOrEmpty(o.Address) ? o.Village.Name + "-" + o.District.Name + "-" + o.Province.Name : o.Address; data.Status = o.Status; data.DiscountValue = o.DiscountValue.HasValue ? o.DiscountValue.Value : 0; data.UserHandleName = o.UserHandleID.HasValue ? o.User.Name : "Chưa cập nhật"; return(data); } catch { return(new OrderDetailOuputModel()); } }
//Xuất hóa đơn public ExcelPackage ExportBill(int id) { try { OrderDetailOuputModel data = GetOrderDetail(id); string path = HttpContext.Current.Server.MapPath(@"/Template/Bill.xlsx"); FileInfo file = new FileInfo(path); ExcelPackage pack = new ExcelPackage(file); ExcelWorksheet sheet = pack.Workbook.Worksheets[1]; sheet.Cells[4, 2].Value = data.Code; sheet.Cells[5, 2].Value = data.CreatedDate.ToString(SystemParam.CONVERT_DATETIME_HAVE_HOUR); sheet.Cells[6, 2].Value = data.ServiceName; sheet.Cells[7, 2].Value = data.LocationRequest; sheet.Cells[8, 2].Value = String.Format("0n:0", data.TotalPrice); sheet.Cells[9, 2].Value = data.AdminNote; sheet.Cells[10, 2].Value = data.DiscountValue; sheet.Cells[11, 2].Value = data.Discount; sheet.Cells[12, 2].Value = data.UserHandleName; sheet.Cells[16, 2].Value = data.CusName; sheet.Cells[17, 2].Value = data.CusPhone; sheet.Cells[18, 2].Value = data.CusEmail; return(pack); } catch (Exception e) { e.ToString(); return(null); } }
public JsonResult UpdateBill(OrderDetailOuputModel input) { return(Json(orderBusiness.UpdateBill(input, admin.Id, admin.Role))); }
//Cập nhật đơn hàng public JsonResultModel UpdateBill(OrderDetailOuputModel input, int userID, int role) { try { EmailBusiness email = new EmailBusiness(); if (role.Equals(SystemParam.ROLE_TECHNICAL_STAFF)) { return(rp.response(SystemParam.ERROR, SystemParam.FAIL, "Bạn không được phép sửa đơn hàng", null)); } Order o = cnn.Orders.Find(input.ID); switch (input.Status) { case SystemParam.PENDING: o.DiscountValue = input.DiscountValue; o.Discount = input.Discount; o.TotalPrice = input.TotalPrice; o.AdminNote = input.AdminNote; if (o.Status != input.Status) { email.configClient(o.Customer.Email, "[NEXUS SYSTEM THÔNG BÁO]", "Đơn hàng " + o.Code + " của bạn đang chờ xác nhận"); } o.Status = input.Status; o.UserHandleID = userID; break; case SystemParam.ACCEPT: o.DiscountValue = input.DiscountValue; o.Discount = input.Discount; o.TotalPrice = input.TotalPrice; o.AdminNote = input.AdminNote; if (o.Status != input.Status) { email.configClient(o.Customer.Email, "[NEXUS SYSTEM THÔNG BÁO]", "Đơn hàng " + o.Code + " của bạn đã được xác nhận"); } o.Status = input.Status; o.UserHandleID = userID; break; case SystemParam.COMPLETE: o.DiscountValue = input.DiscountValue; o.Discount = input.Discount; o.TotalPrice = input.TotalPrice; o.AdminNote = input.AdminNote; if (o.Status != input.Status) { //Lưu lịch sử List <HistoryCustomerServicePlan> history = new List <HistoryCustomerServicePlan>(); HistoryCustomerServicePlan h = new HistoryCustomerServicePlan(); h.Note = "Dịch vụ dược kích hoạt"; h.UserID = userID; h.IsActive = SystemParam.ACTIVE; h.CreatedDate = DateTime.Now; history.Add(h); //Kích hoạt gói cước CustomerServicePlan c = new CustomerServicePlan(); c.CustomerID = o.CustomerID; c.ActiveDate = DateTime.Now; c.ExtendDate = DateTime.Now; c.ExpiryDate = DateTime.Now.AddMonths(o.ServicePlan.Value); c.CreatedDate = DateTime.Now; c.code = o.Code; c.OrderID = o.ID; c.Status = SystemParam.ACTIVE_STATUS; c.IsActive = SystemParam.ACTIVE; c.HistoryCustomerServicePlans = history; c.Address = !String.IsNullOrEmpty(o.Address) ? o.Customer.Village.Name + " " + o.Customer.District.Name + " " + o.Customer.Province.Name : o.Address; cnn.CustomerServicePlans.Add(c); email.configClient(o.Customer.Email, "[NEXUS SYSTEM THÔNG BÁO]", "Đơn hàng " + o.Code + " của bạn đã được hoàn thành"); } o.Status = input.Status; o.UserHandleID = userID; break; case SystemParam.CANCEL: o.DiscountValue = input.DiscountValue; o.Discount = input.Discount; o.TotalPrice = input.TotalPrice; o.AdminNote = input.AdminNote; if (o.Status != input.Status) { email.configClient(o.Customer.Email, "[NEXUS SYSTEM THÔNG BÁO]", "Đơn hàng " + o.Code + " của bạn bị trừ chối vì lý do: " + input.AdminNote); } o.Status = input.Status; break; default: break; } cnn.SaveChanges(); return(rp.response(SystemParam.SUCCESS, SystemParam.SUCCESS_CODE, SystemParam.SUCCESS_MESSAGE, "")); } catch (Exception e) { e.ToString(); return(rp.serverError()); } }