SELECT sum(b.amountdr) as currentyeardebit, sum(b.amountcr) as currentyearcredit, sum(b.total) as total, `a`.*, `ref`.`acctTypeID`
FROM (`comp_chart_of_acct` a)
LEFT OUTER JOIN `view_comp_acc_det` b ON `b`.`acctID` = `a`.`ID` and CONCAT(b.year,if(b.period <=9, CONCAT("0",b.period),b.period)) <= 201512 and b.companyID = 3
LEFT JOIN `_ref_acct_group` ref ON `ref`.`ID` = `a`.`acctGroupID`
WHERE `a`.`companyID` =  '3'
AND `a`.`ID` =  '32517'
GROUP BY `a`.`ID`