コード例 #1
0
 public static Common.Models.Billing.BillingRate Create(
     Transaction t,
     Common.Models.Billing.BillingRate model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }
コード例 #2
0
 public static Common.Models.Billing.BillingRate Edit(
     Transaction t,
     Common.Models.Billing.BillingRate model,
     Common.Models.Account.Users modifier)
 {
     return(Edit(model, modifier, t.Connection, false));
 }
コード例 #3
0
        public static Common.Models.Billing.BillingRate Edit(Common.Models.Billing.BillingRate model,
                                                             Common.Models.Account.Users modifier)
        {
            model.ModifiedBy = modifier;
            model.Modified   = DateTime.UtcNow;
            DBOs.Billing.BillingRate dbo = Mapper.Map <DBOs.Billing.BillingRate>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("UPDATE \"billing_rate\" SET " +
                             "\"title\"=@Title, \"price_per_unit\"=@PricePerUnit, \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " +
                             "WHERE \"id\"=@Id", dbo);
            }

            return(model);
        }
コード例 #4
0
        public static Common.Models.Billing.BillingRate Create(Common.Models.Billing.BillingRate model,
                                                               Common.Models.Account.Users creator)
        {
            model.CreatedBy = model.ModifiedBy = creator;
            model.Created   = model.Modified = DateTime.UtcNow;
            DBOs.Billing.BillingRate dbo = Mapper.Map <DBOs.Billing.BillingRate>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("INSERT INTO \"billing_rate\" (\"title\", \"price_per_unit\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                             "VALUES (@Title, @PricePerUnit, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                             dbo);

                model.Id = conn.Query <DBOs.Billing.BillingRate>("SELECT currval(pg_get_serial_sequence('billing_rate', 'id')) AS \"id\"").Single().Id;
            }

            return(model);
        }
コード例 #5
0
        public static Common.Models.Billing.BillingRate Edit(
            Common.Models.Billing.BillingRate model,
            Common.Models.Account.Users modifier,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            model.ModifiedBy = modifier;
            model.Modified   = DateTime.UtcNow;
            DBOs.Billing.BillingRate dbo = Mapper.Map <DBOs.Billing.BillingRate>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("UPDATE \"billing_rate\" SET " +
                         "\"title\"=@Title, \"price_per_unit\"=@PricePerUnit, \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " +
                         "WHERE \"id\"=@Id", dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
コード例 #6
0
        public static Common.Models.Billing.BillingRate Create(
            Common.Models.Billing.BillingRate model,
            Common.Models.Account.Users creator,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            model.CreatedBy = model.ModifiedBy = creator;
            model.Created   = model.Modified = DateTime.UtcNow;
            DBOs.Billing.BillingRate dbo = Mapper.Map <DBOs.Billing.BillingRate>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            if (conn.Execute("INSERT INTO \"billing_rate\" (\"title\", \"price_per_unit\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                             "VALUES (@Title, @PricePerUnit, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                             dbo) > 0)
            {
                model.Id = conn.Query <DBOs.Billing.BillingRate>("SELECT currval(pg_get_serial_sequence('billing_rate', 'id')) AS \"id\"").Single().Id;
            }

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
コード例 #7
0
        public ViewModels.Billing.GroupInvoiceViewModel BuildGroupInvoiceViewModel(int id, DateTime?startDate = null, DateTime?stopDate = null, string rateFrom = null)
        {
            Common.Models.Billing.BillingRate        billingRate = null;
            Common.Models.Billing.BillingGroup       billingGroup;
            ViewModels.Billing.GroupInvoiceViewModel viewModel       = new ViewModels.Billing.GroupInvoiceViewModel();
            Common.Models.Billing.Invoice            previousInvoice = null;
            List <Common.Models.Matters.Matter>      mattersList;

            if (!string.IsNullOrEmpty(Request["StartDate"]))
            {
                startDate = DateTime.Parse(Request["StartDate"]);
            }
            if (!string.IsNullOrEmpty(Request["StopDate"]))
            {
                stopDate = DateTime.Parse(Request["StopDate"]);
            }

            billingGroup    = Data.Billing.BillingGroup.Get(id);
            previousInvoice = Data.Billing.Invoice.GetMostRecentInvoiceForContact(billingGroup.BillTo.Id.Value);

            billingGroup.NextRun = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1);

            viewModel.Id           = Guid.NewGuid();
            viewModel.BillTo       = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(billingGroup.BillTo.Id.Value));
            viewModel.Date         = DateTime.Now;
            viewModel.Due          = DateTime.Now.AddDays(30);
            viewModel.BillingGroup = Mapper.Map <ViewModels.Billing.BillingGroupViewModel>(billingGroup);

            if (previousInvoice == null)
            {
                viewModel.BillTo_NameLine1 = viewModel.BillTo.DisplayName;
                if (string.IsNullOrEmpty(viewModel.BillTo.Address1AddressPostOfficeBox))
                {
                    viewModel.BillTo_AddressLine1 = viewModel.BillTo.Address1AddressStreet;
                }
                else
                {
                    viewModel.BillTo_AddressLine1 = "P.O. Box " + viewModel.BillTo.Address1AddressPostOfficeBox;
                }
                viewModel.BillTo_City  = viewModel.BillTo.Address1AddressCity;
                viewModel.BillTo_State = viewModel.BillTo.Address1AddressStateOrProvince;
                viewModel.BillTo_Zip   = viewModel.BillTo.Address1AddressPostalCode;
            }
            else
            {
                viewModel.BillTo_NameLine1    = previousInvoice.BillTo_NameLine1;
                viewModel.BillTo_NameLine2    = previousInvoice.BillTo_NameLine2;
                viewModel.BillTo_AddressLine1 = previousInvoice.BillTo_AddressLine1;
                viewModel.BillTo_AddressLine2 = previousInvoice.BillTo_AddressLine2;
                viewModel.BillTo_City         = previousInvoice.BillTo_City;
                viewModel.BillTo_State        = previousInvoice.BillTo_State;
                viewModel.BillTo_Zip          = previousInvoice.BillTo_Zip;
            }

            // Get list of matters for the group
            mattersList = Data.Billing.BillingGroup.ListMattersForGroup(billingGroup.Id.Value);

            for (int i = 0; i < mattersList.Count; i++)
            {
                ViewModels.Billing.GroupInvoiceItemViewModel giivm = new ViewModels.Billing.GroupInvoiceItemViewModel();
                Common.Models.Matters.Matter matter = mattersList[i];

                giivm.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter);

                Data.Timing.Time.ListUnbilledAndBillableTimeForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
                {
                    ViewModels.Billing.InvoiceTimeViewModel vm = new ViewModels.Billing.InvoiceTimeViewModel()
                    {
                        //Invoice = viewModel,
                        Time    = Mapper.Map <ViewModels.Timing.TimeViewModel>(x),
                        Details = x.Details
                    };
                    if (x.Stop.HasValue)
                    {
                        vm.Duration = x.Stop.Value - x.Start;
                    }
                    else
                    {
                        vm.Duration = new TimeSpan(0);
                    }

                    if (string.IsNullOrEmpty(Request["RateFrom"]))
                    { // Not specified in URL
                        if (matter.OverrideMatterRateWithEmployeeRate)
                        {
                            Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value);
                            if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                            {
                                billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value);
                            }
                        }
                    }
                    else
                    { // Overridden by current user in URL
                        if (Request["RateFrom"] == "Employee")
                        {
                            Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value);
                            if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                            {
                                billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value);
                            }
                        }
                    }

                    if (billingRate != null)
                    {
                        vm.PricePerHour = billingRate.PricePerUnit;
                    }

                    giivm.Times.Add(vm);
                });

                Data.Billing.Expense.ListUnbilledExpensesForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
                {
                    giivm.Expenses.Add(new ViewModels.Billing.InvoiceExpenseViewModel()
                    {
                        //Invoice = viewModel,
                        Expense = Mapper.Map <ViewModels.Billing.ExpenseViewModel>(x),
                        Details = x.Details,
                        Amount  = x.Amount
                    });
                });

                Data.Billing.Fee.ListUnbilledFeesForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
                {
                    giivm.Fees.Add(new ViewModels.Billing.InvoiceFeeViewModel()
                    {
                        //Invoice = viewModel,
                        Fee     = Mapper.Map <ViewModels.Billing.FeeViewModel>(x),
                        Details = x.Details,
                        Amount  = x.Amount
                    });
                });

                if ((giivm.Times.Count > 0) ||
                    (giivm.Expenses.Count > 0) ||
                    (giivm.Fees.Count > 0))
                {
                    viewModel.Matters.Add(giivm);
                }
            }

            ViewData["FirmName"]    = Common.Settings.Manager.Instance.System.BillingFirmName;
            ViewData["FirmAddress"] = Common.Settings.Manager.Instance.System.BillingFirmAddress;
            ViewData["FirmCity"]    = Common.Settings.Manager.Instance.System.BillingFirmCity;
            ViewData["FirmState"]   = Common.Settings.Manager.Instance.System.BillingFirmState;
            ViewData["FirmZip"]     = Common.Settings.Manager.Instance.System.BillingFirmZip;
            ViewData["FirmPhone"]   = Common.Settings.Manager.Instance.System.BillingFirmPhone;
            ViewData["FirmWeb"]     = Common.Settings.Manager.Instance.System.BillingFirmWeb;

            return(viewModel);
        }
コード例 #8
0
        public ViewModels.Billing.InvoiceViewModel BuildSingleMatterViewModel(Guid id, DateTime?startDate = null, DateTime?stopDate = null, string rateFrom = null)
        {
            Common.Models.Billing.BillingRate   billingRate     = null;
            ViewModels.Billing.InvoiceViewModel viewModel       = new ViewModels.Billing.InvoiceViewModel();
            Common.Models.Billing.Invoice       previousInvoice = null;
            Common.Models.Matters.Matter        matter;

            matter = Data.Matters.Matter.Get(id);

            previousInvoice = Data.Billing.Invoice.GetMostRecentInvoiceForContact(matter.BillTo.Id.Value);

            // Set default billing rate
            if (matter.DefaultBillingRate != null && matter.DefaultBillingRate.Id.HasValue)
            {
                billingRate = Data.Billing.BillingRate.Get(matter.DefaultBillingRate.Id.Value);
            }

            viewModel.Id     = Guid.NewGuid();
            viewModel.BillTo = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(matter.BillTo.Id.Value));
            viewModel.Date   = DateTime.Now;
            viewModel.Due    = DateTime.Now.AddDays(30);
            viewModel.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter);

            if (previousInvoice == null)
            {
                viewModel.BillTo_NameLine1 = viewModel.BillTo.DisplayName;
                if (string.IsNullOrEmpty(viewModel.BillTo.Address1AddressPostOfficeBox))
                {
                    viewModel.BillTo_AddressLine1 = viewModel.BillTo.Address1AddressStreet;
                }
                else
                {
                    viewModel.BillTo_AddressLine1 = "P.O. Box " + viewModel.BillTo.Address1AddressPostOfficeBox;
                }
                viewModel.BillTo_City  = viewModel.BillTo.Address1AddressCity;
                viewModel.BillTo_State = viewModel.BillTo.Address1AddressStateOrProvince;
                viewModel.BillTo_Zip   = viewModel.BillTo.Address1AddressPostalCode;
            }
            else
            {
                viewModel.BillTo_NameLine1    = previousInvoice.BillTo_NameLine1;
                viewModel.BillTo_NameLine2    = previousInvoice.BillTo_NameLine2;
                viewModel.BillTo_AddressLine1 = previousInvoice.BillTo_AddressLine1;
                viewModel.BillTo_AddressLine2 = previousInvoice.BillTo_AddressLine2;
                viewModel.BillTo_City         = previousInvoice.BillTo_City;
                viewModel.BillTo_State        = previousInvoice.BillTo_State;
                viewModel.BillTo_Zip          = previousInvoice.BillTo_Zip;
            }

            Data.Timing.Time.ListUnbilledAndBillableTimeForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
            {
                ViewModels.Billing.InvoiceTimeViewModel vm = new ViewModels.Billing.InvoiceTimeViewModel()
                {
                    Invoice = viewModel,
                    Time    = Mapper.Map <ViewModels.Timing.TimeViewModel>(x),
                    Details = x.Details
                };
                if (x.Stop.HasValue)
                {
                    vm.Duration = x.Stop.Value - x.Start;
                }
                else
                {
                    vm.Duration = new TimeSpan(0);
                }

                if (string.IsNullOrEmpty(rateFrom))
                { // Not specified in URL
                    if (matter.OverrideMatterRateWithEmployeeRate)
                    {
                        Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value);
                        if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                        {
                            billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value);
                        }
                    }
                }
                else
                { // Overridden by current user in URL
                    if (rateFrom == "employee")
                    {
                        Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value);
                        if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                        {
                            billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value);
                        }
                    }
                }

                if (billingRate != null)
                {
                    vm.PricePerHour = billingRate.PricePerUnit;
                }
                viewModel.Times.Add(vm);
            });

            Data.Billing.Expense.ListUnbilledExpensesForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
            {
                viewModel.Expenses.Add(new ViewModels.Billing.InvoiceExpenseViewModel()
                {
                    Invoice = viewModel,
                    Expense = Mapper.Map <ViewModels.Billing.ExpenseViewModel>(x),
                    Details = x.Details,
                    Amount  = x.Amount
                });
            });

            Data.Billing.Fee.ListUnbilledFeesForMatter(matter.Id.Value, startDate, stopDate).ForEach(x =>
            {
                viewModel.Fees.Add(new ViewModels.Billing.InvoiceFeeViewModel()
                {
                    Invoice = viewModel,
                    Fee     = Mapper.Map <ViewModels.Billing.FeeViewModel>(x),
                    Details = x.Details,
                    Amount  = x.Amount
                });
            });

            ViewData["MatterTitle"] = matter.Title;
            ViewData["CaseNumber"]  = matter.CaseNumber;
            ViewData["FirmName"]    = Common.Settings.Manager.Instance.System.BillingFirmName;
            ViewData["FirmAddress"] = Common.Settings.Manager.Instance.System.BillingFirmAddress;
            ViewData["FirmCity"]    = Common.Settings.Manager.Instance.System.BillingFirmCity;
            ViewData["FirmState"]   = Common.Settings.Manager.Instance.System.BillingFirmState;
            ViewData["FirmZip"]     = Common.Settings.Manager.Instance.System.BillingFirmZip;
            ViewData["FirmPhone"]   = Common.Settings.Manager.Instance.System.BillingFirmPhone;
            ViewData["FirmWeb"]     = Common.Settings.Manager.Instance.System.BillingFirmWeb;

            return(viewModel);
        }
コード例 #9
0
        public ViewModels.Billing.GroupInvoiceViewModel BuildGroupInvoiceViewModel(int id, IDbConnection conn, bool closeConnection, DateTime?startDate = null, DateTime?stopDate = null, string rateFrom = null)
        {
            Common.Models.Billing.BillingRate        billingRate = null;
            Common.Models.Billing.BillingGroup       billingGroup;
            ViewModels.Billing.GroupInvoiceViewModel viewModel       = new ViewModels.Billing.GroupInvoiceViewModel();
            Common.Models.Billing.Invoice            previousInvoice = null;
            List <Common.Models.Matters.Matter>      mattersList;

            if (!string.IsNullOrEmpty(Request["StartDate"]))
            {
                startDate = DateTime.Parse(Request["StartDate"]);
            }
            if (!string.IsNullOrEmpty(Request["StopDate"]))
            {
                stopDate = DateTime.Parse(Request["StopDate"]);
            }

            billingGroup    = Data.Billing.BillingGroup.Get(id, conn, false);
            previousInvoice = Data.Billing.Invoice.GetMostRecentInvoiceForContact(billingGroup.BillTo.Id.Value, conn, false);

            billingGroup.NextRun = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1);

            viewModel.Id           = Guid.NewGuid();
            viewModel.BillTo       = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(billingGroup.BillTo.Id.Value, conn, false));
            viewModel.Date         = DateTime.Now;
            viewModel.Due          = DateTime.Now.AddDays(30);
            viewModel.BillingGroup = Mapper.Map <ViewModels.Billing.BillingGroupViewModel>(billingGroup);

            if (previousInvoice == null)
            {
                viewModel.BillTo_NameLine1 = viewModel.BillTo.DisplayName;
                if (string.IsNullOrEmpty(viewModel.BillTo.Address1AddressPostOfficeBox))
                {
                    viewModel.BillTo_AddressLine1 = viewModel.BillTo.Address1AddressStreet;
                }
                else
                {
                    viewModel.BillTo_AddressLine1 = "P.O. Box " + viewModel.BillTo.Address1AddressPostOfficeBox;
                }
                viewModel.BillTo_City  = viewModel.BillTo.Address1AddressCity;
                viewModel.BillTo_State = viewModel.BillTo.Address1AddressStateOrProvince;
                viewModel.BillTo_Zip   = viewModel.BillTo.Address1AddressPostalCode;
            }
            else
            {
                viewModel.BillTo_NameLine1    = previousInvoice.BillTo_NameLine1;
                viewModel.BillTo_NameLine2    = previousInvoice.BillTo_NameLine2;
                viewModel.BillTo_AddressLine1 = previousInvoice.BillTo_AddressLine1;
                viewModel.BillTo_AddressLine2 = previousInvoice.BillTo_AddressLine2;
                viewModel.BillTo_City         = previousInvoice.BillTo_City;
                viewModel.BillTo_State        = previousInvoice.BillTo_State;
                viewModel.BillTo_Zip          = previousInvoice.BillTo_Zip;
            }

            // Get list of matters for the group
            mattersList = Data.Billing.BillingGroup.ListMattersForGroup(billingGroup.Id.Value, conn, false);

            for (int i = 0; i < mattersList.Count; i++)
            {
                ViewModels.Billing.GroupInvoiceItemViewModel giivm = new ViewModels.Billing.GroupInvoiceItemViewModel();
                Common.Models.Matters.Matter matter = mattersList[i];

                giivm.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter);

                Data.Timing.Time.ListUnbilledAndBillableTimeForMatter(matter.Id.Value, startDate, stopDate, conn, false).ForEach(x =>
                {
                    ViewModels.Billing.InvoiceTimeViewModel vm = new ViewModels.Billing.InvoiceTimeViewModel()
                    {
                        //Invoice = viewModel,
                        Time    = Mapper.Map <ViewModels.Timing.TimeViewModel>(x),
                        Details = x.Details
                    };
                    if (x.Stop.HasValue)
                    {
                        vm.Duration = x.Stop.Value - x.Start;
                    }
                    else
                    {
                        vm.Duration = new TimeSpan(0);
                    }

                    if (string.IsNullOrEmpty(Request["RateFrom"]))
                    { // Not specified in URL
                        if (matter.OverrideMatterRateWithEmployeeRate)
                        {
                            Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value, conn, false);
                            if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                            {
                                billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value, conn, false);
                            }
                        }
                    }
                    else
                    { // Overridden by current user in URL
                        if (Request["RateFrom"] == "Employee")
                        {
                            Common.Models.Contacts.Contact contact = Data.Contacts.Contact.Get(x.Worker.Id.Value, conn, false);
                            if (contact.BillingRate != null && contact.BillingRate.Id.HasValue)
                            {
                                billingRate = Data.Billing.BillingRate.Get(contact.BillingRate.Id.Value, conn, false);
                            }
                        }
                    }

                    if (billingRate != null)
                    {
                        vm.PricePerHour = billingRate.PricePerUnit;
                    }

                    ViewModels.Billing.InvoiceTimeGroupViewModel timeGroup;
                    if (x.TimeCategory == null || !x.TimeCategory.Id.HasValue)
                    {
                        timeGroup = giivm.TimeGroups.SingleOrDefault(y => y.Id == 0);
                    }
                    else
                    {
                        timeGroup = giivm.TimeGroups.SingleOrDefault(y => y.Id == x.TimeCategory.Id);
                    }
                    if (timeGroup == null || timeGroup.Id == -1)
                    {
                        Common.Models.Timing.TimeCategory tc = Data.Timing.TimeCategory.Get(x.TimeCategory.Id.Value, conn, false);
                        timeGroup = new ViewModels.Billing.InvoiceTimeGroupViewModel()
                        {
                            Id        = tc.Id.Value,
                            GroupName = tc.Title,
                            Times     = new List <ViewModels.Billing.InvoiceTimeViewModel>()
                        };
                        timeGroup.Times.Add(vm);
                        giivm.TimeGroups.Add(timeGroup);
                    }
                    else
                    {
                        timeGroup.Times.Add(vm);
                    }
                });
                // On instantiation, GroupInvoiceItemViewModel.TimeGroups has the first element created as "Standard"
                // if it is not used, we need to drop it
                if (giivm.TimeGroups.Count > 1 && giivm.TimeGroups[0].Times.Count == 0)
                {
                    giivm.TimeGroups.RemoveAt(0);
                }

                Data.Billing.Expense.ListUnbilledExpensesForMatter(matter.Id.Value, startDate, stopDate, conn, false).ForEach(x =>
                {
                    giivm.Expenses.Add(new ViewModels.Billing.InvoiceExpenseViewModel()
                    {
                        //Invoice = viewModel,
                        Expense = Mapper.Map <ViewModels.Billing.ExpenseViewModel>(x),
                        Details = x.Details,
                        Amount  = x.Amount
                    });
                });

                Data.Billing.Fee.ListUnbilledFeesForMatter(matter.Id.Value, startDate, stopDate, conn, false).ForEach(x =>
                {
                    giivm.Fees.Add(new ViewModels.Billing.InvoiceFeeViewModel()
                    {
                        //Invoice = viewModel,
                        Fee     = Mapper.Map <ViewModels.Billing.FeeViewModel>(x),
                        Details = x.Details,
                        Amount  = x.Amount
                    });
                });

                if ((giivm.TimeGroups.Count(x => x.Times.Count > 0) > 0) ||
                    (giivm.Expenses.Count > 0) ||
                    (giivm.Fees.Count > 0))
                {
                    viewModel.Matters.Add(giivm);
                }
            }

            ViewData["FirmName"]    = Common.Settings.Manager.Instance.System.BillingFirmName;
            ViewData["FirmAddress"] = Common.Settings.Manager.Instance.System.BillingFirmAddress;
            ViewData["FirmCity"]    = Common.Settings.Manager.Instance.System.BillingFirmCity;
            ViewData["FirmState"]   = Common.Settings.Manager.Instance.System.BillingFirmState;
            ViewData["FirmZip"]     = Common.Settings.Manager.Instance.System.BillingFirmZip;
            ViewData["FirmPhone"]   = Common.Settings.Manager.Instance.System.BillingFirmPhone;
            ViewData["FirmWeb"]     = Common.Settings.Manager.Instance.System.BillingFirmWeb;

            return(viewModel);
        }
コード例 #10
0
        public ActionResult MatterEdit(Guid id)
        {
            Common.Models.Billing.BillingRate   billingRate = null;
            Common.Models.Matters.Matter        matter      = null;
            Common.Models.Billing.Invoice       invoice     = null;
            ViewModels.Billing.InvoiceViewModel viewModel   = new ViewModels.Billing.InvoiceViewModel();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                invoice   = Data.Billing.Invoice.Get(id, conn, false);
                viewModel = Mapper.Map <ViewModels.Billing.InvoiceViewModel>(invoice);

                if (invoice.Matter != null)
                {
                    matter           = Data.Matters.Matter.Get(invoice.Matter.Id.Value, conn, false);
                    viewModel.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter);
                    if (matter.DefaultBillingRate != null && matter.DefaultBillingRate.Id.HasValue)
                    {
                        billingRate = Data.Billing.BillingRate.Get(matter.DefaultBillingRate.Id.Value, conn, false);
                    }
                }

                invoice.BillTo = Data.Contacts.Contact.Get(invoice.BillTo.Id.Value, conn, false);

                Data.Billing.Invoice.ListInvoiceExpensesForInvoice(invoice.Id.Value, conn, false).ForEach(x =>
                {
                    ViewModels.Billing.InvoiceExpenseViewModel vm = Mapper.Map <ViewModels.Billing.InvoiceExpenseViewModel>(x);
                    vm.Expense = Mapper.Map <ViewModels.Billing.ExpenseViewModel>(
                        Data.Billing.Expense.Get(vm.Expense.Id.Value, conn, false));
                    viewModel.Expenses.Add(vm);
                });

                Data.Billing.Invoice.ListInvoiceFeesForInvoice(invoice.Id.Value, conn, false).ForEach(x =>
                {
                    ViewModels.Billing.InvoiceFeeViewModel vm = Mapper.Map <ViewModels.Billing.InvoiceFeeViewModel>(x);
                    vm.Fee = Mapper.Map <ViewModels.Billing.FeeViewModel>(
                        Data.Billing.Fee.Get(vm.Fee.Id.Value, conn, false));
                    viewModel.Fees.Add(vm);
                });

                Data.Billing.Invoice.ListInvoiceTimesForInvoice(invoice.Id.Value, conn, false).ForEach(x =>
                {
                    ViewModels.Billing.InvoiceTimeViewModel vm = Mapper.Map <ViewModels.Billing.InvoiceTimeViewModel>(x);
                    vm.Time = Mapper.Map <ViewModels.Timing.TimeViewModel>(
                        Data.Timing.Time.Get(vm.Time.Id.Value, conn, false));

                    ViewModels.Billing.InvoiceTimeGroupViewModel timeGroup;
                    if (vm.Time.TimeCategory == null || !vm.Time.TimeCategory.Id.HasValue)
                    {
                        timeGroup = viewModel.TimeGroups.SingleOrDefault(y => y.Id == 0);
                    }
                    else
                    {
                        timeGroup = viewModel.TimeGroups.SingleOrDefault(y => y.Id == vm.Time.TimeCategory.Id);
                    }
                    if (timeGroup == null || timeGroup.Id == -1)
                    {
                        Common.Models.Timing.TimeCategory tc = Data.Timing.TimeCategory.Get(vm.Time.TimeCategory.Id.Value, conn, false);
                        timeGroup = new ViewModels.Billing.InvoiceTimeGroupViewModel()
                        {
                            Id        = tc.Id.Value,
                            GroupName = tc.Title,
                            Times     = new List <ViewModels.Billing.InvoiceTimeViewModel>()
                        };
                        timeGroup.Times.Add(vm);
                        viewModel.TimeGroups.Add(timeGroup);
                    }
                    else
                    {
                        timeGroup.Times.Add(vm);
                    }
                });
            }

            ViewData["MatterTitle"] = matter.Title;
            ViewData["CaseNumber"]  = matter.CaseNumber;
            ViewData["FirmName"]    = Common.Settings.Manager.Instance.System.BillingFirmName;
            ViewData["FirmAddress"] = Common.Settings.Manager.Instance.System.BillingFirmAddress;
            ViewData["FirmCity"]    = Common.Settings.Manager.Instance.System.BillingFirmCity;
            ViewData["FirmState"]   = Common.Settings.Manager.Instance.System.BillingFirmState;
            ViewData["FirmZip"]     = Common.Settings.Manager.Instance.System.BillingFirmZip;
            ViewData["FirmPhone"]   = Common.Settings.Manager.Instance.System.BillingFirmPhone;
            ViewData["FirmWeb"]     = Common.Settings.Manager.Instance.System.BillingFirmWeb;

            return(View(viewModel));
        }