diff --git a/backend/Admin/marketing/trigger_campaign.php b/backend/Admin/marketing/trigger_campaign.php index cc415080..db227fba 100644 --- a/backend/Admin/marketing/trigger_campaign.php +++ b/backend/Admin/marketing/trigger_campaign.php @@ -74,17 +74,23 @@ try { $allPassengers = $stmtTarget->fetchAll(PDO::FETCH_ASSOC); $targets = []; + $debugCounts = ['JO' => 0, 'SY' => 0, 'EG' => 0, 'IQ' => 0, 'UNKNOWN' => 0, 'DECRYPT_FAIL' => 0]; foreach ($allPassengers as $p) { $decryptedPhone = $encryptionHelper->decryptData($p['phone']); - if (!$decryptedPhone) continue; + if (!$decryptedPhone) { + $debugCounts['DECRYPT_FAIL']++; + continue; + } $cleanPhone = preg_replace('/[^0-9]/', '', $decryptedPhone); - $pCountry = ''; + $pCountry = 'UNKNOWN'; if (strpos($cleanPhone, '962') === 0 || strpos($cleanPhone, '07') === 0) $pCountry = 'JO'; elseif (strpos($cleanPhone, '963') === 0 || (strpos($cleanPhone, '09') === 0 && strlen($cleanPhone) == 10)) $pCountry = 'SY'; elseif (strpos($cleanPhone, '20') === 0 || (strpos($cleanPhone, '01') === 0 && strlen($cleanPhone) == 11)) $pCountry = 'EG'; elseif (strpos($cleanPhone, '964') === 0) $pCountry = 'IQ'; + $debugCounts[$pCountry]++; + if ($pCountry === strtoupper($countryCode)) { $targets[] = ['passenger_id' => $p['passenger_id'], 'decrypted_phone' => $decryptedPhone]; } @@ -206,7 +212,13 @@ try { 'whatsapp_sent_count' => $sentWhatsApp, 'sms_sent_count' => $sentSms ], - 'total_dispatched' => count($dispatchedPassengers) + 'total_dispatched' => count($dispatchedPassengers), + 'debug_info' => [ + 'requested_country' => $countryCode, + 'total_passengers_in_db' => count($allPassengers), + 'matched_targets' => count($targets), + 'distribution' => $debugCounts + ] ]); } catch (Exception $e) {