This should fix the transactions again.

This commit is contained in:
James Cole
2014-11-12 20:46:55 +01:00
parent 7f175a4870
commit 4e166c7d2e
2 changed files with 122 additions and 54 deletions

View File

@@ -310,7 +310,7 @@ class TransactionController extends BaseController
Session::flash('successes', $messageBags['successes']); Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']); Session::flash('errors', $messageBags['errors']);
return Redirect::route('transactions.create')->withInput(); return Redirect::route('transactions.create',$what)->withInput();
break; break;
} }

View File

@@ -5,13 +5,12 @@ namespace FireflyIII\Database;
use Carbon\Carbon; use Carbon\Carbon;
use Firefly\Exception\FireflyException; use Firefly\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use LaravelBook\Ardent\Ardent;
use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\CUD;
use FireflyIII\Database\Ifaces\TransactionJournalInterface; use FireflyIII\Database\Ifaces\TransactionJournalInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use LaravelBook\Ardent\Ardent;
/** /**
* Class TransactionJournal * Class TransactionJournal
@@ -191,31 +190,100 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
$errors->add('date', 'This date is invalid.'); $errors->add('date', 'This date is invalid.');
} }
if (isset($model['to_id']) && intval($model['to_id']) < 1) { /*
$errors->add('account_to', 'Invalid to-account'); * Amount:
*/
if (isset($model['amount']) && floatval($model['amount']) < 0.01) {
$errors->add('amount', 'Amount must be > 0.01');
} else if (!isset($model['amount'])) {
$errors->add('amount', 'Amount must be set!');
} else {
$successes->add('amount', 'OK');
} }
if (isset($model['from_id']) && intval($model['from_id']) < 1) { /*
$errors->add('account_from', 'Invalid from-account'); * Budget:
*/
if (isset($model['budget_id']) && !ctype_digit($model['budget_id'])) {
$errors->add('budget_id', 'Invalid budget');
} else {
$successes->add('budget_id', 'OK');
}
$successes->add('category', 'OK');
/*
* Many checks to catch invalid or not-existing accounts.
*/
$accountError = false;
switch (true) {
// this combination is often seen in withdrawals.
case (isset($model['account_id']) && isset($model['expense_account'])):
if (intval($model['account_id']) < 1) {
$errors->add('account_id', 'Invalid account.');
} else {
$successes->add('account_id', 'OK');
} }
if (isset($model['account_id']) && intval($model['account_id']) < 1) { $successes->add('expense_account', 'OK');
$errors->add('account_id', 'Invalid account!'); break;
case (isset($model['account_id']) && isset($model['revenue_account'])):
if (intval($model['account_id']) < 1) {
$errors->add('account_id', 'Invalid account.');
} else {
$successes->add('account_id', 'OK');
} }
if (isset($model['to']) && !($model['to'] instanceof \Account)) { $successes->add('revenue_account', 'OK');
$errors->add('account_to', 'Invalid to-account'); break;
case (isset($model['account_from_id']) && isset($model['account_to_id'])):
if (intval($model['account_from_id']) < 1 || intval($model['account_from_id']) < 1) {
$errors->add('account_from_id', 'Invalid account selected.');
$errors->add('account_to_id', 'Invalid account selected.');
} else {
if (intval($model['account_from_id']) == intval($model['account_from_id'])) {
$errors->add('account_to_id', 'Cannot be the same as "from" account.');
$errors->add('account_from_id', 'Cannot be the same as "to" account.');
} else {
$successes->add('account_from_id', 'OK');
$successes->add('account_to_id', 'OK');
} }
if (isset($model['from']) && !($model['from'] instanceof \Account)) {
$errors->add('account_from', 'Invalid from-account');
} }
if (!isset($model['amount']) || (isset($model['amount']) && floatval($model['amount']) < 0)) { break;
$errors->add('amount', 'Invalid amount');
case (isset($model['to']) && isset($model['from'])):
if (is_object($model['to']) && is_object($model['from'])) {
$successes->add('from', 'OK');
$successes->add('to', 'OK');
} }
if (!isset($model['from']) && !isset($model['to'])) { break;
$errors->add('account_to', 'No accounts found!');
$errors->add('account_id', 'No accounts found!'); default:
throw new FireflyException('Cannot validate accounts for transaction journal.');
break;
} }
// 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']) < 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');
// }
// if (isset($model['from']) && !($model['from'] instanceof \Account)) {
// $errors->add('account_from', 'Invalid from-account');
// }
// if (!isset($model['amount']) || (isset($model['amount']) && floatval($model['amount']) < 0)) {
// $errors->add('amount', 'Invalid amount');
// }
$validator = \Validator::make([$model], \Transaction::$rules); $validator = \Validator::make([$model], \Transaction::$rules);
if ($validator->invalid()) { if ($validator->invalid()) {
$errors->merge($errors); $errors->merge($errors);