Bug fix in new accounts.

This commit is contained in:
James Cole 2015-01-13 20:43:54 +01:00
parent 83190572c7
commit 21d5420b2a
5 changed files with 73 additions and 2291 deletions

View File

@ -37,8 +37,8 @@ return [
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
// 'Barryvdh\Debugbar\ServiceProvider',
// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
// 'Barryvdh\Debugbar\ServiceProvider',
'FireflyIII\FF3ServiceProvider',
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
'Grumpydictator\Gchart\GchartServiceProvider',

View File

@ -7,11 +7,12 @@ use FireflyIII\Database\CommonDatabaseCallsInterface;
use FireflyIII\Database\CUDInterface;
use FireflyIII\Database\SwitchUser;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
/**
* Class Account
*
@ -199,8 +200,26 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
// data for transaction journal:
$balance = $balance < 0 ? $balance * -1 : $balance;
$opening = ['what' => 'opening', 'currency' => 'EUR', 'amount' => $balance, 'from' => $from, 'to' => $to, 'date' => $date,
'description' => 'Opening balance for new account ' . $account->name,];
// find the account type:
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
$type = $typeRepository->findByWhat('opening');
// find the currency.
$currency = \Amount::getDefaultCurrency();
$opening = [
'transaction_type_id' => $type->id,
'transaction_currency_id' => $currency->id,
'amount' => $balance,
'from' => $from,
'completed' => 0,
'currency' => 'EUR',
'what' => 'opening',
'to' => $to,
'date' => $date,
'description' => 'Opening balance for new account ' . $account->name,];
$validation = $tj->validate($opening);
@ -209,6 +228,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
return true;
} else {
\Log::error('Initial balance created is not valid (Database/Account)');
\Log::error($validation['errors']->all());
\App::abort(500);
}
@ -314,6 +334,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
$data = array_except($data, ['_token', 'what']);
$account = new \Account($data);
if (!$account->isValid()) {
\Log::error('Account created is not valid (Database/Account)');
\Log::error($account->getErrors()->all());
\App::abort(500);
}

View File

@ -74,8 +74,15 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
list($fromAccount, $toAccount) = $this->storeAccounts($data);
$this->storeTransaction(['account' => $fromAccount, 'transaction_journal' => $journal, 'amount' => floatval($data['amount'] * -1)]);
$this->storeTransaction(['account' => $toAccount, 'transaction_journal' => $journal, 'amount' => floatval($data['amount'])]);
$this->storeTransaction(
['account_id' => $fromAccount->id, 'account' => $fromAccount, 'transaction_journal' => $journal, 'transaction_journal_id' => $journal->id,
'amount' => floatval($data['amount'] * -1)]
);
$this->storeTransaction(
['account_id' => $toAccount->id, 'account' => $toAccount, 'transaction_journal' => $journal, 'transaction_journal_id' => $journal->id,
'amount' => floatval($data['amount'])]
);
$this->storeBudget($data, $journal);
$this->storeCategory($data, $journal);
@ -278,6 +285,8 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
$toAccount = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
break;
case 'opening':
$fromAccount = $data['from'];
$toAccount = $data['to'];
break;
case 'deposit':
$fromAccount = $accountRepository->firstRevenueAccountOrCreate($data['revenue_account']);

View File

@ -145,4 +145,21 @@ class Amount
return $currency->code;
}
/**
* @return string
*/
public function getDefaultCurrency()
{
/** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
$currencies = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
$preferences = \App::make('FireflyIII\Shared\Preferences\Preferences');
$currencyPreference = $preferences->get('currencyPreference', 'EUR');
$currency = $currencies->findByCode($currencyPreference->data);
return $currency;
}
}

2301
composer.lock generated

File diff suppressed because it is too large Load Diff