$diff = date('z',$due) - date('z', $now);
i suspect this line is the problem. the "z" switch to the [man]date[/man] function calculates the day of the year starting at 0 for that calender year, so a day next year will reset back to 0 (giving you a negative number the for the $diff). you probably want something more like:
$diff = floor(($due - $now) / 86400);
this will calulate the absolute difference in days between now and the due date.