First attempt at storing an account.

This commit is contained in:
James Cole
2015-02-09 07:23:39 +01:00
parent 169d1065cc
commit 3841259779
12 changed files with 258 additions and 111 deletions

View File

@@ -0,0 +1,63 @@
<?php
namespace FireflyIII\Repositories\Account;
use App;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
/**
* Class AccountRepository
*
* @package FireflyIII\Repositories\Account
*/
class AccountRepository implements AccountRepositoryInterface
{
/**
* @param array $data
*
* @return Account;
*/
public function store(array $data)
{
$newAccount = $this->_store($data);
// continue with the opposing account:
if ($data['openingBalance'] != 0) {
$type = $data['openingBalance'] < 0 ? 'expense' : 'revenue';
$opposing = [
'user' => $data['user'],
'accountType' => $type,
'name' => $data['name'] . ' initial balance',
'active' => false,
];
$this->_store($opposing);
}
return $newAccount;
}
/**
* @param array $data
*/
protected function _store(array $data)
{
$accountType = AccountType::whereType($data['accountType'])->first();
$newAccount = new Account(
[
'user_id' => $data['user'],
'account_type_id' => $accountType->id,
'name' => $data['name'],
'active' => $data['active'] === true ? true : false,
]
);
if (!$newAccount->isValid()) {
App::abort(500);
}
$newAccount->save();
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace FireflyIII\Repositories\Account;
interface AccountRepositoryInterface
{
public function store(array $data);
}

View File

@@ -0,0 +1,8 @@
<?php
namespace FireflyIII\Repositories\Journal;
class JournalRepository implements JournalRepositoryInterface {
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 08/02/15
* Time: 18:15
*/
namespace FireflyIII\Repositories\Journal;
interface JournalRepositoryInterface {
}