From 9d6c1d3692554ca870e0578e547ae38f5c1ffbeb Mon Sep 17 00:00:00 2001 From: "Sang, Le Thanh" Date: Thu, 22 Jan 2015 16:52:26 +0700 Subject: [PATCH] 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 59aa2d8e7a..bb549bbd79 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 af538c4481..ce82286c1b 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 +