Code and tests for #615

This commit is contained in:
James Cole 2017-03-09 08:19:05 +01:00
parent 176c44e2b9
commit 0e59f7433c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 72 additions and 41 deletions

View File

@ -14,13 +14,13 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Controllers\Transaction; namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon; use Carbon\Carbon;
use ExpandedForm;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\MassDeleteJournalRequest; use FireflyIII\Http\Requests\MassDeleteJournalRequest;
use FireflyIII\Http\Requests\MassEditJournalRequest; use FireflyIII\Http\Requests\MassEditJournalRequest;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences; use Preferences;
@ -119,7 +119,12 @@ class MassController extends Controller
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$accountList = ExpandedForm::makeSelectList($repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
// get budgets
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budgets = $budgetRepository->getBudgets();
// skip transactions that have multiple destinations // skip transactions that have multiple destinations
// or multiple sources: // or multiple sources:
@ -177,7 +182,7 @@ class MassController extends Controller
$journals = $filtered; $journals = $filtered;
return view('transactions.mass.edit', compact('journals', 'subTitle', 'accountList')); return view('transactions.mass.edit', compact('journals', 'subTitle', 'accounts', 'budgets'));
} }
/** /**
@ -200,7 +205,7 @@ class MassController extends Controller
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? ''; $sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0; $destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? ''; $destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0; $budgetId = $request->get('budget_id')[$journal->id] ?? 0;
$category = $request->get('category')[$journal->id]; $category = $request->get('category')[$journal->id];
$tags = $journal->tags->pluck('tag')->toArray(); $tags = $journal->tags->pluck('tag')->toArray();
@ -214,12 +219,12 @@ class MassController extends Controller
'destination_account_id' => intval($destAccountId), 'destination_account_id' => intval($destAccountId),
'destination_account_name' => $destAccountName, 'destination_account_name' => $destAccountName,
'amount' => round($request->get('amount')[$journal->id], 12), 'amount' => round($request->get('amount')[$journal->id], 12),
'currency_id' => intval($request->get('amount_currency_id_amount_' . $journal->id)), 'currency_id' => $journal->transaction_currency_id,
'date' => new Carbon($request->get('date')[$journal->id]), 'date' => new Carbon($request->get('date')[$journal->id]),
'interest_date' => $journal->interest_date, 'interest_date' => $journal->interest_date,
'book_date' => $journal->book_date, 'book_date' => $journal->book_date,
'process_date' => $journal->process_date, 'process_date' => $journal->process_date,
'budget_id' => $budgetId, 'budget_id' => intval($budgetId),
'category' => $category, 'category' => $category,
'tags' => $tags, 'tags' => $tags,

View File

@ -22,66 +22,87 @@
<tr> <tr>
<tr> <tr>
<th class="">&nbsp;</th> <th class="">&nbsp;</th>
<th class="col-lg-4 col-md-4 col-sm-4">{{ trans('list.description') }}</th> <th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.description') }}</th>
<th class="col-lg-1 col-md-1 col-sm-1">{{ trans('list.amount') }}</th> <th class="col-lg-1 col-md-1 col-sm-1">{{ trans('list.amount') }}</th>
<th class="col-lg-1 col-md-1 col-sm-1">{{ trans('list.date') }}</th> <th class="col-lg-1 col-md-1 col-sm-1">{{ trans('list.date') }}</th>
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.from') }}</th> <th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.from') }}</th>
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.to') }}</th> <th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.to') }}</th>
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.category') }}</th> <th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.category') }}</th>
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.budget') }}</th>
</tr> </tr>
{% for journal in journals %} {% for journal in journals %}
{% if journal.transaction_count == 2 %} {% if journal.transaction_count == 2 %}
<tr> <tr>
<td> <td>
<!-- LINK TO EDIT FORM --> {# LINK TO EDIT FORM #}
<a href="{{ route('transactions.edit', journal.id) }}" class="btn btn-xs btn-default"> <a href="{{ route('transactions.edit', journal.id) }}" class="btn btn-xs btn-default"><i
<i class="fa fa-fw fa-pencil"></i> class="fa fa-fw fa-pencil"></i></a>
</a>
<input type="hidden" name="journals[]" value="{{ journal.id }}"/> <input type="hidden" name="journals[]" value="{{ journal.id }}"/>
</td> </td>
<td> <td>
<!-- DESCRIPTION --> {# DESCRIPTION #}
<input <input class="form-control input-sm" autocomplete="off"
class="form-control" placeholder="{{ journal.description }}" name="description[{{ journal.id }}]"
id="ffInput_description_{{ journal.id }}" autocomplete="off"
placeholder="Description" name="description[{{ journal.id }}]"
type="text" value="{{ journal.description }}"> type="text" value="{{ journal.description }}">
</td> </td>
<td> <td>
<!-- AMOUNT --> <div class="input-group input-group-sm">
{{ ExpandedForm.amountSmall('amount_'~journal.id, journal.amount, {'name' : 'amount['~journal.id~']', 'currency' : journal.transactionCurrency}) }} <span class="input-group-addon">{{ journal.transactionCurrency.symbol }}</span>
</td> <input name="amount[{{ journal.id }}]" class="form-control" autocomplete="off"
<td> step="any" type="number" value="{{ journal.amount }}">
<!-- DATE --> </div>
<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 ID FOR TRANSFER OR WITHDRAWAL --> </td>
<td>
{# DATE #}
<input class="form-control input-sm" autocomplete="off"
name="date[{{ journal.id }}]" type="date" value="{{ journal.date.format('Y-m-d') }}">
</td>
<td>
{# SOURCE ACCOUNT ID FOR TRANSFER OR WITHDRAWAL #}
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == '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'}) }} <select class="form-control input-sm" name="source_account_id[{{ journal.id }}]">
{% for account in accounts %}
<option value="{{ account.id }}"{% if account.id==journal.source_account_id %} selected="selected"{% endif %}
label="{{ account.name }}">{{ account.name }}</option>
{% endfor %}
</select>
{% else %} {% else %}
<!-- SOURCE ACCOUNT NAME FOR DEPOSIT --> {# SOURCE ACCOUNT NAME FOR DEPOSIT #}
{{ Form.input('text', 'source_account_name['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }} <input class="form-control input-sm" placeholder="{{ journal.source_account_name }}" name="source_account_name[{{ journal.id }}]" type="text" value="{{ journal.source_account_name }}">
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %} {% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
<!-- DESTINATION ACCOUNT NAME FOR TRANSFER AND DEPOSIT --> {# DESTINATION ACCOUNT NAME FOR TRANSFER AND DEPOSIT #}
{{ Form.select('destination_account_id['~journal.id~']', accountList, journal.destination_account_id, {'class': 'form-control'}) }} <select class="form-control input-sm" name="destination_account_id[{{ journal.id }}]">
{% for account in accounts %}
<option value="{{ account.id }}"{% if account.id==journal.destination_account_id %} selected="selected"{% endif %}
label="{{ account.name }}">{{ account.name }}</option>
{% endfor %}
</select>
{% else %} {% else %}
<!-- DESTINATION ACCOUNT NAME FOR EXPENSE--> {# DESTINATION ACCOUNT NAME FOR EXPENSE #}
<input class="form-control input-sm" placeholder="{{ journal.destination_account_name }}" name="destination_account_name[{{ journal.id }}]" type="text" value="{{ journal.destination_account_name }}">
{{ Form.input('text', 'destination_account_name['~journal.id~']', journal.destination_account_name, {'class': 'form-control', 'placeholder': trans('form.expense_account')}) }}
{% endif %} {% endif %}
</td> </td>
<!-- category --> {# category #}
<td> <td>
{{ Form.input('text', 'category['~journal.id~']', journal.categories[0].name, {'class': 'form-control', 'placeholder': trans('form.category')}) }} <input class="form-control input-sm" placeholder="{{ journal.categories[0].name }}" name="category[{{ journal.id }}]" type="text" value="{{ journal.categories[0].name }}">
</td>
{# budget #}
<td>
{% if journal.transaction_type_type == 'Withdrawal' %}
<select class="form-control input-sm" name="budget_id[{{ journal.id }}]">
<option value="0" label="(none)"
{% if journal.budgets.count == 0 %}selected="selected"{% endif %}
>(none)</option>
{% for budget in budgets %}
<option value="{{ budget.id }}"{% if budget.id==journal.budgets[0].id %} selected="selected"{% endif %}
label="{{ budget.name }}">{{ budget.name }}</option>
{% endfor %}
</select>
{% endif %}
</td> </td>
</tr> </tr>
{% endif %} {% endif %}

View File

@ -16,6 +16,7 @@ use DB;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -77,6 +78,10 @@ class MassControllerTest extends TestCase
$repository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection); $repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
// mock more stuff:
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray(); $transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
$this->be($this->user()); $this->be($this->user());