mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-23 09:26:29 -06:00
Some more work on the transactions.
This commit is contained in:
parent
0a627f6f9e
commit
7f175a4870
@ -100,9 +100,8 @@ class TransactionController extends BaseController
|
||||
}
|
||||
Session::put('prefilled', $prefilled);
|
||||
|
||||
return View::make('transactions.create')->with('accounts', $assetAccounts)->with('budgets', $budgets)->with(
|
||||
'what', $what
|
||||
)->with('piggies', $piggies)->with('subTitle', 'Add a new ' . $what);
|
||||
return View::make('transactions.create')->with('accounts', $assetAccounts)->with('budgets', $budgets)->with('what', $what)->with('piggies', $piggies)
|
||||
->with('subTitle', 'Add a new ' . $what);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,7 +271,50 @@ class TransactionController extends BaseController
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store($what) {
|
||||
public function store($what)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['what'] = $what;
|
||||
$data['currency'] = 'EUR';
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $repository */
|
||||
$repository = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
switch ($data['post_submit_action']) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'store':
|
||||
$messages = $repository->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save transaction: ' . $messages['errors']->first());
|
||||
return Redirect::route('transactions.create', $what)->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repository->store($data);
|
||||
Session::flash('success', 'New transaction stored!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('transactions.create', $what);
|
||||
} else {
|
||||
return Redirect::route('transactions.index');
|
||||
}
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $repository->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
|
||||
return Redirect::route('transactions.create')->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
throw new NotImplementedException;
|
||||
/*
|
||||
* Collect data to process:
|
||||
@ -331,7 +373,8 @@ class TransactionController extends BaseController
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(TransactionJournal $journal) {
|
||||
public function update(TransactionJournal $journal)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
switch (Input::get('post_submit_action')) {
|
||||
case 'update':
|
||||
|
@ -191,11 +191,16 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
$errors->add('date', 'This date is invalid.');
|
||||
}
|
||||
|
||||
if (isset($model['to_id']) && intval($model['to_id']) < 0) {
|
||||
if (isset($model['to_id']) && intval($model['to_id']) < 1) {
|
||||
$errors->add('account_to', 'Invalid to-account');
|
||||
}
|
||||
if (isset($model['from_id']) && intval($model['from_id']) < 0) {
|
||||
|
||||
if (isset($model['from_id']) && intval($model['from_id']) < 1) {
|
||||
$errors->add('account_from', 'Invalid from-account');
|
||||
|
||||
}
|
||||
if (isset($model['account_id']) && intval($model['account_id']) < 1) {
|
||||
$errors->add('account_id', 'Invalid account!');
|
||||
}
|
||||
if (isset($model['to']) && !($model['to'] instanceof \Account)) {
|
||||
$errors->add('account_to', 'Invalid to-account');
|
||||
@ -208,6 +213,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
}
|
||||
if (!isset($model['from']) && !isset($model['to'])) {
|
||||
$errors->add('account_to', 'No accounts found!');
|
||||
$errors->add('account_id', 'No accounts found!');
|
||||
}
|
||||
|
||||
$validator = \Validator::make([$model], \Transaction::$rules);
|
||||
@ -358,7 +364,6 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user