/// <summary>
        /// Generate PhieuNhap based on PhieuKiemKe
        /// </summary>
        /// <param name="lstItems"></param>
        /// <returns></returns>
        private int GeneratePhieuNhap(IEnumerable <PhieuKiemKeChiTiet> lstItems)
        {
            var phieuNhap = new PhieuNhap
            {
                MaPhieuNhap = 0,
                //MaNhaThuoc = this.GetNhaThuoc().MaNhaThuoc,
                //MaNguoiTao = WebSecurity.GetCurrentUserId,
                //MaLoaiXuatNhap = 3,
                //MaKhachHang = 1,
                //NgayTao = DateTime.Today,
                NgayNhap          = DateTime.Today,
                DaTra             = 0,
                VAT               = 0,
                SoPhieuNhap       = db.PhieuNhaps.Where(x => x.NhaThuoc.MaNhaThuoc == this.GetNhaThuoc().MaNhaThuoc).OrderByDescending(x => x.SoPhieuNhap).FirstOrDefault().SoPhieuNhap,
                PhieuNhapChiTiets = new List <PhieuNhapChiTiet>()
            };

            foreach (var nhap in lstItems)
            {
                phieuNhap.PhieuNhapChiTiets.Add(new PhieuNhapChiTiet()
                {
                    //ThuocId = nhap.ThuocId,
                    //MaNhaThuoc = this.GetNhaThuoc().MaNhaThuoc,
                    // MaDonViTinh = db.Thuocs.FirstOrDefault(x => x.ThuocId == nhap.ThuocId).DonViXuatLe.MaDonViTinh,
                    SoLuong = nhap.ThucTe.HasValue ? nhap.ThucTe.Value - nhap.TonKho : nhap.TonKho * -1,
                    //HanDung = db.PhieuNhapChiTiets.Where(x => x.MaNhaThuoc == this.GetNhaThuoc().MaNhaThuoc).OrderByDescending(x => x.HanDung).FirstOrDefault().HanDung,
                    MaPhieuNhapCt = 0
                });
            }
            db.PhieuNhaps.Add(phieuNhap);
            db.SaveChanges();

            return(phieuNhap.MaPhieuNhap);
        }