public JsonResult GetThuocsWithHetHan(string sType, string sNhomThuocId, string sTenThuoc) { var result = new List <CanhBaoHetHan>(); var lstThuoc = new List <Thuoc>(); CanhBaoHetHan cbhh; var manhathuoc = this.GetNhaThuoc().MaNhaThuoc; switch (sType) { case "1": { lstThuoc = unitOfWork.ThuocRepository.GetMany(x => x.NhaThuoc.MaNhaThuoc == manhathuoc && x.RecordStatusID == (byte)RecordStatus.Activated).ToList(); } break; case "2": { lstThuoc = unitOfWork.ThuocRepository.GetMany(x => x.RecordStatusID == (byte)RecordStatus.Activated && x.NhaThuoc.MaNhaThuoc == manhathuoc && x.NhomThuoc.MaNhomThuoc == int.Parse(sNhomThuocId)).ToList(); } break; case "3": { lstThuoc = unitOfWork.ThuocRepository.GetMany(x => x.RecordStatusID == (byte)RecordStatus.Activated && x.NhaThuoc.MaNhaThuoc == manhathuoc && x.TenThuoc.Contains(sTenThuoc)).ToList(); } break; } Setting setting = unitOfWork.SettingRepository.Get(c => c.MaNhaThuoc == manhathuoc && c.Key == Constants.Settings.SoNgayHetHan).FirstOrDefault(); if (setting == null) { setting = new Setting() { Value = "0" }; } foreach (Thuoc item in lstThuoc) { cbhh = new CanhBaoHetHan(); cbhh.ThuocId = item.ThuocId; cbhh.MaThuoc = item.MaThuoc; cbhh.TenThuoc = item.TenThuoc; cbhh.SoLuong = TonKho(item.ThuocId).ToString("#,##0"); cbhh.Han = string.Empty; cbhh.HangItGiaoDich = string.Empty; if (decimal.Parse(cbhh.SoLuong) < decimal.Parse(setting.Value)) { result.Add(cbhh); } } return(new JsonResult() { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult CanhBaoHangHetHan(int?page) { var manhathuoc = this.GetNhaThuoc().MaNhaThuoc; var list = new List <Med.Entity.Thuoc>(); var tenDonViTinhs = new Dictionary <int, string>(); var dataFilterService = IoC.Container.Resolve <IDataFilterService>(); list = dataFilterService.GetValidDrugs(manhathuoc).Where(i => i.HanDung.HasValue).ToList(); tenDonViTinhs = dataFilterService.GetValidUnits(manhathuoc) .Select(i => new { i.MaDonViTinh, i.TenDonViTinh }).ToDictionary(i => i.MaDonViTinh, i => i.TenDonViTinh); var listCanhBaoHetHan = new List <CanhBaoHetHan>(); var songaysaphethan = unitOfWork.SettingRepository.Get(c => c.MaNhaThuoc == manhathuoc && c.Key == Constants.Settings.SoNgayHetHan).FirstOrDefault().Value; var handung = DateTime.Now.AddDays(int.Parse(songaysaphethan) - 1).Date; foreach (var item in list) { if (item.HanDung.Value.Date <= handung) { var thuoc = new CanhBaoHetHan() { ThuocId = item.ThuocId, MaThuoc = item.MaThuoc, TenThuoc = item.TenThuoc, HangItGiaoDich = string.Empty, SoLuong = TonKho(item.ThuocId).ToString("#,##0"), Han = item.HanDung.Value.ToString("dd/MM/yyyy") }; if (tenDonViTinhs.ContainsKey(item.DonViXuatLe_MaDonViTinh.Value)) { thuoc.DonVi = tenDonViTinhs[item.DonViXuatLe_MaDonViTinh.Value]; } listCanhBaoHetHan.Add(thuoc); } } ViewBag.NhomThuoc = unitOfWork.NhomThuocRepository.Get(c => c.MaNhaThuoc == manhathuoc).ToList(); if (listCanhBaoHetHan != null) { Session["hethan"] = listCanhBaoHetHan; } const int pageSize = 10; int pageNumber = (page ?? 1); return(View(listCanhBaoHetHan.OrderBy(c => c.TenThuoc).ToPagedList(pageNumber, pageSize))); }
public void AddHetHan(int id) { var result = new CanhBaoHetHan(); var manhathuoc = this.GetNhaThuoc().MaNhaThuoc; if (id != null) { var item = unitOfWork.ThuocRepository.Get(x => x.ThuocId == id).FirstOrDefault(); result.ThuocId = item.ThuocId; result.MaThuoc = item.MaThuoc; result.TenThuoc = item.TenThuoc; result.SoLuong = TonKho(item.ThuocId).ToString("#,##0"); result.Han = string.Empty; var list = new List <CanhBaoHetHan>(); if (Session["hethan"] != null) { list = Session["hethan"] as List <CanhBaoHetHan>; } list.Add(result); Session["hethan"] = list; } }