diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 403b24f8b847..debe28872c84 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -7,8 +7,7 @@ class DashboardController extends \BaseController // total_income, billed_clients, invoice_sent and active_clients $select = DB::raw('COUNT(DISTINCT CASE WHEN invoices.id IS NOT NULL THEN clients.id ELSE null END) billed_clients, SUM(CASE WHEN invoices.invoice_status_id >= '.INVOICE_STATUS_SENT.' THEN 1 ELSE 0 END) invoices_sent, - COUNT(DISTINCT clients.id) active_clients, - AVG(invoices.amount) as invoice_avg'); + COUNT(DISTINCT clients.id) active_clients'); $metrics = DB::table('accounts') ->select($select) @@ -22,15 +21,18 @@ class DashboardController extends \BaseController ->groupBy('accounts.id') ->first(); - $select = DB::raw('SUM(clients.paid_to_date) as value'); + $select = DB::raw('SUM(clients.paid_to_date) as value, AVG(invoices.amount) as invoice_avg, + clients.currency_id as currency_id'); - $totalIncome = DB::table('accounts') + $totalIncomes = DB::table('accounts') ->select($select) ->leftJoin('clients', 'accounts.id', '=', 'clients.account_id') + ->leftJoin('invoices', 'clients.id', '=', 'invoices.client_id') ->where('accounts.id', '=', Auth::user()->account_id) ->where('clients.is_deleted', '=', false) ->groupBy('accounts.id') - ->first(); + ->groupBy('clients.currency_id') + ->get(); $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id) ->orderBy('created_at', 'desc')->take(6)->get(); @@ -52,11 +54,10 @@ class DashboardController extends \BaseController ->orderBy('due_date', 'asc')->take(6)->get(); $data = [ - 'totalIncome' => Utils::formatMoney($totalIncome ? $totalIncome->value : 0, Session::get(SESSION_CURRENCY)), + 'totalIncomes' => $totalIncomes, 'billedClients' => $metrics ? $metrics->billed_clients : 0, 'invoicesSent' => $metrics ? $metrics->invoices_sent : 0, 'activeClients' => $metrics ? $metrics->active_clients : 0, - 'invoiceAvg' => Utils::formatMoney(($metrics ? $metrics->invoice_avg : 0), Session::get(SESSION_CURRENCY)), 'activities' => $activities, 'pastDue' => $pastDue, 'upcoming' => $upcoming, diff --git a/app/views/dashboard.blade.php b/app/views/dashboard.blade.php index 2373f41e3c6c..ce82286c1ba1 100644 --- a/app/views/dashboard.blade.php +++ b/app/views/dashboard.blade.php @@ -8,7 +8,9 @@
- {{ $totalIncome }} + @foreach ($totalIncomes as $totalIncome) + {{ Utils::formatMoney($totalIncome->value, $totalIncome->currency_id); }} + @endforeach
{{ trans('texts.in_total_revenue') }} @@ -139,10 +141,15 @@
{{ trans('texts.average_invoice') }}
-
{{ $invoiceAvg }}
+
+ @foreach ($totalIncomes as $totalIncome) + {{ Utils::formatMoney($totalIncome->invoice_avg, $totalIncome->currency_id); }} + @endforeach +
-@stop \ No newline at end of file +@stop +