PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.26
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.26
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
fluent-cart / app / Services / Widgets / DashboardWidget.php

DashboardWidget.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.26, at app/Services/Widgets/DashboardWidget.php

81 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Widgets;
4
5 use FluentCart\App\App;
6 use FluentCart\App\Helpers\Status;
7 use FluentCart\App\Models\Coupon;
8 use FluentCart\App\Models\Order;
9 use FluentCart\App\Models\Product;
10 use FluentCart\App\Services\DateTime\DateTime;
11 use FluentCart\App\Services\URL;
12
13
14 class DashboardWidget extends BaseWidget
15 {
16
17 public function widgetName(): string
18 {
19 return 'dashboard_stats';
20 }
21
22 public function widgetData(): array
23 {
24 $startDate = (new DateTime())->subMonth()->startOfDay();
25 $endDate = (new DateTime())->endOfDay();
26
27 $counts = Product::query()->selectRaw("
28 COUNT(*) as total_products
29 ")
30 ->whereNotIn('post_status', ['trash', 'auto-draft'])
31 ->first();
32
33 $sales = App::db()->table('fct_orders as o')->selectRaw("
34 COUNT(o.id) AS orders,
35
36 SUM(
37 o.total_paid
38 - o.total_refund
39 - o.tax_total
40 - o.shipping_tax
41 ) / 100 AS net_revenue,
42
43 SUM(o.total_refund) / 100 AS total_refunds
44 ")
45 ->whereBetween('o.created_at', [$startDate, $endDate])
46 ->whereNotIn('o.status', [Status::ORDER_ON_HOLD, Status::ORDER_FAILED])
47 ->first();
48
49 return [
50 [
51 'title' => __('Total Products', 'fluent-cart'),
52 'current_count' => $counts->total_products,
53 'icon' => 'Frame',
54 'url' => URL::getDashboardUrl('products', [
55 'active_view' => 'all',
56 ]),
57 ],
58 [
59 'title' => __('Orders', 'fluent-cart'),
60 'current_count' => $sales->orders,
61 'icon' => 'AllOrdersIcon',
62 'url' => URL::getDashboardUrl('orders'),
63 ],
64 [
65 'title' => __('Revenue', 'fluent-cart'),
66 'current_count' => $sales->net_revenue,
67 'icon' => 'Currency',
68 'url' => URL::getDashboardUrl('reports/revenue'),
69 'has_currency' => true,
70 ],
71 [
72 'title' => __('Refund', 'fluent-cart'),
73 'current_count' => $sales->total_refunds,
74 'icon' => 'Failed',
75 'url' => URL::getDashboardUrl('reports/refunds'),
76 'has_currency' => true,
77 ],
78 ];
79 }
80 }
81