mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
First attempt at storing an account.
This commit is contained in:
63
app/Repositories/Account/AccountRepository.php
Normal file
63
app/Repositories/Account/AccountRepository.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
9
app/Repositories/Account/AccountRepositoryInterface.php
Normal file
9
app/Repositories/Account/AccountRepositoryInterface.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Account;
|
||||
|
||||
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
public function store(array $data);
|
||||
}
|
8
app/Repositories/Journal/JournalRepository.php
Normal file
8
app/Repositories/Journal/JournalRepository.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
|
||||
class JournalRepository implements JournalRepositoryInterface {
|
||||
|
||||
}
|
14
app/Repositories/Journal/JournalRepositoryInterface.php
Normal file
14
app/Repositories/Journal/JournalRepositoryInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 08/02/15
|
||||
* Time: 18:15
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
|
||||
interface JournalRepositoryInterface {
|
||||
|
||||
}
|
Reference in New Issue
Block a user