public InventoryResponseModel GetInventoryDetailById(long inventoryId) { var inventoryModel = new InventoryResponseModel(); var inventoryDetail = _inventoryRepository.GetInventoryDetailById(inventoryId); if (inventoryDetail == null) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Inventarielista saknas."); } var webUrl = ConfigurationManager.AppSettings["WebUrl"] + "/"; inventoryModel.Id = inventoryDetail.Id; inventoryModel.BrandName = inventoryDetail.BrandName; inventoryModel.Name = inventoryDetail.Name; inventoryModel.Price = inventoryDetail.OutPriceIncVat; inventoryModel.Description = inventoryDetail.Specification; inventoryModel.CreatedBy = inventoryDetail.CreatedBy; inventoryModel.ImagePath = !string.IsNullOrEmpty(inventoryDetail.ImagePath) ? inventoryDetail.ImagePath.Replace("~/", webUrl) : null; inventoryModel.InventoryCode = inventoryDetail.InventoryCode; inventoryDetail.REA = inventoryDetail.REA; //inventoryModel.TerminalId = inventoryDetail.TerminalId; return(inventoryModel); }
// lấy danh sách toàn bộ Phiếu Kiểm kê (lọc theo thuốc và ngày tìm kiếm nếu có) public InventoryResponseModel GetInventoryList(String maNhaThuoc, int thuocId, DateTime?fromDate, DateTime?toDate) { var phieuKiemKeRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKe> >().GetAll(); var phieuKiemKeChiTietRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKeChiTiet> >().GetAll(); var userProfileRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, UserProfile> >().GetAll(); // cau query de lay danh sach phieu kiem ke theo ma Nha thuoc var query = from pkk in phieuKiemKeRepo join up in userProfileRepo on pkk.CreatedBy_UserId equals up.UserId join pkkct in phieuKiemKeChiTietRepo on pkk.MaPhieuKiemKe equals pkkct.PhieuKiemKe_MaPhieuKiemKe where (pkk.NhaThuoc_MaNhaThuoc == maNhaThuoc && pkk.RecordStatusID == (byte)RecordStatus.Activated && pkkct.RecordStatusID == (byte)RecordStatus.Activated) group new { pkk.Created, pkk.DaCanKho, pkkct.MaPhieuKiemKeCt, up.TenDayDu } by pkk.MaPhieuKiemKe into g select new InventoryDetailModel { Id = g.Key, CreateTime = g.Select(x => x.Created.Value).FirstOrDefault(), DaCanKho = g.Select(x => x.DaCanKho).FirstOrDefault(), FullName = g.Select(x => x.TenDayDu).FirstOrDefault(), DrugQuantity = g.Select(x => x.MaPhieuKiemKeCt).Distinct().Count() }; // loc theo Id cua thuoc tim kiem if (thuocId > 0) { query = from q in query join pkkct in phieuKiemKeChiTietRepo on q.Id equals pkkct.PhieuKiemKe_MaPhieuKiemKe where (pkkct.Thuoc_ThuocId == thuocId) select q; } // Lọc theo tham số fromDate và toDate nếu có if (fromDate != null && toDate != null) { query = query.Where(x => x.CreateTime >= fromDate && x.CreateTime < toDate); } // trả về danh sách phiếu và order theo thời gian tạo phiếu giảm dần InventoryResponseModel inventoryResponseModel = new InventoryResponseModel { InventoryDetailModels = query.OrderByDescending(x => x.CreateTime).ToList() }; return(inventoryResponseModel); }
// lấy danh sách thuốc chưa được Kiểm kê public InventoryResponseModel GetDrugsHaveNotInventoried(String maNhaThuoc, DateTime?fromDate, DateTime?toDate) { var phieuKiemKeRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKe> >().GetAll(); var phieuKiemKeChiTietRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, PhieuKiemKeChiTiet> >().GetAll(); var drugRepo = _dataFilterService.GetValidDrugs(maNhaThuoc); var donViTinhRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, DonViTinh> >().GetAll(); var nhomThuocRepo = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, NhomThuoc> >().GetAll(); // lấy danh sách thuốc thuộc các phiếu Kiêm kê đã tạo, lọc theo thời gian tạo phiếu (nếu có) var thuocDaKiemKeQuery = from pkk in phieuKiemKeRepo join pkkct in phieuKiemKeChiTietRepo on pkk.MaPhieuKiemKe equals pkkct.PhieuKiemKe_MaPhieuKiemKe where (pkk.NhaThuoc_MaNhaThuoc == maNhaThuoc && pkk.RecordStatusID == (byte)RecordStatus.Activated && pkkct.RecordStatusID == (byte)RecordStatus.Activated && ((fromDate == null && toDate == null) || (pkk.Created >= fromDate && pkk.Created < toDate) )) select pkkct.Thuoc_ThuocId; // danh sách thuốc thuộc các phiếu Kiêm kê đã tạo var thuocDaKiemKes = thuocDaKiemKeQuery.Distinct().ToList(); // Thuốc chưa kiểm kê là những thuốc KHÔNG thuộc danh sách trên var query = from dr in drugRepo join dvt in donViTinhRepo on dr.DonViXuatLe_MaDonViTinh equals dvt.MaDonViTinh join nt in nhomThuocRepo on dr.NhomThuoc_MaNhomThuoc equals nt.MaNhomThuoc where (!thuocDaKiemKes.Contains(dr.ThuocId) && dvt.MaNhaThuoc == maNhaThuoc && nt.MaNhaThuoc == maNhaThuoc) select new ThuocModel { ThuocId = dr.ThuocId, TenNhomThuoc = nt.TenNhomThuoc, MaThuoc = dr.MaThuoc, TenThuoc = dr.TenThuoc, TenDonViTinh = dvt.TenDonViTinh, }; InventoryResponseModel inventoryResponseModel = new InventoryResponseModel { ThuocModels = query.ToList() }; return(inventoryResponseModel); }
public async Task <IActionResult> Get(Guid?id) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new GetInventoryServiceModel { Id = id.Value, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new GetInventoryModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var inventoryProduct = await this.inventoriesService.GetAsync(serviceModel); if (inventoryProduct != null) { var response = new InventoryResponseModel { Id = inventoryProduct.Id, ProductId = inventoryProduct.ProductId, ProductName = inventoryProduct.ProductName, ProductSku = inventoryProduct.ProductSku, WarehouseId = inventoryProduct.WarehouseId.Value, WarehouseName = inventoryProduct.WarehouseName, Quantity = inventoryProduct.Quantity, AvailableQuantity = inventoryProduct.AvailableQuantity, RestockableInDays = inventoryProduct.RestockableInDays, ExpectedDelivery = inventoryProduct.ExpectedDelivery, LastModifiedDate = inventoryProduct.LastModifiedDate, CreatedDate = inventoryProduct.CreatedDate, }; return(this.StatusCode((int)HttpStatusCode.OK, response)); } else { return(this.StatusCode((int)HttpStatusCode.NotFound)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }