This part of the query doesn’t seem to be working
$iThisYear = date('Y');
$iLastYear = $iThisYear-1;
SELECT * FROM `{$this->_sPrefix}clicks`
WHERE `affiliate_id` = '{$iAid}'
AND `raw` = '1'
AND YEAR(`date`) = '{$iLastYear}'
It grabs from this year still. Does YEAR work?
Could you use DATE_SUB instead