private void processClaimExpenses(int claimID, CarrierInvoiceProfile invoiceProfile, int invoiceID) { CarrierInvoiceProfileFeeItemized profileTEFee = null; List<ClaimExpense> claimExpenses = null; decimal lineTotal = 0; decimal quantity = 0; decimal operand = 0; decimal expenseAmount = 0; decimal rateAmount = 0; string serviceDescription = null; string serviceComments = null; bool billed = true; // get TE services for claim entered by adjuster using (ClaimExpenseManager repositiory = new ClaimExpenseManager()) { claimExpenses = repositiory.GetExpenseForInvoice(claimID); } if (claimExpenses != null && claimExpenses.Count > 0) { foreach (ClaimExpense claimExpense in claimExpenses) { rateAmount = 0; int claimExpenseID = claimExpense.ClaimExpenseID; profileTEFee = (from x in invoiceProfile.CarrierInvoiceProfileFeeItemized where x.ExpenseTypeID == claimExpense.ExpenseTypeID select x ).FirstOrDefault(); if (profileTEFee != null) { // use override from invoice profile serviceDescription = claimExpense.ExpenseType.ExpenseName;// profileTEFee.ExpenseType == null ? string.Empty : profileTEFee.ExpenseType.ExpenseDescription; serviceComments = claimExpense.ExpenseDescription; // profileTEFee.ItemDescription; operand = profileTEFee.LogicalOperatorOperand ?? 0; billed = claimExpense.Billed.Value; rateAmount = profileTEFee.ItemRate; //claimExpense.ExpenseAmount; quantity = Convert.ToDecimal(claimExpense.ExpenseQty); Session["ExpAmount"] = claimExpense.ExpenseAmount; if ((profileTEFee.LogicalOperator ?? 0) > 0 && operand > 0) { quantity = claimExpense.ExpenseQty ?? 0; expenseAmount = claimExpense.ExpenseAmount; switch (profileTEFee.LogicalOperator) { case 1: // = //if (expenseAmount > 0 && expenseAmount == operand) { // rateAmount = profileTEFee.ItemRate; // expenseAmount = quantity * rateAmount; //} //else if (quantity > 0 && quantity == operand) { // rateAmount = profileTEFee.ItemRate; // expenseAmount = quantity * rateAmount; //} break; case 2: // < case 3: // <= if (expenseAmount > 0 && expenseAmount <= operand) { quantity = 1; rateAmount = profileTEFee.ItemRate; } else if (quantity > 0 && quantity <= operand) { rateAmount = profileTEFee.ItemRate; //; } break; case 4: // > case 5: // >= if (expenseAmount > 0 && expenseAmount >= operand) { quantity = 1; rateAmount = operand; } else if (quantity > 0 && quantity >= operand) { quantity = quantity - operand; rateAmount = profileTEFee.ItemRate; } break; default: quantity = 1; rateAmount = profileTEFee.ItemRate; //claimExpense.ExpenseAmount; break; } if (billed == false) { insertDetailLine(invoiceID, serviceDescription, quantity, rateAmount, claimExpense.ExpenseDate, serviceComments); using (ClaimExpenseManager myRepositiory = new ClaimExpenseManager()) { ClaimExpense myClaimExpense = myRepositiory.Get(claimExpenseID); myClaimExpense.Billed = true; myRepositiory.Save(myClaimExpense); } } } else if (profileTEFee.ItemRate > 0) { // no condition specified quantity = claimExpense.ExpenseQty ?? 1; rateAmount = profileTEFee.ItemRate; lineTotal = expenseAmount; if (billed == false) { insertDetailLine(invoiceID, serviceDescription, quantity, rateAmount, claimExpense.ExpenseDate, serviceComments); using (ClaimExpenseManager myRepositiory = new ClaimExpenseManager()) { ClaimExpense myClaimExpense = myRepositiory.Get(claimExpenseID); myClaimExpense.Billed = true; myRepositiory.Save(myClaimExpense); } } } else if (profileTEFee.ItemPercentage > 0) { } } else { // no override found serviceDescription = claimExpense.ExpenseType.ExpenseDescription; serviceComments = claimExpense.ExpenseDescription; quantity = claimExpense.ExpenseQty ?? 1; rateAmount = claimExpense.ExpenseAmount; if (billed == false) { insertDetailLine(invoiceID, serviceDescription, quantity, rateAmount, claimExpense.ExpenseDate, serviceComments); using (ClaimExpenseManager myRepositiory = new ClaimExpenseManager()) { ClaimExpense myClaimExpense = myRepositiory.Get(claimExpenseID); myClaimExpense.Billed = true; myRepositiory.Save(myClaimExpense); } } } } } }