Fix split deposit.

This commit is contained in:
James Cole
2016-07-26 20:26:46 +02:00
parent 90865a5284
commit ce191fa6d3
5 changed files with 168 additions and 167 deletions

View File

@@ -105,9 +105,6 @@ class Journal implements JournalInterface
*/ */
public function updateJournal(TransactionJournal $journal, array $data): TransactionJournal public function updateJournal(TransactionJournal $journal, array $data): TransactionJournal
{ {
echo '<pre>';
print_r($data);
$journal->description = $data['journal_description']; $journal->description = $data['journal_description'];
$journal->transaction_currency_id = $data['journal_currency_id']; $journal->transaction_currency_id = $data['journal_currency_id'];
$journal->date = $data['date']; $journal->date = $data['date'];
@@ -167,7 +164,8 @@ class Journal implements JournalInterface
{ {
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']); $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
if (strlen($data['source_account_name']) > 0) {
if (isset($data['source_account_name']) && strlen($data['source_account_name']) > 0) {
$sourceType = AccountType::where('type', 'Revenue account')->first(); $sourceType = AccountType::where('type', 'Revenue account')->first();
$sourceAccount = Account::firstOrCreateEncrypted( $sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1] ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1]

View File

@@ -59,14 +59,10 @@ class SplitJournalFormRequest extends Request
'amount' => round($this->get('amount')[$index], 2), 'amount' => round($this->get('amount')[$index], 2),
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0, 'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
'category' => $this->get('category')[$index] ?? '', 'category' => $this->get('category')[$index] ?? '',
'source_account_id' => intval($this->get('journal_source_account_id')), 'source_account_id' => isset($this->get('source_account_id')[$index]) ? intval($this->get('source_account_id')[$index]) : intval($this->get('journal_source_account_id')),
'source_account_name' => $this->get('journal_source_account_name'), 'source_account_name' => $this->get('source_account_name')[$index] ?? '',
'piggy_bank_id' => isset($this->get('piggy_bank_id')[$index]) 'piggy_bank_id' => isset($this->get('piggy_bank_id')[$index]) ? intval($this->get('piggy_bank_id')[$index]) : 0,
? intval($this->get('piggy_bank_id')[$index]) 'destination_account_id' => isset($this->get('destination_account_id')[$index]) ? intval($this->get('destination_account_id')[$index]) : intval($this->get('journal_destination_account_id')),
: 0,
'destination_account_id' => isset($this->get('destination_account_id')[$index])
? intval($this->get('destination_account_id')[$index])
: intval($this->get('journal_destination_account_id')),
'destination_account_name' => $this->get('destination_account_name')[$index] ?? '', 'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',
]; ];
$data['transactions'][] = $transaction; $data['transactions'][] = $transaction;

View File

@@ -29,6 +29,7 @@ return [
'lastMatch' => 'Last match', 'lastMatch' => 'Last match',
'split_number' => 'Split #', 'split_number' => 'Split #',
'destination' => 'Destination', 'destination' => 'Destination',
'source' => 'Source',
'expectedMatch' => 'Expected match', 'expectedMatch' => 'Expected match',
'automatch' => 'Auto match?', 'automatch' => 'Auto match?',
'repeat_freq' => 'Repeats', 'repeat_freq' => 'Repeats',

View File

@@ -7,193 +7,196 @@
<form method="POST" action="{{ route('split.journal.store',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update" <form method="POST" action="{{ route('split.journal.store',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update"
enctype="multipart/form-data"> enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}"> <input name="_token" type="hidden" value="{{ csrf_token() }}">
<input type="hidden" name="id" value="{{ journal.id }}"/> <input type="hidden" name="id" value="{{ journal.id }}"/>
<input type="hidden" name="what" value="{{ preFilled.what }}"/> <input type="hidden" name="what" value="{{ preFilled.what }}"/>
{% if errors.all()|length > 0 %} {% if errors.all()|length > 0 %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">{{ 'errors'|_ }}</h3>
</div>
<div class="box-body">
<ul>
{% for key, err in errors.all() %}
<li class="text-danger">{{ err }}</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-6 col-md-6 col-sm-6">
<div class="box box-danger"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'errors'|_ }}</h3> <h3 class="box-title">{{ 'transaction_meta_data'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<ul> {{ ExpandedForm.text('journal_description', journal.description) }}
{% for key, err in errors.all() %} {{ ExpandedForm.select('journal_currency_id', currencies, journal.transaction_currency_id) }}
<li class="text-danger">{{ err }}</li> {{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }}
{% endfor %} <input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
</ul> <!-- show source if withdrawal or transfer -->
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
{{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }}
{% endif %}
<!-- show static source if deposit: -->
{% if preFilled.what == 'deposit' %}
{{ ExpandedForm.text('journal_source_account_name', preFilled.journal_source_account_name) }}
{% endif %}
<!-- show static destination if transfer -->
{% if preFilled.what == 'transfer' %}
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
{% endif %}
</div> </div>
</div> </div>
</div> </div>
</div> <div class="col-lg-6 col-md-6 col-sm-6">
{% endif %} <div class="box">
<div class="row"> <div class="box-header with-border">
<div class="col-lg-6 col-md-6 col-sm-6"> <h3 class="box-title">{{ 'transaction_dates'|_ }}</h3>
<div class="box"> </div>
<div class="box-header with-border"> <div class="box-body">
<h3 class="box-title">{{ 'transaction_meta_data'|_ }}</h3> {{ ExpandedForm.date('date', journal.date) }}
</div>
<div class="box-body"> {{ ExpandedForm.date('interest_date', journal.interest_date) }}
{{ ExpandedForm.text('journal_description', journal.description) }}
{{ ExpandedForm.select('journal_currency_id', currencies, journal.transaction_currency_id) }} {{ ExpandedForm.date('book_date', journal.book_date) }}
{{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }}
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/> {{ ExpandedForm.date('process_date', journal.process_date) }}
<!-- show source if withdrawal or transfer --> </div>
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
{{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }}
{% endif %}
<!-- show static source if deposit: -->
{% if preFilled.what == 'deposit' %}
{{ ExpandedForm.text('journal_source_account_name', preFilled.journal_source_account_name) }}
{% endif %}
<!-- show static destination if transfer -->
{% if preFilled.what == 'transfer' %}
{{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }}
{% endif %}
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-6 col-md-6 col-sm-6"> <div class="row">
<div class="box"> <div class="col-lg-12 col-md-12 col-sm-12">
<div class="box-header with-border"> <div class="box">
<h3 class="box-title">{{ 'transaction_dates'|_ }}</h3> <div class="box-header with-border">
</div> <h3 class="box-title">{{ 'splits'|_ }}</h3>
<div class="box-body"> </div>
{{ ExpandedForm.date('date', journal.date) }} <div class="box-body">
<table class="table table-bordered table-condensed table-striped split-table">
{{ ExpandedForm.date('interest_date', journal.interest_date) }} <thead>
<tr>
{{ ExpandedForm.date('book_date', journal.book_date) }} <th>{{ trans('list.split_number') }}</th>
<th>{{ trans('list.description') }}</th>
{{ ExpandedForm.date('process_date', journal.process_date) }}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'splits'|_ }}</h3>
</div>
<div class="box-body">
<table class="table table-bordered table-condensed table-striped split-table">
<thead>
<tr>
<th>{{ trans('list.split_number') }}</th>
<th>{{ trans('list.description') }}</th>
{% if preFilled.what == 'withdrawal' or preFilled.what == 'deposit' %}
<th>{{ trans('list.destination') }}</th>
{% endif %}
<th>{{ trans('list.amount') }}</th>
{% if preFilled.what == 'withdrawal' %}
<th>{{ trans('list.budget') }}</th>
{% endif %}
<th>{{ trans('list.category') }}</th>
{% if preFilled.what == 'transfer' %}
<th>{{ trans('list.piggy_bank') }}</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for index, descr in preFilled.description %}
<tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}">
<td class="count">#{{ loop.index }}</td>
<td>
<input type="text" name="description[]" value="{{ descr }}" class="form-control"/>
</td>
<!-- withdrawal has several destination names. -->
{% if preFilled.what == 'withdrawal' %} {% if preFilled.what == 'withdrawal' %}
<td> <th>{{ trans('list.destination') }}</th>
<input type="text" name="destination_account_name[]" value="{{ preFilled.destination_account_name[index] }}"
class="form-control"/>
</td>
{% endif %} {% endif %}
<!-- deposit has several destination id's -->
{% if preFilled.what == 'deposit' %} {% if preFilled.what == 'deposit' %}
<td> <th>{{ trans('list.source') }}</th>
{{ Form.select('destination_account_id[]', assetAccounts, preFilled.destination_account_id[index], {class: 'form-control'}) }}
</td>
{% endif %} {% endif %}
<th>{{ trans('list.amount') }}</th>
<td style="width:10%;">
<input type="number" name="amount[]" value="{{ preFilled.amount[index] }}"
class="form-control" autocomplete="off" step="any" min="0.01">
</td>
{% if preFilled.what == 'withdrawal' %} {% if preFilled.what == 'withdrawal' %}
<td> <th>{{ trans('list.budget') }}</th>
<select class="form-control" name="budget_id[]">
{% for key, budget in budgets %}
<option label="{{ budget }}" value="{{ key }}"
{% if preFilled.budget_id[index] == key %}
selected="selected"
{% endif %}
>{{ budget }}</option>
{% endfor %}
</select>
</td>
{% endif %} {% endif %}
<td> <th>{{ trans('list.category') }}</th>
<input type="text" name="category[]" value="{{ preFilled.category[index] }}" class="form-control"/>
</td>
{% if preFilled.what == 'transfer' %} {% if preFilled.what == 'transfer' %}
<td> <th>{{ trans('list.piggy_bank') }}</th>
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
{{ Form.select('piggy_bank_id[]',piggyBanks, preFilled.piggy_bank_id[index], {class: 'form-control'}) }}
</td>
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} </thead>
</tbody> <tbody>
</table> {% for index, descr in preFilled.description %}
<p> <tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}">
<br/> <td class="count">#{{ loop.index }}</td>
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a> <td>
</p> <input type="text" name="description[]" value="{{ descr }}" class="form-control"/>
<!--<p class="pull-right"> </td>
<!-- withdrawal has several destination names. -->
{% if preFilled.what == 'withdrawal' %}
<td>
<input type="text" name="destination_account_name[]" value="{{ preFilled.destination_account_name[index] }}"
class="form-control"/>
</td>
{% endif %}
<!-- deposit has several destination id's -->
{% if preFilled.what == 'deposit' %}
<td>
{{ Form.select('destination_account_id[]', assetAccounts, preFilled.destination_account_id[index], {class: 'form-control'}) }}
</td>
{% endif %}
<td style="width:10%;">
<input type="number" name="amount[]" value="{{ preFilled.amount[index] }}"
class="form-control" autocomplete="off" step="any" min="0.01">
</td>
{% if preFilled.what == 'withdrawal' %}
<td>
<select class="form-control" name="budget_id[]">
{% for key, budget in budgets %}
<option label="{{ budget }}" value="{{ key }}"
{% if preFilled.budget_id[index] == key %}
selected="selected"
{% endif %}
>{{ budget }}</option>
{% endfor %}
</select>
</td>
{% endif %}
<td>
<input type="text" name="category[]" value="{{ preFilled.category[index] }}" class="form-control"/>
</td>
{% if preFilled.what == 'transfer' %}
<td>
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
{{ Form.select('piggy_bank_id[]',piggyBanks, preFilled.piggy_bank_id[index], {class: 'form-control'}) }}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
<p>
<br/>
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
</p>
<!--<p class="pull-right">
<button type="submit" id="transaction-btn" class="btn btn-success pull-right"> <button type="submit" id="transaction-btn" class="btn btn-success pull-right">
{{ ('update_splitted_'~preFilled.what)|_ }} {{ ('update_splitted_'~preFilled.what)|_ }}
</button> </button>
</p> </p>
--> -->
</div>
</div> </div>
</div> </div>
</div> </div>
</div> <div class="row">
<div class="row"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3> <h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
</div>
<div class="box-body">
<!-- ATTACHMENTS -->
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
</div>
</div> </div>
<div class="box-body"> </div>
<!-- ATTACHMENTS --> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }} <!-- 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('create','split-transaction') }}
</div>
<div class="box-footer">
<button type="submit" class="pull-right btn btn-success">{{ ('store_' ~ preFilled.what)|_ }}</button>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<!-- 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('create','split-transaction') }}
</div>
<div class="box-footer">
<button type="submit" class="pull-right btn btn-success">{{ ('store_' ~ preFilled.what)|_ }}</button>
</div>
</div>
</div>
</div>
</form> </form>
{% endblock %} {% endblock %}

View File

@@ -94,9 +94,12 @@
<th>{{ trans('list.description') }}</th> <th>{{ trans('list.description') }}</th>
<!-- withdrawal and deposit have a destination. --> <!-- withdrawal and deposit have a destination. -->
{% if preFilled.what == 'withdrawal' or preFilled.what == 'deposit' %} {% if preFilled.what == 'withdrawal' %}
<th>{{ trans('list.destination') }}</th> <th>{{ trans('list.destination') }}</th>
{% endif %} {% endif %}
{% if preFilled.what == 'deposit' %}
<th>{{ trans('list.source') }}</th>
{% endif %}
<th>{{ trans('list.amount') }}</th> <th>{{ trans('list.amount') }}</th>