Cleanup and refactor

This commit is contained in:
James Cole
2015-01-18 09:49:32 +01:00
parent 10a93df653
commit 1068dcb8a4
8 changed files with 91 additions and 150 deletions

View File

@@ -156,10 +156,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
*/
public function destroy(Eloquent $model)
{
// delete piggy banks
// delete journals:
$journals = \TransactionJournal::whereIn(
$journals = \TransactionJournal::whereIn(
'id', function (QueryBuilder $query) use ($model) {
$query->select('transaction_journal_id')
->from('transactions')->whereIn(
@@ -183,9 +180,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
)->get();
}
)->get();
/*
* Get all transactions.
*/
$transactions = [];
/** @var \TransactionJournal $journal */
foreach ($journals as $journal) {
@@ -195,18 +189,10 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
}
$journal->delete();
}
// also delete transactions.
if (count($transactions) > 0) {
\Transaction::whereIn('id', $transactions)->delete();
}
/*
* Trigger deletion:
*/
\Event::fire('account.destroy', [$model]);
// delete accounts:
\Account::where(
function (EloquentBuilder $q) use ($model) {
$q->where('id', $model->id);

View File

@@ -114,7 +114,7 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
$warnings = new MessageBag;
$successes = new MessageBag;
$errors = new MessageBag;
if (isset($model['amount_min']) && isset($model['amount_max']) && floatval($model['amount_min']) > floatval($model['amount_max'])) {
if (floatval($model['amount_min']) > floatval($model['amount_max'])) {
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
}

View File

@@ -158,31 +158,13 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$journal->isValid();
$errors = $journal->getErrors();
/*
* Is not in rules.
*/
if (!isset($model['what'])) {
$errors->add('description', 'Internal error: need to know type of transaction!');
}
/*
* Is not in rules.
*/
$errors = $errors->merge($this->_validateAmount($model));
$errors = $errors->merge($this->_validateBudget($model));
$errors = $errors->merge($this->_validateAccount($model));
/*
* Add "OK"
*/
/**
* else {
* $successes->add('account_from_id', 'OK');
* $successes->add('account_to_id', 'OK');
* }
* else {
*/
$list = ['date', 'description', 'amount', 'budget_id', 'from', 'to', 'account_from_id', 'account_to_id', 'category', 'account_id', 'expense_account',
'revenue_account'];
foreach ($list as $entry) {