Fix bugs.

This commit is contained in:
James Cole 2016-05-20 11:27:41 +02:00
parent 7d7ff71384
commit 7dd858be39
3 changed files with 81 additions and 95 deletions

View File

@ -116,6 +116,24 @@ class MassController extends Controller
Session::flash('gaEventCategory', 'transactions');
Session::flash('gaEventAction', 'mass-edit');
// set some values to be used in the edit routine:
$journals->each(
function (TransactionJournal $journal) {
$journal->amount = TransactionJournal::amountPositive($journal);
$sources = TransactionJournal::sourceAccountList($journal);
$destinations = TransactionJournal::destinationAccountList($journal);
$journal->transaction_count = $journal->transactions()->count();
if (!is_null($sources->first())) {
$journal->source_account_id = $sources->first()->id;
$journal->source_account_name = $sources->first()->name;
}
if (!is_null($destinations->first())) {
$journal->destination_account_id = $destinations->first()->id;
$journal->destination_account_name = $destinations->first()->name;
}
}
);
return view('transactions.mass-edit', compact('journals', 'subTitle', 'accountList'));
}

View File

@ -47,15 +47,15 @@ use Watson\Validating\ValidatingTrait;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal after($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal before($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal transactionTypes($types)
* @property-read string $transaction_type_type
* @property string $transaction_type_type
* @property-read string $transaction_currency_code
* @property-read string $destination_amount
* @property-read string $destination_account_id
* @property-read string $destination_account_name
* @property string $destination_account_id
* @property string $destination_account_name
* @property-read string $destination_account_type
* @property-read string $source_amount
* @property-read string $source_account_id
* @property-read string $source_account_name
* @property string $source_account_id
* @property string $source_account_name
* @property-read string $source_account_type
* @property \Carbon\Carbon $process_date
* @property int $account_id
@ -178,20 +178,6 @@ class TransactionJournal extends TransactionJournalSupport
return $value;
}
/**
* @param $value
*
* @return string
*/
public function getDestinationAccountNameAttribute($value)
{
if (!is_null($value) && strlen(strval($value)) > 0) {
return Crypt::decrypt($value);
}
return null;
}
/**
*
* @param string $fieldName
@ -209,21 +195,6 @@ class TransactionJournal extends TransactionJournalSupport
return '';
}
/**
* @param $value
*
* @return string
*/
public function getSourceAccountNameAttribute($value)
{
if (!is_null($value) && strlen(strval($value)) > 0) {
return Crypt::decrypt($value);
}
return null;
}
/**
* @return bool
*/
@ -322,17 +293,6 @@ 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');
$query->orderBy('transaction_journals.order', 'ASC');
$query->orderBy('transaction_journals.id', 'DESC');
}
/**
* @param EloquentBuilder $query
*/
@ -351,6 +311,17 @@ class TransactionJournal extends TransactionJournalSupport
$query->with(['categories', 'budgets', 'attachments', 'bill', 'transactions']);
}
/**
* @param EloquentBuilder $query
*/
public function scopeSortCorrectly(EloquentBuilder $query)
{
$query->orderBy('transaction_journals.date', 'DESC');
$query->orderBy('transaction_journals.order', 'ASC');
$query->orderBy('transaction_journals.id', 'DESC');
}
/**
*
* @param EloquentBuilder $query

View File

@ -27,61 +27,58 @@
<th style="width: 20%;">{{ trans('list.to') }}</th>
</tr>
{% for journal in journals %}
<tr>
<td>
<!-- LINK TO EDIT FORM -->
<a href="{{ route('transactions.edit', journal.id) }}" class="btn btn-xs btn-default">
<i class="fa fa-fw fa-pencil"></i>
</a>
<input type="hidden" name="journals[]" value="{{ journal.id }}"/>
</td>
<td>
<!-- DESCRIPTION -->
<input
class="form-control"
id="ffInput_description_{{ journal.id }}" autocomplete="off"
placeholder="Description" name="description[{{ journal.id }}]"
type="text" value="{{ journal.description }}">
</td>
<td>
<!-- AMOUNT -->
{% if journal.destination_amount > 0 %}
{% set amount = journal.destination_amount %}
{% else %}
{% set amount = journal.source_amount %}
{% endif %}
{% if journal.transaction_count == 2 %}
<tr>
<td>
<!-- LINK TO EDIT FORM -->
<a href="{{ route('transactions.edit', journal.id) }}" class="btn btn-xs btn-default">
<i class="fa fa-fw fa-pencil"></i>
</a>
<input type="hidden" name="journals[]" value="{{ journal.id }}"/>
</td>
<td>
<!-- DESCRIPTION -->
<input
class="form-control"
id="ffInput_description_{{ journal.id }}" autocomplete="off"
placeholder="Description" name="description[{{ journal.id }}]"
type="text" value="{{ journal.description }}">
</td>
<td>
<!-- AMOUNT -->
{{ ExpandedForm.amountSmall('amount_'~journal.id, journal.amount, {'name' : 'amount['~journal.id~']', 'currency' : journal.transactionCurrency}) }}
</td>
<td>
<!-- DATE -->
<input
class="form-control" id="ffInput_date_{{ journal.id }}"
autocomplete="off" name="date[{{ journal.id }}]" type="date" value="{{ journal.date.format('Y-m-d') }}">
</td>
<td>
{{ ExpandedForm.amountSmall('amount_'~journal.id, amount, {'name' : 'amount['~journal.id~']', 'currency' : journal.transactionCurrency}) }}
</td>
<td>
<!-- DATE -->
<input
class="form-control" id="ffInput_date_{{ journal.id }}"
autocomplete="off" name="date[{{ journal.id }}]" type="date" value="{{ journal.date.format('Y-m-d') }}">
</td>
<td>
<!-- SOURCE ACCOUNT FOR TRANSFER OR WITHDRAWAL -->
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Withdrawal' %}
{{ Form.select('source_account_id['~journal.id~']', accountList, journal.source_account_id, {'class': 'form-control'}) }}
{% else %}
<!-- if is income -->
{{ Form.input('text', 'revenue_account['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
{% endif %}
<!-- SOURCE ACCOUNT FOR TRANSFER OR WITHDRAWAL -->
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Withdrawal' %}
{{ Form.select('source_account_id['~journal.id~']', accountList, journal.source_account_id, {'class': 'form-control'}) }}
{% else %}
<!-- if is income -->
{{ Form.input('text', 'revenue_account['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
{% endif %}
</td>
<td>
</td>
<td>
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
<!-- is is transfer or income -->
{{ Form.select('destination_account_id['~journal.id~']', accountList, journal.destination_account_id, {'class': 'form-control'}) }}
{% else %}
<!-- if is expense -->
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
<!-- is is transfer or income -->
{{ Form.select('destination_account_id['~journal.id~']', accountList, journal.destination_account_id, {'class': 'form-control'}) }}
{% else %}
<!-- if is expense -->
{{ Form.input('text', 'expense_account['~journal.id~']', journal.destination_account_name, {'class': 'form-control', 'placeholder': trans('form.expense_account')}) }}
{% endif %}
{{ Form.input('text', 'expense_account['~journal.id~']', journal.destination_account_name, {'class': 'form-control', 'placeholder': trans('form.expense_account')}) }}
{% endif %}
</td>
</tr>
</td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>