// ---- Weekly VBs (current calendar week, Sun 00:00 - Sat 23:59 Eastern) ---- // Callers have a $500/week VB limit. Sum tips across calls, custom_audios, // and paid_emails for this caller within the current week. // Matched the same way as call history: last-name prefix + first initial. $today = new \DateTime('now', new \DateTimeZone('America/New_York')); $dow = (int) $today->format('w'); // 0 = Sunday $weekStart = (clone $today)->modify("-{$dow} days")->setTime(0, 0, 0); $weekEnd = (clone $weekStart)->modify('+6 days')->setTime(23, 59, 59); $wkFrom = $weekStart->format('Y-m-d'); $wkTo = $weekEnd->format('Y-m-d'); $vbParams = [ 'last_prefix' => $lastPrefix, 'wk_from' => $wkFrom, 'wk_to' => $wkTo, ]; $initialClause = ''; if ($firstInitial !== '') { $initialClause = " AND UPPER(LEFT(callerfirst, 1)) = :first_initial"; $vbParams['first_initial'] = $firstInitial; } foreach (['calls' => 'calldate', 'custom_audios' => 'auddate', 'paid_emails' => 'auddate'] as $tbl => $dateCol) { $q = $this->pdo->prepare( "SELECT COALESCE(SUM(tip),0) FROM {$tbl} WHERE UPPER(callerlast) = :last_prefix{$initialClause} AND {$dateCol} BETWEEN :wk_from AND :wk_to" ); $q->execute($vbParams); $weeklyVbs += (float) $q->fetchColumn(); }