public void CalculateCommission(BO.HomeProduct homeProduct, BO.HomeInsurancePolicy policy,
                                        long homeID, string documentNo, string LinkID, int renewalCount)
        {
            try
            {
                int lineNo = 0;
                if (homeProduct.Category != null && homeProduct.Category.Count > 0)
                {
                    List <PolicyCategory> policyCategories = new List <PolicyCategory>();
                    foreach (var dr in homeProduct.Category)
                    {
                        lineNo++;
                        if (!policy.UserChangedPremium)
                        {
                            if (dr.ValueType == "Percent" && dr.Code == "BASICCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = TotalBasicPremium * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = TotalBasicPremium * dr.Value / 100;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = TotalBasicPremium;
                                policyCategory.PremiumBeforeDiscount         = TotalBasicPremium;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(TotalBasicPremium, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(TotalBasicPremium, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                            if (dr.ValueType == "Percent" && dr.Code == "SRCCCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = TotalSRCCPremium * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = TotalSRCCPremium * dr.Value / 100;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = TotalSRCCPremium;
                                policyCategory.PremiumBeforeDiscount         = TotalSRCCPremium;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(TotalSRCCPremium, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(TotalSRCCPremium, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                            if (dr.ValueType == "Percent" && dr.Code == "AGTCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = TotalPremium * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = TotalPremium * dr.Value / 100;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = TotalPremium;
                                policyCategory.PremiumBeforeDiscount         = TotalPremium;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(TotalPremium, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(TotalPremium, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                        }
                        else
                        {
                            if (dr.ValueType == "Percent" && dr.Code == "BASICCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = TotalBasicPremium * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = CommissionAfterDiscount;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = PremiumAfterDiscount;
                                policyCategory.PremiumBeforeDiscount         = TotalBasicPremium;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(TotalBasicPremium, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                            if (dr.ValueType == "Percent" && dr.Code == "SRCCCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = TotalSRCCPremium * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = policy.IsRiotStrikeDamage.ToString().ToLower() == "y" ? CommissionAfterDiscount : 0;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = policy.IsRiotStrikeDamage.ToString().ToLower() == "y" ? PremiumAfterDiscount : 0;
                                policyCategory.PremiumBeforeDiscount         = TotalSRCCPremium;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(TotalSRCCPremium, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                            if (dr.ValueType == "Percent" && dr.Code == "AGTCOMM")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = PremiumBeforeDiscount * dr.Value / 100;
                                policyCategory.CommissionAfterDiscount  = PremiumAfterDiscount * dr.Value / 100;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = homeID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = PremiumAfterDiscount;
                                policyCategory.PremiumBeforeDiscount         = PremiumBeforeDiscount;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(PremiumBeforeDiscount, homeProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, homeProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.HomeID       = homeID;

                                policyCategories.Add(policyCategory);
                            }
                        }
                    }
                    if (policy.UserChangedPremium)
                    {
                        var commissionDiscount = policy.CommissionAfterDiscount;
                        foreach (var pc in policyCategories)
                        {
                            if (pc.IsDeductable)
                            {
                                if (pc.CommissionBeforeDiscount < commissionDiscount)
                                {
                                    pc.CommissionAfterDiscount      = pc.CommissionBeforeDiscount;
                                    pc.TaxOnCommissionAfterDiscount = GetTax(pc.CommissionBeforeDiscount, homeProduct.TaxRate);
                                    commissionDiscount = commissionDiscount - pc.CommissionBeforeDiscount;
                                }
                                else
                                {
                                    pc.CommissionAfterDiscount      = commissionDiscount;
                                    pc.TaxOnCommissionAfterDiscount = GetTax(commissionDiscount, homeProduct.TaxRate);
                                    commissionDiscount = 0;
                                }
                            }
                        }
                    }
                    InsertCategory(policy, policyCategories);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public void CalculateCommission(BO.MotorProduct motorProduct, BO.MotorInsurancePolicy policy,
                                        long motorID, string documentNo, string LinkID, int renewalCount)
        {
            try
            {
                int lineNo = 0;
                if (motorProduct.Category != null && motorProduct.Category.Count > 0)
                {
                    List <PolicyCategory> policyCategories = new List <PolicyCategory>();
                    foreach (var dr in motorProduct.Category)
                    {
                        lineNo++;
                        if (!policy.UserChangedPremium)
                        {
                            if (dr.ValueType == "Percent")
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = Math.Round(dr.IsDeductable ?
                                                                                     PremiumBeforeDiscount * dr.Value / 100
                                                                          : PremiumAfterDiscount * dr.Value / 100, 3, MidpointRounding.AwayFromZero);

                                policyCategory.CommissionAfterDiscount = Math.Round(PremiumAfterDiscount * dr.Value / 100, 3, MidpointRounding.AwayFromZero);
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = motorID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = PremiumAfterDiscount;
                                policyCategory.PremiumBeforeDiscount         = PremiumBeforeDiscount;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(PremiumBeforeDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, motorProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.MotorID      = motorID;

                                policyCategories.Add(policyCategory);
                            }
                        }
                        else
                        {
                            if (dr.ValueType == "Percent" && dr.IsDeductable)
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = Math.Round(PremiumBeforeDiscount * dr.Value / 100, 3, MidpointRounding.AwayFromZero);
                                policyCategory.CommissionAfterDiscount  = CommissionAfterDiscount - NonDeductableCommission;
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = motorID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = PremiumAfterDiscount;
                                policyCategory.PremiumBeforeDiscount         = PremiumBeforeDiscount;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(PremiumBeforeDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, motorProduct.TaxRate);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.MotorID      = motorID;

                                policyCategories.Add(policyCategory);
                            }
                            if (dr.ValueType == "Percent" && !dr.IsDeductable)
                            {
                                var policyCategory = new PolicyCategory();
                                policyCategory.Agency    = dr.Agency;
                                policyCategory.AgentCode = dr.AgentCode;
                                policyCategory.Code      = dr.Code;
                                policyCategory.Category  = dr.Category;
                                policyCategory.CommissionBeforeDiscount = Math.Round(PremiumAfterDiscount * dr.Value / 100, 3, MidpointRounding.AwayFromZero);
                                policyCategory.CommissionAfterDiscount  = Math.Round(PremiumAfterDiscount * dr.Value / 100, 3, MidpointRounding.AwayFromZero);
                                policyCategory.DocumentNo                    = documentNo;
                                policyCategory.EndorsementCount              = 0;
                                policyCategory.EndorsementNo                 = string.Empty;
                                policyCategory.DocumentID                    = motorID;
                                policyCategory.LineNo                        = lineNo.ToString();
                                policyCategory.LinkID                        = LinkID;
                                policyCategory.PremiumAfterDiscount          = PremiumAfterDiscount;
                                policyCategory.PremiumBeforeDiscount         = PremiumAfterDiscount;
                                policyCategory.TaxOnCommissionBeforeDiscount = GetTax(policyCategory.CommissionBeforeDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnCommissionAfterDiscount  = GetTax(policyCategory.CommissionAfterDiscount, motorProduct.TaxRate);
                                policyCategory.TaxOnPremiumBeforeDiscount    = GetTax(PremiumAfterDiscount, 5);
                                policyCategory.TaxOnPremiumAfterDiscount     = GetTax(PremiumAfterDiscount, 5);
                                policyCategory.Value        = dr.Value;
                                policyCategory.ValueType    = dr.ValueType;
                                policyCategory.IsDeductable = dr.IsDeductable;
                                policyCategory.RenewalCount = renewalCount;
                                policyCategory.MotorID      = motorID;

                                policyCategories.Add(policyCategory);
                            }
                        }
                    }
                    if (policy.UserChangedPremium)
                    {
                        var commissionDiscount = policy.CommissionAfterDiscount;
                        foreach (var pc in policyCategories)
                        {
                            if (pc.IsDeductable)
                            {
                                if (pc.CommissionBeforeDiscount < commissionDiscount)
                                {
                                    pc.CommissionAfterDiscount      = pc.CommissionBeforeDiscount;
                                    pc.TaxOnCommissionAfterDiscount = GetTax(pc.CommissionBeforeDiscount, motorProduct.TaxRate);
                                    commissionDiscount = commissionDiscount - pc.CommissionBeforeDiscount;
                                }
                                else
                                {
                                    pc.CommissionAfterDiscount      = commissionDiscount;
                                    pc.TaxOnCommissionAfterDiscount = GetTax(commissionDiscount, motorProduct.TaxRate);
                                    commissionDiscount = 0;
                                }
                            }
                        }
                    }
                    InsertCategory(policy, policyCategories);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }