Skip to content

Commit

Permalink
Merge pull request #7 from coralsio/postgress-support
Browse files Browse the repository at this point in the history
fix monthly revenue widget issue to support postgres
  • Loading branch information
saeed-corals authored Dec 12, 2023
2 parents 0b4debe + 7cbb8bd commit f76d504
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Common/Widgets/MonthlyRevenueWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ public function __construct()

public function run($args)
{
$connection = config('database.default');

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("DATE_FORMAT(due_date,'%M %Y') as months")
\DB::raw("$dateFormatMethod(due_date, $dateFormat) as months")
)
->groupBy('months')
->pluck('sums', 'months')->toArray();
Expand Down

0 comments on commit f76d504

Please sign in to comment.