mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
First attempt at an import/migration procedure.
This commit is contained in:
@@ -11,53 +11,51 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->accounts()->count();
|
||||
|
||||
}
|
||||
|
||||
public function store() {
|
||||
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0)
|
||||
{
|
||||
|
||||
$account = $this->store($data);
|
||||
|
||||
$initialBalanceAT = \AccountType::where('description', 'Initial balance account')->first();
|
||||
$initial = new \Account;
|
||||
$initial->accountType()->associate($initialBalanceAT);
|
||||
$initial->user()->associate(\Auth::user());
|
||||
$initial->name = $data['name'] . ' initial balance';
|
||||
$initial->active = 0;
|
||||
$initial->save();
|
||||
|
||||
// create new transaction journal (and transactions):
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalInterface $transactionJournal */
|
||||
$transactionJournal = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalInterface');
|
||||
$transactionJournal->createSimpleJournal(
|
||||
$initial, $account, 'Initial Balance for ' . $data['name'], $amount, $date
|
||||
);
|
||||
|
||||
|
||||
$default = \AccountType::where('description','Default account')->first();
|
||||
$balanceAT = \AccountType::where('description','Initial balance account')->first();
|
||||
return $account;
|
||||
|
||||
$account = new \Account;
|
||||
$account->active = true;
|
||||
|
||||
$account->user()->associate(\Auth::user());
|
||||
$account->name = \Input::get('name');
|
||||
$account->accountType()->associate($default);
|
||||
|
||||
if(!$account->isValid()) {
|
||||
\Log::error('Could not create account: ' . $account->validator->messages()->first());
|
||||
$this->validator = $account->validator;
|
||||
return false;
|
||||
}
|
||||
|
||||
$account->save();
|
||||
|
||||
$balance = floatval(\Input::get('openingbalance'));
|
||||
if($balance != 0.00) {
|
||||
// create account
|
||||
$initial = new \Account;
|
||||
$account->active = false;
|
||||
|
||||
$account->user()->associate(\Auth::user());
|
||||
$account->name = \Input::get('name').' initial balance';
|
||||
$account->accountType()->associate($balanceAT);
|
||||
$account->save();
|
||||
|
||||
// create journal (access helper!)
|
||||
|
||||
|
||||
// create journal
|
||||
|
||||
// create transaction
|
||||
|
||||
// create
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function store($data)
|
||||
{
|
||||
$defaultAT = \AccountType::where('description', 'Default account')->first();
|
||||
|
||||
$at = isset($data['account_type']) ? $data['account_type'] : $defaultAT;
|
||||
|
||||
$account = new \Account;
|
||||
$account->accountType()->associate($at);
|
||||
$account->user()->associate(\Auth::user());
|
||||
$account->name = $data['name'];
|
||||
$account->active = isset($data['active']) ? $data['active'] : 1;
|
||||
$account->save();
|
||||
return $account;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user