Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some new code, transaction groups among them.
James Cole0a2cbaa04770
diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.phpindex 6583a95554..368296481b 100644--- a/app/controllers/ReportController.php+++ b/app/controllers/ReportController.php@@ -115,8 +115,11 @@ class ReportController extends BaseController$journals = App::make('FireflyIII\Database\TransactionJournal');/** @var TransactionJournal $journal */$journal = $journals->first();-- $date = clone $journal->date;+ if (is_null($journal)) {+ $date = Carbon::now();+ } else {+ $date = clone $journal->date;+ }$years = [];$months = [];while ($date <= Carbon::now()) {@@ -124,7 +127,11 @@ class ReportController extends BaseController$date->addYear();}// months- $date = clone $journal->date;+ if (is_null($journal)) {+ $date = Carbon::now();+ } else {+ $date = clone $journal->date;+ }while ($date <= Carbon::now()) {$months[] = ['formatted' => $date->format('F Y'),@@ -182,15 +189,15 @@ class ReportController extends BaseController});/*- * Filter transfers:+ * Filter transfers (not yet used)*/- $transfers = $journals->filter(- function (TransactionJournal $journal) {- if ($journal->transactionType->type == 'Transfer') {- return $journal;- }- }- );+ // $transfers = $journals->filter(+ // function (TransactionJournal $journal) {+ // if ($journal->transactionType->type == 'Transfer') {+ // return $journal;+ // }+ // }+ // );/** Filter withdrawals without a counter-transfer (into this account)@@ -205,24 +212,22 @@ class ReportController extends BaseController->where('account_id', '=', $transaction->account_id)->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%')- ->count();- if($counters == 0) {+ ->get(['transactions.*']);+ if ($counters->count() == 0) {return $journal;}}}});-/** Filter deposits without a counter-transfer (away from this account)*/$deposits = $deposits->filter(function (TransactionJournal $journal) {- echo 'Now at #'.$journal->id.': '.$journal->description.'<br>';foreach ($journal->transactions as $transaction) {- if (floatval($transaction->amount) < 0) {+ if (floatval($transaction->amount) > 0) {$account = $transaction->account;// find counter transfer:$counters = $account->transactions()->where('amount', floatval($transaction->amount) * -1)@@ -230,21 +235,15 @@ class ReportController extends BaseController->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%')->get(['transactions.*']);- /** @var Transaction $transaction */- foreach($counters as $transaction) {- echo 'Found possible counter: #'.$transaction->transaction_journal_id.': '.$transaction->transactionJournal->description.'<br>';- }- if($counters->count() == 0) {+ if ($counters->count() == 0) {return $journal;}}}- echo '<br>';});- exit;- return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals','deposits'));+ return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals', 'deposits'));}/**@@ -276,9 +275,10 @@ class ReportController extends BaseController// draw some charts etc.- return View::make('reports.year', compact('summary'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart')->with('subTitle', $year)->with(- 'subTitleIcon', 'fa-bar-chart'- )->with('year', $year);+ return View::make('reports.year', compact('summary', 'date'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart')->with('subTitle', $year)+ ->with(+ 'subTitleIcon', 'fa-bar-chart'+ )->with('year', $year);}}\ No newline at end of filediff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.phpindex d02e9ca6ce..14f0fbf4a5 100644--- a/app/controllers/TransactionController.php+++ b/app/controllers/TransactionController.php@@ -2,6 +2,7 @@use FireflyIII\Exception\FireflyException;+use Illuminate\Support\Collection;use Illuminate\Support\MessageBag;/**@@ -286,10 +287,27 @@ class TransactionController extends BaseControllerbreak;}- return View::make('transactions.index', compact('subTitle', 'subTitleIcon', 'journals'))->with('what', $what);+ return View::make('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals'));}+ public function relate(TransactionJournal $journal)+ {+ $groups = $journal->transactiongroups()->get();+ $members = new Collection;+ /** @var TransactionGroup $group */+ foreach ($groups as $group) {+ /** @var TransactionJournal $jrnl */+ foreach ($group->transactionjournals()->get() as $jrnl) {+ if ($jrnl->id != $journal->id) {+ $members->push($jrnl);+ }+ }+ }++ return View::make('transactions.relate', compact('journal', 'members'));+ }+/*** @param TransactionJournal $journal*@@ -309,9 +327,18 @@ class TransactionController extends BaseController$t->after = $t->before + $t->amount;});+ $members = new Collection;+ /** @var TransactionGroup $group */+ foreach($journal->transactiongroups()->get() as $group) {+ /** @var TransactionJournal $jrnl */+ foreach($group->transactionjournals()->get() as $jrnl) {+ if($jrnl->id != $journal->id) {+ $members->push($jrnl);+ }+ }+ }-- return View::make('transactions.show')->with('journal', $journal)->with(+ return View::make('transactions.show', compact('journal', 'members'))->with('subTitle', $journal->transactionType->type . ' "' . $journal->description . '"');}diff --git a/app/database/migrations/2014_11_25_204833_cacheTable.php b/app/database/migrations/2014_11_25_204833_cacheTable.phpnew file mode 100644index 0000000000..2ffbce905d--- /dev/null+++ b/app/database/migrations/2014_11_25_204833_cacheTable.php@@ -0,0 +1,34 @@+<?php++use Illuminate\Database\Migrations\Migration;++class CacheTable extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::drop('cache');+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ Schema::create(+ 'cache', function ($table) {+ $table->string('key')->unique();+ $table->text('value');+ $table->integer('expiration');+ }+ );+ }++}diff --git a/app/database/migrations/2014_11_29_135749_transactiongroups.php b/app/database/migrations/2014_11_29_135749_transactiongroups.phpnew file mode 100644index 0000000000..56049750b0--- /dev/null+++ b/app/database/migrations/2014_11_29_135749_transactiongroups.php@@ -0,0 +1,41 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;++class Transactiongroups extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::drop('transaction_groups');+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ Schema::create(+ 'transaction_groups', function (Blueprint $table) {+ $table->increments('id');+ $table->timestamps();+ $table->integer('user_id')->unsigned();+ $table->enum('relation', ['balance']);++ // connect reminders to users+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');+ }+ );+++ }++}diff --git a/app/database/migrations/2014_11_29_140217_transactiongroupsjoin.php b/app/database/migrations/2014_11_29_140217_transactiongroupsjoin.phpnew file mode 100644index 0000000000..a670661ff3--- /dev/null+++ b/app/database/migrations/2014_11_29_140217_transactiongroupsjoin.php@@ -0,0 +1,41 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;++class Transactiongroupsjoin extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ //+ Schema::drop('transaction_group_transaction_journal');+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {++ Schema::create(+ 'transaction_group_transaction_journal', function (Blueprint $table) {+ $table->increments('id');+ $table->integer('transaction_group_id')->unsigned();+ $table->integer('transaction_journal_id')->unsigned();++ $table->foreign('transaction_group_id','tr_grp_id')->references('id')->on('transaction_groups')->onDelete('cascade');+ $table->foreign('transaction_journal_id','tr_trj_id')->references('id')->on('transaction_journals')->onDelete('cascade');++ $table->unique(['transaction_group_id','transaction_journal_id'],'tt_joined');+ });+ }++}diff --git a/app/models/Component.php b/app/models/Component.phpindex 36493d8f65..932e3c678d 100644--- a/app/models/Component.php+++ b/app/models/Component.php@@ -1,4 +1,5 @@<?php+use Carbon\Carbon;use FireflyIII\Shared\SingleTableInheritanceEntity;diff --git a/app/models/TransactionGroup.php b/app/models/TransactionGroup.phpnew file mode 100644index 0000000000..bb29b3f3b4--- /dev/null+++ b/app/models/TransactionGroup.php@@ -0,0 +1,38 @@+<?php+use LaravelBook\Ardent\Ardent;++class TransactionGroup extends Ardent+{++ public static $rules = [+ 'relation' => 'required|in:balance'+ ];++ /**+ * @return array+ */+ public function getDates()+ {+ return ['created_at', 'updated_at'];+ }++ /**+ * @return \Illuminate\Database\Eloquent\Relations\HasMany+ */+ public function transactionjournals()+ {+ return $this->belongsToMany('TransactionJournal');+ }++ /**+ * User+ *+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo+ */+ public function user()+ {+ return $this->belongsTo('User');+ }+++}\ No newline at end of filediff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.phpindex 2796563950..84cdb06353 100644--- a/app/models/TransactionJournal.php+++ b/app/models/TransactionJournal.php@@ -71,7 +71,6 @@ class TransactionJournal extends Ardent'date' => 'required|date','completed' => 'required|between:0,1'];-/*** @return \Illuminate\Database\Eloquent\Relations\BelongsToMany*/@@ -278,4 +277,9 @@ class TransactionJournal extends Ardentreturn $this->belongsTo('User');}+ public function transactiongroups()+ {+ return $this->belongsToMany('TransactionGroup');+ }+}\ No newline at end of filediff --git a/app/models/TransactionRelation.php b/app/models/TransactionRelation.phpnew file mode 100644index 0000000000..ee49e2dcab--- /dev/null+++ b/app/models/TransactionRelation.php@@ -0,0 +1,7 @@+<?php+use Carbon\Carbon;+use LaravelBook\Ardent\Ardent;++class TransactionRelation extends Ardent {++}\ No newline at end of filediff --git a/app/routes.php b/app/routes.phpindex 52899b07cc..c0b0db1226 100644--- a/app/routes.php+++ b/app/routes.php@@ -255,6 +255,7 @@ Route::group(Route::get('/transaction/edit/{tj}', ['uses' => 'TransactionController@edit', 'as' => 'transactions.edit']);Route::get('/transaction/delete/{tj}', ['uses' => 'TransactionController@delete', 'as' => 'transactions.delete']);Route::get('/transaction/show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'transactions.show']);+ Route::get('/transaction/relate/{tj}', ['uses' => 'TransactionController@relate', 'as' => 'transactions.relate']);// user controllerRoute::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);diff --git a/app/views/transactions/relate.blade.php b/app/views/transactions/relate.blade.phpnew file mode 100644index 0000000000..c83380916f--- /dev/null+++ b/app/views/transactions/relate.blade.php@@ -0,0 +1,18 @@+<div class="modal-dialog modal-lg">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>+ <h4 class="modal-title" id="myModalLabel">Relate "{{{$journal->description}}}" to other transactions</h4>+ </div>+ <div class="modal-body">++ <h5>Search results</h5>+ <h5>Related transactions</h5>+ @include('list.journals-tiny',['transactions' => $members])++ </div>+ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>+ </div>+ </div>+</div>diff --git a/app/views/transactions/show.blade.php b/app/views/transactions/show.blade.phpindex ddd5be189e..0605bb4e9a 100644--- a/app/views/transactions/show.blade.php+++ b/app/views/transactions/show.blade.php@@ -57,8 +57,34 @@@include('list.piggybank-events',['events' => $journal->piggybankevents,'showPiggybank' => true])</div></div>-@endif+ <div class="panel panel-default">+ <div class="panel-heading">+ Related transactions+ </div>+ @if($members->count() == 0)+ <div class="panel-body">+ <p>+ <em>No related transactions</em>+ </p>+ </div>+ @else+ <table class="table">+ @foreach($members as $jrnl)+ <tr>+ <td><input type="checkbox" checked="checked" data-id="{{$jrnl->id}}" class="relate-checkbox" /></td>+ <td><a href="#">{{{$jrnl->description}}}</a></td>+ <td>{{mf($jrnl->getAmount())}}</td>+ </tr>+ @endforeach+ </table>+ @endif+ <div class="panel-footer">+ <p>+ <a href="#" id="relateTransaction" data-id="{{$journal->id}}" class="btn btn-default"><i data-id="{{$journal->id}}" class="fa fa-compress"></i> Relate to another transaction</a>+ </p>+ </div>+ </div></div><div class="col-lg-6 col-md-6 col-sm-12">@@ -97,8 +123,13 @@</div></div></div>+<!-- modal to relate transactions to each other -->+<div class="modal fade" id="relationModal">++</div>@stop@section('scripts')+{{HTML::script('assets/javascript/firefly/transactions.js')}}@stop\ No newline at end of filediff --git a/public/assets/javascript/firefly/transactions.js b/public/assets/javascript/firefly/transactions.jsindex 5719db469c..eadcd2eeeb 100644--- a/public/assets/javascript/firefly/transactions.js+++ b/public/assets/javascript/firefly/transactions.js@@ -18,4 +18,15 @@ $(document).ready(function () {if(typeof googleTablePaged != 'undefined') {googleTablePaged('table/transactions/' + what,'transaction-table');}-});\ No newline at end of file+ if($('#relateTransaction').length == 1) {+ $('#relateTransaction').click(relateTransaction);+ }+});+++function relateTransaction(e) {+ var target = $(e.target);+ var ID = target.data('id');+ $('#relationModal').empty().load('transaction/relate/' + ID).modal('show');+ return false;+}\ No newline at end of file