Animal Ages at Induction and Adoption
###
Movements
###
3001/PostgreSQL rev02
###
Ages at induction and adoption for all animals adopted between two dates.
###
en
###
SELECT DISTINCT a.ShelterCode, a.AnimalName, a.ID AS AID,
CAST(justify_interval(age(a.DateBroughtIn, a.DateOfBirth)) AS VARCHAR) AS InductionAge,
a.ActiveMovementDate As AdoptionDate,
CAST(justify_interval(age(a.ActiveMovementDate, a.DateOfBirth)) AS VARCHAR) AS AdoptionAge, 
o.OwnerName, o.ID AS OID, o.OwnerAddress, o.OwnerTown, o.OwnerCounty, o.OwnerPostcode, 
o.HomeTelephone, o.WorkTelephone, o.MobileTelephone, o.EmailAddress 
FROM animal a 
INNER JOIN adoption ad ON ad.AnimalID = a.ID
INNER JOIN owner o ON ad.OwnerID = o.ID
WHERE a.ActiveMovementType = 1 
AND a.ActiveMovementDate >= '$ASK DATE Enter from date$' 
AND a.ActiveMovementDate <= '$ASK DATE Enter to date$'
ORDER BY a.ActiveMovementDate
###
$$HEADER
<table border="1">
<thead>
<tr>
<th>Animal</th>
<th>Age at Induction</th>
<th>Date Adopted</th>
<th>Age at Adoption</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
HEADER$$

$$BODY
<tr>
<td>$SHELTERCODE - <a target="_blank" href="animal?id=$AID">$ANIMALNAME</a></td>
<td>$INDUCTIONAGE</td>
<td>$ADOPTIONDATE</td>
<td>$ADOPTIONAGE</td>
<td><b><a target="_blank" href="person?id=$OID">$OWNERNAME</a></b><br />
$OWNERADDRESS<br />
$OWNERTOWN<br />
$OWNERCOUNTY<br />
$OWNERPOSTCODE<br />
$HOMETELEPHONE<br />
$MOBILETELEPHONE<br />
<i>$EMAILADDRESS</i></td>
</tr>
BODY$$

$$FOOTER
</tbody>
</table>
FOOTER$$
