Esempio n. 1
0
        /// <summary>
        /// view list of HoaDon with filter
        /// </summary>
        public ActionResult Index(HoaDonFilterModel filter, Pager pager, String todo, ViewMode viewMode = ViewMode.Default)
        {
            title = "Quản lý công nợ khách hàng";

            // default values
            if (filter.Mode == null || filter.Mode == HoaDonFilterModel.FilterByUserInfo)   // not in filter
            {
                if ((filter.Month == null) || filter.TrangThaiThu == HDNHD.Models.Constants.ETrangThaiThu.DaQuaHan)
                {
                    filter.Month = DateTime.Now.Month;
                    filter.Year  = DateTime.Now.Year;

                    if (filter.TrangThaiThu == null)
                    {
                        filter.TrangThaiThu = HDNHD.Models.Constants.ETrangThaiThu.ChuaNopTien;
                    }
                    if (filter.HinhThucThanhToan == null)
                    {
                        filter.HinhThucThanhToan = HDNHD.Models.Constants.EHinhThucThanhToan.TienMat;
                    }
                }

                // set selected to, quan huyen = nhanVien's to, quan huyen
                if (nhanVien != null && filter.QuanHuyenID == null)
                {
                    filter.NhanVienID = nhanVien.NhanvienID;
                    filter.ToID       = nhanVien.ToQuanHuyenID;

                    var to = toRepository.GetByID(nhanVien.ToQuanHuyenID ?? 0);
                    if (to != null)
                    {
                        filter.QuanHuyenID = to.QuanHuyenID;
                    }
                }
            }

            // query items
            var items = hoaDonRepository.GetAllHoaDonModel(true); // đã in

            items = filter.ApplyFilter(items);

            ViewBag.TongSoTienTrenHoaDon = items.Sum(m => m.SoTienTrenHoaDon) ?? 0;
            ViewBag.TongSoTienPhaiNop    = items.Sum(m => m.SoTienNopTheoThang.SoTienPhaiNop) ?? 0;
            ViewBag.TongSoTienDaNop      = items.Sum(m => m.SoTienNopTheoThang.SoTienDaThu) ?? 0;
            ViewBag.TongDuCo             = items.Where(m => m.DuCo != null).Sum(m => m.DuCo.SoTienDu) ?? 0;
            ViewBag.TongDuNo             = items.Sum(m => m.DuNo) ?? 0;

            if (viewMode == ViewMode.Excel)
            {
                return(ExcelResult("IndexExport", items.ToList()));
            }

            items = pager.ApplyPager(items);

            #region view data
            ViewBag.NhanVien = nhanVien;
            ViewBag.Filter   = filter;
            ViewBag.Pager    = pager;
            ViewBag.ToDo     = todo; // actions
            #endregion
            return(View(items.ToList()));
        }