mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Check for double files and some code clean up.
This commit is contained in:
@@ -54,6 +54,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
public function saveAttachmentsForModel(Model $model)
|
public function saveAttachmentsForModel(Model $model)
|
||||||
{
|
{
|
||||||
$files = Input::file('attachments');
|
$files = Input::file('attachments');
|
||||||
|
|
||||||
foreach ($files as $entry) {
|
foreach ($files as $entry) {
|
||||||
if (!is_null($entry)) {
|
if (!is_null($entry)) {
|
||||||
$this->processFile($entry, $model);
|
$this->processFile($entry, $model);
|
||||||
@@ -71,11 +72,19 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
*/
|
*/
|
||||||
protected function hasFile(UploadedFile $file, Model $model)
|
protected function hasFile(UploadedFile $file, Model $model)
|
||||||
{
|
{
|
||||||
$md5 = md5_file($file->getPath());
|
$md5 = md5_file($file->getRealPath());
|
||||||
|
$name = $file->getClientOriginalName();
|
||||||
$class = get_class($model);
|
$class = get_class($model);
|
||||||
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||||
|
|
||||||
return ($count > 0);
|
if ($count > 0) {
|
||||||
|
$err = 'File ' . e($name) . ' already attached to this object.';
|
||||||
|
$this->errors->add('attachments', $err);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +106,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
$attachment = new Attachment;
|
$attachment = new Attachment;
|
||||||
$attachment->user()->associate(Auth::user());
|
$attachment->user()->associate(Auth::user());
|
||||||
$attachment->attachable()->associate($model);
|
$attachment->attachable()->associate($model);
|
||||||
$attachment->md5 = md5_file($file->getPath());
|
$attachment->md5 = md5_file($file->getRealPath());
|
||||||
$attachment->filename = $file->getClientOriginalName();
|
$attachment->filename = $file->getClientOriginalName();
|
||||||
$attachment->mime = $file->getMimeType();
|
$attachment->mime = $file->getMimeType();
|
||||||
$attachment->size = $file->getSize();
|
$attachment->size = $file->getSize();
|
||||||
@@ -128,6 +137,11 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UploadedFile $file
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function validMime(UploadedFile $file)
|
protected function validMime(UploadedFile $file)
|
||||||
{
|
{
|
||||||
$mime = $file->getMimeType();
|
$mime = $file->getMimeType();
|
||||||
@@ -143,6 +157,11 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UploadedFile $file
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function validSize(UploadedFile $file)
|
protected function validSize(UploadedFile $file)
|
||||||
{
|
{
|
||||||
$size = $file->getSize();
|
$size = $file->getSize();
|
||||||
|
@@ -311,16 +311,29 @@ class TransactionController extends Controller
|
|||||||
/**
|
/**
|
||||||
* @param JournalFormRequest $request
|
* @param JournalFormRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
* @param JournalRepositoryInterface $repository
|
||||||
|
* @param AttachmentHelperInterface $att
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
|
|
||||||
$journalData = $request->getJournalData();
|
$journalData = $request->getJournalData();
|
||||||
$repository->update($journal, $journalData);
|
$repository->update($journal, $journalData);
|
||||||
|
|
||||||
|
// save attachments:
|
||||||
|
$att->saveAttachmentsForModel($journal);
|
||||||
|
|
||||||
|
if ($att->getErrors()->count() > 0) {
|
||||||
|
// todo moet beter
|
||||||
|
Session::flash('error', '<ul>' . join('', $att->getErrors()->get('attachments', '<li>:message</li>')) . '</ul>');
|
||||||
|
}
|
||||||
|
if ($att->getMessages()->count() > 0) {
|
||||||
|
// todo moet beter
|
||||||
|
Session::flash('info', '<ul>' . join('', $att->getMessages()->get('attachments', '<li>:message</li>')) . '</ul>');
|
||||||
|
}
|
||||||
|
|
||||||
event(new JournalSaved($journal));
|
event(new JournalSaved($journal));
|
||||||
// update, get events by date and sort DESC
|
// update, get events by date and sort DESC
|
||||||
|
|
||||||
|
@@ -5,94 +5,99 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Form.open({'class' : 'form-horizontal','id' : 'update','url' : route('transactions.update',journal.id)}) }}
|
<form method="POST" action="{{ route('transactions.update',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update"
|
||||||
|
enctype="multipart/form-data">
|
||||||
|
|
||||||
<input type="hidden" name="id" value="{{ journal.id }}"/>
|
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||||
<input type="hidden" name="what" value="{{ what }}"/>
|
<input type="hidden" name="id" value="{{ journal.id }}"/>
|
||||||
|
<input type="hidden" name="what" value="{{ what }}"/>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
|
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<!-- ALWAYS AVAILABLE -->
|
||||||
|
{{ ExpandedForm.text('description',journal.description) }}
|
||||||
|
|
||||||
|
<!-- SHOW ACCOUNT (FROM) ONLY FOR WITHDRAWALS AND DEPOSITS -->
|
||||||
|
{% if what == 'deposit' or what == 'withdrawal' %}
|
||||||
|
{{ ExpandedForm.select('account_id',accounts,data['account_id']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- SHOW EXPENSE ACCOUNT ONLY FOR WITHDRAWALS -->
|
||||||
|
{% if what == 'withdrawal' %}
|
||||||
|
{{ ExpandedForm.text('expense_account',data['expense_account']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- SHOW REVENUE ACCOUNT ONLY FOR DEPOSITS -->
|
||||||
|
{% if what == 'deposit' %}
|
||||||
|
{{ ExpandedForm.text('revenue_account',data['revenue_account']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ONLY SHOW FROM/TO ACCOUNT WHEN CREATING TRANSFER -->
|
||||||
|
{% if what == 'transfer' %}
|
||||||
|
{{ ExpandedForm.select('account_from_id',accounts,data['account_from_id']) }}
|
||||||
|
{{ ExpandedForm.select('account_to_id',accounts,data['account_to_id']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ALWAYS SHOW AMOUNT -->
|
||||||
|
{{ ExpandedForm.amount('amount',data.amount,{'currency' : journal.transactionCurrency}) }}
|
||||||
|
|
||||||
|
<!-- ALWAYS SHOW DATE -->
|
||||||
|
{{ ExpandedForm.date('date',data['date']) }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<!-- close panel -->
|
||||||
<!-- ALWAYS AVAILABLE -->
|
|
||||||
{{ ExpandedForm.text('description',journal.description) }}
|
|
||||||
|
|
||||||
<!-- SHOW ACCOUNT (FROM) ONLY FOR WITHDRAWALS AND DEPOSITS -->
|
|
||||||
{% if what == 'deposit' or what == 'withdrawal' %}
|
|
||||||
{{ ExpandedForm.select('account_id',accounts,data['account_id']) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- SHOW EXPENSE ACCOUNT ONLY FOR WITHDRAWALS -->
|
|
||||||
{% if what == 'withdrawal' %}
|
|
||||||
{{ ExpandedForm.text('expense_account',data['expense_account']) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- SHOW REVENUE ACCOUNT ONLY FOR DEPOSITS -->
|
|
||||||
{% if what == 'deposit' %}
|
|
||||||
{{ ExpandedForm.text('revenue_account',data['revenue_account']) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- ONLY SHOW FROM/TO ACCOUNT WHEN CREATING TRANSFER -->
|
|
||||||
{% if what == 'transfer' %}
|
|
||||||
{{ ExpandedForm.select('account_from_id',accounts,data['account_from_id']) }}
|
|
||||||
{{ ExpandedForm.select('account_to_id',accounts,data['account_to_id']) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- ALWAYS SHOW AMOUNT -->
|
|
||||||
{{ ExpandedForm.amount('amount',data.amount,{'currency' : journal.transactionCurrency}) }}
|
|
||||||
|
|
||||||
<!-- ALWAYS SHOW DATE -->
|
|
||||||
{{ ExpandedForm.date('date',data['date']) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- close panel -->
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->
|
||||||
|
{% if what == 'withdrawal' %}
|
||||||
|
{{ ExpandedForm.select('budget_id',budgets,data['budget_id']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
<!-- CATEGORY ALWAYS -->
|
||||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
{{ ExpandedForm.text('category',data['category']) }}
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
<!-- TAGS -->
|
||||||
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
{{ ExpandedForm.text('tags') }}
|
||||||
|
|
||||||
|
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
|
||||||
|
{% if what == 'withdrawal' and piggies|length > 0 %}
|
||||||
|
{{ ExpandedForm.select('piggy_bank_id',piggies,data['piggy_bank_id']) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ATTACHMENTS -->
|
||||||
|
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple'}) }}
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<!-- end of panel for options-->
|
||||||
<!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->
|
|
||||||
{% if what == 'withdrawal' %}
|
|
||||||
{{ ExpandedForm.select('budget_id',budgets,data['budget_id']) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- CATEGORY ALWAYS -->
|
<!-- panel for options -->
|
||||||
{{ ExpandedForm.text('category',data['category']) }}
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
<!-- TAGS -->
|
<h3 class="box-title">{{ 'options'|_ }}</h3>
|
||||||
{{ ExpandedForm.text('tags') }}
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
|
{{ ExpandedForm.optionsList('update','transaction') }}
|
||||||
{% if what == 'withdrawal' and piggies|length > 0 %}
|
</div>
|
||||||
{{ ExpandedForm.select('piggy_bank_id',piggies,data['piggy_bank_id']) }}
|
<div class="box-footer">
|
||||||
{% endif %}
|
<button type="submit" class="pull-right btn btn-success">{{ ('update_' ~ what)|_ }}</button>
|
||||||
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- end of panel for options-->
|
|
||||||
|
|
||||||
<!-- panel for options -->
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'options'|_ }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
{{ ExpandedForm.optionsList('update','transaction') }}
|
|
||||||
</div>
|
|
||||||
<div class="box-footer">
|
|
||||||
<button type="submit" class="pull-right btn btn-success">{{ ('update_' ~ what)|_ }}</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{{ Form.close|raw }}
|
</form>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -76,6 +76,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- attachments -->
|
<!-- attachments -->
|
||||||
|
{% if journal.attachments|length > 0 %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'attachments'|_ }}</h3>
|
<h3 class="box-title">{{ 'attachments'|_ }}</h3>
|
||||||
@@ -97,6 +98,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- events, if present -->
|
<!-- events, if present -->
|
||||||
{% if journal.piggyBankEvents|length > 0 %}
|
{% if journal.piggyBankEvents|length > 0 %}
|
||||||
|
Reference in New Issue
Block a user