public static CarrierInvoiceProfile Save(CarrierInvoiceProfile profile)
        {
            if (profile.CarrierInvoiceProfileID == 0) {
                DbContextHelper.DbContext.Add(profile);
            }

            DbContextHelper.DbContext.SaveChanges();

            return profile;
        }
Пример #2
0
        private decimal calculateInvoiceAmount(CRM.Data.Entities.LeadPolicy policy)
        {
            string[] applicableStates = null;
            string   claimState       = null;

            CRM.Data.Entities.CarrierInvoiceProfile profile = null;
            decimal invoiceAmount   = 0;
            decimal netClaimPayable = 0;

            int profileID = Convert.ToInt32(ddlInvoiceProfile.SelectedValue);

            profile = CarrierInvoiceProfileManager.GetProfileForInvoicing(profileID, policy.ClaimDesignationID);

            if (profile != null)
            {
                // check applicable state
                if (!string.IsNullOrEmpty(profile.CoverageArea))
                {
                    applicableStates = profile.CoverageArea.Split(new char[] { ',' });

                    if (policy.Leads != null && policy.Leads.StateId != null && !applicableStates.Contains("all"))
                    {
                        claimState = policy.Leads.StateId.ToString();

                        if (!applicableStates.Contains(claimState))
                        {
                            return(0);
                        }
                    }
                }

                // determine which amount to use as base to calculate invoice amount
                if (profile.InvoiceType != null && profile.InvoiceType == 1)
                {
                    netClaimPayable = (decimal)policy.NetClaimPayable;
                }
                else if (profile.InvoiceType != null && profile.InvoiceType == 2)
                {
                    netClaimPayable = (decimal)policy.GrossLossPayable;
                }

                // apply schedule fee
                if (profile != null && profile.CarrierInvoiceProfileFeeSchedule != null && profile.CarrierInvoiceProfileFeeSchedule.Count() > 0)
                {
                    foreach (CarrierInvoiceProfileFeeSchedule schedule in profile.CarrierInvoiceProfileFeeSchedule)
                    {
                        if (netClaimPayable >= schedule.RangeAmountFrom && netClaimPayable <= schedule.RangeAmountTo)
                        {
                            if (schedule.FlatFee > 0)
                            {
                                invoiceAmount = schedule.FlatFee;
                            }
                            else if (schedule.MinimumFee > 0)
                            {
                                invoiceAmount = schedule.MinimumFee;
                            }
                            else if (schedule.PercentFee > 0)
                            {
                                invoiceAmount = netClaimPayable * schedule.PercentFee;
                            }
                        }
                    }
                }

                // apply pricing provisions
                if (profile != null && profile.CarrierInvoiceProfileFeeProvision != null && profile.CarrierInvoiceProfileFeeProvision.Count() > 0)
                {
                    foreach (CarrierInvoiceProfileFeeProvision feeProvision in profile.CarrierInvoiceProfileFeeProvision)
                    {
                        if (feeProvision.ProvisionAmount > 0)
                        {
                            invoiceAmount += feeProvision.ProvisionAmount;
                        }
                    }
                }
            }

            return(invoiceAmount);
        }