mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Fix #203
This commit is contained in:
parent
cbe39f9aaf
commit
8b486ddfcc
@ -15,9 +15,11 @@ class DashboardController extends BaseController
|
||||
$user_id = Auth::user()->id;
|
||||
|
||||
// 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');
|
||||
$select = DB::raw(
|
||||
'COUNT(DISTINCT CASE WHEN '.DB::getQueryGrammar()->wrap('invoices.id', true).' IS NOT NULL THEN '.DB::getQueryGrammar()->wrap('clients.id', true).' ELSE null END) billed_clients,
|
||||
SUM(CASE WHEN '.DB::getQueryGrammar()->wrap('invoices.invoice_status_id', true).' >= '.INVOICE_STATUS_SENT.' THEN 1 ELSE 0 END) invoices_sent,
|
||||
COUNT(DISTINCT '.DB::getQueryGrammar()->wrap('clients.id', true).') active_clients'
|
||||
);
|
||||
$metrics = DB::table('accounts')
|
||||
->select($select)
|
||||
->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')
|
||||
@ -41,7 +43,10 @@ class DashboardController extends BaseController
|
||||
$metrics = $metrics->groupBy('accounts.id')
|
||||
->first();
|
||||
|
||||
$select = DB::raw('SUM(clients.paid_to_date) as value, clients.currency_id as currency_id');
|
||||
$select = DB::raw(
|
||||
'SUM('.DB::getQueryGrammar()->wrap('clients.paid_to_date', true).') as value,'
|
||||
.DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id'
|
||||
);
|
||||
$paidToDate = DB::table('accounts')
|
||||
->select($select)
|
||||
->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')
|
||||
@ -53,10 +58,13 @@ class DashboardController extends BaseController
|
||||
}
|
||||
|
||||
$paidToDate = $paidToDate->groupBy('accounts.id')
|
||||
->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END'))
|
||||
->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN CASE WHEN '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' IS NULL THEN 1 ELSE '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' END ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END'))
|
||||
->get();
|
||||
|
||||
$select = DB::raw('AVG(invoices.amount) as invoice_avg, clients.currency_id as currency_id');
|
||||
$select = DB::raw(
|
||||
'AVG('.DB::getQueryGrammar()->wrap('invoices.amount', true).') as invoice_avg, '
|
||||
.DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id'
|
||||
);
|
||||
$averageInvoice = DB::table('accounts')
|
||||
->select($select)
|
||||
->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')
|
||||
@ -72,17 +80,20 @@ class DashboardController extends BaseController
|
||||
}
|
||||
|
||||
$averageInvoice = $averageInvoice->groupBy('accounts.id')
|
||||
->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END'))
|
||||
->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN CASE WHEN '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' IS NULL THEN 1 ELSE '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' END ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END'))
|
||||
->get();
|
||||
|
||||
$select = DB::raw('SUM(clients.balance) as value, clients.currency_id as currency_id');
|
||||
$select = DB::raw(
|
||||
'SUM('.DB::getQueryGrammar()->wrap('clients.balance', true).') as value, '
|
||||
.DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id'
|
||||
);
|
||||
$balances = 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')
|
||||
->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END'));
|
||||
->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN CASE WHEN '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' IS NULL THEN 1 ELSE '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' END ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END'));
|
||||
|
||||
if (!$view_all) {
|
||||
$balances->where('clients.user_id', '=', $user_id);
|
||||
|
Loading…
Reference in New Issue
Block a user