Fix edit routine

This commit is contained in:
James Cole 2016-04-30 12:46:21 +02:00
parent 4ec6bcc8c7
commit bdcd033952
3 changed files with 56 additions and 49 deletions

View File

@ -145,42 +145,37 @@ class TransactionController extends Controller
/** @var PiggyBankRepositoryInterface $piggyRepository */
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$accountList = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));
$budgetList = ExpandedForm::makeSelectList($budgetRepository->getActiveBudgets());
$piggyBankList = ExpandedForm::makeSelectList($piggyRepository->getPiggyBanks());
$budgetList[0] = trans('firefly.no_budget');
$piggyBankList[0] = trans('form.noPiggybank');
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));
$budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks());
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
$preFilled = [
'date' => TransactionJournal::dateAsString($journal),
'interest_date' => TransactionJournal::dateAsString($journal, 'interest_date'),
'book_date' => TransactionJournal::dateAsString($journal, 'book_date'),
'process_date' => TransactionJournal::dateAsString($journal, 'process_date'),
'category' => TransactionJournal::categoryAsString($journal),
'budget_id' => TransactionJournal::budgetId($journal),
'piggy_bank_id' => TransactionJournal::piggyBankId($journal),
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
'account_from_id' => TransactionJournal::sourceAccount($journal)->id,
'account_to_id' => TransactionJournal::destinationAccount($journal)->id,
'amount' => TransactionJournal::amountPositive($journal),
'date' => TransactionJournal::dateAsString($journal),
'interest_date' => TransactionJournal::dateAsString($journal, 'interest_date'),
'book_date' => TransactionJournal::dateAsString($journal, 'book_date'),
'process_date' => TransactionJournal::dateAsString($journal, 'process_date'),
'category' => TransactionJournal::categoryAsString($journal),
'budget_id' => TransactionJournal::budgetId($journal),
'piggy_bank_id' => TransactionJournal::piggyBankId($journal),
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
'source_account_id' => TransactionJournal::sourceAccount($journal)->id,
'source_account_name' => TransactionJournal::sourceAccount($journal)->name,
'destination_account_id' => TransactionJournal::destinationAccount($journal)->id,
'destination_account_name' => TransactionJournal::destinationAccount($journal)->name,
'amount' => TransactionJournal::amountPositive($journal),
];
if ($journal->isWithdrawal()) {
$preFilled['account_id'] = TransactionJournal::sourceAccount($journal)->id;
if (TransactionJournal::destinationAccountTypeStr($journal) != 'Cash account') {
$preFilled['expense_account'] = TransactionJournal::destinationAccount($journal)->name;
}
} else {
$preFilled['account_id'] = TransactionJournal::destinationAccount($journal)->id;
if (TransactionJournal::sourceAccountTypeStr($journal) != 'Cash account') {
$preFilled['revenue_account'] = TransactionJournal::sourceAccount($journal)->name;
}
if ($journal->isWithdrawal() && TransactionJournal::destinationAccountTypeStr($journal) == 'Cash account') {
$preFilled['destination_account_name'] = '';
}
if ($journal->isDeposit() && TransactionJournal::sourceAccountTypeStr($journal) == 'Cash account') {
$preFilled['source_account_name'] = '';
}
@ -195,7 +190,7 @@ class TransactionController extends Controller
Session::forget('transactions.edit.fromUpdate');
return view('transactions.edit', compact('journal', 'uploadSize', 'accountList', 'what', 'budgetList', 'piggyBankList', 'subTitle'))->with(
return view('transactions.edit', compact('journal', 'uploadSize', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle'))->with(
'data', $preFilled
);
}
@ -484,7 +479,6 @@ class TransactionController extends Controller
*/
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
{
$journalData = $request->getJournalData();
$repository->update($journal, $journalData);

View File

@ -305,7 +305,7 @@ class JournalRepository implements JournalRepositoryInterface
$journal->budgets()->detach();
if (intval($data['budget_id']) > 0) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($data['budget_id']);
$budget = Budget::where('user_id', $this->user->id)->where('id', $data['budget_id'])->first();
$journal->budgets()->save($budget);
}
@ -402,8 +402,8 @@ class JournalRepository implements JournalRepositoryInterface
break;
case TransactionType::TRANSFER:
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_from_id'])->first();
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_to_id'])->first();
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
break;
default:
throw new FireflyException('Did not recognise transaction type.');

View File

@ -12,6 +12,20 @@
<input type="hidden" name="id" value="{{ journal.id }}"/>
<input type="hidden" name="what" value="{{ what }}"/>
{% if errors.all|length > 0 %}
<div class="row">
<div class="col-lg-12">
<h4>Errors</h4>
<ul>
{% for err in errors.all %}
<li>{{ err }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="box box-primary">
@ -22,25 +36,24 @@
<!-- 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',accountList,data['account_id']) }}
<!-- SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS -->
{% if what == 'transfer' or what == 'withdrawal' %}
{{ ExpandedForm.select('source_account_id',assetAccounts, data.source_account_id, {label: trans('form.asset_source_account')}) }}
{% endif %}
<!-- SHOW EXPENSE ACCOUNT ONLY FOR WITHDRAWALS -->
{% if what == 'withdrawal' %}
{{ ExpandedForm.text('expense_account',data['expense_account']) }}
{% endif %}
<!-- SHOW REVENUE ACCOUNT ONLY FOR DEPOSITS -->
<!-- FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS -->
{% if what == 'deposit' %}
{{ ExpandedForm.text('revenue_account',data['revenue_account']) }}
{{ ExpandedForm.text('source_account_name',data.source_account_name, {label: trans('form.revenue_account')}) }}
{% endif %}
<!-- ONLY SHOW FROM/TO ACCOUNT WHEN CREATING TRANSFER -->
<!-- FREE FORMAT DESTINATION ACCOUNT ONLY FOR EXPENSES -->
{% if what == 'withdrawal' %}
{{ ExpandedForm.text('destination_account_name',data.destination_account_name, {label: trans('form.expense_account')}) }}
{% endif %}
<!-- SELECTABLE DESTINATION ACCOUNT ONLY FOR TRANSFERS -->
{% if what == 'transfer' %}
{{ ExpandedForm.select('account_from_id',accountList,data['account_from_id']) }}
{{ ExpandedForm.select('account_to_id',accountList,data['account_to_id']) }}
{{ ExpandedForm.select('destination_account_id',assetAccounts, data.destination_account_id, {label: trans('form.asset_destination_account')} ) }}
{% endif %}
<!-- ALWAYS SHOW AMOUNT -->