1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Update Average invoice block support multiple currency

This commit is contained in:
Sang, Le Thanh 2015-01-22 16:52:26 +07:00
parent 087fea1f24
commit 9d6c1d3692
2 changed files with 9 additions and 5 deletions

View File

@ -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,

View File

@ -141,7 +141,11 @@
<div class="col-md-3">
<div class="average-invoice">
<div><b>{{ trans('texts.average_invoice') }}</b></div>
<div class="in-bold in-white" style="font-size:42px">{{ $invoiceAvg }}</div>
<div class="in-bold in-white" style="font-size:42px">
@foreach ($totalIncomes as $totalIncome)
{{ Utils::formatMoney($totalIncome->invoice_avg, $totalIncome->currency_id); }}
@endforeach
</div>
</div>
</div>