"SELECT COUNT(*) FROM deductions WHERE contractor_id = ? AND payroll_month = ? AND status IN ('applied','applied_no_response','reduced','accepted') AND deleted_at IS NULL",
[$userId,$month]
);
$bountyCount=(int)$this->db->fetchColumn(
"SELECT COUNT(*) FROM bounty_payouts WHERE recipient_id = ? AND payroll_month = ?",
[$userId,$month]
);
return[
'actual_salary'=>$actualSalary,
'live_salary'=>$liveSalary,
'total_bounties'=>$totalBounties,
'total_deductions'=>$totalDeductions,
'total_pos_adj'=>$totalPosAdj,
'total_neg_adj'=>$totalNegAdj,
'deduction_count'=>$deductionCount,
'bounty_count'=>$bountyCount,
'month'=>$month,
];
try{
$unreadCount=(int)$db->fetchColumn(
"SELECT COUNT(*) FROM notifications WHERE user_id = ? AND is_read = 0",
[$userId]
);
$hasBlocking=(int)$db->fetchColumn(
"SELECT COUNT(*) FROM notifications WHERE user_id = ? AND tier = 'blocking' AND is_acknowledged = 0",
[$userId]
);
$this->sendEvent('notification_count',[
'unread_count'=>$unreadCount,
'has_blocking'=>$hasBlocking>0,
]);
// If there's a blocking notification, send its details
if($hasBlocking>0){
$blocking=$db->fetchOne(
"SELECT id, title, content, link_url FROM notifications
WHERE user_id = ? AND tier = 'blocking' AND is_acknowledged = 0