﻿<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
  <entity name = 'llp_insurancepolicy'>
    <attribute name='llp_policynumber' />
    <attribute name='llp_dateactivated' />
    <attribute name='llp_customerid' />
    <attribute name='llp_daterenew' />
    <attribute name='llp_policystatus_public' />
    <attribute name='llp_policynote_public' />
    <attribute name='createdon' />
    <order attribute='llp_customerid' descending='false' />
    <filter type='and'>
      <condition attribute='llp_policynumber' operator='eq' value='${policyNr}' />
    </filter>
    <link-entity name='product' from='productid' to='llp_productid' visible='false' link-type='outer' alias='product'>
      <attribute name='name' />
    </link-entity>
    <link-entity name="llp_policybenefits" from="llp_insurancepolicyid" to="llp_insurancepolicyid" link-type="outer" alias="policybenefit" >
      <attribute name="llp_name" />
      <attribute name="llp_currentbalance" />
      <attribute name="llp_qualificationdate" />
      <attribute name="llp_benefitname" />
      <filter type='and'>
        <filter type='or'>
          <condition attribute='llp_benefitname' operator='like' value='PBACC%' />
          <condition attribute='llp_benefitname' operator='like' value='PBVET%' />
        </filter>
      </filter>
      <link-entity name="llp_benefit" from="llp_benefitid" to="llp_benefitcodeid" link-type="outer" alias="benefit" >
        <attribute name="llp_benefitcode" />
      </link-entity>
    </link-entity>
  </entity>
</fetch>
