public ResponseModel createSellReceipt(string json) { SellReceiptModel model = JsonConvert.DeserializeObject <SellReceiptModel>(json); CultureInfo provider = CultureInfo.InvariantCulture; DateTime dt = DateTime.ParseExact(model.strNgay + " 00:00:00", "dd-MM-yyyy HH:mm:ss", provider); model.Ngay = dt; model.Id = model.KHId; return(BLLSellReceipt.Instance.Insert(connectString, model)); }
private bool CheckExists(SellReceiptModel SellReceipt, HMSEntities db) { H_SellReceipt obj = null; if (!string.IsNullOrEmpty(SellReceipt.SoPhieu)) { obj = db.H_SellReceipt.FirstOrDefault(x => !x.IsDeleted && x.Id != SellReceipt.Id && x.SoPhieu.Trim().ToUpper().Equals(SellReceipt.SoPhieu.Trim().ToUpper())); } return(obj != null ? true : false); }
public ActionResult Edit(SellReceiptModel model) { string connnect = App_Global.AppGlobal.Connectionstring; ViewBag.Jobs = BLLJob.Instance.GetLookUp(connnect); ViewBag.Models = BLLModel.Instance.GetLookUp(connnect); ViewBag.LoaiXes = BLLWorkType.Instance.GetLookUp(connnect); var result = BLLSellReceipt.Instance.Edit(connnect, model); return(RedirectToAction("index")); }
public ResponseModel Edit(string connectString, SellReceiptModel model) { var result = new ResponseModel(); result.IsSuccess = true; using (var db = new HMSEntities(connectString)) { var obj = db.H_SellReceipt.FirstOrDefault(x => x.Id == model.Id); if (obj != null) { double gt = 0; if (model.ChietKhau == 0) { gt = model.GiaBan; } else { gt = (model.GiaBan - ((model.GiaBan * model.ChietKhau) / 100)); } obj.ModelId = model.ModelId; obj.LicenseNumber = model.BienSo; obj.MachineNumber = model.SoMay; obj.ChassisNumber = model.SoKhung; obj.NV_TuVan = model.TuVanId; obj.Price = model.GiaBan; obj.Discount = model.ChietKhau; obj.Total = gt; obj.Note = model.GhiChu; obj.WorkTypeId = model.WorkTypeId; obj.GuaranteeNumber = model.SoBaoHanh; db.SaveChanges(); } else { result.IsSuccess = false; result.sms = "Số phiếu này đã tồn tại trong hệ thống."; } return(result); } }
public ActionResult Create(string ma) { string connnect = App_Global.AppGlobal.Connectionstring; ViewBag.Jobs = BLLJob.Instance.GetLookUp(connnect); ViewBag.Models = BLLModel.Instance.GetLookUp(connnect); ViewBag.Nhanviens = BLLUser.Instance.GetLookUp(connnect, 0); ViewBag.LoaiXes = BLLWorkType.Instance.GetLookUp(connnect); var dichVuModel = new SellReceiptModel(); dichVuModel.Ngay = DateTime.Now; int index = BLLSellReceipt.Instance.GetLastInDay(connnect, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0)); dichVuModel.SoPhieu = "BH-" + DateTime.Now.ToString("ddMMyy") + "-" + Helper.GPRO_Helper.Instance.getNumber(index); dichVuModel.Index = index; dichVuModel.MaKH = ma; if (!string.IsNullOrEmpty(ma)) { var kh = BLLKhachHang.Instance.GetByCode(connnect, ma); if (kh != null) { dichVuModel.Id = kh.Id; dichVuModel.Ten = kh.Ten; dichVuModel.GTinh = kh.GTinh; dichVuModel.NSinh = kh.NSinh; dichVuModel.DThoai = kh.DThoai; dichVuModel.DChi = kh.DChi; dichVuModel.TPho = kh.TPho; dichVuModel.Huyen = kh.Huyen; dichVuModel.Phuong = kh.Phuong; dichVuModel.Note = kh.Note; dichVuModel.JobId = kh.JobId; } else { ViewBag.alert = "Không tìm thấy thông tin khách hàng trong hệ thống."; } } return(View(dichVuModel)); }
public JsonResult Save(SellReceiptModel model) { return(Json(BLLSellReceipt.Instance.InsertOrUpdate(App_Global.AppGlobal.Connectionstring, model))); }
public ResponseModel InsertOrUpdate(string connectString, SellReceiptModel model) { var result = new ResponseModel(); result.IsSuccess = true; using (var db = new HMSEntities(connectString)) { if (!CheckExists(model, db)) { H_SellReceipt sellInfo; if (model.Id == 0) { var _khIds = (from x in db.H_KhachHang where !x.IsDeleted && x.Code.Trim().ToUpper() == model.MaKH.Trim().ToUpper() select x.Id).ToList(); if (_khIds.Count == 0) { result.IsSuccess = false; result.sms = "Khách hàng đã bị xóa hoặc không tồn tại trong hệ thống.!"; } else { double gt = 0; if (model.ChietKhau == 0) { gt = model.GiaBan; } else { gt = (model.GiaBan - ((model.GiaBan * model.ChietKhau) / 100)); } sellInfo = new H_SellReceipt() { KHId = _khIds[0], SoPhieu = model.SoPhieu, ModelId = model.ModelId, LicenseNumber = model.BienSo, MachineNumber = model.SoMay, ChassisNumber = model.SoKhung, NV_TuVan = model.TuVanId, Price = model.GiaBan, Discount = model.ChietKhau, Total = gt, Note = model.Note, CreatedDate = (model.Ngay.Year == 1 ? DateTime.Now : model.Ngay) }; db.H_SellReceipt.Add(sellInfo); } } else { sellInfo = db.H_SellReceipt.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id); if (sellInfo != null) { sellInfo.SoPhieu = model.SoPhieu; sellInfo.Price = model.GiaBan; sellInfo.Discount = model.ChietKhau; sellInfo.Total = model.ThanhTien; sellInfo.ModelId = model.ModelId; sellInfo.Note = model.Note; sellInfo.NV_TuVan = model.TuVanId; sellInfo.LicenseNumber = model.BienSo; sellInfo.MachineNumber = model.SoMay; sellInfo.ChassisNumber = model.SoKhung; } else { result.IsSuccess = false; result.sms = "Thông tin phiếu đã bị xóa hoặc không tồn tại trong hệ thống.!"; } } if (result.IsSuccess) { db.SaveChanges(); } } else { result.IsSuccess = false; result.sms = "Số phiếu này đã tồn tại trong hệ thống. Vui lòng nhập lại số phiếu khác."; } return(result); } }
//public SellReceiptModel GetByCode(string connectString,string code) //{ // using (var db = new HMSEntities(connectString)) // { // try // { // return (from x in db.H_SellReceipt // where !x.IsDeleted && x.Code.Trim().ToUpper() == code.Trim().ToUpper() // select new SellReceiptModel() // { // Id = x.Id, // Ma = x.Code, // Ten = x.Name, // NSinh = x.Birthday, // GTinh = x.Gender, // DThoai = x.Phone, // DChi = x.Address, // TPho = x.City, // Huyen = x.District, // Phuong = x.Wards, // strModel = (x.H_Model != null ? x.H_Model.Note : ""), // ModelId = x.ModelId, // Note = x.Note, // BienSo = x.LicenseNumber, // SoMay = x.MachineNumber, // SoSuon = x.ChassisNumber, // Km = x.Km, // NNghiep = (x.H_NgheNghiep != null ? x.H_NgheNghiep.Code : ""), // JobId = x.JobId // }).FirstOrDefault(); // } // catch (Exception ex) // { // throw ex; // } // } //} //public List<ModelSelectItem> GetLookUp(string connectString, int loaiNV) //{ // using (var db = new HMSEntities(connectString)) // { // //if (loaiNV != 0) // // return db.H_SellReceipt.Where(x => !x.IsDeleted && !x.H_LoaiNhanVien.IsDeleted && x.LoaiNVId == loaiNV).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList(); // return db.H_SellReceipt.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList(); // } //} public ResponseModel Insert(string connectString, SellReceiptModel model) { var result = new ResponseModel(); result.IsSuccess = true; using (var db = new HMSEntities(connectString)) { if (!CheckExists(model, db)) { H_SellReceipt sellInfo; double gt = 0; if (model.ChietKhau == 0) { gt = model.GiaBan; } else { gt = (model.GiaBan - ((model.GiaBan * model.ChietKhau) / 100)); } H_KhachHang khObj = null; if (model.Id == 0) { khObj = new H_KhachHang() { Code = model.Ma, Name = model.Ten, Gender = model.GTinh, Birthday = model.NSinh, Phone = model.DThoai, Address = model.DChi, City = model.TPho, District = model.Huyen, Wards = model.Phuong, JobId = model.JobId, Note = model.GhiChu }; khObj.H_SellReceipt = new List <H_SellReceipt>(); } sellInfo = new H_SellReceipt() { KHId = model.Id, H_KhachHang = khObj, SoPhieu = model.SoPhieu, ModelId = model.ModelId, LicenseNumber = model.BienSo, MachineNumber = model.SoMay, ChassisNumber = model.SoKhung, NV_TuVan = model.TuVanId, Price = model.GiaBan, Discount = model.ChietKhau, Total = gt, Note = model.Note, CreatedDate = (model.Ngay.Year == 1 ? DateTime.Now : model.Ngay), Index = model.Index, WorkTypeId = model.WorkTypeId, GuaranteeNumber = model.SoBaoHanh }; db.H_SellReceipt.Add(sellInfo); if (result.IsSuccess) { db.SaveChanges(); } } else { result.IsSuccess = false; result.sms = "Số phiếu này đã tồn tại trong hệ thống. Vui lòng nhập lại số phiếu khác."; } return(result); } }