addProperty($object->id); $cache->addProperty(get_class($object)); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty($accounts); $cache->addProperty('balanceInPeriodList'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } $ids = $accounts->pluck('id')->toArray(); $entry = $object->transactionjournals() ->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE]) ->before($end) ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') ->whereIn('accounts.id', $ids) ->after($start) ->first([DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`')]); $amount = $entry->journalAmount; $cache->store($amount); return $amount; } }