internal StatementAccount(StatementInfo parent, string accountName) { Parent = parent; AccountName = accountName; OutstandingBalance = Parent.Person.GetBalance(Parent.StartDate, AccountName); BalanceDue = Math.Max(0, Parent.Person.GetBalance(AccountName)); Func <ITransaction, bool> filter = t => t.Date >= Parent.StartDate && t.Date < Parent.EndDate && t.Account == AccountName; Pledges = new ReadOnlyCollection <Pledge>(Parent.Person.Pledges.Where(p => filter(p)).OrderBy(p => p.Date).ToArray()); Payments = new ReadOnlyCollection <Payment>(Parent.Person.Payments.Where(p => filter(p)).OrderBy(p => p.Date).ToArray()); TotalPledged = OutstandingBalance + Pledges.Sum(p => p.Amount); TotalPaid = Payments.Sum(p => p.Amount); }
internal StatementAccount(StatementInfo parent, string accountName) { Parent = parent; AccountName = accountName; OutstandingBalance = Parent.Person.GetBalance(Parent.StartDate, AccountName); BalanceDue = Math.Max(0, Parent.Person.GetBalance(AccountName)); Func<ITransaction, bool> filter = t => t.Date >= Parent.StartDate && t.Date < Parent.EndDate && t.Account == AccountName; Pledges = new ReadOnlyCollection<Pledge>(Parent.Person.Pledges.Where(p => filter(p)).OrderBy(p => p.Date).ToArray()); Payments = new ReadOnlyCollection<Payment>(Parent.Person.Payments.Where(p => filter(p)).OrderBy(p => p.Date).ToArray()); TotalPledged = OutstandingBalance + Pledges.Sum(p => p.Amount); TotalPaid = Payments.Sum(p => p.Amount); }
static void InsertPayTo(Range range, StatementInfo info) { if (info.TotalBalance == 0) range.Text = ""; else { range.Text = "To pay your balance securely by credit card, go to https://" + Config.DomainName + "/Donate."; range.InsertParagraphAfter(); range.InsertAfter("Please make your checks payable to "); var subRange = range.AppendText(Config.LegalName); range.InsertAfter(", and mail your remittance to:"); range.InsertParagraphAfter(); subRange.Font.Bold = 1; subRange = range.AppendText(mailingAddress); range.InsertParagraphAfter(); subRange.ParagraphFormat.LeftIndent = 36; subRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; } }
public void Populate(Range range, StatementInfo info) { Info = info; base.Populate(range, info.Person); }
//Receipts are the same as bills except that they don't have //Balance Due, the Pledges section, and the Payments header. static void CreateTable(Range targetRange, StatementInfo info) { var table = targetRange.Tables.Add(targetRange, 2, 3); table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter; table.Range.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; table.Range.ParagraphFormat.SpaceAfter = 0; table.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; Range range; Row row; foreach (var account in info.Accounts) { if (info.Kind == StatementKind.Bill) { row = table.AddRow().MakeHeader(); row.Range.Text = account.AccountName + " Pledges"; shadingIndex = 0; row = table.AddRow().MergeFirstCells().StyleAmount().Stripe(); row.Cells[1].Range.Text = "Starting Balance (as of " + info.StartDate.ToShortDateString() + "):"; row.Cells[2].Range.Text = account.OutstandingBalance.ToString("c", Culture); foreach (var pledge in account.Pledges) { row = table.AddRow().StyleAmount().Stripe(); row.Cells[1].Range.Text = pledge.Date.ToShortDateString(); row.Cells[2].Range.Text = pledge.Type + (String.IsNullOrEmpty(pledge.SubType) ? "" : ", " + pledge.SubType); if (!String.IsNullOrEmpty(pledge.Note)) { range = row.Cells[2].Range; range.Start = range.End - 1; range.Text = Environment.NewLine + pledge.Note; range.Font.Italic = 1; } row.Cells[3].Range.Text = pledge.Amount.ToString("c", Culture); } row = table.AddRow().MergeFirstCells().StyleAmount().StyleTotal(); row.Cells[1].Range.Text = "Total:"; row.Cells[2].Range.Text = account.TotalPledged.ToString("c", Culture); } row = table.AddRow().MakeHeader(); row.Range.Text = account.AccountName + " Payments"; if (account.Payments.Count == 0) { row = table.AddRow().MergeRow(); row.Range.Text = "You have no " + account.AccountName.ToLower(Culture) + " payments\von record after " + info.StartDate.ToLongDateString(); } shadingIndex = 0; foreach (var payment in account.Payments) { row = table.AddRow().StyleAmount().Stripe(); row.Cells[1].Range.Text = payment.Date.ToShortDateString(); row.Cells[2].Range.Text = payment.MethodDescription; row.Cells[3].Range.Text = payment.Amount.ToString("c", Culture); } if (account.TotalPaid != 0) { row = table.AddRow().MergeFirstCells().StyleAmount().StyleTotal(); row.Cells[1].Range.Text = "Total:"; row.Cells[2].Range.Text = account.TotalPaid.ToString("c", Culture); } } if (info.Kind == StatementKind.Bill) { row = table.AddRow().MergeFirstCells().StyleAmount(); row.Range.ParagraphFormat.SpaceBefore = 10; row.Cells[1].Range.Text = "Total Pledged:"; row.Cells[2].Range.Text = info.TotalPledged.ToString("c", Culture); row = table.AddRow().MergeFirstCells().StyleAmount(); row.Cells[1].Range.Text = "Total Paid:"; row.Cells[2].Range.Text = "-" + info.TotalPaid.ToString("c", Culture); row = table.AddRow().MergeFirstCells().StyleAmount().StyleTotal(); row.Cells[1].Range.Text = "Balance due:"; row.Cells[2].Range.Text = info.Person.Field<decimal>("BalanceDue").ToString("c", Culture); row.Cells[2].Range.Font.Bold = 1; } table.Rows[table.Rows.Count].Delete(); table.Rows[table.Rows.Count].Delete(); table.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitContent); }