App\Ninja\Repositories\DashboardRepository::balances PHP Method

balances() public method

public balances ( $accountId, $userId, $viewAll )
    public function balances($accountId, $userId, $viewAll)
    {
        $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', '=', $accountId)->where('clients.is_deleted', '=', false)->groupBy('accounts.id')->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 (!$viewAll) {
            $balances->where('clients.user_id', '=', $userId);
        }
        return $balances->get();
    }