From 3f62b647fc9a40ecbf4170509ec20752dfefe401 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 28 Apr 2015 13:50:53 +0200 Subject: [PATCH] Removed code related to "related transactions". --- app/Http/Controllers/RelatedController.php | 164 ------------------ app/Http/routes.php | 22 --- .../Journal/JournalRepository.php | 52 ------ .../Journal/JournalRepositoryInterface.php | 9 - public/js/related-manager.js | 112 ------------ .../views/related/alreadyRelated.blade.php | 63 ------- resources/views/related/relate.blade.php | 29 ---- .../views/related/searchResult.blade.php | 39 ----- resources/views/transactions/show.blade.php | 1 - 9 files changed, 491 deletions(-) delete mode 100644 app/Http/Controllers/RelatedController.php delete mode 100644 public/js/related-manager.js delete mode 100644 resources/views/related/alreadyRelated.blade.php delete mode 100644 resources/views/related/relate.blade.php delete mode 100644 resources/views/related/searchResult.blade.php diff --git a/app/Http/Controllers/RelatedController.php b/app/Http/Controllers/RelatedController.php deleted file mode 100644 index d8d914a3ec..0000000000 --- a/app/Http/Controllers/RelatedController.php +++ /dev/null @@ -1,164 +0,0 @@ -transactiongroups()->get() as $group) { - /** @var TransactionJournal $loopJournal */ - foreach ($group->transactionjournals()->get() as $loopJournal) { - if ($loopJournal->id != $journal->id) { - $ids[] = $loopJournal->id; - } - } - } - $unique = array_unique($ids); - $journals = new Collection; - if (count($unique) > 0) { - $journals = Auth::user()->transactionjournals()->whereIn('id', $unique)->get(); - } - $parent = $journal; - - return view('related.alreadyRelated', compact('parent', 'journals')); - } - - /** - * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. - * - * @param TransactionJournal $parentJournal - * @param TransactionJournal $childJournal - * - * @return \Illuminate\Http\JsonResponse - * @throws Exception - */ - public function getRemoveRelation(TransactionJournal $parentJournal, TransactionJournal $childJournal) - { - $groups = $parentJournal->transactiongroups()->get(); - /** @var TransactionGroup $group */ - foreach ($groups as $group) { - foreach ($group->transactionjournals()->get() as $loopJournal) { - if ($loopJournal->id == $childJournal->id) { - // remove from group: - $group->transactionjournals()->detach($childJournal); - } - } - if ($group->transactionjournals()->count() == 1) { - $group->delete(); - } - } - - return Redirect::to(URL::previous()); - } - - /** - * @param TransactionJournal $parentJournal - * @param TransactionJournal $childJournal - * - * @return \Illuminate\Http\JsonResponse - */ - public function relate(TransactionJournal $parentJournal, TransactionJournal $childJournal) - { - $group = new TransactionGroup; - $group->relation = 'balance'; - $group->user_id = Auth::user()->id; - $group->save(); - $group->transactionjournals()->save($parentJournal); - $group->transactionjournals()->save($childJournal); - - return Response::json(true); - - } - - /** - * @param TransactionJournal $journal - * - * @return \Illuminate\View\View - */ - public function related(TransactionJournal $journal) - { - $groups = $journal->transactiongroups()->get(); - $members = new Collection; - /** @var TransactionGroup $group */ - foreach ($groups as $group) { - /** @var TransactionJournal $loopJournal */ - foreach ($group->transactionjournals()->get() as $loopJournal) { - if ($loopJournal->id != $journal->id) { - $members->push($loopJournal); - } - } - } - - return view('related.relate', compact('journal', 'members')); - } - - /** - * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. - * - * @param TransactionJournal $parentJournal - * @param TransactionJournal $childJournal - * - * @return \Illuminate\Http\JsonResponse - * @throws Exception - */ - public function removeRelation(TransactionJournal $parentJournal, TransactionJournal $childJournal) - { - $groups = $parentJournal->transactiongroups()->get(); - /** @var TransactionGroup $group */ - foreach ($groups as $group) { - foreach ($group->transactionjournals()->get() as $loopJournal) { - if ($loopJournal->id == $childJournal->id) { - // remove from group: - $group->transactionjournals()->detach($childJournal); - } - } - if ($group->transactionjournals()->count() == 1) { - $group->delete(); - } - } - - return Response::json(true); - } - - /** - * @param TransactionJournal $journal - * - * @return \Illuminate\Http\JsonResponse - */ - public function search(TransactionJournal $journal, JournalRepositoryInterface $repository) - { - - $search = e(trim(Input::get('searchValue'))); - $parent = $journal; - - $journals = $repository->searchRelated($search, $journal); - - return view('related.searchResult', compact('journals', 'search', 'parent')); - - } - -} diff --git a/app/Http/routes.php b/app/Http/routes.php index abbffd9d7c..ecb1e96c3a 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -30,18 +30,6 @@ Route::bind( } ); -Route::bind( - 'tjSecond', function ($value, $route) { - if (Auth::check()) { - $object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first(); - if ($object) { - return $object; - } - } - throw new NotFoundHttpException; -} -); - Route::bind( 'tj', function ($value, $route) { if (Auth::check()) { @@ -328,16 +316,6 @@ Route::group( Route::post('/profile/delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account-post']); Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password-post']); - /** - * Related transactions controller - */ - Route::get('/related/alreadyRelated/{tj}', ['uses' => 'RelatedController@alreadyRelated', 'as' => 'related.alreadyRelated']); - Route::post('/related/relate/{tj}/{tjSecond}', ['uses' => 'RelatedController@relate', 'as' => 'related.relate']); - Route::post('/related/removeRelation/{tj}/{tjSecond}', ['uses' => 'RelatedController@removeRelation', 'as' => 'related.removeRelation']); - Route::get('/related/remove/{tj}/{tjSecond}', ['uses' => 'RelatedController@getRemoveRelation', 'as' => 'related.getRemoveRelation']); - Route::get('/related/related/{tj}', ['uses' => 'RelatedController@related', 'as' => 'related.related']); - Route::post('/related/search/{tj}', ['uses' => 'RelatedController@search', 'as' => 'related.search']); - /** * Reminder Controller */ diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 9d8a757e3d..508269047b 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -142,58 +142,6 @@ class JournalRepository implements JournalRepositoryInterface } } - /** - * @param string $query - * @param TransactionJournal $journal - * - * @return Collection - */ - public function searchRelated($query, TransactionJournal $journal) - { - $start = clone $journal->date; - $end = clone $journal->date; - $start->startOfMonth(); - $end->endOfMonth(); - - // get already related transactions: - $exclude = [$journal->id]; - foreach ($journal->transactiongroups()->get() as $group) { - foreach ($group->transactionjournals()->get() as $current) { - $exclude[] = $current->id; - } - } - $exclude = array_unique($exclude); - - /** @var Collection $collection */ - $collection = Auth::user()->transactionjournals() - ->withRelevantData() - ->before($end)->after($start)->where('encrypted', 0) - ->whereNotIn('id', $exclude) - ->where('description', 'LIKE', '%' . $query . '%') - ->get(); - - // manually search encrypted entries: - /** @var Collection $encryptedCollection */ - $encryptedCollection = Auth::user()->transactionjournals() - ->withRelevantData() - ->before($end)->after($start) - ->where('encrypted', 1) - ->whereNotIn('id', $exclude) - ->get(); - $encrypted = $encryptedCollection->filter( - function (TransactionJournal $journal) use ($query) { - $strPos = strpos(strtolower($journal->description), strtolower($query)); - if ($strPos !== false) { - return $journal; - } - - return null; - } - ); - - return $collection->merge($encrypted); - } - /** * @param array $data * diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php index af608699fe..5175c3edaa 100644 --- a/app/Repositories/Journal/JournalRepositoryInterface.php +++ b/app/Repositories/Journal/JournalRepositoryInterface.php @@ -55,15 +55,6 @@ interface JournalRepositoryInterface */ public function getJournalsOfType(TransactionType $dbType); - /** - * @param string $query - * @param TransactionJournal $journal - * - * @return Collection - */ - public function searchRelated($query, TransactionJournal $journal); - - /** * @param $type * diff --git a/public/js/related-manager.js b/public/js/related-manager.js deleted file mode 100644 index 276532d77f..0000000000 --- a/public/js/related-manager.js +++ /dev/null @@ -1,112 +0,0 @@ -$(document).ready(function () { - $('.relateTransaction').click(relateTransactionDialog); - //$('.unrelate-checkbox').click(unrelateTransaction); - -}); - -function unrelateTransaction(e) { - var target = $(e.target); - var id = target.data('id'); - var parent = target.data('parent'); - - if(typeof id == "undefined" && typeof parent == "undefined") { - target = target.parent(); - id = target.data('id'); - parent = target.data('parent'); - } - console.log('unlink ' + id + ' from ' + parent); - - $.post('related/removeRelation/' + id + '/' + parent, {_token: token}).success(function (data) { - target.parent().parent().remove(); - }).fail(function () { - alert('Could not!'); - }); - - - return false; - - - //$.post('related/removeRelation/' + id + '/' + relatedTo, {_token: token}).success(function (data) { - // target.parent().parent().remove(); - //}).fail(function () { - // alert('Could not!'); - //}); - -} - -function relateTransactionDialog(e) { - var target = $(e.target); - var ID = target.data('id'); - - - $('#relationModal').empty().load('related/related/' + ID, function () { - - $('#relationModal').modal('show'); - getAlreadyRelatedTransactions(e, ID); - $('#searchRelated').submit(function (e) { - searchRelatedTransactions(e, ID); - - return false; - }); - }); - - - return false; -} - - -function searchRelatedTransactions(e, ID) { - var searchValue = $('#relatedSearchValue').val(); - if (searchValue != '') { - $.post('related/search/' + ID, {searchValue: searchValue, _token: token}).success(function (data) { - // post the results to some div. - $('#relatedSearchResultsTitle').show(); - $('#relatedSearchResults').empty().html(data); - // remove any clicks. - $('.relate').unbind('click').on('click', doRelateNewTransaction); - - }).fail(function () { - alert('Could not search. Sorry.'); - }); - } - - return false; -} - -function doRelateNewTransaction(e) { - // remove the row from the table: - var target = $(e.target); - var id = target.data('id'); - var parent = target.data('parent'); - - if (typeof id == "undefined" && typeof parent == "undefined") { - target = target.parent(); - console.log(target); - id = target.data('id'); - parent = target.data('parent'); - } - - console.log('Relate ' + id + ' to ' + parent); - $.post('related/relate/' + parent + '/' + id, {_token: token}).success(function (data) { - // success! remove entry: - target.parent().parent().remove(); - // get related stuff (again). - getAlreadyRelatedTransactions(null, parent); - }).fail(function () { - // could not relate. - alert('Could not relate this transaction to the intended target.'); - }); - return false; -} - -function getAlreadyRelatedTransactions(e, ID) { - //#alreadyRelated - $.get('related/alreadyRelated/' + ID).success(function (data) { - $('#alreadyRelated').empty().html(data); - // some event triggers. - $('.unrelate').unbind('click').on('click', unrelateTransaction); - - }).fail(function () { - alert('Cannot get related stuff.'); - }); -} \ No newline at end of file diff --git a/resources/views/related/alreadyRelated.blade.php b/resources/views/related/alreadyRelated.blade.php deleted file mode 100644 index 0940d7a770..0000000000 --- a/resources/views/related/alreadyRelated.blade.php +++ /dev/null @@ -1,63 +0,0 @@ -@if($journals->count() > 0) - - @foreach($journals as $journal) - - - - - - - - -{{-- - - - - - - -@if(isset($account)) - @foreach($journal->transactions as $index => $t) - @if($t->account_id == $account->id) - {!! Amount::formatTransaction($t) !!} - @endif - @endforeach - @else - @foreach($journal->transactions as $index => $t) - @if($index == 0) - {!! Amount::formatTransaction($t) !!} - @endif - @endforeach - @endif - - - - --}} - @endforeach -
- - @if($journal->transactiontype->type == 'Withdrawal') - - @endif - @if($journal->transactiontype->type == 'Deposit') - - @endif - @if($journal->transactiontype->type == 'Transfer') - - @endif - {{$journal->date->format('jS M Y')}} - {{{$journal->description}}} - - @if($journal->transactiontype->type == 'Withdrawal') - {{Amount::formatTransaction($journal->transactions[0],false)}} - @endif - @if($journal->transactiontype->type == 'Deposit') - {{Amount::formatTransaction($journal->transactions[1],false)}} - @endif - @if($journal->transactiontype->type == 'Transfer') - {{Amount::formatTransaction($journal->transactions[1],false)}} - @endif -
-@else -

No related transactions

-@endif diff --git a/resources/views/related/relate.blade.php b/resources/views/related/relate.blade.php deleted file mode 100644 index 194b4d74a8..0000000000 --- a/resources/views/related/relate.blade.php +++ /dev/null @@ -1,29 +0,0 @@ - diff --git a/resources/views/related/searchResult.blade.php b/resources/views/related/searchResult.blade.php deleted file mode 100644 index 4d267a9e38..0000000000 --- a/resources/views/related/searchResult.blade.php +++ /dev/null @@ -1,39 +0,0 @@ - -@if($journals->count() > 0) - - @foreach($journals as $journal) - - - - - - - - - @endforeach -
- @if($journal->transactiontype->type == 'Withdrawal') - - @endif - @if($journal->transactiontype->type == 'Deposit') - - @endif - @if($journal->transactiontype->type == 'Transfer') - - @endif - {{$journal->date->format('jS M Y')}} - {{{$journal->description}}} - - @if($journal->transactiontype->type == 'Withdrawal') - {{Amount::formatTransaction($journal->transactions[0],false)}} - @endif - @if($journal->transactiontype->type == 'Deposit') - {{Amount::formatTransaction($journal->transactions[1],false)}} - @endif - @if($journal->transactiontype->type == 'Transfer') - {{Amount::formatTransaction($journal->transactions[1],false)}} - @endif -
-@else -

No results

-@endif diff --git a/resources/views/transactions/show.blade.php b/resources/views/transactions/show.blade.php index d8c0c1e0f7..5e43dc035d 100644 --- a/resources/views/transactions/show.blade.php +++ b/resources/views/transactions/show.blade.php @@ -130,5 +130,4 @@ @stop @section('scripts') - @stop