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>")); } var runningtotals = new ContributionsRun { Started = DateTime.Now, Count = 0, Processed = 0 }; var cs = Models.Report.ContributionStatements.GetStatementSpecification(customstatement); if (!startswith.HasValue()) { startswith = null; } if (exportcontributors) { var db = DbUtil.Db; var noaddressok = !db.Setting("RequireAddressOnStatement", true); const bool useMinAmt = true; if (tagid == 0) { tagid = null; } var qc = APIContribution.Contributors(db, fromDate.Value, endDate.Value, 0, 0, 0, cs.Funds, noaddressok, useMinAmt, startswith, sort, tagid: tagid, excludeelectronic: excludeelectronic); return(ExcelExportModel.ToDataTable(qc.ToList()).ToExcel("Contributors.xlsx")); } DbUtil.Db.ContributionsRuns.InsertOnSubmit(runningtotals); DbUtil.Db.SubmitChanges(); var cul = DbUtil.Db.Setting("Culture", "en-US"); var host = Util.Host; var output = Output(); if (tagid == 0) { tagid = null; } HostingEnvironment.QueueBackgroundWorkItem(ct => { Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cul); var m = new ContributionStatementsExtract(host, fromDate.Value, endDate.Value, output, startswith, sort, tagid, excludeelectronic); m.DoWork(cs); }); return(Redirect("/Statements/Progress")); }
public override void ExecuteResult(ControllerContext context) { var response = context.HttpContext.Response; response.ContentType = "application/pdf"; var filename = $"Statement-{ToDate:d}".SlugifyString("-", false); response.AddHeader("content-disposition", $"filename={filename}.pdf"); var cs = ContributionStatementsExtract.GetStatementSpecification(CurrentDatabase, statementType ?? "all"); var c = new ContributionStatements { FamilyId = FamilyId, FromDate = FromDate, PeopleId = PeopleId, SpouseId = SpouseId, ToDate = ToDate, typ = typ, //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 }; IEnumerable <ContributorInfo> q = null; switch (typ) { case 1: q = APIContribution.Contributors(CurrentDatabase, FromDate, ToDate, PeopleId, SpouseId, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 2: FamilyId = CurrentDatabase.People.Single(p => p.PeopleId == PeopleId).FamilyId; q = APIContribution.Contributors(CurrentDatabase, FromDate, ToDate, 0, 0, FamilyId, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 3: q = APIContribution.Contributors(CurrentDatabase, FromDate, ToDate, 0, 0, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; } c.Run(response.OutputStream, CurrentDatabase, q, cs); }
public override void ExecuteResult(ControllerContext context) { var response = context.HttpContext.Response; response.ContentType = "application/pdf"; response.AddHeader("content-disposition", "filename=foo.pdf"); var cs = ContributionStatements.GetStatementSpecification(statementType ?? "all"); if (showCheckNo || showNotes) { var c = new ContributionStatementsExtra { FamilyId = FamilyId, FromDate = FromDate, PeopleId = PeopleId, SpouseId = SpouseId, ToDate = ToDate, typ = typ, ShowCheckNo = showCheckNo, ShowNotes = showNotes }; IEnumerable <ContributorInfo> q = null; switch (typ) { case 1: q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, PeopleId, SpouseId, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 2: FamilyId = DbUtil.Db.People.Single(p => p.PeopleId == PeopleId).FamilyId; q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, 0, 0, FamilyId, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 3: q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, 0, 0, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; } c.Run(response.OutputStream, DbUtil.Db, q, cs); } else { var c = new ContributionStatements { FamilyId = FamilyId, FromDate = FromDate, PeopleId = PeopleId, SpouseId = SpouseId, ToDate = ToDate, typ = typ }; IEnumerable <ContributorInfo> q = null; switch (typ) { case 1: q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, PeopleId, SpouseId, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 2: FamilyId = DbUtil.Db.People.Single(p => p.PeopleId == PeopleId).FamilyId; q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, 0, 0, FamilyId, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; case 3: q = APIContribution.Contributors(DbUtil.Db, FromDate, ToDate, 0, 0, 0, cs.Funds, noaddressok, useMinAmt, singleStatement: singleStatement); break; } c.Run(response.OutputStream, DbUtil.Db, q, cs); } }
public void DoWork(ContributionStatements.StatementSpecification cs) { Db = DbUtil.Create(Host); DbUtil.Db.CommandTimeout = 1200; var noaddressok = !DbUtil.Db.Setting("RequireAddressOnStatement", true); showCheckNo = DbUtil.Db.Setting("RequireCheckNoOnStatement"); showNotes = DbUtil.Db.Setting("RequireNotesOnStatement"); const bool UseMinAmt = true; var qc = APIContribution.Contributors(DbUtil.Db, fd, td, 0, 0, 0, cs.Funds, noaddressok, UseMinAmt, StartsWith, Sort, tagid: TagId, excludeelectronic: ExcludeElectronic); var runningtotals = DbUtil.Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First(); runningtotals.Count = qc.Count(); DbUtil.Db.SubmitChanges(); if (showCheckNo || showNotes) { var c = new ContributionStatementsExtra { FromDate = fd, ToDate = td, typ = 3, ShowCheckNo = showCheckNo, ShowNotes = showNotes }; using (var stream = new FileStream(OutputFile, FileMode.Create)) { c.Run(stream, Db, qc, cs); } LastSet = c.LastSet(); var sets = c.Sets(); foreach (var set in sets) { using (var stream = new FileStream(Output(OutputFile, set), FileMode.Create)) { c.Run(stream, Db, qc, cs, set); } } runningtotals = DbUtil.Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First(); runningtotals.LastSet = LastSet; runningtotals.Sets = string.Join(",", sets); runningtotals.Completed = DateTime.Now; DbUtil.Db.SubmitChanges(); } else { var c = new ContributionStatements { FromDate = fd, ToDate = td, typ = 3 }; using (var stream = new FileStream(OutputFile, FileMode.Create)) { c.Run(stream, Db, qc, cs); } LastSet = c.LastSet(); var sets = c.Sets(); foreach (var set in sets) { using (var stream = new FileStream(Output(OutputFile, set), FileMode.Create)) { c.Run(stream, Db, qc, cs, set); } } runningtotals = DbUtil.Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First(); runningtotals.LastSet = LastSet; runningtotals.Sets = string.Join(",", sets); runningtotals.Completed = DateTime.Now; DbUtil.Db.SubmitChanges(); } }
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}")); }