PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | app/Services/Report/SubscriptionReportService.php +11 -5 1.5.2 → 1.6.5 View file →
@@ -3,8 +3,9 @@
3 3 namespace FluentCart\App\Services\Report;
4 4
5 5 use FluentCart\App\App;
6 6 use FluentCart\App\Helpers\Status;
7 +use FluentCart\Framework\Support\Arr;
7 8 use FluentCart\App\Services\Report\Concerns\Subscription\FutureRenewals;
8 9
9 10 class SubscriptionReportService extends ReportService
10 11 {
@@ -11,21 +12,26 @@
11 12 use FutureRenewals;
12 13
13 14 public function getRetentionChart($params = [])
14 15 {
16 + $customDays = max(0, (int) Arr::get($params, 'customDays', 0));
17 + $variationIds = Arr::get($params, 'variationIds', []);
18 + $startDate = Arr::get($params, 'startDate');
19 + $endDate = Arr::get($params, 'endDate');
20 +
15 21 $baseQuery = App::db()->query()
16 22 ->from('fct_subscriptions as s')
17 - ->whereBetween('s.created_at', [$params['startDate'], $params['endDate']])
18 - ->when($params['variationIds'], fn ($q) => $q->whereIn('s.variation_id', $params['variationIds']));
23 + ->whereBetween('s.created_at', [$startDate, $endDate])
24 + ->when($variationIds, fn ($q) => $q->whereIn('s.variation_id', $variationIds));
19 25
20 - if ($params['customDays']) {
21 - $query = $baseQuery->selectRaw("COUNT(*) AS day_{$params['customDays']}")
26 + if ($customDays) {
27 + $query = $baseQuery->selectRaw("COUNT(*) AS day_{$customDays}")
22 28 ->whereRaw('
23 29 DATEDIFF(
24 30 COALESCE(s.canceled_at, NOW()),
25 31 s.created_at
26 32 ) <= ?
27 - ', $params['customDays']);
33 + ', [$customDays]);
28 34 } else {
29 35 $baseQuery->selectRaw('DATEDIFF(COALESCE(s.canceled_at, NOW()), s.created_at) AS lifespan');
30 36
31 37 $query = App::db()->query()->selectRaw('