public IList <BaoCaoDatHangViewModel> ListView(string nhanVienCode, DateTime dateFrom, DateTime dateTo)
        {
            IQueryable <PhieuDatHang>     danhSachPhieuDatHang = _phieuDatHangRepo.GetAll();
            List <BaoCaoDatHangViewModel> allForManager        = new List <BaoCaoDatHangViewModel>();

            if ((!(dateFrom == default(DateTime))) && (!(dateTo == default(DateTime))))
            {
                allForManager = (from phieuDatHang in danhSachPhieuDatHang
                                 join nhanVien in _nhanVienRepo.GetAll()
                                 on phieuDatHang.MaNhanVien equals nhanVien.MaNhanVien
                                 where phieuDatHang.NgayDat >= dateFrom.Date && phieuDatHang.NgayDat <= dateTo.Date
                                 group phieuDatHang by phieuDatHang.NgayDat into pgroup
                                 select new
                {
                    NgayDat = pgroup.Key,
                    SoDonHang = pgroup.Count(),
                    TongTien = pgroup.Sum(phieuDatHang => phieuDatHang.TongTien)
                }).AsEnumerable().Select(x => new BaoCaoDatHangViewModel()
                {
                    ngayDat   = x.NgayDat,
                    soDonHang = x.SoDonHang,
                    tongTien  = x.TongTien
                }).OrderBy(x => x.ngayDat).ToList();
                return(allForManager);
            }
            else
            {
                allForManager = (from phieuDatHang in danhSachPhieuDatHang
                                 join nhanVien in _nhanVienRepo.GetAll()
                                 on phieuDatHang.MaNhanVien equals nhanVien.MaNhanVien
                                 where phieuDatHang.NgayDat.Month == DateTime.Now.Month && phieuDatHang.NgayDat.Year == DateTime.Now.Year
                                 group phieuDatHang by phieuDatHang.NgayDat into pgroup
                                 select new
                {
                    NgayDat = pgroup.Key,
                    SoDonHang = pgroup.Count(),
                    TongTien = pgroup.Sum(phieuDatHang => phieuDatHang.TongTien)
                }).AsEnumerable().Select(x => new BaoCaoDatHangViewModel()
                {
                    ngayDat   = x.NgayDat,
                    soDonHang = x.SoDonHang,
                    tongTien  = x.TongTien
                }).OrderBy(x => x.ngayDat).ToList();
                return(allForManager);
            }
        }
Beispiel #2
0
        public IList <PhieuDatHangViewModel> ListView(string nhanVienCode)
        {
            var phieuBanHang = (new PhieuBanHangRepository(dbContext)).GetAll();
            IQueryable <PhieuDatHang>    danhSachPhieuDatHang = _phieuDatHangRepo.GetAll();
            List <PhieuDatHangViewModel> all           = new List <PhieuDatHangViewModel>();
            List <PhieuDatHangViewModel> allForManager = new List <PhieuDatHangViewModel>();

            if (_nhanVienBus.layMaChucVu(nhanVienCode) != 4 &&
                _nhanVienBus.layMaChucVu(nhanVienCode) != 3)
            {
                return(all);
            }

            if (_nhanVienBus.layMaChucVu(nhanVienCode) == 4)
            {
                all = (from phieuDatHang in danhSachPhieuDatHang
                       where phieuDatHang.TrangThai == true
                       select new
                {
                    SoPhieuDatHang = phieuDatHang.SoPhieuDatHang,
                    NgayDat = phieuDatHang.NgayDat,
                    MaNhanVien = phieuDatHang.MaNhanVien,
                    TenKhachHang = phieuDatHang.TenKhachHang,
                    SoDienThoai = phieuDatHang.SoDienThoai,
                    DiaChi = phieuDatHang.Diachi,
                    Email = phieuDatHang.Email,
                    TongTien = phieuDatHang.TongTien,
                    HinhThucThanhToan = phieuDatHang.HinhThucThanhToan,
                    GhiChu = phieuDatHang.Ghichu,
                    NgayGiao = phieuDatHang.NgayGiao,
                    DaXacNhan = phieuDatHang.DaXacNhan,
                    DaThanhToan = phieuDatHang.DaThanhToan,
                    TrangThai = phieuDatHang.TrangThai,
                }).AsEnumerable().Select(x => new PhieuDatHangViewModel()
                {
                    soPhieuDatHang    = x.SoPhieuDatHang,
                    ngayDat           = x.NgayDat,
                    maNhanVien        = x.MaNhanVien,
                    tenKhachHang      = x.TenKhachHang,
                    soDienThoai       = x.SoDienThoai,
                    diaChi            = x.DiaChi,
                    email             = x.Email,
                    tongTien          = x.TongTien,
                    hinhThucThanhToan = x.HinhThucThanhToan,
                    ghiChu            = x.GhiChu,
                    ngayGiao          = x.NgayGiao,
                    daXacNhan         = x.DaXacNhan,
                    daThanhToan       = x.DaThanhToan,
                    trangThai         = x.TrangThai
                }).ToList();

                return(all);
            }
            else
            {
                allForManager = (from phieuDatHang in danhSachPhieuDatHang
                                 select new
                {
                    SoPhieuDatHang = phieuDatHang.SoPhieuDatHang,
                    NgayDat = phieuDatHang.NgayDat,
                    MaNhanVien = phieuDatHang.MaNhanVien,
                    TenKhachHang = phieuDatHang.TenKhachHang,
                    SoDienThoai = phieuDatHang.SoDienThoai,
                    DiaChi = phieuDatHang.Diachi,
                    Email = phieuDatHang.Email,
                    TongTien = phieuDatHang.TongTien,
                    HinhThucThanhToan = phieuDatHang.HinhThucThanhToan,
                    GhiChu = phieuDatHang.Ghichu,
                    NgayGiao = phieuDatHang.NgayGiao,
                    DaXacNhan = phieuDatHang.DaXacNhan,
                    DaThanhToan = phieuDatHang.DaThanhToan
                }).AsEnumerable().Select(x => new PhieuDatHangViewModel()
                {
                    soPhieuDatHang    = x.SoPhieuDatHang,
                    ngayDat           = x.NgayDat,
                    maNhanVien        = x.MaNhanVien,
                    tenKhachHang      = x.TenKhachHang,
                    soDienThoai       = x.SoDienThoai,
                    diaChi            = x.DiaChi,
                    email             = x.Email,
                    tongTien          = x.TongTien,
                    hinhThucThanhToan = x.HinhThucThanhToan,
                    ghiChu            = x.GhiChu,
                    ngayGiao          = x.NgayGiao,
                    daXacNhan         = x.DaXacNhan,
                    daThanhToan       = x.DaThanhToan
                }).ToList();

                return(allForManager);
            }
        }