| @@ -180,11 +180,12 @@ | ||
| 180 | 180 | |
| 181 | 181 | $startDate = $data['start_date']; |
| 182 | 182 | $endDate = $data['end_date']; |
| 183 | 183 | $formId = $data['form_id']; |
| 184 | + $breakdown = ReportHelper::getPaymentBreakdown($startDate, $endDate, $formId); | |
| 184 | 185 | $data['payment_types'] = [ |
| 185 | - 'subscription' => ReportHelper::getPaymentsByType($startDate, $endDate, 'subscription', $formId), | |
| 186 | - 'onetime' => ReportHelper::getPaymentsByType($startDate, $endDate, 'onetime', $formId), | |
| 186 | + 'subscription' => $breakdown['subscription'] ?? [], | |
| 187 | + 'onetime' => $breakdown['onetime'] ?? [], | |
| 187 | 188 | ]; |
| 188 | 189 | return $data; |
| 189 | 190 | } |
| 190 | 191 | |
| @@ -205,16 +206,18 @@ | ||
| 205 | 206 | $startDate = Arr::get($data, 'start_date'); |
| 206 | 207 | $endDate = Arr::get($data, 'end_date'); |
| 207 | 208 | $formId = Acl::normalizeFormId(Arr::get($data, 'form_id')); |
| 208 | 209 | |
| 209 | - // Set default date range if not provided | |
| 210 | + // Default to the last 30 days, measured on the SITE's clock. created_at is | |
| 211 | + // written by current_time('mysql') and compared here as a raw string, while | |
| 212 | + // PHP's default timezone is UTC under WordPress — so a bare new \DateTime() | |
| 213 | + // would close the window at the end of the UTC day and drop everything | |
| 214 | + // submitted since local midnight on any site east of UTC. | |
| 210 | 215 | if (!$startDate || !$endDate) { |
| 211 | - $now = new \DateTime(); | |
| 212 | - $endDate = $now->format('Y-m-d 23:59:59'); | |
| 216 | + $today = current_time('Y-m-d'); | |
| 213 | 217 | |
| 214 | - $thirtyDaysAgo = new \DateTime(); | |
| 215 | - $thirtyDaysAgo->modify('-30 days'); | |
| 216 | - $startDate = $thirtyDaysAgo->format('Y-m-d 00:00:00'); | |
| 218 | + $endDate = $today . ' 23:59:59'; | |
| 219 | + $startDate = (new \DateTime($today))->modify('-30 days')->format('Y-m-d 00:00:00'); | |
| 217 | 220 | } |
| 218 | 221 | |
| 219 | 222 | return [ |
| 220 | 223 | 'start_date' => $startDate, |