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/RevenueReportService.php +9 -7 1.5.3 → 1.6.5 View file →
@@ -16,22 +16,24 @@
16 16 ->leftJoinSub($itemsSub, 'oi_sum', fn($join) => $join->on('oi_sum.order_id', '=', 'o.id'));
17 17
18 18 $query = $this->applyFilters($query, $params);
19 19
20 + $groupKey = ReportHelper::sanitizeGroupKey($params['groupKey'] ?? null);
21 +
20 22 $groupKeyExpression = '';
21 23
22 - if (in_array($params['groupKey'], ['billing_country', 'shipping_country'])) {
23 - $type = $params['groupKey'] === 'billing_country' ? 'billing' : 'shipping';
24 + if (in_array($groupKey, ['billing_country', 'shipping_country'])) {
25 + $type = $groupKey === 'billing_country' ? 'billing' : 'shipping';
24 26
25 27 $query->leftJoin('fct_order_addresses as a', function ($join) use ($type) {
26 28 $join->on('o.id', 'a.order_id')->where('a.type', $type);
27 29 });
28 30
29 - $groupKeyExpression = "COALESCE(a.country, 'Uncategorized') AS `{$params['groupKey']}`";
30 - } elseif ($params['groupKey'] === 'payment_method') {
31 - $groupKeyExpression = "COALESCE(o.payment_method, 'Unknown') AS `{$params['groupKey']}`";
31 + $groupKeyExpression = "COALESCE(a.country, 'Uncategorized') AS `{$groupKey}`";
32 + } elseif ($groupKey === 'payment_method') {
33 + $groupKeyExpression = "COALESCE(o.payment_method, 'Unknown') AS `{$groupKey}`";
32 34 } else {
33 - $groupKeyExpression = "COALESCE(o.{$params['groupKey']}, 'Unknown') AS `{$params['groupKey']}`";
35 + $groupKeyExpression = "COALESCE(o.{$groupKey}, 'Unknown') AS `{$groupKey}`";
34 36 }
35 37
36 38 $query->selectRaw("{$groupKeyExpression},
37 39
@@ -72,9 +74,9 @@
72 74 SUM(o.total_refund) / 100 AS total_refunds,
73 75
74 76 COUNT(DISTINCT o.customer_id) AS customer_count");
75 77
76 - return $query->groupByRaw($params['groupKey'])->orderByRaw($params['groupKey'])->get()->toArray();
78 + return $query->groupByRaw($groupKey)->orderByRaw($groupKey)->get()->toArray();
77 79 }
78 80
79 81 public function getRevenueData($params = []): array
80 82 {