diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php
index 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.'
';
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.'
';
- }
- if($counters->count() == 0) {
+ if ($counters->count() == 0) {
return $journal;
}
}
}
- echo '
';
}
);
- 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 file
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 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 BaseController
break;
}
- 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.php
new file mode 100644
index 0000000000..2ffbce905d
--- /dev/null
+++ b/app/database/migrations/2014_11_25_204833_cacheTable.php
@@ -0,0 +1,34 @@
+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.php
new file mode 100644
index 0000000000..56049750b0
--- /dev/null
+++ b/app/database/migrations/2014_11_29_135749_transactiongroups.php
@@ -0,0 +1,41 @@
+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.php
new file mode 100644
index 0000000000..a670661ff3
--- /dev/null
+++ b/app/database/migrations/2014_11_29_140217_transactiongroupsjoin.php
@@ -0,0 +1,41 @@
+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.php
index 36493d8f65..932e3c678d 100644
--- a/app/models/Component.php
+++ b/app/models/Component.php
@@ -1,4 +1,5 @@
'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 file
diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php
index 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 Ardent
return $this->belongsTo('User');
}
+ public function transactiongroups()
+ {
+ return $this->belongsToMany('TransactionGroup');
+ }
+
}
\ No newline at end of file
diff --git a/app/models/TransactionRelation.php b/app/models/TransactionRelation.php
new file mode 100644
index 0000000000..ee49e2dcab
--- /dev/null
+++ b/app/models/TransactionRelation.php
@@ -0,0 +1,7 @@
+ '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 controller
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
diff --git a/app/views/transactions/relate.blade.php b/app/views/transactions/relate.blade.php
new file mode 100644
index 0000000000..c83380916f
--- /dev/null
+++ b/app/views/transactions/relate.blade.php
@@ -0,0 +1,18 @@
+
+ No related transactions +
++ | {{{$jrnl->description}}} | +{{mf($jrnl->getAmount())}} | +