private void bindTimeExpenseForInvoice(int claimID)
        {
            List<InvoiceDetail> invoiceDetails = new List<InvoiceDetail>();
            InvoiceDetail invoiceDetail = null;
            decimal serviceRate = 0;
            decimal servicePercentage = 0;
            decimal rate = 0;

            List<ClaimService> claimServices = null;
            List<ClaimExpense> claimExpenses = null;

            using (ClaimServiceManager repository = new ClaimServiceManager()) {
                claimServices = repository.GetAll(claimID);
            }
            using (ClaimExpenseManager repository = new ClaimExpenseManager()) {
                claimExpenses = repository.GetAll(claimID);
            }

            // add claim services to invoice
            if (claimServices != null) {
                foreach (ClaimService service in claimServices) {
                    invoiceDetail = new InvoiceDetail();
                    invoiceDetail.LineDate = service.ServiceDate;
                    invoiceDetail.ServiceTypeID = service.ServiceTypeID;
                    invoiceDetail.LineDescription = service.InvoiceServiceType.ServiceDescription;
                    invoiceDetail.Qty = service.ServiceQty;
                    invoiceDetail.Comments = service.ServiceDescription;

                    serviceRate = service.InvoiceServiceType.ServiceRate ?? 0;
                    servicePercentage = service.InvoiceServiceType.ServicePercentage ?? 0;

                    if (serviceRate > 0) {
                        rate = serviceRate;
                    }
                    else {
                        rate = servicePercentage / 100;
                    }

                    invoiceDetail.LineAmount = invoiceDetail.Qty * rate;
                    invoiceDetail.Rate = rate;

                    // add service to invoicedetail list
                    invoiceDetails.Add(invoiceDetail);
                }
            }
            // add claim expenses to invoice
            if (claimExpenses != null) {
                foreach (ClaimExpense expense in claimExpenses) {

                    invoiceDetail = new InvoiceDetail();
                    invoiceDetail.ExpenseTypeID = expense.ExpenseTypeID;
                    invoiceDetail.LineDate = expense.ExpenseDate;
                    invoiceDetail.LineDescription = expense.ExpenseDescription;
                    invoiceDetail.Comments = expense.ExpenseDescription;
                    invoiceDetail.LineAmount = expense.ExpenseAmount;
                    invoiceDetail.Qty = 1;
                    invoiceDetail.Rate = expense.ExpenseAmount;
                    // add expense to invoicedetail list
                    invoiceDetails.Add(invoiceDetail);

                }
            }

            // bind invoice detail lines
            gvTimeExpense.DataSource = invoiceDetails;
            gvTimeExpense.DataBind();
        }
        private void processClaimServices(int claimID, CarrierInvoiceProfile invoiceProfile, int invoiceID)
        {
            CarrierInvoiceProfileFeeItemized profileTEFee = null;
            List<ClaimService> claimServices = null;
            decimal lineTotal = 0;
            decimal quantity = 0;
            decimal rateAmount = 0;
            string serviceDescription = null;
            string serviceComments = null;
            InvoiceServiceType invoiceServiceType = null;

            // get TE services for claim entered by adjuster
            using (ClaimServiceManager repositiory = new ClaimServiceManager())
            {
                claimServices = repositiory.GetAll(claimID);
            }

            if (claimServices != null && claimServices.Count > 0)
            {
                foreach (ClaimService claimService in claimServices)
                {
                    profileTEFee = (from x in invoiceProfile.CarrierInvoiceProfileFeeItemized
                                    where x.ServiceTypeID == claimService.ServiceTypeID
                                    select x
                                 ).FirstOrDefault();

                    quantity = (claimService.ServiceQty ?? 0);
                    serviceDescription = claimService.InvoiceServiceType == null ? string.Empty : claimService.InvoiceServiceType.ServiceDescription;
                    invoiceServiceType = claimService.InvoiceServiceType;

                    if (profileTEFee != null)
                    {
                        // use override from invoice profile
                        if (profileTEFee.ItemRate > 0)
                        {
                            serviceComments = profileTEFee.ItemDescription;
                            rateAmount = profileTEFee.ItemRate;

                            lineTotal = rateAmount * quantity;

                            insertDetailLine(invoiceID, serviceDescription, lineTotal, quantity, rateAmount, claimService.ServiceDate, serviceComments);
                        }
                        else if (profileTEFee.ItemPercentage > 0)
                        {
                        }
                    }
                    else
                    {
                        if ((invoiceServiceType.ServiceRate ?? 0) > 0)
                        {
                            rateAmount = invoiceServiceType.ServiceRate ?? 0;
                            quantity = claimService.ServiceQty ?? 0;
                            lineTotal = rateAmount * quantity;
                        }
                        else if ((invoiceServiceType.ServicePercentage ?? 0) > 0)
                        {
                        }

                        insertDetailLine(invoiceID, serviceDescription, lineTotal, quantity, rateAmount, claimService.ServiceDate, serviceComments);
                    }
                }
            }
        }