Unsuccessful Trial Adoptions
###
Movements
###
3200/Any rev02
###
Trial adoptions that were not successful with the animal returned
###
en
###
SELECT a.AnimalName, a.ID AS AID, a.ShelterCode, sx.Sex, a.BreedName, a.AnimalAge, s.SpeciesName, atp.AnimalType, 
ad.MovementDate, ad.TrialEndDate, 
o.OwnerName, o.ID AS OID, o.OwnerAddress, o.OwnerTown, o.OwnerCounty, o.OwnerPostcode, o.HomeTelephone, ad.ReturnDate
FROM animal a
INNER JOIN adoption ad ON ad.AnimalID = a.ID
INNER JOIN owner o ON o.ID = ad.OwnerID
INNER JOIN species s ON a.SpeciesID = s.ID
INNER JOIN animaltype atp ON atp.ID = a.AnimalTypeID
INNER JOIN lksex sx ON sx.ID = a.Sex
WHERE ad.TrialEndDate Is Not Null AND ad.IsTrial = 1 AND ad.MovementType = 1 AND ad.ReturnDate Is Not Null
AND MovementDate >= '$ASK DATE Enter from date$' AND MovementDate <= '$ASK DATE Enter to date$'
ORDER BY ad.MovementDate
###
$$HEADER
<table border="1">
<thead>
<tr>
<th>Animal</th>
<th>Type</th>
<th>Adopted</th>
<th>Trial Ended</th>
<th>Returned</th>
<th>Adopter</th>
</tr>
</thead>
<tbody>
HEADER$$

$$BODY
<tr>
<td><b><a target="_blank" href="animal?id=$AID">$SHELTERCODE - $ANIMALNAME</a></b><br/>
$SEX $BREEDNAME $SPECIESNAME aged $ANIMALAGE</td>
<td>$ANIMALTYPE</td>
<td>$MOVEMENTDATE</td>
<td>$TRIALENDDATE</td>
<td>$RETURNDATE</td>
<td><b><a target="_blank" href="person?id=$OID">$OWNERNAME</a></b><br/>
$OWNERADDRESS<br/>
$OWNERTOWN<br/>
$OWNERCOUNTY<br/>
$OWNERPOSTCODE<br/>
$HOMETELEPHONE</td>
</tr>
BODY$$

$$FOOTER
</tbody>
</table>
<p>Total successful trial adoptions: {COUNT.SHELTERCODE}</p>
FOOTER$$
