mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
Fixed transactions and attachments.
This commit is contained in:
parent
2d8449ed68
commit
aa59227786
@ -14,6 +14,7 @@ use ExpandedForm;
|
||||
use FireflyIII\Crud\Split\JournalInterface;
|
||||
use FireflyIII\Events\TransactionJournalUpdated;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -150,21 +151,31 @@ class SplitController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param SplitJournalFormRequest $request
|
||||
* @param JournalInterface $repository
|
||||
* @param TransactionJournal $journal
|
||||
* @param SplitJournalFormRequest $request
|
||||
* @param JournalInterface $repository
|
||||
* @param AttachmentHelperInterface $att
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(TransactionJournal $journal, SplitJournalFormRequest $request, JournalInterface $repository)
|
||||
public function update(TransactionJournal $journal, SplitJournalFormRequest $request, JournalInterface $repository, AttachmentHelperInterface $att)
|
||||
{
|
||||
|
||||
$data = $request->getSplitData();
|
||||
$journal = $repository->updateJournal($journal, $data);
|
||||
|
||||
// save attachments:
|
||||
$att->saveAttachmentsForModel($journal);
|
||||
|
||||
event(new TransactionJournalUpdated($journal));
|
||||
// update, get events by date and sort DESC
|
||||
|
||||
// flash messages
|
||||
if (count($att->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $att->getMessages()->get('attachments'));
|
||||
}
|
||||
|
||||
|
||||
$type = strtolower($journal->transaction_type_type ?? TransactionJournal::transactionTypeStr($journal));
|
||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));
|
||||
Preferences::mark();
|
||||
|
@ -22,6 +22,7 @@ use FireflyIII\Http\Requests\MassDeleteJournalRequest;
|
||||
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
@ -408,7 +409,7 @@ class TransactionController extends Controller
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(TransactionJournal $journal)
|
||||
public function show(TransactionJournal $journal, JournalRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
/** @var Collection $set */
|
||||
@ -420,11 +421,21 @@ class TransactionController extends Controller
|
||||
);
|
||||
|
||||
// TODO different for each transaction type!
|
||||
/** @var Collection $transactions */
|
||||
$transactions = $journal->transactions()->groupBy('transactions.account_id')->orderBy('amount', 'ASC')->get(
|
||||
['transactions.*', DB::raw('SUM(`transactions`.`amount`) as `sum`')]
|
||||
);
|
||||
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
|
||||
|
||||
// foreach do balance thing
|
||||
$transactions->each(
|
||||
function (Transaction $t) use ($repository) {
|
||||
$t->before = $repository->balanceBeforeTransaction($t);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
|
||||
|
||||
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
|
||||
}
|
||||
|
@ -319,6 +319,9 @@ class TransactionJournal extends TransactionJournalSupport
|
||||
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
*/
|
||||
public function scopeSortCorrectly(EloquentBuilder $query)
|
||||
{
|
||||
$query->orderBy('transaction_journals.date', 'DESC');
|
||||
|
@ -435,6 +435,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
|
@ -41,6 +41,44 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount in the account before the specified transaction took place.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function balanceBeforeTransaction(Transaction $transaction): string
|
||||
{
|
||||
// some dates from journal
|
||||
$journal = $transaction->transactionJournal;
|
||||
$query = Transaction::
|
||||
leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $transaction->account_id)
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where(
|
||||
function (Builder $q) use ($journal) {
|
||||
$q->where('transaction_journals.date', '<', $journal->date->format('Y-m-d'));
|
||||
$q->orWhere(
|
||||
function (Builder $qq) use ($journal) {
|
||||
$qq->where('transaction_journals.date', '=', $journal->date->format('Y-m-d'));
|
||||
$qq->where('transaction_journals.order', '>', $journal->order);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
)
|
||||
->where('transactions.id', '!=', $transaction->id)
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
$sum = $query->sum('transactions.amount');
|
||||
|
||||
return strval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
|
@ -41,6 +41,16 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function first(): TransactionJournal;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the amount in the account before the specified transaction took place.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function balanceBeforeTransaction(Transaction $transaction): string;
|
||||
|
||||
/**
|
||||
* Returns the amount in the account before the specified transaction took place.
|
||||
*
|
||||
|
@ -4,7 +4,8 @@
|
||||
{{ Breadcrumbs.renderIfExists }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{{ Form.model(journal, {'class' : 'form-horizontal','id' : 'update','url' : route('split.journal.update',journal.id) } ) }}
|
||||
<form method="POST" action="{{ route('split.journal.update',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update"
|
||||
enctype="multipart/form-data">
|
||||
|
||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="id" value="{{ journal.id }}"/>
|
||||
|
@ -100,8 +100,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- attachments -->
|
||||
{% if journal.attachments|length > 0 %}
|
||||
<!-- attachments for unsplitted journals -->
|
||||
{% if journal.attachments|length > 0 and transactions.count == 2 %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'attachments'|_ }}</h3>
|
||||
@ -171,11 +171,11 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ 'amount'|_ }}</td>
|
||||
<td>{{ t|formatTransaction }}</td>
|
||||
<td>{{ t.before|formatAmount}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ 'newBalance'|_ }}</td>
|
||||
<td>null</td>
|
||||
<td>{{ (t.before+t.amount)|formatAmount }}</td>
|
||||
</tr>
|
||||
{% if t.description %}
|
||||
<tr>
|
||||
@ -203,6 +203,48 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<!-- attachments for splitted journals -->
|
||||
{% if journal.attachments|length > 0 and transactions.count > 2 %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'attachments'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body table-responsive no-padding">
|
||||
<table class="table table-hover">
|
||||
{% for att in journal.attachments %}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="btn-group btn-group-xs">
|
||||
<a href="{{ route('attachments.edit', att.id) }}" class="btn btn-default"><i class="fa fa-pencil"></i></a>
|
||||
<a href="{{ route('attachments.delete', att.id) }}" class="btn btn-danger"><i class="fa fa-trash"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<i class="fa {{ att.mime|mimeIcon }}"></i>
|
||||
<a href="{{ route('attachments.download', att.id) }}" title="{{ att.filename }}">
|
||||
{% if att.title %}
|
||||
{{ att.title }}
|
||||
{% else %}
|
||||
{{ att.filename }}
|
||||
{% endif %}
|
||||
</a>
|
||||
({{ att.size|filesize }})
|
||||
{% if att.description %}
|
||||
<br/>
|
||||
<em>{{ att.description }}</em>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td style="width:100px;">
|
||||
<img src="{{ route('attachments.preview', att.id) }}"/>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -233,7 +275,7 @@
|
||||
<td><a href="{{ route('accounts.show',t.account.id) }}">{{ t.account.name }}</a></td>
|
||||
<td>{{ t.account.accounttype.type|_ }}</td>
|
||||
<td>{{ t.sum|formatAmount }}</td>
|
||||
<td>null</td>
|
||||
<td>{{ t.before|formatAmount }} → {{ (t.sum+t.before)|formatAmount }}</td>
|
||||
<td>{{ t.description }}</td>
|
||||
<td>
|
||||
{% if t.categories[0] %}
|
||||
|
Loading…
Reference in New Issue
Block a user