view for Dispatches view and Wrapping filtering criteria objects
        /// <summary>
        /// Gets the distribution report.
        /// </summary>
        /// <param name="hubID">The hub ID.</param>
        /// <param name="distributionViewModel">The distribution view model.</param>
        /// <returns></returns>
        public List<DistributionRows> GetDistributionReport(int hubID, DistributionViewModel distributionViewModel)
        {
            var dbDistributionReport = _unitOfWork.ReportRepository.RPT_Distribution(hubID).ToList();

            if (distributionViewModel.PeriodId.HasValue && distributionViewModel.PeriodId != 0)
            {
                dbDistributionReport = dbDistributionReport.Where(p => p.Quarter == distributionViewModel.PeriodId.Value).ToList();
            }
            if (distributionViewModel.ProgramId.HasValue && distributionViewModel.ProgramId != 0)
            {
                dbDistributionReport = dbDistributionReport.Where(p => p.ProgramID == distributionViewModel.ProgramId.Value).ToList();
            }
            if (distributionViewModel.AreaId.HasValue && distributionViewModel.AreaId != 0)
            {
                dbDistributionReport = dbDistributionReport.Where(p => p.RegionID == distributionViewModel.AreaId.Value).ToList();
            }

            return (from t in dbDistributionReport
                    //  group t by new { t.BudgetYear }
                    //      into b
                    select new DistributionRows()
                    {
                        BudgetYear = t.PeriodYear,
                        Program = t.ProgramName,
                        DistributedAmount = t.DispatchedQuantity.Value,
                        Month = Convert.ToString(t.PeriodMonth),
                        Quarter = t.Quarter.Value,
                        Region = t.RegionName
                    }).ToList();
        }
        public ActionResult DistributionReport()
        {
            DistributionViewModel newDistributionViewModel = new DistributionViewModel();
            newDistributionViewModel.PeriodId = (DateTime.Now.Month - 1/3) + 1;// current quarter by default
            MasterReportBound report = GetDistributionReportPivot(newDistributionViewModel);
            BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name);
            var codes=ConstantsService.GetAllCodes();
            var commodityTypes=_commodityTypeService.GetAllCommodityTypeForReprot();
            var programs=_programService.GetAllProgramsForReport();
            var stores=_hubService.GetAllStoreByUser(user);
            var areas=_adminUnitService.GetAllAreasForReport();
            var bidRefs=_dispatchAllocationService.GetAllBidRefsForReport();
            var viewModel = new DistributionViewModel(codes,commodityTypes,programs,stores,areas,bidRefs);
            ViewBag.Filters = viewModel;

            return View(report);
        }
 public ActionResult DistributionReportViewerExportTo(DistributionViewModel distributionViewModel)
 {
     //DRMFSS.Web.Reports.MasterReportBound rep = GetDistributionReport();
     MasterReportBound report = GetDistributionReportPivot(distributionViewModel);
     return DevExpress.Web.Mvc.ReportViewerExtension.ExportTo(report);
 }
        public MasterReportBound GetDistributionReportPivot(DistributionViewModel distributionViewModel)
        {
            List<DRMFSS.BLL.ViewModels.Report.Data.DistributionReport> reports = new List<BLL.ViewModels.Report.Data.DistributionReport>();
            DRMFSS.BLL.ViewModels.Report.Data.DistributionReport distribution = new BLL.ViewModels.Report.Data.DistributionReport();
            BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name);

            distribution.PreparedBy = user.GetFullName();
            distribution.HubName = user.DefaultHub.HubNameWithOwner;
            distribution.ReportCode = DateTime.Now.ToString();
            distribution.ReportDate = DateTime.Now;
            distribution.ReportName = "DistributionReport";
            distribution.ReportTitle = "Distribution Report";
            distribution.Rows = new List<DistributionRows>();

            distribution.Rows = _transactionService.GetDistributionReport(user.DefaultHub.HubID, distributionViewModel);
             //   new List<DistributionRows>();
            //for (int i = 1; i < 5; i++)
            //{
            //    DistributionRows r = new DistributionRows();
            //    r.BudgetYear = DateTime.Now.Year;
            //    r.Region = (i % 2 == 0) ? "Amhara" : "Benshangul";
            //    r.Program = "Program " + i.ToString();
            //    r.DistributedAmount = i * decimal.Parse("2340.43674") * 45;
            //    int month = i;
            //    if (month == 0)
            //        month++;
            //    r.Month = month.ToString();
            //    r.Quarter = (i % 3 > 0) ? (i / 3) + 1 : i / 3;
            //    distribution.Rows.Add(r);
            //}

            reports.Add(distribution);

            DRMFSS.Web.Reports.DistributionReportPivot rpt = new Web.Reports.DistributionReportPivot();
            rpt.xrPivotGrid1.DataSource = reports[0].Rows;
            MasterReportBound report = new MasterReportBound() { Name = "Distribution Report - " + DateTime.Now.ToShortDateString(), DataSource = reports };
            report.rptSubReport.ReportSource = rpt;
            return report;
        }
 public ActionResult DistributionReportPartial(DistributionViewModel distributionViewModel)
 {
     MasterReportBound report = GetDistributionReportPivot(distributionViewModel);
     return PartialView("DistributionReportPartial", report);
 }