mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some new code, transaction groups among them.
This commit is contained in:
parent
3e5f615ffc
commit
0a2cbaa047
@ -115,8 +115,11 @@ class ReportController extends BaseController
|
||||
$journals = App::make('FireflyIII\Database\TransactionJournal');
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $journals->first();
|
||||
|
||||
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
|
||||
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,19 +235,13 @@ 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) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '<br>';
|
||||
}
|
||||
);
|
||||
exit;
|
||||
|
||||
return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals', 'deposits'));
|
||||
}
|
||||
@ -276,7 +275,8 @@ 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(
|
||||
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);
|
||||
}
|
||||
|
@ -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 . '"'
|
||||
);
|
||||
}
|
||||
|
34
app/database/migrations/2014_11_25_204833_cacheTable.php
Normal file
34
app/database/migrations/2014_11_25_204833_cacheTable.php
Normal file
@ -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');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Shared\SingleTableInheritanceEntity;
|
||||
|
||||
|
||||
|
38
app/models/TransactionGroup.php
Normal file
38
app/models/TransactionGroup.php
Normal file
@ -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');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
7
app/models/TransactionRelation.php
Normal file
7
app/models/TransactionRelation.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
|
||||
class TransactionRelation extends Ardent {
|
||||
|
||||
}
|
@ -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 controller
|
||||
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
|
||||
|
18
app/views/transactions/relate.blade.php
Normal file
18
app/views/transactions/relate.blade.php
Normal file
@ -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>
|
@ -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
|
@ -18,4 +18,15 @@ $(document).ready(function () {
|
||||
if(typeof googleTablePaged != 'undefined') {
|
||||
googleTablePaged('table/transactions/' + what,'transaction-table');
|
||||
}
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user