public ActionResult Index() { ViewModels.Billing.BillingViewModel viewModel = new ViewModels.Billing.BillingViewModel(); ViewModels.Billing.BillingViewModel.Item item; ViewModels.Billing.BillingViewModel.GroupItem groupItem; using (IDbConnection conn = Data.Database.Instance.GetConnection()) { Data.Billing.Invoice.ListBillableMatters(conn, false).ForEach(matter => { item = new ViewModels.Billing.BillingViewModel.Item(); item.Matter = Mapper.Map<ViewModels.Matters.MatterViewModel>(matter); if (matter.BillTo != null && matter.BillTo.Id.HasValue) item.BillTo = Mapper.Map<ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(matter.BillTo.Id.Value, conn, false)); item.Expenses = Data.Billing.Expense.SumUnbilledExpensesForMatter(matter.Id.Value, conn, false); item.Fees = Data.Billing.Fee.SumUnbilledFeesForMatter(matter.Id.Value, conn, false); item.Time = Data.Timing.Time.SumUnbilledAndBillableTimeForMatter(matter.Id.Value, conn, false); if ((item.Expenses + item.Fees + (decimal)item.Time.TotalHours) > 0) viewModel.Items.Add(item); }); Data.Billing.Invoice.ListBillableBillingGroups(conn, false).ForEach(group => { groupItem = new ViewModels.Billing.BillingViewModel.GroupItem(); groupItem.BillingGroup = Mapper.Map<ViewModels.Billing.BillingGroupViewModel>(group); groupItem.BillingGroup.BillTo = Mapper.Map<ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(group.BillTo.Id.Value, conn, false)); groupItem.Expenses = Data.Billing.BillingGroup.SumBillableExpensesForGroup(group.Id.Value, conn, false); groupItem.Fees = Data.Billing.BillingGroup.SumBillableFeesForGroup(group.Id.Value, conn, false); groupItem.Time = Data.Timing.Time.SumUnbilledAndBillableTimeForBillingGroup(group.Id.Value, conn, false); viewModel.GroupItems.Add(groupItem); }); Data.Billing.Invoice.GetMostRecentInvoices(10).ForEach(invoice => { ViewModels.Billing.InvoiceViewModel vm = Mapper.Map<ViewModels.Billing.InvoiceViewModel>(invoice); if (invoice.Matter != null && invoice.Matter.Id.HasValue) vm.Matter = Mapper.Map<ViewModels.Matters.MatterViewModel>(Data.Matters.Matter.Get(invoice.Matter.Id.Value, conn, false)); else vm.Matter = null; if (invoice.BillingGroup != null && invoice.BillingGroup.Id.HasValue) vm.BillingGroup = Mapper.Map<ViewModels.Billing.BillingGroupViewModel>(Data.Billing.BillingGroup.Get(invoice.BillingGroup.Id.Value, conn, false)); else vm.BillingGroup = null; vm.BillTo = Mapper.Map<ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(invoice.BillTo.Id.Value, conn, false)); viewModel.RecentInvoices.Add(vm); }); } return View(viewModel); }
public ActionResult Index() { ViewModels.Billing.BillingViewModel viewModel = new ViewModels.Billing.BillingViewModel(); ViewModels.Billing.BillingViewModel.Item item; ViewModels.Billing.BillingViewModel.GroupItem groupItem; Data.Billing.Invoice.ListBillableMatters().ForEach(matter => { item = new ViewModels.Billing.BillingViewModel.Item(); item.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter); if (matter.BillTo != null && matter.BillTo.Id.HasValue) { item.BillTo = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(matter.BillTo.Id.Value)); } item.Expenses = Data.Billing.Expense.SumUnbilledExpensesForMatter(matter.Id.Value); item.Fees = Data.Billing.Fee.SumUnbilledFeesForMatter(matter.Id.Value); item.Time = Data.Timing.Time.SumUnbilledAndBillableTimeForMatter(matter.Id.Value); if ((item.Expenses + item.Fees + (decimal)item.Time.TotalHours) > 0) { viewModel.Items.Add(item); } }); Data.Billing.Invoice.ListBillableBillingGroups().ForEach(group => { groupItem = new ViewModels.Billing.BillingViewModel.GroupItem(); groupItem.BillingGroup = Mapper.Map <ViewModels.Billing.BillingGroupViewModel>(group); groupItem.BillingGroup.BillTo = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(group.BillTo.Id.Value)); groupItem.Expenses = Data.Billing.BillingGroup.SumBillableExpensesForGroup(group.Id.Value); groupItem.Fees = Data.Billing.BillingGroup.SumBillableFeesForGroup(group.Id.Value); groupItem.Time = Data.Timing.Time.SumUnbilledAndBillableTimeForBillingGroup(group.Id.Value); viewModel.GroupItems.Add(groupItem); }); Data.Billing.Invoice.GetMostRecentInvoices(10).ForEach(invoice => { ViewModels.Billing.InvoiceViewModel vm = Mapper.Map <ViewModels.Billing.InvoiceViewModel>(invoice); if (invoice.Matter != null && invoice.Matter.Id.HasValue) { vm.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(Data.Matters.Matter.Get(invoice.Matter.Id.Value)); } else { vm.Matter = null; } if (invoice.BillingGroup != null && invoice.BillingGroup.Id.HasValue) { vm.BillingGroup = Mapper.Map <ViewModels.Billing.BillingGroupViewModel>(Data.Billing.BillingGroup.Get(invoice.BillingGroup.Id.Value)); } else { vm.BillingGroup = null; } vm.BillTo = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(invoice.BillTo.Id.Value)); viewModel.RecentInvoices.Add(vm); }); return(View(viewModel)); }