From d91b9e71d510029ea9d8f53cd50fdc372990ae93 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 5 Dec 2016 20:44:20 +0100 Subject: [PATCH] Remove unused code. --- app/Helpers/Report/ReportHelper.php | 51 ------ app/Helpers/Report/ReportHelperInterface.php | 22 --- app/Repositories/Account/AccountTasker.php | 146 ------------------ .../Account/AccountTaskerInterface.php | 26 ---- 4 files changed, 245 deletions(-) diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 53e1a28fb9..e75c49ae79 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -136,57 +136,6 @@ class ReportHelper implements ReportHelperInterface return $object; } - /** - * Get a full report on the users expenses during the period for a list of accounts. - * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * - * @return Expense - */ - public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): Expense - { - $object = new Expense; - - /** @var AccountTaskerInterface $tasker */ - $tasker = app(AccountTaskerInterface::class); - $collection = $tasker->expenseReport($accounts, $accounts, $start, $end); - - /** @var stdClass $entry */ - foreach ($collection as $entry) { - $object->addToTotal($entry->amount); - $object->addOrCreateExpense($entry); - } - - return $object; - } - - /** - * Get a full report on the users incomes during the period for the given accounts. - * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * - * @return Income - */ - public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): Income - { - $object = new Income; - /** @var AccountTaskerInterface $tasker */ - $tasker = app(AccountTaskerInterface::class); - $collection = $tasker->incomeReport($accounts, $accounts, $start, $end); - - /** @var stdClass $entry */ - foreach ($collection as $entry) { - $object->addToTotal($entry->amount); - $object->addOrCreateIncome($entry); - } - - return $object; - } - /** * @param Carbon $date * diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 47af08976b..a4ec6ad874 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -51,28 +51,6 @@ interface ReportHelperInterface */ public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts): CategoryCollection; - /** - * Get a full report on the users expenses during the period for a list of accounts. - * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * - * @return Expense - */ - public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): Expense; - - /** - * Get a full report on the users incomes during the period for the given accounts. - * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * - * @return Income - */ - public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): Income; - /** * @param Carbon $date * diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php index 691181b40f..b485fed700 100644 --- a/app/Repositories/Account/AccountTasker.php +++ b/app/Repositories/Account/AccountTasker.php @@ -105,35 +105,6 @@ class AccountTasker implements AccountTaskerInterface } - /** - * @param Collection $accounts - * @param Collection $excluded - * @param Carbon $start - * @param Carbon $end - * - * @return Collection - * @see self::financialReport - * - */ - public function expenseReport(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): Collection - { - $idList = [ - 'accounts' => $accounts->pluck('id')->toArray(), - 'exclude' => $excluded->pluck('id')->toArray(), - ]; - - Log::debug( - 'Now calling expenseReport.', - ['accounts' => $idList['accounts'], 'excluded' => $idList['exclude'], - 'start' => $start->format('Y-m-d'), - 'end' => $end->format('Y-m-d'), - ] - ); - - return $this->financialReport($idList, $start, $end, false); - - } - /** * @param Carbon $start * @param Carbon $end @@ -190,35 +161,6 @@ class AccountTasker implements AccountTaskerInterface return $object; } - /** - * @param Collection $accounts - * @param Collection $excluded - * @param Carbon $start - * @param Carbon $end - * - * @see AccountTasker::financialReport() - * - * @return Collection - * - */ - public function incomeReport(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): Collection - { - $idList = [ - 'accounts' => $accounts->pluck('id')->toArray(), - 'exclude' => $excluded->pluck('id')->toArray(), - ]; - - Log::debug( - 'Now calling expenseReport.', - ['accounts' => $idList['accounts'], 'excluded' => $idList['exclude'], - 'start' => $start->format('Y-m-d'), - 'end' => $end->format('Y-m-d'), - ] - ); - - return $this->financialReport($idList, $start, $end, true); - } - /** * Will return how much money has been going out (ie. spent) by the given account(s). * Alternatively, will return how much money has been coming in (ie. earned) by the given accounts. @@ -278,92 +220,4 @@ class AccountTasker implements AccountTaskerInterface return $sum; } - /** - * - * This method will determin how much has flown (in the given period) from OR to $accounts to/from anywhere else, - * except $excluded. This could be a list of incomes, or a list of expenses. This method shows - * the name, the amount and the number of transactions. It is a summary, and only used in some reports. - * - * $incoming=true a list of incoming money (earnings) - * $incoming=false a list of outgoing money (expenses). - * - * @param array $accounts - * @param Carbon $start - * @param Carbon $end - * @param bool $incoming - * - * Opening balances are ignored. - * - * @return Collection - */ - protected function financialReport(array $accounts, Carbon $start, Carbon $end, bool $incoming): Collection - { - $collection = new Collection; - $joinModifier = $incoming ? '<' : '>'; - $selection = $incoming ? '>' : '<'; - $query = Transaction::distinct() - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') - ->leftJoin( - 'transactions as other_side', function (JoinClause $join) use ($joinModifier) { - $join->on('transaction_journals.id', '=', 'other_side.transaction_journal_id')->where( - 'other_side.amount', $joinModifier, 0 - ); - } - ) - ->leftJoin('accounts as other_account', 'other_account.id', '=', 'other_side.account_id') - ->where('transaction_types.type', '!=', TransactionType::OPENING_BALANCE) - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('transaction_journals.user_id', $this->user->id) - ->whereNull('transactions.deleted_at') - ->whereNull('other_side.deleted_at') - ->whereNull('transaction_journals.deleted_at') - ->whereIn('transactions.account_id', $accounts['accounts']) - ->where('other_side.amount', '=', DB::raw('transactions.amount * -1')) - ->where('transactions.amount', $selection, 0) - ->orderBy('transactions.amount'); - - if (count($accounts['exclude']) > 0) { - $query->whereNotIn('other_side.account_id', $accounts['exclude']); - } - $set = $query->get( - [ - 'transaction_journals.id', - 'other_side.account_id', - 'other_account.name', - 'other_account.encrypted', - 'transactions.amount', - ] - ); - // summarize ourselves: - $temp = []; - foreach ($set as $entry) { - // save into $temp: - $id = intval($entry->account_id); - if (isset($temp[$id])) { - $temp[$id]['count']++; - $temp[$id]['amount'] = bcadd($temp[$id]['amount'], $entry->amount); - } - if (!isset($temp[$id])) { - $temp[$id] = [ - 'name' => intval($entry->encrypted) === 1 ? Crypt::decrypt($entry->name) : $entry->name, - 'amount' => $entry->amount, - 'count' => 1, - ]; - } - } - - // loop $temp and create collection: - foreach ($temp as $key => $entry) { - $object = new stdClass(); - $object->id = $key; - $object->name = $entry['name']; - $object->count = $entry['count']; - $object->amount = $entry['amount']; - $collection->push($object); - } - - return $collection; - } } diff --git a/app/Repositories/Account/AccountTaskerInterface.php b/app/Repositories/Account/AccountTaskerInterface.php index dbf1892667..4e023abeac 100644 --- a/app/Repositories/Account/AccountTaskerInterface.php +++ b/app/Repositories/Account/AccountTaskerInterface.php @@ -49,19 +49,6 @@ interface AccountTaskerInterface */ public function amountOutInPeriod(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): string; - /** - * @param Collection $accounts - * @param Collection $excluded - * @param Carbon $start - * @param Carbon $end - * - * @see AccountTasker::financialReport() - * - * @return Collection - * - */ - public function expenseReport(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): Collection; - /** * @param Carbon $start * @param Carbon $end @@ -71,17 +58,4 @@ interface AccountTaskerInterface */ public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection; - /** - * @param Collection $accounts - * @param Collection $excluded - * @param Carbon $start - * @param Carbon $end - * - * @see AccountTasker::financialReport() - * - * @return Collection - * - */ - public function incomeReport(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): Collection; - }