Пример #1
0
        public IActionResult XemDanhSachHoaDonYeuCauHuy()
        {
            var dbContext = new shopContext();
            // lấy thông tin trong bảng hóa đơn
            var hoadon = (from hd in dbContext.Hoadon
                          join ps in dbContext.Phiship
                          on hd.PhiShipId equals ps.PhiShipId
                          join kh in dbContext.Khachhang
                          on hd.KhachHangId equals kh.KhachHangId
                          join nv in dbContext.Nhanvien
                          on hd.NhanVienId equals nv.NhanVienId into x
                          from subnv in x.DefaultIfEmpty()
                          where hd.TrangThai == "Yêu cầu hủy"
                          select new{
                hoadonid = hd.HoaDonId,
                ngaytao = hd.NgayTao,
                ngaygiao = hd.NgayGiao,
                sonha = hd.SoNha,
                quan = hd.Quan,
                phiship = ps.ChiPhi,
                thanhtoan = hd.TongTienThanhToan,
                trangthai = hd.TrangThai,
                nhanvien = subnv.HoTen,
                khachhang = kh.HoTen,
                tennguoinhan = hd.TenNguoiNhan,
                sdt = hd.Sdt,
                tienchuaship = hd.TongTienChuaShip,
                tiengiamgia = hd.TienGiamGia
            });
            List <Hoadon> ListHD = new List <Hoadon>();

            foreach (var item in hoadon)
            {
                Hoadon    hd = new Hoadon();
                Nhanvien  nv = new Nhanvien();
                Khachhang kh = new Khachhang();
                Phiship   ps = new Phiship();
                hd.HoaDonId          = item.hoadonid;
                hd.NgayTao           = item.ngaytao;
                hd.NgayGiao          = item.ngaygiao;
                hd.SoNha             = item.sonha;
                hd.Quan              = item.quan;
                ps.ChiPhi            = item.phiship;
                hd.TongTienThanhToan = item.thanhtoan;
                hd.TrangThai         = item.trangthai;
                nv.HoTen             = item.nhanvien;
                kh.HoTen             = item.khachhang;
                hd.TenNguoiNhan      = item.tennguoinhan;
                hd.Sdt = item.sdt;
                hd.TongTienChuaShip = item.tienchuaship;
                hd.TienGiamGia      = item.tiengiamgia;
                hd.NhanVien         = nv;
                hd.KhachHang        = kh;
                hd.PhiShip          = ps;
                ListHD.Add(hd);
            }
            ViewBag.dsYeuCauHuy = ListHD;
            return(View());
        }
Пример #2
0
        public IActionResult InHoaDon(int id)
        {
            var dbContext = new shopContext();
            var hoadon    = (from hd in dbContext.Hoadon
                             join ps in dbContext.Phiship
                             on hd.PhiShipId equals ps.PhiShipId
                             join kh in dbContext.Khachhang
                             on hd.KhachHangId equals kh.KhachHangId
                             join nv in dbContext.Nhanvien
                             on hd.NhanVienId equals nv.NhanVienId
                             where hd.HoaDonId == id
                             select new{
                idhd = hd.HoaDonId,
                TenKhachHang = kh.HoTen,
                quan = hd.Quan,
                ngaytao = hd.NgayTao,
                TenNguoiNhan = hd.TenNguoiNhan,
                soNha = hd.SoNha,
                sdt = hd.Sdt,
                phiship = ps.ChiPhi,
                tienkhuyenmai = hd.TienGiamGia,
                TongTienChuaShip = hd.TongTienChuaShip,
                tongcong = hd.TongTienThanhToan
            }).ToList();
            List <Hoadon> DSHoaDon = new List <Hoadon>();

            foreach (var item in hoadon)
            {
                Hoadon hd = new Hoadon();
                hd.HoaDonId          = item.idhd;
                hd.NgayTao           = item.ngaytao;
                hd.TenNguoiNhan      = item.TenNguoiNhan;
                hd.SoNha             = item.soNha;
                hd.Sdt               = item.sdt;
                hd.TienGiamGia       = item.tienkhuyenmai;
                hd.TongTienChuaShip  = item.TongTienChuaShip;
                hd.TongTienThanhToan = item.tongcong;
                hd.Quan              = item.quan;
                Phiship ps = new Phiship();
                ps.ChiPhi = item.phiship;
                Khachhang kh = new Khachhang();
                kh.HoTen     = item.TenKhachHang;
                hd.KhachHang = kh;
                hd.PhiShip   = ps;
                DSHoaDon.Add(hd);
            }
            // ViewBag.hoadon = DSHoaDon;
            var chitiet = (from ct in dbContext.Chitiethoadon
                           join hd in dbContext.Hoadon
                           on ct.HoaDonId equals hd.HoaDonId
                           join sp in dbContext.Sanpham
                           on ct.SanPhamId equals sp.SanPhamId
                           join kt in dbContext.Kichthuoc
                           on ct.KichThuocId equals kt.KichThuocid
                           join ha in dbContext.Hinhanh
                           on sp.HinhAnhId equals ha.HinhAnhId
                           join km in dbContext.Khuyenmai
                           on sp.KhuyenMaiId equals km.KhuyenMaiId into x
                           from subnv in x.DefaultIfEmpty()
                           where hd.HoaDonId == id
                           select new{
                tensp = sp.TenSanPham,
                hinhanh = ha.TenFile,
                gia = ct.TongTien,
                soluong = ct.SoLuong,
                giam = subnv.PhanTramGiam * sp.GiaBanLe,
                tamtinh = ct.TongSauKm,
                tenKichThuoc = kt.TenKichThuoc
            }).ToList();
            List <Chitiethoadon> DSChiTiet = new List <Chitiethoadon>();

            foreach (var item in chitiet)
            {
                Sanpham       sp = new Sanpham();
                Chitiethoadon ct = new Chitiethoadon();
                Hinhanh       ha = new Hinhanh();
                Kichthuoc     kt = new Kichthuoc();
                sp.TenSanPham    = item.tensp;
                ha.TenFile       = item.hinhanh;
                ct.TongTien      = item.gia;
                ct.SoLuong       = item.soluong;
                ct.TienKhuyenMai = item.giam;
                ct.TongSauKm     = item.tamtinh;
                kt.TenKichThuoc  = item.tenKichThuoc;
                sp.HinhAnh       = ha;
                ct.SanPham       = sp;
                ct.KichThuoc     = kt;
                DSChiTiet.Add(ct);
            }

            var hoadon_cthd = new Tuple <List <Hoadon>, List <Chitiethoadon> >(DSHoaDon, DSChiTiet);

            return(new ViewAsPdf(hoadon_cthd));
        }