public FinancialTransactionContext(ClaimHeader claimHeader, ClaimDetail claimDetail, ClaimTransactionHeader claimTransactionHeader, ClaimTransactionGroup claimTransactionGroup, User user)
            {
                this.ClaimHeader = claimHeader;
                this.ClaimDetail = claimDetail;
                this.ClaimTransactionHeader = claimTransactionHeader;
                this.ClaimTransactionGroup = claimTransactionGroup;
                this.CurrentUser = user;
                this.TransactionSource = (StaticValues.ClaimTransactionSource)this.ClaimTransactionHeader.ClaimTransactionSource;

                this.Product = claimHeader.GetProduct();
                this.ProductClaimDefinition = this.Product.ProductClaimDefinition;
                this.ProductClaimDetails = this.Product.ClaimDetails;
            }
        /// <summary>
        /// Load historical reserves/payments/recovery reserves/recovery receipts for the specified claim detail
        /// </summary>
        /// <param name="transactionSource">transaction source</param>
        /// <param name="productClaimDefinition">claim product</param>
        /// <param name="claimDetail">claim detail</param>
        /// <param name="reserves">resulting reserves</param>
        /// <param name="payments">resulting payments and recovery receipts</param>
        /// <param name="recoveryReserves">resulting recovery reserves</param>
        private static void LoadFinancialAmounts(StaticValues.ClaimTransactionSource transactionSource, ProductClaimDefinition productClaimDefinition, ClaimDetail claimDetail, ClaimTransactionHeader claimtransactionheader, out IEnumerable<ClaimFinancialAmount> reserves, out IEnumerable<ClaimFinancialAmount> payments, out IEnumerable<ClaimFinancialAmount> recoveryReserves)
        {
            var inProgressData = ObjectFactory.Resolve<IInProgressFinancialAmountData>();
            var historicalData = ObjectFactory.Resolve<IHistoricalFinancialAmountData>();

            var claimDetailArg = new ClaimDetailArgument(AmountDataSource.Both, claimDetail, null);

            var reserveCalculation = new TotalClaimDetailReserveFinancialCalculation(inProgressData, historicalData);
            var paymentCalcuation = new TotalClaimDetailPaymentFinancialCalculation(inProgressData, historicalData);
            var recoveryReceiptCalculation = new TotalClaimDetailReceiptFinancialCalculation(inProgressData, historicalData);
            var recoveryRerserveCalculation = new TotalClaimDetailRecoveryReserveFinancialCalculation(inProgressData, historicalData);
            bool includeEstimated = productClaimDefinition.RecoveryIncurredAmountDerivationMethod == (short)StaticValues.RecoveryIncurredAmountDerivationMethod.ReceiptsRecoveryReservesincludingEstimated;
            bool includeRecoveryEstimated = productClaimDefinition.RecoveryIncurredAmountDerivationMethod == (short)StaticValues.RecoveryIncurredAmountDerivationMethod.ReceiptsRecoveryReservesincludingEstimated;
            reserves = reserveCalculation.ReadLatestClaimDetailReserves(claimDetailArg, includeEstimated);
            payments = paymentCalcuation.ReadClaimDetailPayments(claimDetailArg);
            payments = payments.Concat(recoveryReceiptCalculation.ReadClaimDetailReceipt(claimDetailArg));
            recoveryReserves = recoveryRerserveCalculation.ReadLatestClaimDetailRecoveryReserves(claimDetailArg, includeRecoveryEstimated);

            var excludedMovementTypes = ClaimsBusinessLogicHelper.GetExcludedMovementTypesFromAutomaticDeductibleCalculations();
            reserves = FilterExcludedMovementTypes(reserves, excludedMovementTypes);
            recoveryReserves = FilterExcludedMovementTypes(recoveryReserves, excludedMovementTypes);
            payments = FilterExcludedMovementTypes(payments, excludedMovementTypes);

            reserves = CreateAmountsForCalculation(reserves);
            recoveryReserves = CreateAmountsForCalculation(recoveryReserves);
            payments = CreateAmountsForCalculation(payments);
        }
        private static decimal AddReserve(decimal amount, FinancialTransactionContext financialContext, ClaimDetail claimDetail, ClaimTransactionGroup claimTransactionGroup, DeductibleDefinition deductibleDefinition, DeductibleReserveCapacity deductibleReserveContext, ClaimFinancialAmount latestReserve = null)
        {
            StaticValues.AmountType amountType;
            string nonFundedMovementType;
            if (IsRecovery(financialContext.TransactionSource))
            {
                amountType = StaticValues.AmountType.RecoveryReserve;
                nonFundedMovementType = deductibleDefinition.RecoveryNonFundedMovementType;
            }
            else
            {
                amountType = StaticValues.AmountType.Reserve;
                nonFundedMovementType = deductibleDefinition.NonFundedMovementType;
            }


            if (latestReserve == null)
            {
                if (amount > 0)
                {
                    AddClaimTransactionDetails(financialContext.ClaimTransactionHeader.TransactionDate.GetValueOrDefault(DateTime.MinValue), claimTransactionGroup, amountType, deductibleDefinition, amount, latestReserve);
                    deductibleReserveContext.AdjustDeductibleAttached(claimDetail.ClaimDetailReference, nonFundedMovementType, amount);
                }
                else
                {
                    amount = 0;
                }
            }
            else if (amount != Math.Abs(latestReserve.TransactionAmountClaimCurrency.GetValueOrDefault(0)))
            {
                AddClaimTransactionDetails(financialContext.ClaimTransactionHeader.TransactionDate.GetValueOrDefault(DateTime.MinValue), claimTransactionGroup, amountType, deductibleDefinition, amount, latestReserve);
                deductibleReserveContext.AdjustDeductibleAttached(claimDetail.ClaimDetailReference, nonFundedMovementType, amount + latestReserve.TransactionAmountClaimCurrency.GetValueOrDefault());
            }

            return amount;
        }
 private static bool IsCalculatingExcess(ProductClaimDetail productClaimDetail, ClaimDetail claimDetail)
 {
     return productClaimDetail.ClaimDetailAutomaticDeductibleProcessingMethod == (short)StaticValues.ClaimDetailAutomaticDeductibleProcessingMethod.StandardClaimDetailDeductible
         && claimDetail.IsAutomaticDeductibleProcessingApplied == true;
 }
        private static ClaimTransactionGroup ResolveClaimTransactionGroup(ClaimTransactionHeader claimTransactionHeader, ClaimTransactionGroup currentClaimTransactionGroup, ClaimDetail claimDetail)
        {
            var claimTransactionGroup = claimTransactionHeader.ClaimTransactionGroups.SingleOrDefault(a => a.ClaimDetail == claimDetail);
            if (claimTransactionGroup == null)
            {
                claimTransactionGroup = claimTransactionHeader.AddNewClaimTransactionGroup(claimDetail, false);
                claimTransactionGroup.UpdateData(currentClaimTransactionGroup);
                // don't want to copy the id accross
                claimTransactionGroup.ClaimTransactionGroupID = 0;
            }

            return claimTransactionGroup;
        }