public void SetHIR(BO.HomeProduct product, BO.HomeInsurancePolicy policy)
        {
            bool isAdded = false;

            if (product.MaximumBuildingValue < policy.BuildingValue)
            {
                IsHIR     = true;
                HIRReason = "Building value exceeded the limit";
                HIRStatus = 1;
                isAdded   = true;
            }
            if (product.MaximumContentValue < policy.ContentValue)
            {
                IsHIR     = true;
                HIRReason = HIRReason = isAdded ? HIRReason + ", " + "Content Value exceeded the limit" : "Content Value exceeded the limit";
                HIRStatus = 1;
                isAdded   = true;
            }
            if (product.MaximumJewelleryValue < policy.JewelleryValue)
            {
                IsHIR     = true;
                HIRReason = HIRReason = isAdded ? HIRReason + ", " + "Jewellery Value exceeded the limit" : "Jewellery Value exceeded the limit";
                HIRStatus = 1;
                isAdded   = true;
            }
            if (product.MaximumTotalValue < policy.BuildingValue + policy.ContentValue)
            {
                IsHIR     = true;
                HIRReason = HIRReason = isAdded ? ", " + "Total Value exceeded the limit" : "Total Value exceeded the limit";
                HIRStatus = 1;
                isAdded   = true;
            }
        }
 private void InsertCategory(BO.HomeInsurancePolicy policy, List <PolicyCategory> policyCategories)
 {
     if (policyCategories != null && policyCategories.Count > 0)
     {
         foreach (var dr in policyCategories)
         {
             SqlParameter[] paras = new SqlParameter[]
             {
                 new SqlParameter("@DocumentID", dr.DocumentID),
                 new SqlParameter("@InsuredCode", policy.InsuredCode),
                 new SqlParameter("@LinkID", dr.LinkID),
                 new SqlParameter("@DocumentNo", dr.DocumentNo),
                 new SqlParameter("@EndorsementNo", dr.EndorsementNo ?? string.Empty),
                 new SqlParameter("@EndorsementCount", dr.EndorsementCount),
                 new SqlParameter("@AgentCode", dr.AgentCode),
                 new SqlParameter("@LineNo", dr.LineNo),
                 new SqlParameter("@Category", dr.Category),
                 new SqlParameter("@Code", dr.Code),
                 new SqlParameter("@ValueType", dr.ValueType),
                 new SqlParameter("@Value", dr.Value),
                 new SqlParameter("@PremiumBeforeDiscount", dr.PremiumBeforeDiscount),
                 new SqlParameter("@PremiumAfterDiscount", dr.PremiumAfterDiscount),
                 new SqlParameter("@CommissionBeforeDiscount", dr.CommissionBeforeDiscount),
                 new SqlParameter("@CommissionAfterDiscount", dr.CommissionAfterDiscount),
                 new SqlParameter("@TaxOnPremiumBeforeDiscount", dr.TaxOnPremiumBeforeDiscount),
                 new SqlParameter("@TaxOnPremiumAfterDiscount", dr.TaxOnPremiumAfterDiscount),
                 new SqlParameter("@TaxOnCommissionBeforeDiscount", dr.TaxOnCommissionBeforeDiscount),
                 new SqlParameter("@TaxOnCommissionAfterDiscount", dr.TaxOnCommissionAfterDiscount),
                 new SqlParameter("@IsDeductable", dr.IsDeductable),
                 new SqlParameter("@RenewalCount", dr.RenewalCount),
                 new SqlParameter("@DomesticID", DBNull.Value),
                 new SqlParameter("@TravelID", DBNull.Value),
                 new SqlParameter("@HomeID", dr.HomeID),
                 new SqlParameter("@MotorID", DBNull.Value),
                 new SqlParameter("@MotorEndorsementID", DBNull.Value),
                 new SqlParameter("@TravelEndorsementID", DBNull.Value),
                 new SqlParameter("@HomeEndorsementID", DBNull.Value),
             };
             BKICSQL.edt(MotorInsuranceSP.PolicyCategoryInsert, paras);
         }
     }
 }
        public decimal GetCommision(BO.HomeInsurancePolicy policy, decimal totalBasicPremium, decimal totalSRCCPremium)
        {
            decimal CommissionAmount = 0;

            var commisionRequest = new BO.HomeCommissionRequest
            {
                AgentCode         = policy.AgentCode,
                Agency            = policy.Agency,
                SubClass          = policy.SubClass,
                TotalBasicPremium = totalBasicPremium,
                TotalSRCCPremium  = totalSRCCPremium
            };

            var commissionResponse = _insurancePortalRepository.GetHomePolicyCommission(commisionRequest);

            if (commissionResponse.IsTransactionDone)
            {
                CommissionAmount = commissionResponse.BasicCommission;
            }
            return(CommissionAmount);
        }
        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;
            }
        }