public ActionResult DonorTotalSummaryOptions()
        {
            var m = new DonorTotalSummaryOptionsModel
            {
                StartDate          = DateTime.Today,
                NumberOfYears      = 5,
                MinimumMedianTotal = 100,
                Campus             = new CodeInfo("Campus0"),
                Fund = new CodeInfo("Fund"),
            };
            var customfunds = ContributionStatements.CustomFundSetSelectList();

            if (customfunds != null)
            {
                m.FundSet = new CodeInfo(null, customfunds);
            }
            return(View(m));
        }
Example #2
0
        public IEnumerable <SelectListItem> CustomFundsList()
        {
            var clist = ContributionStatements.CustomFundSetSelectList(CurrentDatabase);

            if (clist.IsNull())
            {
                return(null);
            }
            var q = from s in clist
                    select new SelectListItem
            {
                Value    = $"{s.Text}",
                Text     = s.Text,
                Selected = s.Text == (Selected.FundSet ?? "(not specified)")
            };
            var listItems = q.ToList();

            return(listItems);
        }
Example #3
0
        public ActionResult DonorTotalSummaryOptions()
        {
            var model = new DonorTotalSummaryOptionsModel
            {
                StartDate          = DateTime.Today,
                NumberOfYears      = 5,
                MinimumMedianTotal = 100,
                Campus             = CreateCodeInfoForField("Campus0"),
                Fund = CreateCodeInfoForField("Fund")
            };

            var customFundsList = ContributionStatements.CustomFundSetSelectList(CurrentDatabase);

            if (customFundsList != null)
            {
                model.FundSet = new CodeInfo(null, customFundsList);
            }

            return(View(model));
        }
        public ActionResult ContributionStatements(DateTime?fromDate, DateTime?endDate, string startswith, string sort, int?tagid, bool excludeelectronic, string customstatement = null, bool exportcontributors = false)
        {
            if (!fromDate.HasValue || !endDate.HasValue)
            {
                return(Content("<h3>Must have a Startdate and Enddate</h3>"));
            }

            if (fromDate.Value > endDate.Value)
            {
                return(Content("<h3>The Startdate must be earlier than the Enddate</h3>"));
            }

            var spec = ContributionStatementsExtract.GetStatementSpecification(CurrentDatabase, customstatement);

            if (!startswith.HasValue())
            {
                startswith = null;
            }
            var        noaddressok = !CurrentDatabase.Setting("RequireAddressOnStatement", true);
            const bool useMinAmt   = true;

            if (tagid == 0)
            {
                tagid = null;
            }
            var qc           = APIContribution.Contributors(CurrentDatabase, fromDate.Value, endDate.Value, 0, 0, 0, spec.Funds, noaddressok, useMinAmt, startswith, sort, tagid: tagid, excludeelectronic: excludeelectronic);
            var contributors = qc.ToList();

            if (exportcontributors)
            {
                return(ExcelExportModel.ToDataTable(contributors).ToExcel("Contributors.xlsx"));
            }
            var statementsRun = new ContributionsRun
            {
                Started   = DateTime.Now,
                Count     = contributors.Count,
                Processed = 0,
                UUId      = Guid.NewGuid(),
                UserId    = CurrentDatabase.UserId,
            };

            CurrentDatabase.ContributionsRuns.InsertOnSubmit(statementsRun);
            CurrentDatabase.SubmitChanges();
            var cul  = CurrentDatabase.Setting("Culture", "en-US");
            var host = CurrentDatabase.Host;
            var id   = $"{statementsRun.UUId:n}";

            var output = Output(host, id);

            if (tagid == 0)
            {
                tagid = null;
            }

            var showCheckNo = CurrentDatabase.Setting("RequireCheckNoOnStatement");
            var showNotes   = CurrentDatabase.Setting("RequireNotesOnStatement");
            var statements  = new ContributionStatements
            {
                UUId     = Guid.Parse(id),
                FromDate = fromDate.Value,
                ToDate   = endDate.Value,
                typ      = 3,
                //TODO: once we switch to entirely html-based statement templates we won't need to check for these options
                NumberOfColumns = showCheckNo || showNotes ? 1 : 2,
                ShowCheckNo     = showCheckNo,
                ShowNotes       = showNotes,
            };

            if (CurrentDatabase.Setting("UseNewStatementsFormat"))
            {
                // Must do this before entering the background worker because it relies on the Application context
                statements.GetConverter();
            }

            var elmah = Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current);

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
                Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);
                try
                {
                    var m = new ContributionStatementsExtract(host, fromDate.Value, endDate.Value, output, startswith, sort, tagid, excludeelectronic)
                    {
                        id = id
                    };
                    m.DoWork(statements, spec, contributors);
                }
                catch (Exception e)
                {
                    elmah.Log(new Elmah.Error(e));
                    var db        = CMSDataContext.Create(host);
                    var run       = db.ContributionsRuns.Single(c => c.UUId == Guid.Parse(id));
                    run.Error     = e.Message;
                    run.Completed = DateTime.Now;
                    db.SubmitChanges();
                }
            });
            return(Redirect($"/Statements/Progress/{id}"));
        }