From b772a12759286499238eaeefd0a51455c97d03ea Mon Sep 17 00:00:00 2001 From: moayad Date: Sun, 10 Dec 2023 14:02:05 +0200 Subject: [PATCH 1/2] fix monthly revenue widget issue to support postgres --- src/Common/Widgets/MonthlyRevenueWidget.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Common/Widgets/MonthlyRevenueWidget.php b/src/Common/Widgets/MonthlyRevenueWidget.php index 2cfb95c..f88c655 100644 --- a/src/Common/Widgets/MonthlyRevenueWidget.php +++ b/src/Common/Widgets/MonthlyRevenueWidget.php @@ -13,9 +13,17 @@ public function __construct() public function run($args) { + $connection = config('database.default'); + + if ($connection === 'mysql') { + $dateFormatMethod = 'DATE_FORMAT'; + } else if ($connection === 'pgsql') { + $dateFormatMethod = 'TO_CHAR'; + } + $data = Invoice::where('status', 'paid')->select( \DB::raw('sum(total) as sums'), - \DB::raw("DATE_FORMAT(due_date,'%M %Y') as months") + \DB::raw("$dateFormatMethod(due_date,'%M %Y') as months") ) ->groupBy('months') ->pluck('sums', 'months')->toArray(); From 7cbb8bd35e17f4dd7894d681f5bda7420614bb7a Mon Sep 17 00:00:00 2001 From: saeed-corals <33281100+saeed-corals@users.noreply.github.com> Date: Tue, 12 Dec 2023 22:51:56 +0200 Subject: [PATCH 2/2] Update MonthlyRevenueWidget.php fix date format --- src/Common/Widgets/MonthlyRevenueWidget.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Common/Widgets/MonthlyRevenueWidget.php b/src/Common/Widgets/MonthlyRevenueWidget.php index f88c655..0f409ba 100644 --- a/src/Common/Widgets/MonthlyRevenueWidget.php +++ b/src/Common/Widgets/MonthlyRevenueWidget.php @@ -17,13 +17,15 @@ public function run($args) if ($connection === 'mysql') { $dateFormatMethod = 'DATE_FORMAT'; + $dateFormat='%M %Y'; } else if ($connection === 'pgsql') { $dateFormatMethod = 'TO_CHAR'; + $dateFormat='MM-YY'; } $data = Invoice::where('status', 'paid')->select( \DB::raw('sum(total) as sums'), - \DB::raw("$dateFormatMethod(due_date,'%M %Y') as months") + \DB::raw("$dateFormatMethod(due_date, $dateFormat) as months") ) ->groupBy('months') ->pluck('sums', 'months')->toArray();