From 087fea1f24da29eca35b171397c125f5de435200 Mon Sep 17 00:00:00 2001 From: "Sang, Le Thanh" Date: Thu, 22 Jan 2015 16:31:43 +0700 Subject: [PATCH 1/2] Multiple currency support in dashboard --- app/controllers/DashboardController.php | 9 +++++---- app/views/dashboard.blade.php | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 7e8fa5a58be7..59aa2d8e7ab3 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -19,15 +19,16 @@ 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, clients.currency_id as currency_id'); - $totalIncome = DB::table('accounts') + $totalIncomes = DB::table('accounts') ->select($select) ->leftJoin('clients', 'accounts.id', '=', 'clients.account_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(); @@ -49,7 +50,7 @@ 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, diff --git a/app/views/dashboard.blade.php b/app/views/dashboard.blade.php index 2373f41e3c6c..af538c448192 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') }} @@ -145,4 +147,5 @@
-@stop \ No newline at end of file +@stop + From 9d6c1d3692554ca870e0578e547ae38f5c1ffbeb Mon Sep 17 00:00:00 2001 From: "Sang, Le Thanh" Date: Thu, 22 Jan 2015 16:52:26 +0700 Subject: [PATCH 2/2] Update Average invoice block support multiple currency --- app/controllers/DashboardController.php | 8 ++++---- app/views/dashboard.blade.php | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 59aa2d8e7ab3..bb549bbd797d 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) @@ -19,11 +18,13 @@ class DashboardController extends \BaseController ->groupBy('accounts.id') ->first(); - $select = DB::raw('SUM(clients.paid_to_date) as value, clients.currency_id as currency_id'); + $select = DB::raw('SUM(clients.paid_to_date) as value, AVG(invoices.amount) as invoice_avg, + clients.currency_id as currency_id'); $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') @@ -54,7 +55,6 @@ class DashboardController extends \BaseController '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 af538c448192..ce82286c1ba1 100644 --- a/app/views/dashboard.blade.php +++ b/app/views/dashboard.blade.php @@ -141,7 +141,11 @@
{{ trans('texts.average_invoice') }}
-
{{ $invoiceAvg }}
+
+ @foreach ($totalIncomes as $totalIncome) + {{ Utils::formatMoney($totalIncome->invoice_avg, $totalIncome->currency_id); }} + @endforeach +