{%- set rq = document.InsuranceSvcRq.HomePolicyQuoteInqRq -%} {%- set pp = rq.PersPolicy -%} {%- set dwell = rq.HomeLineBusiness.Dwell -%} {%- set co_insureds = rq.xpath("InsuredOrPrincipal[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd='Coinsured']") -%} {%- set add_interests = rq.xpath("InsuredOrPrincipal[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd='AI']") -%} {%- set named_insureds = rq.xpath("InsuredOrPrincipal[InsuredOrPrincipalInfo/InsuredOrPrincipalRoleCd='Insured']") + co_insureds -%} {%- set effective_year = parse_date(rq.TransactionEffectiveDt.text).year -%} {%- do var_data.update({ 'changes': [] }) -%} {%- do var_data.update({ 'hard_stops': [] }) -%} {%- macro phone_map(phones) -%} {%- for phone in phones -%} {%- if phone.CommunicationUseCd == 'Home' -%} {%- set phone_type = 'Home' -%} {%- elif phone.CommunicationUseCd in ['Business', 'Work'] -%} {%- set phone_type = 'Work' -%} {%- else -%} {%- set phone_type = 'Cell' -%} {%- endif -%} {%- set num_list = (phone.PhoneNumber|replace('+1-', '')).split('-') -%} {%- if num_list|length > 1 -%} {%- set area_code = num_list[0] -%} {%- set first_three = num_list[1][:3] -%} {%- set last_four = num_list[1][3:] -%} {"number": "{{ "({}) {}-{}".format(area_code, first_three, last_four) }}", "type": "{{ phone_type }}"} {%- else -%} {%- set area_code = num_list[0][:3] -%} {%- set first_three = num_list[0][3:6] -%} {%- set last_four = num_list[0][6:] -%} {"number": "{{ "({}) {}-{}".format(area_code, first_three, last_four) }}", "type": "{{ phone_type }}"} {%- endif -%} {{ ', ' if not loop.last }} {%- endfor -%} {% endmacro %} {%- macro email_map(emails) -%} {%- for email in emails -%} {%- if email.CommunicationUseCd -%} {%- if email.CommunicationUseCd == 'Home' -%} {%- set email_type = 'Home' -%} {%- elif email.CommunicationUseCd in ['Business', 'Work'] -%} {%- set email_type = 'Work' -%} {%- elif email.CommunicationUseCd == 'ICE' -%} {%- set email_type = 'Notifications' -%} {%- else -%} {%- set email_type = 'Others' -%} {%- endif -%} {%- else -%} {%- set email_type = 'Home' -%} {%- endif -%} {%- if email.EmailAddr -%} {"email": "{{ email.EmailAddr }}", "type": "{{ email_type }}", "id": ""} {%- endif -%} {{ ', ' if not loop.last }} {%- endfor -%} {%- endmacro -%} {%- macro get_limit(cov_code) -%} {%- set limit_els = dwell.xpath("Coverage[CoverageCd='" ~ cov_code ~ "']/Limit") -%} {%- if limit_els|length > 0 -%} {{ limit_els[0].FormatInteger }} {%- else -%} {{ 0 }} {%- endif -%} {%- endmacro -%} {%- macro get_limit_pct(cov_code) -%} {%- set limit_els = dwell.xpath("Coverage[CoverageCd='" ~ cov_code ~ "']/Limit") -%} {%- if limit_els|length > 0 -%} {{ limit_els[0].FormatPct }} {%- else -%} {{ 0 }} {%- endif -%} {%- endmacro -%} {%- macro get_deductible_pct(cov_code, deductible_applies_to) -%} {%- set cov_a_limit = get_limit("DWELL") -%} {%- set deductible_els_matching_applies_to = dwell.xpath("Coverage[CoverageCd='" ~ cov_code ~ "']/Deductible[DeductibleAppliesToCd='" ~ deductible_applies_to ~ "']") -%} {%- if deductible_els_matching_applies_to|length > 0 -%} {%- if deductible_els_matching_applies_to[0].FormatPct -%} {{ deductible_els_matching_applies_to[0].FormatPct }} {%- elif deductible_els_matching_applies_to[0].FormatInteger -%} {{ deductible_els_matching_applies_to[0].FormatInteger|int * 100 / cov_a_limit|float }} {%- endif -%} {%- else -%} {%- set deductible_els = dwell.xpath("Coverage[CoverageCd='" ~ cov_code ~ "']/Deductible") -%} {%- if deductible_els|length > 0 -%} {%- if deductible_els[0].FormatPct -%} {{ deductible_els[0].FormatPct }} {%- elif deductible_els[0].FormatInteger -%} {{ deductible_els[0].FormatInteger|int * 100 / cov_a_limit|float }} {%- endif -%} {%- else -%} {{ 0 }} {%- endif -%} {%- endif -%} {%- endmacro -%} {%- macro numerical_value_bounce(requested_value, available_values, has_float=False) -%} {%- set requested_value = requested_value|int if not has_float else requested_value|float -%} {%- if requested_value in available_values -%} {{ requested_value }} {%- else -%} {%- if requested_value > available_values|max -%} {{ available_values|max }} {%- elif requested_value < available_values|min -%} {{ available_values|min }} {%- else -%} {%- for value in available_values -%} {%- if requested_value > value -%} {%- if requested_value < loop.nextitem -%} {%- set abs_diff = (requested_value - value)|abs -%} {%- set value_range = value - loop.nextitem -%} {%- if abs_diff < (value_range / 2) -%} {{ value }} {%- else -%} {{ loop.nextitem }} {%- endif -%} {%- endif -%} {%- endif -%} {%- endfor -%} {%- endif -%} {%- endif -%} {%- endmacro -%} {%- macro format_money(amount) -%} {{ "${:,.0f}".format(amount|float) if amount|int > 0 else "-${:,.0f}".format(amount|float|abs) }} {%- endmacro -%} {%- set ACORD_CONSTRUCTION_TYPE_MAP = { 'F': 'Frame', 'BRICK': 'Masonry', 'JM': 'Masonry', 'MY': 'Masonry', 'V': 'Masonry Veneer', 'MFR': 'Masonry', 'R': 'Masonry', 'SNC': 'Masonry', 'StuccoF': 'Stucco', 'N': 'Frame', 'ConPour': 'Masonry', 'Steel': 'Frame', 'T': 'Frame', 'L': 'Frame' } -%} {%- set ACORD_ROOF_MATERIAL_MAP = { 'ALUM': 'Metal', 'ARCH': 'Architectural Shingle', 'ASBO': 'Other', 'ASPHS': 'Architectural Shingle', 'CEDRK': 'Wood', 'CEDRS': 'Wood', 'CLAY': 'Concrete/Clay Tile', 'COMP': 'Composition Shingle', 'CONC': 'Concrete/Clay Tile', 'CONCRETE': 'Concrete/Clay Tile', 'COPP': 'Metal', 'FIBER': 'Other', 'FOAM': 'Other', 'GRAVL': 'Tar/Gravel', 'METL': 'Metal', 'MINFR': 'Other', 'MissTile': 'Concrete/Clay Tile', 'OT': 'Other', 'PLAS': 'Other', 'POUR': 'Poured', 'RECYC': 'Other', 'ROCK': 'Other', 'ROLL': 'Other', 'RUBB': 'Other', 'SLAT': 'Slate', 'SpTile': 'Concrete/Clay Tile', 'STCOR': 'Metal', 'STPOR': 'Other', 'TAR': 'Tar/Gravel', 'TILE': 'Concrete/Clay Tile', 'TIN': 'Metal', 'WF': 'Wood', 'WOODK': 'Wood', 'WOODS': 'Wood', 'WOODSS': 'Wood' } -%} {%- set COUNTY_CODE_MAP = { "Adams": "001", "Alexander": "003", "Bond": "005", "Boone": "007", "Brown": "009", "Bureau": "011", "Calhoun": "013", "Carroll": "015", "Cass": "017", "Champaign": "019", "Christian": "021", "Clark": "023", "Clay": "025", "Clinton": "027", "Coles": "029", "Cook": "031", "Crawford": "033", "Cumberland": "035", "De Witt": "039", "DeKalb": "037", "Douglas": "041", "DuPage": "043", "Edgar": "045", "Edwards": "047", "Effingham": "049", "Fayette": "051", "Ford": "053", "Franklin": "055", "Fulton": "057", "Gallatin": "059", "Greene": "061", "Grundy": "063", "Hamilton": "065", "Hancock": "067", "Hardin": "069", "Henderson": "071", "Henry": "073", "Iroquois": "075", "Jackson": "077", "Jasper": "079", "Jefferson": "081", "Jersey": "083", "Jo Daviess": "085", "Johnson": "087", "Kane": "089", "Kankakee": "091", "Kendall": "093", "Knox": "095", "Lake": "097", "LaSalle": "099", "Lawrence": "101", "Lee": "103", "Livingston": "105", "Logan": "107", "Macon": "115", "Macoupin": "117", "Madison": "119", "Marion": "121", "Marshall": "123", "Mason": "125", "Massac": "127", "McDonough": "109", "McHenry": "111", "McLean": "113", "Menard": "129", "Mercer": "131", "Monroe": "133", "Montgomery": "135", "Morgan": "137", "Moultrie": "139", "Ogle": "141", "Peoria": "143", "Perry": "145", "Piatt": "147", "Pike": "149", "Pope": "151", "Pulaski": "153", "Putnam": "155", "Randolph": "157", "Richland": "159", "Rock Island": "161", "Saline": "165", "Sangamon": "167", "Schuyler": "169", "Scott": "171", "Shelby": "173", "St. Clair": "163", "Stark": "175", "Stephenson": "177", "Tazewell": "179", "Union": "181", "Vermilion": "183", "Wabash": "185", "Warren": "187", "Washington": "189", "Wayne": "191", "White": "193", "Whiteside": "195", "Will": "197", "Williamson": "199", "Winnebago": "201", "Woodford": "203" } -%} {%- if dwell.DwellOccupancy.ResidenceTypeCd != 'DW' or (dwell.DwellOccupancy.DwellUseCd | int) not in [1, 4] or dwell.DwellOccupancy.OccupancyTypeCd != 'OWNER' -%} {%- do var_data.hard_stops.append("Property must be owner-occupied.") -%} {%- endif -%} {%- if var_data.hard_stops -%} {%- do raise_hard_stop() -%} {%- endif -%} { "run_stateless": true, "quote_info": { "effective_date": "{{ rq.TransactionEffectiveDt }}", "line_name": "Homeowners", "agency_id": "{{ document.SignonRq.ClientApp['com.britecore_AgencyId'] }}", "agent_id": "{{ document.SignonRq.ClientApp['com.britecore_AgentId'] }}", "policy_type_name": "IL Homeowners", "underwriting_options": [], "underwriting_questions": [], "named_insureds": [ {%- for insured in named_insureds -%} {%- set first = insured.GeneralPartyInfo.NameInfo.PersonName.GivenName -%} {%- set middle = insured.GeneralPartyInfo.NameInfo.PersonName.OtherGivenName -%} {%- set last = insured.GeneralPartyInfo.NameInfo.PersonName.Surname -%} {%- set insured_name = [first, middle, last]|select()|join(' ') -%} {%- set insured_phones = insured.xpath("GeneralPartyInfo/Communications/PhoneInfo") -%} {%- set insured_emails = insured.xpath("GeneralPartyInfo/Communications/EmailInfo") -%} { "addresses": [ { "address_line1": "{{ insured.xpath("GeneralPartyInfo/Addr[AddrTypeCd='InsuredsAddress']/Addr1")[0]|title }}", "address_line2": "", "address_city": "{{ insured.xpath("GeneralPartyInfo/Addr[AddrTypeCd='InsuredsAddress']/City")[0]|title }}", "address_county": "{{ insured.xpath("GeneralPartyInfo/Addr[AddrTypeCd='InsuredsAddress']/County")[0]|title }}", "address_state": "{{ insured.xpath("GeneralPartyInfo/Addr[AddrTypeCd='InsuredsAddress']/StateProvCd")[0] }}", "address_country": "USA", "address_zip": "{{ insured.xpath("GeneralPartyInfo/Addr[AddrTypeCd='InsuredsAddress']/PostalCode")[0] }}" } ], "ssn": "{{ insured.xpath("GeneralPartyInfo/NameInfo/TaxIdentity[TaxIdTypeCd='SSN']/TaxId")[0] }}", "name": "{{ insured_name }}", "dob": "{{ insured.InsuredOrPrincipalInfo.PersonInfo.BirthDt }}", "phones": [{{ phone_map(insured_phones) }}], "emails": [{{ email_map(insured_emails) }}], "retrieve_credit_report": {{ 'true' if rq.CreditCheckAuthorized and rq.CreditCheckAuthorized.text.lower() == 'yes' else 'false' }} } {{ ', ' if not loop.last }} {%- endfor -%} ], "locations": [ { "address_line1": "{{ rq.Location.Addr.Addr1 }}", "address_line2": "{{ rq.Location.Addr.Addr2 if rq.Location.Addr.Addr2 else "" }}", "address_city": "{{ rq.Location.Addr.City|title() }}", "address_county": "{{ rq.Location.Addr.County|title() }}", "address_county_specify": null, "address_state": "{{ rq.Location.Addr.StateProvCd }}", "address_zip": "{{ rq.Location.Addr.PostalCode }}", "address_country": "USA" } ], "items": [ {%- set roof_year = dwell.Construction.YearBuilt | int -%} {%- set entire_roof = true -%} {%- if dwell.BldgImprovements.RoofingImprovementYear -%} {%- set roof_year = dwell.BldgImprovements.RoofingImprovementYear | int -%} {%- set entire_roof = dwell.BldgImprovements.RoofingImprovementCd == 'C' -%} {%- endif -%} {%- if effective_year - roof_year < 2 -%} { "name": "New Roof Discount", "questions": { "Was the entire roof replaced?": "{{ 'Yes' if entire_roof else 'No' }}" } }, {%- endif -%} { "name": "Rating Information", "questions": { {%- set purchase_date = parse_date(dwell.PurchaseDt.text) -%} "Date of Purchase": "{{ purchase_date.strftime('%m/%d/%Y') if purchase_date else '' }}", "Square Feet of Living Space": "{{ dwell.Construction.BldgArea.NumUnits }}", "Last Home Inspection Date": "", "Flooring": "Other", "Portable Space Heater": "None", "Central Alarm - Burglary": "{{ 'No' if dwell.BldgProtection.ProtectionDeviceBurglarCd.text.lower() == 'no' else 'Yes' }}", "Mine Subsidence Coverage": "Default", {%- set num_residents_in_household = (dwell.DwellOccupancy.NumResidentsInHousehold | int) -%} "Household Occupants": "{{ num_residents_in_household if num_residents_in_household <= 3 else '4+' }}", "VA Loan": "No", "Payment Mode": "Annual", {%- set requested_ded_pct = get_deductible_pct('DWELL', 'Wind') -%} {%- set bounced_ded_pct = numerical_value_bounce(requested_ded_pct, [1, 2, 3, 5]) -%} "Wind Deductible": "{{ bounced_ded_pct }}%", {%- if requested_ded_pct|float != bounced_ded_pct|float -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "DWELL - Dwelling (Cov. A): Requested Wind Deductible {}%, Quoted {}%".format(requested_ded_pct, bounced_ded_pct)}) -%} {%- endif -%} {%- set requested_ded_pct = get_deductible_pct('DWELL', 'AllOth') -%} {%- set bounced_ded_pct = numerical_value_bounce(requested_ded_pct, [1, 2, 3, 5]) -%} "All Other Perils Deductible": "{{ bounced_ded_pct }}%", {%- if requested_ded_pct|float != bounced_ded_pct|float -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "DWELL - Dwelling (Cov. A): Requested All Other Deductible {}%, Quoted {}%".format(requested_ded_pct, bounced_ded_pct)}) -%} {%- endif -%} "Water Heater #2 Location": "None Present", "Central Alarm - Fire": "{{ 'No' if dwell.BldgProtection.ProtectionDeviceFireCd.text.lower() == 'no' else 'Yes' }}", {%- set num_families = dwell.DwellInspectionValuation.NumFamilies | int -%} "Number of Family Units": "{%- if num_families == 1 -%}Single Unit{%- elif num_families == 2 -%}2 Units{%- else -%}Greater than 2 Units{%- endif -%}", "Number of Stories": "{{ dwell.Construction.NumStories }}", "Roof Impact Rating": "None", "Gated Community": "No", "Smart Home Protection": "No", "Water Damage Coverage": "Full", "Roof Year": "{{ effective_year - roof_year }}", "Seasonal Dwelling": "{{ 'No' if (dwell.DwellOccupancy.DwellUseCd | int) == 1 else 'Yes' }}", "Roof Material": "{{ ACORD_ROOF_MATERIAL_MAP[dwell.Construction.RoofingMaterial.RoofMaterialCd] }}", "Protection Class": "{{ dwell.BldgProtection.FireProtectionClassCd }}", "Increased Replacement Cost on Dwelling Endorsement": "None", "Year Built": "{{ effective_year - (dwell.Construction.YearBuilt.text | int) }}", "Construction Type": "{{ ACORD_CONSTRUCTION_TYPE_MAP[dwell.Construction.ConstructionCd] }}", "Plumbing": "PEX (up to 50% CPVC)", "Replacement Cost on Personal Property": "No", "Water Heater #1 Location": "Basement", "Accredited Builder": "No", {%- set num_full_bathrooms = (dwell.DwellInspectionValuation.xpath('BathroomInfo[BathroomTypeCd="Full"]')[0].NumBathrooms | int) -%} "Bathrooms": "{{ num_full_bathrooms if num_full_bathrooms <= 3 else '4+' }}", {%- set cov_a_limit = get_limit("DWELL") -%} {%- set requested_limit = get_limit("PP") -%} {%- set requested_limit_pct = requested_limit|float * 100 / cov_a_limit|float -%} {%- set bounced_limit_pct = numerical_value_bounce(requested_limit_pct, [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) -%} "Personal Property Limit (% of Dwelling Limit)": "{{ bounced_limit_pct }}%", {%- if requested_limit_pct|int != bounced_limit_pct|int -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "PP - Personal Property: Requested {}, Quoted {}".format(format_money(requested_limit), format_money((cov_a_limit|float * bounced_limit_pct|float / 100) | int))}) -%} {%- endif -%} {%- set final_personal_property_limit_pct = bounced_limit_pct -%} "Companion Product": "No", {%- set county_name = rq.Location.Addr.County|title() -%} "County": "{{ '{} ({})'.format(county_name, COUNTY_CODE_MAP[county_name]) }}" } }, { "name": "Dwelling", {%- set cov_a_limit = get_limit("DWELL") -%} "limit": {{ cov_a_limit }}, "questions" : { "Increased Replacement Cost on Dwelling Endorsement": "None" } }, { "name": "Other Structures", "questions": { {%- set requested_limit = get_limit("OS") -%} {%- set requested_limit_pct = requested_limit|float * 100 / cov_a_limit|float -%} {%- set bounced_limit_pct = numerical_value_bounce(requested_limit_pct, [2, 5, 7, 10, 15, 20]) -%} "Other Structures Limit (% of Dwelling Limit)": "{{ bounced_limit_pct }}%" {%- if requested_limit_pct|int != bounced_limit_pct|int -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "OS - Other Structures (Cov. B): Requested {}, Quoted {}".format(format_money(requested_limit), format_money((cov_a_limit|float * bounced_limit_pct|float / 100) | int))}) -%} {%- endif -%} } }, { "name": "Personal Property", "questions": { "Personal Property Limit (% of Dwelling Limit)": "{{ final_personal_property_limit_pct }}%", "Replacement Cost on Personal Property": "No" } }, { "name": "Personal Property Off Premises" }, { "name": "Loss of Use" }, { "name": "Personal Liability", {%- set requested_limit = get_limit("PL") -%} {%- set bounced_limit = numerical_value_bounce(requested_limit, [100000, 300000, 500000]) -%} "limit": {{ bounced_limit }} {%- if requested_limit != bounced_limit -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "PL - Personal Liability (Cov. E): Requested {}, Quoted {}".format(format_money(requested_limit), format_money(bounced_limit))}) -%} {%- endif -%} }, { "name": "Medical Payments to Others", {%- set requested_limit = get_limit("MEDPM") -%} {%- set bounced_limit = numerical_value_bounce(requested_limit, [1000, 2500, 5000]) -%} "limit": {{ bounced_limit }} {%- if requested_limit != bounced_limit -%} {%- do var_data['changes'].append({"ActionCd": "M", "ChangeDesc": "MEDPM - Medical Payments: Requested {}, Quoted {}".format(format_money(requested_limit), format_money(bounced_limit))}) -%} {%- endif -%} }, { "name": "Security Features Discount" } ], "activated": false, "soft_geoservice_bypass": false, "hard_geoservice_bypass": false }, "run_uw_rules": true }