Code for optional fields #301

Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole
2016-09-09 11:19:40 +02:00
parent 8d19f60091
commit 176752e219
7 changed files with 212 additions and 54 deletions

View File

@@ -44,6 +44,12 @@ class TransactionController extends Controller
parent::__construct();
View::share('title', trans('firefly.transactions'));
View::share('mainTitleIcon', 'fa-repeat');
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
View::share('uploadSize', $uploadSize);
}
/**
@@ -136,17 +142,20 @@ class TransactionController extends Controller
if ($count > 2) {
return redirect(route('split.journal.edit', [$journal->id]));
}
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['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]);
// code to get list data:
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
$budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks());
// view related code
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
// journal related code
$sourceAccounts = TransactionJournal::sourceAccountList($journal);
$destinationAccounts = TransactionJournal::destinationAccountList($journal);
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
@@ -164,6 +173,12 @@ class TransactionController extends Controller
'destination_account_id' => $destinationAccounts->first()->id,
'destination_account_name' => $destinationAccounts->first()->name,
'amount' => TransactionJournal::amountPositive($journal),
// new custom fields:
'due_date' => TransactionJournal::dateAsString($journal, 'due_date'),
'payment_date' => TransactionJournal::dateAsString($journal, 'payment_date'),
'interal_reference' => $journal->getMeta('internal_reference'),
'notes' => $journal->getMeta('notes'),
];
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
@@ -187,7 +202,7 @@ class TransactionController extends Controller
return view(
'transactions.edit',
compact('journal', 'optionalFields', 'uploadSize', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle')
compact('journal', 'optionalFields', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle')
)->with('data', $preFilled);
}

View File

@@ -60,6 +60,13 @@ class JournalFormRequest extends Request
'category' => $this->get('category') ?? '',
'tags' => explode(',', $tags),
'piggy_bank_id' => $this->get('piggy_bank_id') ? intval($this->get('piggy_bank_id')) : 0,
// new custom fields here:
'due_date' => $this->get('due_date') ? new Carbon($this->get('due_date')) : null,
'payment_date' => $this->get('payment_date') ? new Carbon($this->get('payment_date')) : null,
'internal_reference' => $this->get('internal_reference'),
'notes' => $this->get('notes'),
];
}
@@ -81,6 +88,12 @@ class JournalFormRequest extends Request
'category' => 'between:1,255',
'amount_currency_id_amount' => 'required|exists:transaction_currencies,id',
'piggy_bank_id' => 'numeric',
// new custom fields here:
'due_date' => 'date',
'payment_date' => 'date',
'internal_reference' => 'min:1,max:255',
'notes' => 'min:1,max:65536',
];
switch ($what) {