mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-11 07:55:51 -06:00
Cleaned up some code and added a small feature for transaction views.
This commit is contained in:
parent
a6b89879c5
commit
d56c00915c
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
|
||||
/**
|
||||
@ -102,15 +103,15 @@ class TransactionController extends BaseController
|
||||
$piggies = $piggyRepository->get();
|
||||
// piggy bank id?
|
||||
$piggyBankId = null;
|
||||
foreach($journal->transactions as $t) {
|
||||
foreach ($journal->transactions as $t) {
|
||||
$piggyBankId = $t->piggybank_id;
|
||||
}
|
||||
|
||||
// data to properly display form:
|
||||
$data = [
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0,
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0,
|
||||
'piggybank_id' => $piggyBankId
|
||||
];
|
||||
$category = $journal->categories()->first();
|
||||
@ -141,7 +142,7 @@ class TransactionController extends BaseController
|
||||
|
||||
return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(
|
||||
'what', $what
|
||||
)->with('budgets', $budgets)->with('data', $data)->with('piggies',$piggies);
|
||||
)->with('budgets', $budgets)->with('data', $data)->with('piggies', $piggies);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,9 +150,22 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$journals = $this->_repository->paginate(25);
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate(25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate(25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals);
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,14 +24,17 @@ class Budget implements BudgetInterface
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
|
||||
/** @var \LimitRepetition $rep */
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$periodOrder = $rep->periodOrder();
|
||||
$period = $rep->periodShow();
|
||||
$return[$periodOrder] = isset($return[$periodOrder])
|
||||
? $return[$periodOrder]
|
||||
: ['date' => $period,
|
||||
: ['date' => $period,
|
||||
'dateObject' => $rep->startdate,
|
||||
'budget_id' => $limit->budget_id];
|
||||
'start' => $rep->startdate,
|
||||
'end' => $rep->enddate,
|
||||
'budget_id' => $limit->budget_id];
|
||||
|
||||
}
|
||||
}
|
||||
@ -63,27 +66,27 @@ class Budget implements BudgetInterface
|
||||
$repetition = \LimitRepetition::with('limit', 'limit.budget')->leftJoin(
|
||||
'limits', 'limit_repetitions.limit_id', '=', 'limits.id'
|
||||
)->leftJoin('components', 'limits.component_id', '=', 'components.id')->where(
|
||||
'components.user_id', \Auth::user()->id
|
||||
)
|
||||
'components.user_id', \Auth::user()->id
|
||||
)
|
||||
->where('limit_repetitions.id', $repetitionId)->first(['limit_repetitions.*']);
|
||||
|
||||
// get transactions:
|
||||
$set = $repetition->limit->budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype'
|
||||
)->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
|
||||
$result[0] = [
|
||||
'date' => $repetition->periodShow(),
|
||||
'limit' => $repetition->limit,
|
||||
'date' => $repetition->periodShow(),
|
||||
'limit' => $repetition->limit,
|
||||
'limitrepetition' => $repetition,
|
||||
'journals' => $set,
|
||||
'paginated' => false
|
||||
'journals' => $set,
|
||||
'paginated' => false
|
||||
];
|
||||
|
||||
return $result;
|
||||
@ -91,7 +94,8 @@ class Budget implements BudgetInterface
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param bool $useSessionDates
|
||||
* @param bool $useSessionDates
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
@ -105,8 +109,9 @@ class Budget implements BudgetInterface
|
||||
|
||||
// get the limits:
|
||||
if ($useSessionDates) {
|
||||
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->
|
||||
where('startdate', '<=', $sessionEnd->format('Y-m-d'))->get();
|
||||
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->where(
|
||||
'startdate', '<=', $sessionEnd->format('Y-m-d')
|
||||
)->get();
|
||||
} else {
|
||||
$limits = $budget->limits;
|
||||
}
|
||||
@ -116,22 +121,22 @@ class Budget implements BudgetInterface
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$order = $repetition->periodOrder();
|
||||
$result[$order] = [
|
||||
'date' => $repetition->periodShow(),
|
||||
'date' => $repetition->periodShow(),
|
||||
'limitrepetition' => $repetition,
|
||||
'limit' => $limit,
|
||||
'journals' => [],
|
||||
'paginated' => false
|
||||
'limit' => $limit,
|
||||
'journals' => [],
|
||||
'paginated' => false
|
||||
];
|
||||
$transactions = [];
|
||||
$set = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype'
|
||||
)->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
foreach ($set as $entry) {
|
||||
$transactions[] = $entry;
|
||||
$inRepetition[] = $entry->id;
|
||||
@ -146,17 +151,17 @@ class Budget implements BudgetInterface
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->whereNotIn(
|
||||
'transaction_journals.id', $inRepetition
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
'transaction_journals.id', $inRepetition
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
} else {
|
||||
$query = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
}
|
||||
|
||||
// build paginator:
|
||||
@ -173,8 +178,8 @@ class Budget implements BudgetInterface
|
||||
$items[] = $item;
|
||||
}
|
||||
$paginator = \Paginator::make($items, $totalItems, $perPage);
|
||||
$result['0000'] = ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
'journals' => $paginator];
|
||||
$result['0000'] = ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
'journals' => $paginator];
|
||||
}
|
||||
krsort($result);
|
||||
|
||||
@ -194,10 +199,10 @@ class Budget implements BudgetInterface
|
||||
$set = $budget->transactionjournals()->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.id']
|
||||
);
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.id']
|
||||
);
|
||||
foreach ($set as $item) {
|
||||
$inRepetitions[] = $item->id;
|
||||
}
|
||||
@ -209,10 +214,10 @@ class Budget implements BudgetInterface
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->whereNotIn(
|
||||
'transaction_journals.id', $inRepetitions
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
'transaction_journals.id', $inRepetitions
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
|
||||
// build paginator:
|
||||
$perPage = 25;
|
||||
@ -228,8 +233,8 @@ class Budget implements BudgetInterface
|
||||
$items[] = $item;
|
||||
}
|
||||
$paginator = \Paginator::make($items, $totalItems, $perPage);
|
||||
$result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
'journals' => $paginator]];
|
||||
$result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
'journals' => $paginator]];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -121,7 +121,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$fromTransaction->description = null;
|
||||
$fromTransaction->amount = $amountFrom;
|
||||
if (!$fromTransaction->validate()) {
|
||||
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first());
|
||||
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
|
||||
));
|
||||
}
|
||||
$fromTransaction->save();
|
||||
|
||||
@ -150,9 +151,9 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
['transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
)
|
||||
->where('id', $journalId)->first();
|
||||
}
|
||||
@ -167,7 +168,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@ -196,9 +197,9 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@ -230,13 +231,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function paginate($count = 25)
|
||||
public function paginate($count = 25, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
[
|
||||
'transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
},
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
},
|
||||
'transactions.account',
|
||||
'transactions.account.accounttype',
|
||||
'transactioncurrency',
|
||||
@ -244,10 +245,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
]
|
||||
)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->paginate($count);
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
if (!is_null($start)) {
|
||||
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d'));
|
||||
}
|
||||
if (!is_null($end)) {
|
||||
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
|
||||
return $query;
|
||||
$result = $query->paginate($count);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,12 +336,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$connected = true;
|
||||
$transaction->piggybank()->associate($piggyBank);
|
||||
$transaction->save();
|
||||
\Event::fire('piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]);
|
||||
\Event::fire(
|
||||
'piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($connected === false) {
|
||||
\Session::flash('warning', 'Piggy bank "' . e($piggyBank->name) . '" is not set to draw money from any of the accounts in this transfer');
|
||||
\Session::flash(
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -462,7 +475,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
}
|
||||
}
|
||||
if ($connected === false) {
|
||||
\Session::flash('warning', 'Piggy bank "' . e($piggyBank->name) . '" is not set to draw money from any of the accounts in this transfer');
|
||||
\Session::flash(
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -479,7 +495,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if ($journal->validate()) {
|
||||
$journal->save();
|
||||
}
|
||||
if($fireEvent) {
|
||||
if ($fireEvent) {
|
||||
\Event::fire('piggybanks.updateRelatedTransfer', [$piggyBank]);
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,6 @@ interface TransactionJournalRepositoryInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function paginate($count = 25);
|
||||
public function paginate($count = 25, Carbon $start = null, Carbon $end = null);
|
||||
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
@foreach($budgets as $date => $entry)
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h3><a href="#transactions-in-this-period">{{$entry['date']}}</a>
|
||||
<h3><a href="{{route('transactions.index')}}?startdate={{$entry['start']->format('Y-m-d')}}&enddate={{$entry['end']->format('Y-m-d')}}">{{$entry['date']}}</a>
|
||||
<a class="btn btn-default btn-xs" href ="{{route('budgets.limits.create')}}?startdate={{$entry['dateObject']->format('Y-m-d')}}"><span class="glyphicon glyphicon-plus-sign"></span> Create a new envelope for {{$entry['date']}}</a>
|
||||
</h3>
|
||||
<table class="table table-bordered table-striped">
|
||||
|
@ -1,6 +1,18 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
|
||||
|
||||
@if($filtered === true)
|
||||
<p class="bg-primary" style="padding:15px;">
|
||||
This view is filtered to show only the transactions between
|
||||
{{$filters['start']->format('M jS, Y')}} and {{$filters['end']->format('M jS, Y')}}.
|
||||
</p>
|
||||
<p class="bg-info" style="padding:15px;">
|
||||
<a href="{{route('transactions.index')}}" class="text-info">Reset the filter.</a>
|
||||
</p>
|
||||
@endif
|
||||
|
||||
|
||||
@include('paginated.transactions')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user